Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     try {
         $configHelper->getConfiguration()->getVhostConfiguration($input->getArgument('vhost'));
         throw new VhostExistsException($input->getArgument('vhost'));
     } catch (NoSuchVhostException $ex) {
         // noop
     }
     $application = $configHelper->getConfiguration()->getApplication($input->getArgument('application'));
     $vhostConfig = VhostConfiguration::create($configHelper->getConfiguration(), $input->getArgument('vhost'), $application);
     if (!is_dir($vhostConfig->getLink()->getPath())) {
         FsUtil::mkdir($vhostConfig->getLink()->getPath(), true);
         $output->writeln(sprintf('Created directory <info>%s</info>', $vhostConfig->getLink()->getPath()), OutputInterface::VERBOSITY_VERY_VERBOSE);
     }
     FsUtil::symlink($vhostConfig->getTarget(), $vhostConfig->getLink());
     $output->writeln(sprintf('Created vhost <info>%s</info> for <info>%s</info> (<comment>%s</comment>)', $input->getArgument('vhost'), $vhostConfig->getApplication(), $vhostConfig->getTarget()));
     $configHelper->getConfiguration()->write();
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $extractHelper = $this->getHelper('extract');
     /* @var $extractHelper ExtractHelper */
     if (!$input->getArgument('application')) {
         $appName = basename($input->getArgument('archive'));
         $input->setArgument('application', preg_replace('/\\.(zip|rar|(tar(\\.(gz|bz2|xz|Z))?))$/i', '', $appName));
     }
     $application = Application::create($configHelper->getConfiguration(), $input->getArgument('application'));
     if (!is_dir($application->getPath())) {
         FsUtil::mkdir($application->getPath(), true);
         $output->writeln(sprintf('Created directory <info>%s</info>', $application->getPath()), OutputInterface::VERBOSITY_VERY_VERBOSE);
     }
     NotEmptyException::assert($application->getPath());
     $appDir = $application->getPath();
     $configHelper->getConfiguration()->removeApplication($application->getName());
     // Clean up application again, so application:add further down does not complain.
     if (strpos($input->getArgument('archive'), '://') !== false) {
         // This is an url
         $outputFile = $extractHelper->downloadFile($input->getArgument('archive'), $output);
         $extractHelper->extractArchive($outputFile, $appDir, $output);
         $this->getApplication()->find('application:add')->run(new ArrayInput(['application' => $input->getArgument('application'), '--archive-url' => $input->getArgument('archive')]), $output);
     } else {
         $extractHelper->extractArchive($input->getArgument('archive'), $application->getPath(), $output);
         $this->getApplication()->find('application:add')->run(new ArrayInput(['application' => $input->getArgument('application')]), $output);
     }
     if ($input->getOption('override')) {
         $input1 = new ArrayInput(['application' => $input->getArgument('application'), 'config-file' => $input->getOption('override')]);
         if ($input->getOption('override-type')) {
             $input1->setOption('type', $input->getOption('override-type'));
         }
         $this->getApplication()->find('application:override')->run($input1, $output);
     }
     if (!$input->getOption('no-scripts')) {
         /*
          * Run post-extract script
          */
         return $this->getApplication()->find('application:execute')->run(new ArrayInput(['script' => 'post-extract', 'application' => $input->getArgument('application')]), $output);
     }
     return 0;
 }
Example #3
0
 public function getTempDir($seed)
 {
     $configHelper = $this->getHelperSet()->get('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $tempDir = $configHelper->getConfiguration()->getClicDirectory() . '/tmp/' . sha1(time() . $seed);
     if (!is_dir($tempDir)) {
         FsUtil::mkdir($tempDir, true);
     }
     return $tempDir;
 }
 public function write()
 {
     if (file_exists($this->getConfigFile()->getPathname())) {
         $backupDir = $this->getClicDirectory() . '/settings-backup/' . sha1($this->getConfigFile()->getPathname());
         if (!is_dir($backupDir)) {
             FsUtil::mkdir($backupDir, true);
         }
         $backupFile = $backupDir . '/' . time();
         FsUtil::rename($this->getConfigFile()->getPathname(), $backupFile);
         if (file_exists($backupDir . '/prev')) {
             FsUtil::unlink($backupDir . '/prev');
         }
         FsUtil::symlink($backupFile, $backupDir . '/prev');
     }
     parent::write();
 }
Example #5
0
 private function askDirectoryQuestion(callable $getter, callable $setter, $questionText, InputInterface $input, OutputInterface $output)
 {
     try {
         $directory = $getter();
     } catch (MissingConfigurationParameterException $ex) {
         $directory = null;
     } catch (FileException $ex) {
         $directory = $ex->getFilename();
     }
     $question = new Question($questionText, $directory);
     $question->setValidator(function ($dir) use($input, $output) {
         if (!is_dir($dir)) {
             if (!$input->getOption('no-create-missing')) {
                 FsUtil::mkdir($dir, true);
                 $output->writeln(sprintf('Created directory <info>%s</info>', $dir), OutputInterface::VERBOSITY_VERBOSE);
             }
         }
         return $dir;
     });
     $questionHelper = $this->getHelper('question');
     /* @var $questionHelper QuestionHelper */
     $dirAnswer = $questionHelper->ask($input, $output, $question);
     $validator = $question->getValidator();
     $dirAnswer = $validator($dirAnswer);
     $setter($dirAnswer);
 }
Example #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $processHelper = $this->getHelper('process');
     /* @var $processHelper ProcessHelper */
     $questionHelper = $this->getHelper('question');
     /* @var $questionHelper QuestionHelper */
     if (!$input->getArgument('application')) {
         $input->setArgument('application', basename($input->getArgument('repository'), '.git'));
     }
     try {
         $repositoryConfiguration = $configHelper->getConfiguration()->getRepositoryConfiguration($input->getArgument('repository'));
     } catch (NoSuchRepositoryException $ex) {
         $repositoryConfiguration = null;
     }
     $repositoryParts = Util::parseRepositoryUrl($input->getArgument('repository'));
     if (!Util::isSshRepositoryUrl($repositoryParts)) {
         $input->setOption('no-deploy-key', true);
     }
     $application = Application::create($configHelper->getConfiguration(), $input->getArgument('application'));
     if (!is_dir($application->getPath())) {
         FsUtil::mkdir($application->getPath(), true);
         $output->writeln(sprintf('Created directory <info>%s</info>', $application->getPath()), OutputInterface::VERBOSITY_VERY_VERBOSE);
     }
     NotEmptyException::assert($application->getPath());
     if (!$repositoryConfiguration && !$input->getOption('no-deploy-key')) {
         $output->writeln('You do not have a deploy key configured for this repository.', OutputInterface::VERBOSITY_VERBOSE);
         $repositoryConfiguration = new RepositoryConfiguration();
         $repositoryConfiguration->setSshAlias(sha1($input->getArgument('repository')) . '-' . basename($input->getArgument('application')));
         /*
          * Generate a new deploy key, link it to the repository and print it.
          */
         $keyFile = $configHelper->getConfiguration()->getSshDirectory() . '/id_rsa-' . $repositoryConfiguration->getSshAlias();
         try {
             $this->getApplication()->find('repository:generate-key')->run(new ArrayInput(['key' => $keyFile, '--comment' => 'clic-deploy-key-' . $repositoryConfiguration->getSshAlias() . '@' . gethostname(), '--target-repository' => $input->getArgument('repository'), '--print-public-key' => true]), $output);
             $repositoryConfiguration = $configHelper->getConfiguration()->getRepositoryConfiguration($input->getArgument('repository'));
         } catch (FileExistsException $ex) {
             $repositoryConfiguration->setIdentityFile($ex->getFilename());
             $output->writeln(sprintf('Key <info>%s</info> already exists. Not generating a new one.', $ex->getFilename()));
         }
         /*
          * Ask to add it as a deploy key to the repo
          */
         $output->writeln('<comment>Please set the public key printed above as a deploy key for the repository</comment>');
         while (!$questionHelper->ask($input, $output, new ConfirmationQuestion('Is the deploy key uploaded?'))) {
         }
     }
     if ($repositoryConfiguration && !$input->getOption('no-deploy-key')) {
         /*
          * If there is a configuration now, save it
          */
         $configHelper->getConfiguration()->setRepositoryConfiguration($input->getArgument('repository'), $repositoryConfiguration);
         $configHelper->getConfiguration()->write();
     } else {
         $repositoryConfiguration = null;
     }
     /*
      * Run a git clone for the application
      */
     $gitClone = ProcessBuilder::create(['git', 'clone', Util::replaceRepositoryUrl($repositoryParts, $repositoryConfiguration), $application->getPath()])->setTimeout(null)->getProcess();
     $processHelper->mustRun($output, $gitClone, null, null, OutputInterface::VERBOSITY_NORMAL, OutputInterface::VERBOSITY_NORMAL);
     $configHelper->getConfiguration()->removeApplication($application->getName());
     // Clean up application again, so application:add further down does not complain.
     $this->getApplication()->find('application:add')->run(new ArrayInput(['application' => $input->getArgument('application'), '--remote' => $input->getArgument('repository')]), $output);
     if ($input->getOption('override')) {
         $input1 = new ArrayInput(['application' => $input->getArgument('application'), 'config-file' => $input->getOption('override')]);
         if ($input->getOption('override-type')) {
             $input1->setOption('type', $input->getOption('override-type'));
         }
         $this->getApplication()->find('application:override')->run($input1, $output);
     }
     if (!$input->getOption('no-scripts')) {
         /*
          * Run post-clone script
          */
         return $this->getApplication()->find('application:execute')->run(new ArrayInput(['script' => 'post-clone', 'application' => $input->getArgument('application')]), $output);
     }
     return 0;
 }
Example #7
0
 /**
  * @param OutputInterface $output
  * @param $configFile
  * @return string
  */
 protected function downloadGit(OutputInterface $output, $configFile)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $processHelper = $this->getHelper('process');
     /* @var $processHelper ProcessHelper */
     $globalConfiguration = $configHelper->getConfiguration();
     $overridesDirectory = $globalConfiguration->getOverridesDirectory();
     $configDir = $overridesDirectory . '/' . sha1($configFile) . '-' . basename($configFile, '.git');
     if (!is_dir($configDir)) {
         FsUtil::mkdir($configDir);
         /*
          * Run a git clone for the application
          */
         $gitClone = ProcessBuilder::create(['git', 'clone', $configFile, $configDir])->setTimeout(null)->getProcess();
         $processHelper->mustRun($output, $gitClone, null, null, OutputInterface::VERBOSITY_NORMAL, OutputInterface::VERBOSITY_NORMAL);
     } else {
         /*
          * Run a git pull for the application
          */
         $gitPull = ProcessBuilder::create(['git', 'pull'])->setTimeout(null)->setWorkingDirectory($configDir)->getProcess();
         $processHelper->mustRun($output, $gitPull, null, null, OutputInterface::VERBOSITY_NORMAL, OutputInterface::VERBOSITY_NORMAL);
     }
     $configFile = $configDir;
     return $configFile;
 }