Commit c0a13cb3 authored by Jon Pugh's avatar Jon Pugh

Add a getAllSubscribers() method to services so we can lookup all platforms on...

Add a getAllSubscribers() method to services so we can lookup all platforms on a web server, so we can set volumes for each one.
parent e8bae8fa
......@@ -10,6 +10,7 @@ namespace Aegir\Provision;
use Aegir\Provision\Common\ContextAwareTrait;
use Aegir\Provision\Common\ProvisionAwareTrait;
use Aegir\Provision\Context\ServerContext;
use Psr\Log\LoggerAwareTrait;
use Robo\Common\BuilderAwareTrait;
use Robo\Common\OutputAdapter;
......@@ -318,4 +319,26 @@ class Service implements BuilderAwareInterface
{
return $this->builder;
}
/**
* Load all contexts that subscribe to this provider's service.
*
* @return array
*/
public function getAllSubscribers() {
$subscribers = [];
foreach ($this->getProvision()->getAllContexts() as $context){
if (get_class($context) != ServerContext::class) {
foreach ($context->getSubscriptions() as $subscription) {
if ($subscription->server->name == $this->provider->name && $subscription->type == $this->type) {
$subscribers[] = $context;
}
}
}
}
return $subscribers;
}
}
\ No newline at end of file
......@@ -92,17 +92,25 @@ class HttpApacheDockerService extends HttpApacheService
return;
}
$path_parts = explode(DIRECTORY_SEPARATOR, $root_on_host);
$directory = array_pop($path_parts);
$root_in_container = $this->provider->getProperty('aegir_root') . DIRECTORY_SEPARATOR . 'platforms' . DIRECTORY_SEPARATOR . $directory;
$config->data['root'] = $root_in_container;
$config->data['root'] = $this->mapContainerPath($root_on_host);
if ($this->context instanceof Context\SiteContext) {
$config->data['site_path'] = $config->data['root'] . '/sites/' . $config->data['uri'];
}
}
/**
* Convert a path on the host like /home/jon/hostmaster to /var/aegir/hostmaster
*
* @param $root_on_host
*
* @return string
*/
function mapContainerPath($root_on_host) {
$path_parts = explode(DIRECTORY_SEPARATOR, $root_on_host);
$directory = array_pop($path_parts);
return $this->provider->getProperty('aegir_root') . DIRECTORY_SEPARATOR . 'platforms' . DIRECTORY_SEPARATOR . $directory;
}
public function verifyServer() {
$tasks = [];
......@@ -201,10 +209,11 @@ class HttpApacheDockerService extends HttpApacheService
->option('rm')
->interactive();
$platforms['/home/jon/Projects/devshop.build'] = '/var/aegir/platforms/devshop.build';
foreach ($platforms as $from => $to) {
$container->volume($from, $to);
// Lookup all subscribers (all platforms that use this web service) and map volumes for root.
foreach ($this->getAllSubscribers() as $platform) {
if (!empty($platform->getProperty('root'))) {
$container->volume($platform->getProperty('root'), $this->mapContainerPath($platform->getProperty('root')));
}
}
$result = $container->run();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment