Ejemplo n.º 1
0
 public function writeConfig($destinationDir = null)
 {
     if (!$destinationDir) {
         $destinationDir = Platform::rootDir();
     }
     return file_put_contents($destinationDir . '/' . self::PLATFORM_CONFIG, Yaml::dump($this->config, 2));
 }
Ejemplo n.º 2
0
 public function copyConfigs()
 {
     // Copy configs
     foreach ($this->configsToCopy() as $fileName) {
         $this->fs->copy($this->resourcesDir . '/conf/' . $fileName, $this->projectPath . '/docker/conf/' . $fileName);
     }
     // Change the default xdebug remote host on Mac, which uses a VM
     if (!Docker::native()) {
         $phpConfFile = $this->projectPath . '/docker/conf/php.ini';
         $phpConf = file_get_contents($phpConfFile);
         $phpConf = str_replace('172.17.42.1', '192.168.99.1', $phpConf);
         file_put_contents($phpConfFile, $phpConf);
     }
     // 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::projectTld(), $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());
     }
     // copy ssl
     $this->fs->copy($this->resourcesDir . '/ssl/nginx.crt', $this->projectPath . '/docker/ssl/nginx.crt');
     $this->fs->copy($this->resourcesDir . '/ssl/nginx.key', $this->projectPath . '/docker/ssl/nginx.key');
 }
Ejemplo n.º 3
0
 /**
  * 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');
 }
Ejemplo n.º 4
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']);
     }
     $stack = StacksFactory::getStack(Platform::webDir());
     switch ($stack->type()) {
         case Stacks\Drupal::TYPE:
             $this->stdOut->writeln("<comment>Patching Drupal for xhprof</comment>");
             $patchProcess = new Process('patch -p1 < ' . CLI_ROOT . '/resources/drupal-enable-profiling.patch', Platform::webDir());
             break;
         case Stacks\WordPress::TYPE:
             $this->stdOut->writeln("<comment>Patching WordPress for xhprof</comment>");
             $patchProcess = new Process('patch -p0 < ' . CLI_ROOT . '/resources/wordpress-enable-profiling.patch', Platform::webDir());
             break;
         default:
             throw new \Exception('Stack type not supported yet.');
     }
     $patchProcess->mustRun();
 }
 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);
 }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
0
 /**
  * {@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);
 }
Ejemplo n.º 8
0
 public function configure()
 {
     $this->fs->copy(CLI_ROOT . '/resources/stacks/wordpress/wp-config.php', Platform::webDir() . '/wp-config.php', true);
     $this->fs->remove(Platform::webDir() . '/wp-confg-sample.php');
     $this->fs->copy(CLI_ROOT . '/resources/stacks/wordpress/wp-config.local.php', Platform::sharedDir() . '/wp-config.local.php');
     $localSettings = file_get_contents(Platform::sharedDir() . '/wp-config.local.php');
     $localSettings = str_replace('{{ salts }}', $this->salts(), $localSettings);
     $localSettings = str_replace('{{ container_name }}', $this->containerName, $localSettings);
     $localSettings = str_replace('{{ project_domain }}', $this->projectName . '.' . $this->projectTld, $localSettings);
     file_put_contents(Platform::sharedDir() . '/wp-config.local.php', $localSettings);
     // Relink if missing.
     if (!$this->fs->exists(Platform::webDir() . '/wp-config.local.php')) {
         $this->fs->symlink('../shared/wp-config.local.php', Platform::webDir() . '/wp-config.local.php');
     }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $stack = StacksFactory::getStack(Platform::webDir());
     switch ($stack->type()) {
         case Stacks\Drupal::TYPE:
             $this->stdOut->writeln("<comment>Removing patch on Drupal for xhprof</comment>");
             $patchProcess = new Process('patch -p1 -R < ' . CLI_ROOT . '/resources/drupal-enable-profiling.patch', Platform::webDir());
             break;
         case Stacks\WordPress::TYPE:
             $this->stdOut->writeln("<comment>Removing patch on WordPress for xhprof</comment>");
             $patchProcess = new Process('patch -p0 -R < ' . CLI_ROOT . '/resources/wordpress-enable-profiling.patch', Platform::webDir());
             break;
         default:
             throw new \Exception('Stack type not supported yet.');
     }
     $patchProcess->mustRun(null);
 }
Ejemplo n.º 11
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;
                 case 'blackfire':
                     $composeContainers->addBlackfire();
                     break;
             }
         }
     }
     $composeConfig->writeDockerCompose($composeContainers);
     $stack = Toolstack::inspect(Platform::webDir());
     if ($stack) {
         $this->stdOut->writeln("<comment>Configuring stack:</comment> " . $stack->type());
         StacksFactory::configure($stack->type());
     }
     $this->stdOut->writeln('<info>Building the containers</info>');
     Compose::build();
     $this->stdOut->writeln('<info>Bringing up the containers</info>');
     Compose::up(['-d']);
 }
Ejemplo n.º 12
0
 /**
  * {@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();
 }
Ejemplo n.º 13
0
 public function testWebRoot()
 {
     mkdir(Platform::webDir());
     $this->assertTrue(is_dir(self::$tmpName . '/www'));
 }
Ejemplo n.º 14
0
 /**
  * Write a drushrc
  */
 public function drushrc()
 {
     // @todo: Check if drushrc.php exists, load in any $conf changes.
     switch ($this->version) {
         case DrupalStackHelper::DRUPAL7:
             $this->fs->copy(CLI_ROOT . '/resources/stacks/drupal7/drushrc.php', Platform::sharedDir() . '/drushrc.php', true);
             break;
         case DrupalStackHelper::DRUPAL8:
             $this->fs->copy(CLI_ROOT . '/resources/stacks/drupal8/drushrc.php', Platform::sharedDir() . '/drushrc.php', true);
             break;
         default:
             throw new \Exception('Unsupported version of Drupal. Write a pull reuqest!');
     }
     // Replace template variables.
     $localSettings = file_get_contents(Platform::sharedDir() . '/drushrc.php');
     // @todo this expects proxy to be running.
     $localSettings = str_replace('{{ project_domain }}', $this->projectName . '.' . $this->projectTld, $localSettings);
     file_put_contents(Platform::sharedDir() . '/drushrc.php', $localSettings);
     $this->fs->symlink('../../../shared/drushrc.php', Platform::webDir() . '/sites/default/drushrc.php');
 }
Ejemplo n.º 15
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;
 }
Ejemplo n.º 16
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());
 }
Ejemplo n.º 17
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]];
 }