示例#1
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();
 }
示例#2
0
 public function writeConfig($destinationDir = null)
 {
     if (!$destinationDir) {
         $destinationDir = Platform::rootDir();
     }
     return file_put_contents($destinationDir . '/' . self::PLATFORM_CONFIG, Yaml::dump($this->config, 2));
 }
示例#3
0
 public function testGetRootDir()
 {
     $this->assertEquals(self::$tmpName, Platform::rootDir());
     mkdir(self::$tmpName . '/sub');
     mkdir(self::$tmpName . '/sub/sub');
     chdir(self::$tmpName . '/sub/sub');
     $this->assertEquals(self::$tmpName, Platform::rootDir());
 }
 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);
 }
示例#5
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);
 }
 /**
  * {@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']);
 }
示例#7
0
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $now = new \DateTime();
     // Hopefully this isn't too opinionated?
     $workingDir = dirname($this->behatLocation);
     if (!is_dir($workingDir . '/vendor')) {
         $output->writeln("<error>Assumed behat directory doesn't have depednencies installed: {$workingDir}.");
         exit(1);
     }
     // Try to find the Behat binary
     $composerData = json_decode(file_get_contents($workingDir . '/composer.json'), true);
     if (isset($composerData['config']['bin-dir'])) {
         $binDir = $composerData['config']['bin-dir'];
     } else {
         $binDir = 'vendor/bin/';
     }
     $outPath = Platform::rootDir() . '/behat-run-' . $now->getTimestamp() . '.log';
     $builder = ProcessBuilder::create([$binDir . 'behat', '--format=pretty', '--out=' . $outPath]);
     $builder->setWorkingDirectory($workingDir);
     $builder->setTimeout(null);
     $process = $builder->getProcess();
     // @todo: export environment variables (postponed.)
     // @note there's also v2 v3 issues we'd have to sort out for exporting.
     //          just run the dang thing.
     $output->writeln("<info>Running Behat, saving output to {$outPath}");
     $this->startSeleniumContainer();
     $output->writeln("<info>Behat is running...");
     $process->run();
     if ($process->getExitCode() > 0) {
         $this->stdOut->writeln("<error>Behat tests had failure.");
         /** @var \Symfony\Component\Console\Helper\ProcessHelper $process */
         $process = $this->getHelper('process');
         $potential = array('xdg-open', 'open', 'start');
         foreach ($potential as $app) {
             // Check if command exists by executing help flag.
             if ($process->run($this->stdOut, "command -v {$app}")->isSuccessful()) {
                 $process->run($this->stdOut, array($app, $outPath));
             }
         }
     }
     $this->stopSeleniumContainer();
 }
示例#8
0
 /**
  *
  */
 public function __construct()
 {
     $this->resourcesDir = CLI_ROOT . '/resources';
     $this->projectPath = Platform::rootDir();
     $this->fs = new Filesystem();
 }