Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/Command/Environment/EnvironmentDeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Platformsh\Cli\Service\ActivityMonitor;
use Platformsh\Client\Model\Activity;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class EnvironmentDeployCommand extends CommandBase
Expand All @@ -23,7 +24,9 @@ protected function configure()
$this
->setName('environment:deploy')
->setAliases(['env:deploy'])
->setDescription('Deploy an environment\'s staged changes');
->setDescription('Deploy an environment\'s staged changes')
->addOption('strategy', 's', InputOption::VALUE_REQUIRED,
'The deployment strategy, stopstart (default, restart with a shutdown) or rolling (zero downtime)');
$this->addProjectOption()
->addEnvironmentOption();
$this->addWaitOptions();
Expand Down Expand Up @@ -81,11 +84,35 @@ protected function execute(InputInterface $input, OutputInterface $output)

/** @var \Platformsh\Cli\Service\QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');

$strategy = $input->getOption('strategy');
if (is_null($strategy)) {
if ($environment->can_rolling_deploy) {
$options = [
'stopstart' => 'Restart with a shutdown',
'rolling' => 'Zero downtime deployment'
];
$strategy = $questionHelper->chooseAssoc($options, 'Choose the deployment strategy: ', 'stopstart');
} else {
$strategy = 'stopstart';
}
} else {
if (!in_array($strategy, ['stopstart', 'rolling'])) {
$this->stdErr->writeln('The chosen strategy is not available for this environment.');
return 1;
} elseif (!$environment->can_rolling_deploy && $strategy === 'rolling') {
$this->stdErr->writeln('The chosen strategy is not available for this environment.');
return 1;
}
}
if ($strategy === 'rolling') {
$this->stdErr->writeln('Please make sure the changes from above are not affecting the state of the services.');
}
if (!$questionHelper->confirm('Are you sure you want to continue?')) {
return 1;
}

$result = $environment->runOperation('deploy');
$result = $environment->runOperation('deploy', 'POST', ['strategy' => $strategy]);

if ($this->shouldWait($input)) {
/** @var \Platformsh\Cli\Service\ActivityMonitor $activityMonitor */
Expand Down
Loading