66use Platformsh \Cli \Service \ActivityMonitor ;
77use Platformsh \Client \Model \Activity ;
88use Symfony \Component \Console \Input \InputInterface ;
9+ use Symfony \Component \Console \Input \InputOption ;
910use Symfony \Component \Console \Output \OutputInterface ;
1011
1112class EnvironmentDeployCommand extends CommandBase
@@ -23,7 +24,9 @@ protected function configure()
2324 $ this
2425 ->setName ('environment:deploy ' )
2526 ->setAliases (['env:deploy ' ])
26- ->setDescription ('Deploy an environment \'s staged changes ' );
27+ ->setDescription ('Deploy an environment \'s staged changes ' )
28+ ->addOption ('strategy ' , 's ' , InputOption::VALUE_REQUIRED ,
29+ 'The deployment strategy, stopstart (default, restart with a shutdown) or rolling (zero downtime) ' );
2730 $ this ->addProjectOption ()
2831 ->addEnvironmentOption ();
2932 $ this ->addWaitOptions ();
@@ -81,11 +84,36 @@ protected function execute(InputInterface $input, OutputInterface $output)
8184
8285 /** @var \Platformsh\Cli\Service\QuestionHelper $questionHelper */
8386 $ questionHelper = $ this ->getService ('question_helper ' );
87+
88+ $ strategy = $ input ->getOption ('strategy ' );
89+ $ can_rolling_deploy = $ environment ->getProperty ('can_rolling_deploy ' , false );
90+ if (is_null ($ strategy )) {
91+ if ($ can_rolling_deploy ) {
92+ $ options = [
93+ 'stopstart ' => 'Restart with a shutdown ' ,
94+ 'rolling ' => 'Zero downtime deployment '
95+ ];
96+ $ strategy = $ questionHelper ->chooseAssoc ($ options , 'Choose the deployment strategy: ' , 'stopstart ' );
97+ } else {
98+ $ strategy = 'stopstart ' ;
99+ }
100+ } else {
101+ if (!in_array ($ strategy , ['stopstart ' , 'rolling ' ])) {
102+ $ this ->stdErr ->writeln ('The chosen strategy is not available for this environment. ' );
103+ return 1 ;
104+ } elseif (!$ can_rolling_deploy && $ strategy === 'rolling ' ) {
105+ $ this ->stdErr ->writeln ('The chosen strategy is not available for this environment. ' );
106+ return 1 ;
107+ }
108+ }
109+ if ($ strategy === 'rolling ' ) {
110+ $ this ->stdErr ->writeln ('Please make sure the changes from above are not affecting the state of the services. ' );
111+ }
84112 if (!$ questionHelper ->confirm ('Are you sure you want to continue? ' )) {
85113 return 1 ;
86114 }
87115
88- $ result = $ environment ->runOperation ('deploy ' );
116+ $ result = $ environment ->runOperation ('deploy ' , ' POST ' , [ ' strategy ' => $ strategy ] );
89117
90118 if ($ this ->shouldWait ($ input )) {
91119 /** @var \Platformsh\Cli\Service\ActivityMonitor $activityMonitor */
0 commit comments