Esempio n. 1
0
 /**
  * Execute the command.
  *
  * @param  InputInterface  $input
  * @param  OutputInterface  $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->setIo($input, $output);
     /** @var Repository $config */
     $config = $this->container['config'];
     $sourceRepoPath = $config['source.directory'];
     $sourceRepoUrl = $config['source.git.url'];
     $sourceRepoBranch = $config['source.git.branch'];
     $this->checkSourceRepoSettings($sourceRepoPath, $sourceRepoUrl);
     $output->writeln(["<b>steak pull configuration:</b>", " Source repository remote is <path>{$sourceRepoUrl}</path>", " Source repository branch is <path>{$sourceRepoBranch}</path>", " Path to local repository is <path>{$sourceRepoPath}</path>"], OutputInterface::VERBOSITY_VERBOSE);
     if ($this->files->exists($sourceRepoPath)) {
         $workingCopy = $this->git->workingCopy($sourceRepoPath);
         if (!$workingCopy->isCloned()) {
             throw new RuntimeException("<path>{$sourceRepoPath}</path> exists but is not a git repository.");
         }
         if ($workingCopy->getBranches()->head() != $sourceRepoBranch) {
             throw new RuntimeException("<path>{$sourceRepoPath}</path> exists but isn't on the <path>{$sourceRepoBranch}</path> branch.");
         }
         $this->git->streamOutput();
         $workingCopy->pull();
     } else {
         $output->writeln(["The source directory <path>{$sourceRepoPath}</path> does not exist.", "  Attempting clone from {$sourceRepoUrl}"]);
         $this->git->streamOutput();
         $this->git->cloneRepository($sourceRepoUrl, $sourceRepoPath, ['single-branch' => true, 'branch' => $sourceRepoBranch]);
         $output->writeln("<info>Clone complete! Edit your sources in <path>{$sourceRepoPath}</path></info>");
     }
     $output->writeln("Try <comment>steak serve</comment> to fire up the local development server...");
 }
Esempio n. 2
0
 public function deploy()
 {
     // Create the wrapper.
     $wrapper = new GitWrapper();
     $wrapper->streamOutput();
     // Iterate through each project.
     foreach ($this->projects as $name => $project) {
         // Check out all branches.
         foreach ($project['branches'] as $branch => $destination) {
             // Build our git interface.
             $git = null;
             if (!is_dir($destination)) {
                 $git = $wrapper->cloneRepository($project['repo'], $destination);
             } else {
                 $git = new GitWorkingCopy($wrapper, $destination);
             }
             // Fetch the latest.
             $git->fetch('origin');
             // Checkout the desired branch.
             $git->checkout($branch, array('force' => true));
             // Reset any local changes.
             $git->reset(array('hard' => true));
             // Pull the latest from the branch.
             $git->pull('origin', $branch, array('force' => true));
         }
     }
 }
Esempio n. 3
0
 /**
  * Clones the source code for this project.
  */
 public function init($path)
 {
     $wrapper = new GitWrapper();
     $wrapper->streamOutput();
     $wrapper->clone($this->app->source_url, $path, array('bare' => TRUE));
     chdir($path);
     $wrapper->git('branch');
 }
Esempio n. 4
0
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dependencies = $input->getArgument('dependency');
     $excludes = $input->getOption('exclude');
     $test = $input->getOption('test');
     $wrapper = new GitWrapper();
     $wrapper->streamOutput();
     $projects = Finder::create()->directories()->depth(0)->exclude($excludes)->in(getcwd());
     /** @var SplFileInfo $project */
     foreach ($projects as $project) {
         if (!file_exists($project->getPathname() . '/composer.json')) {
             continue;
         }
         try {
             $this->resetComposer();
             $this->versionParser = null;
             $this->pool = null;
             chdir($project->getPathname());
             $packages = $this->resolveUpdateablePackages($dependencies);
             if (count($packages) > 0) {
                 $output->writeln(sprintf('<comment> Updating project %s with %s</comment>', $project->getFilename(), implode(', ', $packages)));
                 $git = $wrapper->workingCopy($project->getPathname());
                 $stashed = false;
                 if ($git->hasChanges()) {
                     $git->run(['stash']);
                     $stashed = true;
                 }
                 $git->pull();
                 if (!$test) {
                     $exitCode = $this->update($packages);
                     if (0 === $exitCode) {
                         $git->add('composer.json')->add('composer.lock');
                         // Reissue a install for plugins to work. Slows down :/
                         $this->resetComposer();
                         $this->install($output);
                         if ($git->hasChanges()) {
                             $git->commit('Update ' . implode(', ', $packages))->push();
                         }
                     }
                 }
                 if ($stashed) {
                     $git->run(['stash', 'pop']);
                 }
             }
         } catch (\Exception $e) {
             if ($output instanceof ConsoleOutputInterface) {
                 $this->getApplication()->renderException($e, $output->getErrorOutput());
             } else {
                 $this->getApplication()->renderException($e, $output);
             }
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // App
     $app_name = $input->getArgument('app');
     if (empty($app_name)) {
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('Which app? ', array_keys($this->director->config['apps']), 0);
         $app_name = $helper->ask($input, $output, $question);
     }
     $app = $this->director->getApp($app_name);
     // Environment
     $env_name = $input->getArgument('environment');
     if (empty($env_name)) {
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('Which environment? ', array_keys($app->environments), 0);
         $env_name = $helper->ask($input, $output, $question);
     }
     $environment = $app->getEnvironment($env_name);
     $output->writeln('<info>PATH:</info> ' . $environment->getSourcePath());
     $output->writeln('<info>BRANCH:</info> ' . $environment->getRepo()->getCurrentBranch());
     // Look for .director.yml
     $config = $environment->getConfig();
     if (empty($config)) {
         $output->writeln('<error>CONFIG:</error> .director.yml not found at ' . $environment->getSourcePath());
     } else {
         $output->writeln('<info>CONFIG:</info> Loaded .director.yml');
     }
     // Show git status
     $status = $environment->getRepo()->getStatus();
     if (!empty($status)) {
         $wrapper = new GitWrapper();
         $wrapper->streamOutput();
         chdir($environment->getSourcePath());
         $wrapper->git('status');
     }
     // Save to yml
     $this->director->config['apps'][$app_name]['environments'][$env_name]['config'] = $environment->getConfig();
     $this->director->config['apps'][$app_name]['environments'][$env_name]['git_ref'] = $environment->getRepo()->getCurrentBranch();
     $this->director->saveData();
     $output->writeln("Saved environment details.");
     // Look for services
     if (isset($environment->config['services']) && is_array($environment->config['services'])) {
         foreach ($environment->config['services'] as $service => $type) {
             $serviceFactory = $this->director->getService($service);
             if ($serviceFactory) {
                 $output->writeln("<info>SERVICE:</info> {$service}: {$serviceFactory->galaxy_role}");
             } else {
                 $output->writeln("<error>SERVICE:</error> {$service}: not found. Use service:add to fix.");
                 $output->writeln("Looking for available {$service} {$type}");
             }
         }
     }
 }
Esempio n. 6
0
 /**
  * @param $deployTag
  * @throws \Exception
  * @throws GitException
  */
 public function deployToProduction($deployTag)
 {
     $oldBranch = $this->getCurrentBranchName();
     try {
         $this->precheck();
         $this->wrapper->streamOutput();
         $this->git->fetch()->checkout(BranchEnum::PRODUCTION)->reset('--hard')->merge($deployTag)->push();
     } catch (GitException $e) {
         throw $e;
     } finally {
         $this->git->checkout($oldBranch);
     }
 }
Esempio n. 7
0
 /**
  * Deploy a version to an environment.
  *
  * @param $version
  *   A git branch, tag, or sha.
  */
 public function deploy($version)
 {
     // Checkout the branch
     $wrapper = new GitWrapper();
     $wrapper->streamOutput();
     $git = new GitWorkingCopy($wrapper, $this->getSourcePath());
     $git->checkout($version);
     $git->pull();
     // Reload config so any changes get picked up.
     $this->reloadConfig();
     // Run the deploy hooks, if there are any.
     if (isset($this->config['hooks']['deploy']) && !empty($this->config['hooks']['deploy'])) {
         chdir($this->getSourcePath());
         $process = new Process($this->config['hooks']['deploy']);
         $process->run(function ($type, $buffer) {
             if (Process::ERR === $type) {
                 // Error
                 echo $buffer;
             } else {
                 // OK
                 echo $buffer;
             }
         });
     }
     // @TODO: Save the environment
     // @TODO: Create EnvironmentFactory->save();
     // Returning the branch for now. The command is saving the info.
     return $this->getRepo()->getCurrentBranch();
 }
Esempio n. 8
0
 /**
  * Deploy a version to an environment.
  *
  * @param $version
  *   A git branch, tag, or sha.
  */
 public function deploy($version)
 {
     // Checkout the branch
     $wrapper = new GitWrapper();
     $wrapper->streamOutput();
     $git = new GitWorkingCopy($wrapper, $this->getSourcePath());
     $git->checkout($version);
     $git->pull();
     // Reload config so any changes get picked up.
     $this->reloadConfig();
     // Run the deploy hooks
     chdir($this->getSourcePath());
     $process = new Process($this->config['hooks']['deploy']);
     $process->run(function ($type, $buffer) {
         if (Process::ERR === $type) {
             // Error
             echo $buffer;
         } else {
             // OK
             echo $buffer;
         }
     });
     // Save new branch to yml
     $this->director->config['apps'][$this->app]['environments'][$this->name]['git_ref'] = $this->getRepo()->getCurrentBranch();
     $this->director->saveData();
 }