コード例 #1
0
ファイル: Config.php プロジェクト: pjcdawkins/platform-docker
 public function writeConfig($destinationDir = null)
 {
     if (!$destinationDir) {
         $destinationDir = Platform::rootDir();
     }
     return file_put_contents($destinationDir . '/' . self::PLATFORM_CONFIG, Yaml::dump($this->config, 2));
 }
コード例 #2
0
 public function testAddExtras()
 {
     $config = new ComposeContainers(Platform::rootDir(), Platform::projectName());
     $config->addRedis();
     $config_converted = Yaml::parse($config->yaml());
     $this->assertCount(4, $config_converted);
     $config->addSolr();
     $config_converted = Yaml::parse($config->yaml());
     $this->assertCount(5, $config_converted);
 }
コード例 #3
0
 /**
  * {@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);
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $xhpfg = Platform::rootDir() . '/docker/xhpfg/xhprof-sample-to-flamegraph-stacks';
     $fg = Platform::rootDir() . '/docker/fg/flamegraph.pl';
     $xhprof = Platform::rootDir() . '/xhprof';
     $graphName = $input->getArgument('filename');
     $graphDestination = Platform::rootDir() . '/' . $graphName . '.svg';
     exec("{$xhpfg} {$xhprof} | {$fg} > {$graphDestination}");
     $url = 'file://' . $graphDestination;
     $this->openUrl($url);
 }
コード例 #5
0
    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;
    }
コード例 #6
0
ファイル: Drupal.php プロジェクト: andyg5000/platform-docker
 /**
  *
  */
 public function configure()
 {
     $fs = new Filesystem();
     if (!file_exists(Platform::webDir() . '/sites/default/settings.php')) {
         $fs->copy(CLI_ROOT . '/resources/stacks/drupal/drupal7.settings.php', Platform::webDir() . '/sites/default/settings.php', true);
     }
     $fs->dumpFile(Platform::sharedDir() . '/settings.local.php', $this->string);
     // Relink if missing.
     if (!$fs->exists(Platform::webDir() . '/sites/default/settings.local.php')) {
         $fs->symlink('../../../shared/settings.local.php', Platform::webDir() . '/sites/default/settings.local.php');
     }
 }
コード例 #7
0
 /**
  * {@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']);
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Symfony\Component\Console\Helper\ProcessHelper $process */
     $process = $this->getHelper('process');
     $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
     if (!is_dir(Platform::rootDir() . '/docker/fg')) {
         $process->mustRun($output, ['git', 'clone', 'https://github.com/brendangregg/FlameGraph.git', Platform::rootDir() . '/docker/fg']);
     }
     if (!is_dir(Platform::rootDir() . '/docker/xhpfg')) {
         $process->mustRun($output, ['git', 'clone', 'https://github.com/msonnabaum/xhprof-flamegraphs.git', Platform::rootDir() . '/docker/xhpfg']);
     }
     $this->stdOut->writeln("<comment>Patching Drupal for xhprof</comment>");
     $patchProcess = new Process('patch -p1 < ' . CLI_ROOT . '/resources/drupal-enable-profiling.patch', Platform::webDir());
     $patchProcess->mustRun();
 }
コード例 #9
0
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->stdOut->writeln("<info>Syncing Platform.sh environment database to local</info>");
     /** @var \Symfony\Component\Console\Helper\ProcessHelper $process */
     $process = $this->getHelper('process');
     // If this is a Platform.sh project, get latest dump.
     // @todo: add proper provider integration
     if (Config::get('id')) {
         $process->mustRun($this->stdOut, ['platform', 'sql-dump']);
     }
     $cd = getcwd();
     chdir(Platform::webDir());
     $process->run($this->stdOut, 'drush sqlc < ' . $input->getArgument('file'));
     chdir($cd);
 }
コード例 #10
0
ファイル: Drupal.php プロジェクト: gormus/platform-docker
 /**
  *
  */
 public function configure()
 {
     $fs = new Filesystem();
     if ($this->version == DrupalStackHelper::DRUPAL7) {
         $fs->copy(CLI_ROOT . '/resources/stacks/drupal/drupal7.settings.php', Platform::webDir() . '/sites/default/settings.php', true);
     } elseif ($this->version == DrupalStackHelper::DRUPAL8) {
         $fs->copy(CLI_ROOT . '/resources/stacks/drupal/drupal8.settings.php', Platform::webDir() . '/sites/default/settings.php', true);
     }
     if ($this->version == DrupalStackHelper::DRUPAL8) {
         $fs->mkdir([Platform::sharedDir() . '/config', Platform::sharedDir() . '/config/active', Platform::sharedDir() . '/config/staging']);
     }
     $fs->dumpFile(Platform::sharedDir() . '/settings.local.php', $this->string);
     // Relink if missing.
     if (!$fs->exists(Platform::webDir() . '/sites/default/settings.local.php')) {
         $fs->symlink('../../../shared/settings.local.php', Platform::webDir() . '/sites/default/settings.local.php');
     }
 }
コード例 #11
0
 public function copyConfigs()
 {
     // Copy configs
     foreach ($this->configsToCopy() as $fileName) {
         $this->fs->copy($this->resourcesDir . '/conf/' . $fileName, $this->projectPath . '/docker/conf/' . $fileName);
     }
     // Quick fix to make nginx PHP_IDE_CONFIG dynamic for now.
     $nginxConfFile = $this->projectPath . '/docker/conf/nginx.conf';
     $nginxConf = file_get_contents($nginxConfFile);
     $nginxConf = str_replace('{{ platform }}', Platform::projectName() . '.platform', $nginxConf);
     file_put_contents($nginxConfFile, $nginxConf);
     // stub in for Solr configs
     $finder = new Finder();
     $finder->in($this->resourcesDir . '/conf/solr')->files()->depth('< 1')->name('*');
     /** @var \SplFileInfo $file */
     foreach ($finder as $file) {
         $this->fs->copy($file->getPathname(), $this->projectPath . '/docker/conf/solr/' . $file->getFilename());
     }
 }
コード例 #12
0
 /**
  * {@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']);
 }
コード例 #13
0
 /**
  * {@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);
     }
 }
コード例 #14
0
 public function testWebRoot()
 {
     mkdir(Platform::webDir());
     $this->assertTrue(is_dir(self::$tmpName . '/www'));
 }
コード例 #15
0
 protected function discoverBehatYml()
 {
     $scanDirs = [Platform::sharedDir(), Platform::webDir(), Platform::rootDir() . '/tests'];
     if (is_dir(Platform::repoDir())) {
         $scanDirs[] = Platform::repoDir();
     }
     $finder = new Finder();
     $finder->files()->in($scanDirs)->name('behat.yml');
     return $finder;
 }
コード例 #16
0
ファイル: Drupal.php プロジェクト: pjcdawkins/platform-docker
    /**
     * Write a drushrc
     */
    public function drushrc()
    {
        $drushrc = <<<EOT
<?php
\$options['uri'] = "http://{$this->projectName}.{$this->projectTld}";
EOT;
        $fs = new Filesystem();
        $fs->dumpFile(Platform::sharedDir() . '/drushrc.php', $drushrc);
        $fs->symlink('../../../shared/drushrc.php', Platform::webDir() . '/sites/default/drushrc.php');
    }
コード例 #17
0
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $processBuilder = ProcessBuilder::create(['drush', $input->getArgument('cmd'), '--root=' . Platform::webDir(), '--uri=' . Platform::projectName() . '.' . Platform::projectTld()]);
     passthru($processBuilder->getProcess()->getCommandLine());
 }
コード例 #18
0
 /**
  *
  */
 public function addWebserver()
 {
     $this->config['nginx'] = ['image' => 'nginx:1.9.0', 'volumes' => ['./docker/conf/nginx.conf:/etc/nginx/conf.d/default.conf', './:/var/platform', './docker/ssl/nginx.crt:/etc/nginx/ssl/nginx.crt', './docker/ssl/nginx.key:/etc/nginx/ssl/nginx.key'], 'ports' => ['80', '443'], 'links' => ['phpfpm'], 'environment' => ['VIRTUAL_HOST' => $this->name . '.' . Platform::projectTld(), 'PLATFORM_DOCKER' => $this->name]];
 }
コード例 #19
0
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->stdOut->writeln("<comment>Removing patch on Drupal for xhprof</comment>");
     $process = new Process('patch -p1 -R < ' . CLI_ROOT . '/resources/drupal-enable-profiling.patch', Platform::webDir());
     $process->mustRun(null);
 }
コード例 #20
0
 protected function discoverBehatYml()
 {
     $depth = $this->stdIn->getOption('depth');
     $scanDirs = [Platform::sharedDir(), Platform::webDir()];
     if (is_dir(Platform::repoDir())) {
         $scanDirs[] = Platform::repoDir();
     }
     if (is_dir(Platform::testsDir())) {
         $scanDirs[] = Platform::testsDir();
     }
     $extraDir = $this->stdIn->getOption('folder');
     if ($extraDir && is_dir($extraDir)) {
         $scanDirs[] = $extraDir;
     }
     $finder = new Finder();
     $finder->files()->in($scanDirs)->depth("< {$depth}")->name('behat.yml');
     return $finder;
 }
コード例 #21
0
 /**
  * {@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);
 }