/** * Initiates basic variables. */ public function __construct() { $this->fs = new Filesystem(); $this->projectName = Platform::projectName(); $this->projectTld = Platform::projectTld(); $this->containerName = Compose::getContainerName(Platform::projectName(), 'mariadb'); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $containerName = null; $type = $input->getArgument('service'); switch ($type) { case 'http': Compose::logs(['nginx']); break; case 'php': Compose::logs(['phpfpm']); break; case 'db': Compose::logs(['mariadb']); break; case 'redis': Compose::logs(['redis']); break; case 'solr': Compose::logs(['solr']); break; default: $this->stdOut->writeln("<error>Invalid service type</error>"); break; } }
/** * Builds the settings.local.php file. */ public function __construct() { $this->projectName = Platform::projectName(); $this->containerName = Compose::getContainerName(Platform::projectName(), 'mariadb'); $this->string = "<?php\n\n"; $this->setSalt(); $this->dbFromLocal(); $this->dbFromDocker(); }
/** * {@inheritdoc} * * @see PlatformCommand::getCurrentEnvironment() */ protected function execute(InputInterface $input, OutputInterface $output) { $process = Docker::inspect(['--format="{{ .State.Running }}"', 'nginx-proxy'], true); $url = 'http://' . Platform::projectName() . '.platform'; if (trim($process->getOutput()) != 'true') { $port = Docker::getContainerPort(Compose::getContainerName(Platform::projectName(), 'nginx'), 80); $url .= ':' . $port; } $this->openUrl($url); }
public function dbFromLocal() { $hostname = Compose::getContainerName(Platform::projectName(), 'mariadb'); $name = Platform::projectName(); $this->string .= <<<EOT if (empty(\$_SERVER['PLATFORM_DOCKER'])) { \$cmd = "docker inspect --format='{{(index (index .NetworkSettings.Ports \\"3306/tcp\\") 0).HostPort}}' {$hostname}"; \$port = trim(shell_exec(\$cmd)); define('DB_HOST', "{$name}.platform:\$port"); } EOT; }
/** * {@inheritdoc} * * @see PlatformCommand::getCurrentEnvironment() */ protected function execute(InputInterface $input, OutputInterface $output) { $url = 'http://' . Platform::projectName() . '.' . Platform::projectTld(); // See if the nginx-proxy is running. try { $process = Docker::inspect(['--format="{{ .State.Running }}"', 'nginx-proxy'], true); if (trim($process->getOutput()) != 'true') { $port = Docker::getContainerPort(Compose::getContainerName(Platform::projectName(), 'nginx'), 80); $url .= ':' . $port; } } catch (\Exception $e) { } $this->openUrl($url, $this->stdErr, $this->stdOut); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $composeConfig = new ComposeConfig(); // Create docker folder in project. try { $composeConfig->ensureDirectories(); } catch (IOException $e) { $this->stdOut->writeln("<error>Error while trying to create docker-compose directories.</error>"); exit(1); } $composeConfig->copyImages(); $composeConfig->copyConfigs(); $composeContainers = new ComposeContainers(Platform::rootDir(), Config::get('name')); // @todo: With #20 and making tool provider aware, read those configs. Or push those configs to main. if (isset(Config::get()['services'])) { foreach (Config::get('services') as $service) { switch ($service) { case 'redis': $composeContainers->addRedis(); break; case 'solr': $composeContainers->addSolr(); break; case 'memcached': $composeContainers->addMemcached(); break; } } } $composeConfig->writeDockerCompose($composeContainers); // @todo move this into a static class to run configure based on type. $stack = Toolstack::inspect(Platform::webDir()); if ($stack) { $this->stdOut->writeln("<comment>Configuring stack:</comment> " . $stack->type()); switch ($stack->type()) { case Stacks\Drupal::TYPE: $drupal = new Drupal(); $drupal->configure(); break; case Stacks\WordPress::TYPE: $wordpress = new WordPress(); $wordpress->configure(); break; } } $this->stdOut->writeln('<info>Building the containers</info>'); Compose::build(); $this->stdOut->writeln('<info>Bringing up the containers</info>'); Compose::up(['-d']); }
/** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * * @throws \Exception */ protected function initialize(InputInterface $input, OutputInterface $output) { parent::initialize($input, $output); if (!Docker::exists()) { $this->stdOut->writeln("<error>Cannot find docker command</error>"); exit(1); } if (!Compose::exists()) { $this->stdOut->writeln("<error>Cannot find docker-compose command</error>"); exit(1); } // For Mac OS X we need to ensure a Docker VM is running. if (!Docker::native()) { $this->validateNonNative(); } else { $this->validateNative(); } }
/** * Builds the settings.local.php file. */ public function __construct() { $this->projectName = Platform::projectName(); $this->containerName = Compose::getContainerName(Platform::projectName(), 'mariadb'); /** @var DrupalStackHelper $drupalStack */ $drupalStack = Toolstack::getStackByType('drupal'); $this->version = $drupalStack->version(Platform::webDir()); $this->string = "<?php\n\n"; $this->setSalt(); $this->dbFromLocal(); $this->dbFromDocker(); if ($this->version == DrupalStackHelper::DRUPAL8) { $this->string .= <<<EOT // Configuration directories. \$config_directories = array( CONFIG_ACTIVE_DIRECTORY => '../../../shared/config/active', CONFIG_STAGING_DIRECTORY => '../../../shared/config/staging', ); EOT; } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $composeConfig = new ComposeConfig(); // Create docker folder in project. try { $composeConfig->ensureDirectories(); } catch (IOException $e) { $this->stdOut->writeln("<error>Error while trying to create docker-compose directories.</error>"); exit(1); } $composeConfig->copyImages(); $composeConfig->copyConfigs(); $composeContainers = new ComposeContainers(Platform::rootDir(), Config::get('name')); // @todo check if services.yml has redis $composeContainers->addRedis(); // @todo check to make this optional $composeContainers->addSolr(); $composeConfig->writeDockerCompose($composeContainers); // @todo move this into a static class to run configure based on type. $stack = Toolstack::getStackByDir(Platform::webDir()); if ($stack) { $this->stdOut->writeln("<comment>Configuring stack:</comment> " . $stack->type()); switch ($stack->type()) { case Stacks\Drupal::TYPE: $drupal = new Drupal(); $drupal->configure(); break; case Stacks\WordPress::TYPE: $wordpress = new WordPress(); $wordpress->configure(); break; } } $this->stdOut->writeln('<info>Building the containers</info>'); Compose::build(); $this->stdOut->writeln('<info>Bringing up the containers</info>'); Compose::up(['-d']); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $containerName = null; $type = $input->getArgument('service'); $containerNameMap = ['http' => 'nginx', 'php' => 'phpfpm', 'db' => 'mariadb', 'redis' => 'redis', 'solr' => 'solr', 'memcache' => 'memcached', 'blackfire' => 'blackfire']; if (!isset($containerNameMap[$type])) { $this->stdOut->writeln("<error>Invalid service type</error>"); return 1; } else { $containerName = $containerNameMap[$type]; } $builder = ProcessBuilder::create(['docker', 'exec', '-it', Compose::getContainerName(Platform::projectName(), $containerName), 'bash']); $process = $builder->getProcess(); // Need to set tty true, ProccessHelper doesn't allow this setting. $process->setTty(true); try { $process->mustRun(null); } catch (ProcessFailedException $e) { $message = "The command failed with the exit code: " . $process->getExitCode(); $message .= "\n\nFull command: " . $process->getCommandLine(); throw new \Exception($message); } return $process->isSuccessful(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $containerName = null; $type = $input->getArgument('service'); switch ($type) { case 'http': $containerName = Compose::getContainerName(Platform::projectName(), 'nginx'); break; case 'php': $containerName = Compose::getContainerName(Platform::projectName(), 'phpfpm'); break; case 'db': $containerName = Compose::getContainerName(Platform::projectName(), 'mariadb'); break; case 'redis': $containerName = Compose::getContainerName(Platform::projectName(), 'redis'); break; case 'solr': $containerName = Compose::getContainerName(Platform::projectName(), 'solr'); break; default: $this->stdOut->writeln("<error>Invalid service type</error>"); break; } $builder = ProcessBuilder::create(['docker', 'exec', '-it', $containerName, 'bash']); $process = $builder->getProcess(); // Need to set tty true, ProccessHelper doesn't allow this setting. $process->setTty(true); try { $process->mustRun(null); } catch (ProcessFailedException $e) { $message = "The command failed with the exit code: " . $process->getExitCode(); $message .= "\n\nFull command: " . $process->getCommandLine(); throw new \Exception($message); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { Compose::stop(); }
/** * {@inheritdoc} * * @see PlatformCommand::getCurrentEnvironment() */ protected function execute(InputInterface $input, OutputInterface $output) { $port = Docker::getContainerPort(Compose::getContainerName(Platform::projectName(), 'nginx'), 80); $url = 'http://' . Platform::projectName() . '.platform:' . trim($port); $this->openUrl($url); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $this->stdOut->writeln("<info>Bring up containers</info>"); Compose::up(['-d']); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $this->stdOut->writeln("<info>Restarting containers</info>"); Compose::restart(); }