Esempio n. 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Hello Terra!');
     // Ask for an app and environment.
     $this->getApp($input, $output);
     $this->getEnvironment($input, $output);
     $environment_name = $this->environment->name;
     $app_name = $this->app->name;
     $environment_factory = new EnvironmentFactory($this->environment, $this->app);
     $environment_factory->writeConfig();
     $current_scale = $environment_factory->getScale();
     $output->writeln("Scaling Environment <comment>{$app_name} {$environment_name}</comment>...");
     $output->writeln("Current scale: <comment>{$current_scale}</comment>");
     // If no scale ask for scale.
     if (empty($scale)) {
         $question = new Question('How many app containers? ');
         $helper = $this->getHelper('question');
         $scale = $helper->ask($input, $output, $question);
     }
     $output->writeln("Target scale: <comment>{$scale}</comment>");
     $environment_factory->scale($scale);
     $output->writeln("Environment <comment>{$app_name} {$environment_name}</comment> scaled to <info>{$scale}</info>");
     // Output the new URL.
     $local_url = 'http://' . $environment_factory->getHost() . ':' . $environment_factory->getPort();
     $output->writeln('<info>Environment enabled!</info>  Available at http://' . $environment_factory->getUrl() . ' and ' . $local_url);
 }
Esempio n. 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Ask for an app and environment.
     $this->getApp($input, $output);
     $this->getEnvironment($input, $output);
     $environment_name = $this->environment->name;
     $app_name = $this->app->name;
     // Attempt to enable the environment.
     $environment_factory = new EnvironmentFactory($this->environment, $this->app);
     if (!$environment_factory->enable()) {
         $output->writeln('<error>Something went wrong, environment not enabled.</error>');
         return;
     }
     // Get new port, set new URL to environment object.
     $port = $environment_factory->getPort();
     $host = $environment_factory->getHost();
     $this->environment->url = "http://{$host}:{$port}";
     // When passing to saveEnvironment, it must have app and name properties (for now).
     $this->environment->app = $app_name;
     $this->environment->name = $environment_name;
     // Save environment metadata.
     $this->getApplication()->getTerra()->getConfig()->saveEnvironment($this->environment);
     if ($this->getApplication()->getTerra()->getConfig()->save()) {
         $output->writeln('<info>Environment enabled!</info>  Available at http://' . $environment_factory->getUrl() . ' and ' . $this->environment->url);
     } else {
         $output->writeln('<error>Environment info not saved.</error>');
     }
     // Write drush alias.
     $drush_alias_file_path = "{$_SERVER['HOME']}/.drush/{$app_name}.aliases.drushrc.php";
     if ($environment_factory->writeDrushAlias()) {
         $output->writeln("<info>Drush alias file created at {$drush_alias_file_path}</info>");
         $output->writeln("Wrote drush alias file to <comment>{$drush_alias_file_path}</comment>");
         $output->writeln("Use <info>drush @{$app_name}.{$environment_name}</info> to access the site.");
     } else {
         $output->writeln('<error>Unable to save drush alias.</error>');
     }
     // Run the enable hooks
     $output->writeln('');
     $output->writeln('Running <comment>ENABLE</comment> app hook...');
     $environment_factory->getConfig();
     // @TODO: Figure out how to only run this hook the first time!
     if (!empty($environment_factory->config['hooks']['enable_first'])) {
         // Output what we are running
         $formatter = $this->getHelper('formatter');
         $errorMessages = array($environment_factory->config['hooks']['enable_first']);
         $formattedBlock = $formatter->formatBlock($errorMessages, 'question');
         $output->writeln($formattedBlock);
         chdir($environment_factory->getSourcePath());
         $process = new Process($environment_factory->config['hooks']['enable_first']);
         $process->setTimeout(null);
         $process->run(function ($type, $buffer) {
             if (Process::ERR === $type) {
                 echo $buffer;
             } else {
                 echo $buffer;
             }
         });
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Check if "app" argument is an action.
     if ($input->getArgument('app_name') == 'add' || $input->getArgument('app_name') == 'remove') {
         // Move argument from app_name to action
         $input->setArgument('action', $input->getArgument('app_name'));
         $input->setArgument('app_name', '');
         // Move argument from env_name to domain
         $input->setArgument('domain', $input->getArgument('environment_name'));
         $input->setArgument('environment_name', '');
     }
     // Ask for an app.
     $helper = $this->getHelper('question');
     $this->getApp($input, $output);
     // Ask for an environment.
     $helper = $this->getHelper('question');
     $this->getEnvironment($input, $output);
     // If action argument is empty, show the list.
     if (empty($input->getArgument('action'))) {
         $environment = new EnvironmentFactory($this->environment, $this->app);
         $rows[] = array('http://' . $environment->getHost() . ':' . $environment->getPort());
         $rows[] = array('http://' . $environment->getUrl());
         // Get all domains
         foreach ($environment->environment->domains as $domain) {
             $rows[] = array('http://' . $domain);
         }
         $table = $this->getHelper('table');
         $table->setHeaders(array("Domains for {$this->app->name} {$this->environment->name}"))->setRows($rows);
         $table->render($output);
         return;
     } elseif ($input->getArgument('action') == 'add') {
         $this->executeAddDomain($input, $output);
     } elseif ($input->getArgument('action') == 'remove') {
         $this->executeRemoveDomain($input, $output);
     }
     // Offer to re-enable the environment
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion("Re-enable the environment <info>{$this->app->name}:{$this->environment->name}</info> [y/N]? ", FALSE);
     if ($helper->ask($input, $output, $question)) {
         // Run environment:enable command.
         $command = $this->getApplication()->find('environment:enable');
         $arguments = array('app_name' => $this->app->name, 'environment_name' => $this->environment->name);
         $input = new ArrayInput($arguments);
         $command->run($input, $output);
     }
 }
Esempio n. 4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // If there are no apps, return
     if (count($this->getApplication()->getTerra()->getConfig()->get('apps')) == 0) {
         $output->writeln("<comment>There are no apps to remove!</comment>");
         $output->writeln("Use the command <info>terra app:add</info> to add your first app.");
         return;
     }
     $helper = $this->getHelper('question');
     $app_name = $input->getArgument('app_name');
     $environment_name = $input->getArgument('environment_name');
     // If no name specified provide options
     if (empty($app_name)) {
         $question = new ChoiceQuestion('Which app? ', array_keys($this->getApplication()->getTerra()->getConfig()->get('apps')), NULL);
         $app_name = $helper->ask($input, $output, $question);
     }
     $app = $this->getApplication()->getTerra()->getConfig()->get('apps', $app_name);
     // If no environments:
     if (count($app['environments']) == 0) {
         $output->writeln("<comment>There are no environments for the app {$app_name}!</comment>");
         $output->writeln("Use the command <info>terra environment:add</info> to add your first environment.");
         return;
     }
     // If no environment name specified provide options
     if (empty($environment_name)) {
         $question = new ChoiceQuestion('Which environment? ', array_keys($app['environments']), NULL);
         $environment_name = $helper->ask($input, $output, $question);
     }
     $environment = $app['environments'][$environment_name];
     $environment_factory = new EnvironmentFactory($environment, $app);
     $output->writeln($environment_factory->enable());
     $port = $environment_factory->getPort();
     $port = array_pop(explode(':', $port));
     $app['environments'][$environment_name]['url'] = "http://localhost:{$port}";
     $this->getApplication()->getTerra()->getConfig()->add('apps', $app_name, $app);
     if ($this->getApplication()->getTerra()->getConfig()->save()) {
         $output->writeln('<info>Environment enabled!</info>  Available at http://' . $environment_factory->getUrl());
     } else {
         $output->writeln('<error>Environment info not saved.</error>');
     }
 }
 protected function prepareBehat(InputInterface $input, OutputInterface $output, EnvironmentFactory $environment_factory)
 {
     $output->writeln("I noticed you don't have behat tests for your project.");
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion('Would you like to add behat tests? [y\\N] ');
     if ($helper->ask($input, $output, $question)) {
         $question = new Question('Where would you like to add your tests? (tests) ', 'tests');
         $tests_path = $helper->ask($input, $output, $question);
         // Create tests path
         $fs = new Filesystem();
         try {
             $fs->mkdir($environment_factory->getSourcePath() . '/' . $tests_path);
         } catch (IOException $e) {
             throw \Exception($e->getMessage());
         }
         $output->writeln("<info>SUCCESS</info> Created {$tests_path}.");
         // Create composer.json and behat.yml
         $composer_path = $environment_factory->getSourcePath() . '/' . $tests_path . '/composer.json';
         $behat_yml_path = $environment_factory->getSourcePath() . '/' . $tests_path . '/behat.yml';
         try {
             $fs->dumpFile($composer_path, $this->getBehatDrupalComposer());
             $url = "http://{$environment_factory->getHost()}:{$environment_factory->getPort()}";
             $fs->dumpFile($behat_yml_path, $this->getBehatYml($url));
             $output->writeln("<info>SUCCESS</info> Created composer.json and behat.yml.");
         } catch (IOException $e) {
             throw \Exception($e->getMessage());
         }
         $behat_path = $this->environment->path . '/' . $tests_path;
         // Run composer install
         $output->writeln("<info>RUNNING</info> composer install");
         $output->writeln("in: {$behat_path}");
         $process = new Process('composer install', $behat_path);
         $process->setTimeout(NULL);
         $process->run(function ($type, $buffer) {
             if (Process::ERR === $type) {
                 echo $buffer;
             } else {
                 echo $buffer;
             }
         });
         $output->writeln("");
         // Run behat --init
         $output->writeln("<info>RUNNING</info> bin/behat --init");
         $output->writeln("in: {$behat_path}");
         $process = new Process('bin/behat --init', $behat_path);
         $process->run(function ($type, $buffer) {
             if (Process::ERR === $type) {
                 echo $buffer;
             } else {
                 echo $buffer;
             }
         });
         // Set behat_path in .terra.yml
         $output->writeln("<comment>NOTE You should add `behat_path: {$tests_path}` to .terra.yml.</>");
     }
 }
Esempio n. 6
0
 /**
  * Outputs the status of an environment.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param $app
  * @param $environment
  *
  */
 protected function environmentStatus(InputInterface $input, OutputInterface $output)
 {
     // If there are no apps, return
     if (count($this->getApplication()->getTerra()->getConfig()->get('apps')) == 0) {
         $output->writeln('<comment>There are no apps!</comment>');
         $output->writeln('Use the command <info>terra app:add</info> to add your first app.');
         return;
     }
     $app_name = $input->getArgument('app_name');
     $environment_name = $input->getArgument('environment_name');
     $app = $this->getApplication()->getTerra()->getConfig()->get('apps', $app_name);
     // If no environments:
     if (count($app['environments']) == 0) {
         $output->writeln('<comment>There are no environments!</comment>');
         $output->writeln('Use the command <info>terra environment:add</info> to add your first environment.');
         return;
     }
     // If no environment by that name...
     if (!isset($app['environments'][$environment_name])) {
         $output->writeln("<error>There is no environment named {$environment_name} in the app {$app_name}</error>");
         return;
     }
     $environment = $app['environments'][$environment_name];
     $environment_factory = new EnvironmentFactory($environment, $app);
     $environment['scale'] = $environment_factory->getScale();
     $environment['url'] = 'http://' . $environment_factory->getHost() . ':' . $environment_factory->getPort();
     $environment['url'] .= PHP_EOL . 'http://' . $environment_factory->getUrl();
     $table = $this->getHelper('table');
     $table->setHeaders(array('Name', 'Code Path', 'docroot', 'URLs', 'Version', 'Scale'));
     $rows = array($environment);
     $table->setRows($rows);
     $table->render($output);
     $output->writeln('Docker Compose Path: ' . $environment_factory->getDockerComposePath());
 }
Esempio n. 7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // If there are no apps, return
     if (count($this->getApplication()->getTerra()->getConfig()->get('apps')) == 0) {
         $output->writeln('<comment>There are no apps to remove!</comment>');
         $output->writeln('Use the command <info>terra app:add</info> to add your first app.');
         return;
     }
     $helper = $this->getHelper('question');
     $app_name = $input->getArgument('app_name');
     $environment_name = $input->getArgument('environment_name');
     // If no name specified provide options
     if (empty($app_name)) {
         $question = new ChoiceQuestion('Which app? ', array_keys($this->getApplication()->getTerra()->getConfig()->get('apps')), null);
         $app_name = $helper->ask($input, $output, $question);
     }
     $app = $this->getApplication()->getTerra()->getConfig()->get('apps', $app_name);
     // If no environments:
     if (count($app['environments']) == 0) {
         $output->writeln("<comment>There are no environments for the app {$app_name}!</comment>");
         $output->writeln('Use the command <info>terra environment:add</info> to add your first environment.');
         return;
     }
     // If no environment name specified provide options
     if (empty($environment_name)) {
         $question = new ChoiceQuestion('Which environment? ', array_keys($app['environments']), null);
         $environment_name = $helper->ask($input, $output, $question);
     }
     $environment = $app['environments'][$environment_name];
     // Attempt to enable the environment.
     $environment_factory = new EnvironmentFactory($environment, $app);
     if (!$environment_factory->enable()) {
         $output->writeln('<error>Something went wrong, environment not enabled.</error>');
         return;
     }
     // Get new port, set new URL to environment object.
     $port = $environment_factory->getPort();
     $host = $environment_factory->getHost();
     $app['environments'][$environment_name]['url'] = "http://{$host}:{$port}";
     // Save environment metadata.
     $this->getApplication()->getTerra()->getConfig()->add('apps', array($app_name, 'environments', $environment_name), $app['environments'][$environment_name]);
     // Save config to files.
     if ($this->getApplication()->getTerra()->getConfig()->save()) {
         $output->writeln('<info>Environment enabled!</info>  Available at http://' . $environment_factory->getUrl() . ' and ' . $app['environments'][$environment_name]['url']);
     } else {
         $output->writeln('<error>Environment info not saved.</error>');
     }
     // Write drush alias.
     $drush_alias_file_path = "{$_SERVER['HOME']}/.drush/{$app_name}.aliases.drushrc.php";
     if ($environment_factory->writeDrushAlias()) {
         $output->writeln("<info>Drush alias file created at {$drush_alias_file_path}</info>");
         $output->writeln("Wrote drush alias file to <comment>{$drush_alias_file_path}</comment>");
         $output->writeln("Use <info>drush @{$app_name}.{$environment_name}</info> to access the site.");
     } else {
         $output->writeln('<error>Unable to save drush alias.</error>');
     }
     // Run the enable hooks
     $output->writeln('');
     $output->writeln('Running <comment>ENABLE</comment> app hook...');
     $environment_factory->getConfig();
     if (!empty($environment_factory->config['hooks']['enable'])) {
         // Output what we are running
         $formatter = $this->getHelper('formatter');
         $errorMessages = array($environment_factory->config['hooks']['enable']);
         $formattedBlock = $formatter->formatBlock($errorMessages, 'question');
         $output->writeln($formattedBlock);
         chdir($environment_factory->getSourcePath());
         $process = new Process($environment_factory->config['hooks']['enable']);
         $process->run(function ($type, $buffer) {
             if (Process::ERR === $type) {
                 echo $buffer;
             } else {
                 echo $buffer;
             }
         });
     }
 }