Commit 58ee255a authored by Jon Pugh's avatar Jon Pugh

Issue #30: Make platforms optional!

 - Make SiteContext inherit PlatformContext.
 - Only load platform of site if there is one.
 - Only load http service into site if there isn't one, and there is one on the platform.
 - Add http to SiteContext::serviceRequirements().
 - Remove SiteContext::contextRequirements()
 - Load Platform verify tasks into site verify.
 - Change loading root and other properties from ->platform.
 - Include platform configs in site configs list.
 - Use list of sites to map all volumes.
 - Create getAllSites(), getAllPlatforms() and getAllServers() methods.
parent 9d089975
......@@ -169,7 +169,7 @@ class PlatformContext extends ServiceSubscriber implements ConfigurationInterfac
public function verify()
{
$this->getProvision()->io()->customLite($this->getProperty('root'), 'Code Root: ', 'info');
$this->getProvision()->io()->customLite($this->getProperty('root'), 'Document Root: ', 'info');
$this->getProvision()->io()->customLite($this->getProperty('document_root'), 'Document Root: ', 'info');
if ($this->getProperty('makefile')) {
$this->getProvision()->io()->customLite($this->getProperty('makefile'), 'Makefile: ', 'info');
......
......@@ -14,7 +14,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
*
* @see \Provision_Context_site
*/
class SiteContext extends ServiceSubscriber implements ConfigurationInterface
class SiteContext extends PlatformContext implements ConfigurationInterface
{
/**
* @var string
......@@ -47,12 +47,19 @@ class SiteContext extends ServiceSubscriber implements ConfigurationInterface
// $this->db_server = $application->getContext($this->properties['db_server']);
// Load platform context... @TODO: Automatically do this for required contexts?
$this->platform = $this->getProvision()->getContext($this->properties['platform']);
// Add platform http service subscription.
$this->serviceSubscriptions['http'] = $this->platform->getSubscription('http');
$this->serviceSubscriptions['http']->setContext($this);
if (!empty($this->properties['platform'])) {
$this->platform = $this->getProvision()->getContext($this->properties['platform']);
}
else {
$this->platform = NULL;
}
// Load http service from platform if site doesn't have them.
if (!$this->hasService('http') && $this->platform->hasService('http')) {
$this->serviceSubscriptions['http'] = $this->platform->getSubscription('http');
$this->serviceSubscriptions['http']->setContext($this);
}
$uri = $this->getProperty('uri');
$this->properties['site_path'] = "sites/{$uri}";
......@@ -64,44 +71,57 @@ class SiteContext extends ServiceSubscriber implements ConfigurationInterface
static function option_documentation()
{
return [
'platform' => 'site: the platform the site is run on',
// 'db_server' => 'site: the db server the site is run on',
'uri' => 'site: example.com URI, no http:// or trailing /',
'language' => 'site: site language; default en',
$options = parent::option_documentation();
$options['platform'] = Provision::newProperty()
->description('site: The platform this site is run on. (Optional)')
->required(FALSE)
;
$options['uri'] = 'site: example.com URI, no http:// or trailing /';
$options['language'] = 'site: site language; default en';
$options['profile'] = 'site: Drupal profile to use; default standard';
$options['site_path'] = Provision::newProperty()
->description('site: The site configuration path (sites/domain.com). If left empty, will be generated automatically.')
->required(FALSE)
;
return $options;
// 'uri' => 'site: example.com URI, no http:// or trailing /',
// 'language' => 'site: site language; default en',
// 'aliases' => 'site: comma-separated URIs',
// 'redirection' => 'site: boolean for whether --aliases should redirect; default false',
// 'client_name' => 'site: machine name of the client that owns this site',
// 'install_method' => 'site: How to install the site; default profile. When set to "profile" the install profile will be run automatically. Otherwise, an empty database will be created. Additional modules may provide additional install_methods.',
'profile' => 'site: Drupal profile to use; default standard',
// 'profile' => 'site: Drupal profile to use; default standard',
// 'drush_aliases' => 'site: Comma-separated list of additional Drush aliases through which this site can be accessed.',
'site_path' =>
Provision::newProperty()
->description('site: The site configuration path (sites/domain.com). If left empty, will be generated automatically.')
->required(FALSE)
,
];
//
// 'site_path' =>
// Provision::newProperty()
// ->description('site: The site configuration path (sites/domain.com). If left empty, will be generated automatically.')
// ->required(FALSE)
// ,
//
// ];
}
public static function serviceRequirements() {
return ['db'];
}
public static function contextRequirements() {
return [
'platform' => 'platform'
];
$requirements[] = 'http';
$requirements[] = 'db';
return $requirements;
}
/**
* Output extra info before verifying.
*/
public function verify()
{
$tasks = parent::verify();
$this->getProvision()->io()->customLite($this->getProperty('uri'), 'Site URL: ', 'info');
$this->getProvision()->io()->customLite($this->platform->getProperty('root'), 'Root: ', 'info');
$this->getProvision()->io()->customLite($this->getProperty('root'), 'Root: ', 'info');
$this->getProvision()->io()->customLite($this->config_path, 'Configuration File: ', 'info');
$this->getProvision()->io()->newLine();
......@@ -125,7 +145,7 @@ class SiteContext extends ServiceSubscriber implements ConfigurationInterface
* @see drush_provision_drupal_pre_provision_verify()
*/
->execute(function() {
$docroot = $this->platform->getProperty('document_root_full');
$docroot = $this->getProperty('document_root_full');
$site_path = $docroot . DIRECTORY_SEPARATOR . $this->getProperty('site_path');
// @TODO: These folders are how aegir works now. We might want to rethink what folders are created.
......
......@@ -303,46 +303,49 @@ class Provision implements ConfigAwareInterface, ContainerAwareInterface, Logger
return $this->contexts;
}
}
/**
* Load all server contexts.
* Return all available contexts.
*
* @param null $service
* @return mixed
* @throws \Exception
* @return \Aegir\Provision\Context[]
*/
protected function getAllServers($service = NULL) {
$servers = [];
public function getAllContextsByType($type) {
$contexts = [];
$context_files = $this->getAllContexts();
if (empty($context_files)) {
throw new \Exception('No server contexts found. Use `provision save` to create one.');
}
foreach ($context_files as $context) {
if ($context->type == 'server') {
$servers[$context->name] = $context;
if ($context->type == $type) {
$contexts[$context->name] = $context;
}
}
return $servers;
return $contexts;
}
/**
* Return all Servers.
*
* @return \Aegir\Provision\Context[]
*/
protected function getAllServers() {
return $this->getAllContextsByType('server');
}
/**
* Return all available contexts.
* Return all Platforms.
*
* @return array|Context
* @return \Aegir\Provision\Context[]
*/
public function getAllPlatforms() {
$platforms = [];
$context_files = $this->getAllContexts();
if (empty($context_files)) {
throw new \Exception('No contexts found. Use `provision save` to create one.');
}
foreach ($context_files as $context) {
if ($context->type == 'platform') {
$platforms[$context->name] = $context;
}
}
return $platforms;
return $this->getAllContextsByType('platform');
}
/**
* Return all Platforms.
*
* @return \Aegir\Provision\Context[]
*/
public function getAllSites() {
return $this->getAllContextsByType('site');
}
/**
......
......@@ -20,7 +20,7 @@ class PlatformConfiguration extends Configuration {
public $description = 'platform configuration file';
function filename() {
$file = $this->context->name . '.conf';
$file = 'platform.' . $this->context->name . '.conf';
return $this->context->getProvision()->getConfig()->get('config_path') . '/' . $this->service->provider->name . '/' . $this->service->getType() . '/platform.d/' . $file;
}
......
......@@ -29,7 +29,7 @@ class SiteConfiguration extends Configuration {
function process() {
parent::process();
$this->data['http_port'] = $this->context->getSubscription('http')->service->getProperty('http_port');
$this->data['document_root_full'] = $this->context->platform->getProperty('document_root_full');
$this->data['document_root_full'] = $this->context->getProperty('document_root_full');
$this->data['uri'] = $this->context->getProperty('uri');
$this->data['site_path'] = $this->data['document_root_full'] . '/sites/' . $this->data['uri'];
......
......@@ -113,6 +113,9 @@ class HttpApacheDockerService extends HttpApacheService implements DockerService
{
$configs['server'][] = ServerConfiguration::class;
$configs['platform'][] = PlatformConfiguration::class;
// Make sure to write platform and site config when verifying site.
$configs['site'][] = PlatformConfiguration::class;
$configs['site'][] = SiteConfiguration::class;
return $configs;
}
......@@ -127,10 +130,7 @@ class HttpApacheDockerService extends HttpApacheService implements DockerService
public function processConfiguration(Configuration &$config) {
// Replace platform's stored root with server's root.
if ($this->context instanceof Context\SiteContext) {
$root_on_host = $this->context->platform->getProperty('document_root_full');
}
elseif ($this->context instanceof Context\PlatformContext) {
if ($this->context instanceof Context\SiteContext || $this->context instanceof Context\PlatformContext) {
$root_on_host = $this->context->getProperty('document_root_full');
}
else {
......@@ -339,11 +339,12 @@ YML;
// $volumes[] = "{$platforms_path_host}:{$platforms_path_container}:z";
// }
// Map a volume for every platform.
$platforms = $this->getProvision()->getAllPlatforms();
foreach ($platforms as $platform) {
if ($platform->getSubscription('http')->server->name == $this->provider->name) {
$volumes[] = $platform->getProperty('root') . ':' . $this->mapContainerPath($platform->getProperty('root')) . ':z';
// Map a volume for every site.
$sites = $this->getProvision()->getAllSites();
foreach ($sites as $site) {
if ($site->getSubscription('http')->server->name == $this->provider->name) {
$container_path = $this->mapContainerPath($site->getProperty('root'));
$volumes[$container_path] = $site->getProperty('root') . ':' . $container_path . ':z';
}
}
......
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