@@ -318,6 +318,7 @@ func (h *ServiceHandler) addServiceDefinitionFlagsForAllSources(flags *pflag.Fla
318
318
"To delete an environment variable, prefix its name with '!', for example --env '!FOO'\n " ,
319
319
)
320
320
flags .String ("instance-type" , "nano" , "Instance type" )
321
+ flags .String ("deployment-strategy" , "rolling" , "Deployment strategy" )
321
322
flags .Int64 ("scale" , 1 , "Set both min-scale and max-scale" )
322
323
flags .Int64 ("min-scale" , 1 , "Min scale" )
323
324
flags .Int64 ("max-scale" , 1 , "Max scale" )
@@ -387,6 +388,8 @@ func (h *ServiceHandler) addServiceDefinitionFlagsForAllSources(flags *pflag.Fla
387
388
"health-checks-graee" : "checks-grace-period" ,
388
389
"health-checks-grace-period" : "checks-grace-period" ,
389
390
391
+ "strategy" : "deployment-strategy" ,
392
+
390
393
"route" : "routes" ,
391
394
"volume" : "volumes" ,
392
395
"region" : "regions" ,
@@ -466,6 +469,12 @@ func (h *ServiceHandler) parseServiceDefinitionFlags(ctx *CLIContext, flags *pfl
466
469
}
467
470
definition .SetType (type_ )
468
471
472
+ strategy , err := h .parseDeploymentStrategy (flags , definition .GetStrategy ())
473
+ if err != nil {
474
+ return err
475
+ }
476
+ definition .SetStrategy (strategy )
477
+
469
478
skipCache , _ := flags .GetBool ("skip-cache" )
470
479
definition .SetSkipCache (skipCache )
471
480
@@ -582,6 +591,50 @@ func (h *ServiceHandler) parseInstanceType(flags *pflag.FlagSet, currentInstance
582
591
return []koyeb.DeploymentInstanceType {* ret }
583
592
}
584
593
594
+ // Parse --deployment-strategy
595
+ func (h * ServiceHandler ) parseDeploymentStrategy (flags * pflag.FlagSet , currentStrategy koyeb.DeploymentStrategy ) (koyeb.DeploymentStrategy , error ) {
596
+ if ! flags .Lookup ("deployment-strategy" ).Changed {
597
+ // New service: return the default value
598
+ if currentStrategy .Type == nil {
599
+ value := flags .Lookup ("deployment-strategy" ).DefValue
600
+ enum := fmt .Sprintf ("DEPLOYMENT_STRATEGY_TYPE_%s" , strings .ToUpper (strings .ReplaceAll (value , "-" , "_" )))
601
+ kind , err := koyeb .NewDeploymentStrategyTypeFromValue (enum )
602
+ if err != nil {
603
+ panic (err )
604
+ }
605
+ ret := koyeb.DeploymentStrategy {
606
+ Type : kind ,
607
+ }
608
+ return ret , nil
609
+ }
610
+ // Existing service: return the strategy currently configured
611
+ return currentStrategy , nil
612
+ }
613
+
614
+ value , _ := flags .GetString ("deployment-strategy" )
615
+ enum := fmt .Sprintf ("DEPLOYMENT_STRATEGY_TYPE_%s" , strings .ToUpper (strings .ReplaceAll (value , "-" , "_" )))
616
+ kind , err := koyeb .NewDeploymentStrategyTypeFromValue (enum )
617
+ if err != nil {
618
+ return koyeb.DeploymentStrategy {}, & errors.CLIError {
619
+ What : "Error while updating the service" ,
620
+ Why : "the --deployment-strategy flag is not valid" ,
621
+ Additional : []string {
622
+ "The --deployment-strategy flag must be one of the following:" ,
623
+ " - rolling" ,
624
+ " - canary" ,
625
+ " - blue-green" ,
626
+ " - immediate" ,
627
+ },
628
+ Orig : nil ,
629
+ Solution : "Fix the --deployment-strategy flag and try again" ,
630
+ }
631
+ }
632
+ ret := koyeb.DeploymentStrategy {
633
+ Type : kind ,
634
+ }
635
+ return ret , nil
636
+ }
637
+
585
638
// parseListFlags is the generic function parsing --env, --port, --routes, --checks, --regions and --volumes
586
639
// It gets the arguments given from the command line for the given flag, then
587
640
// builds a list of flags_list.Flag entries, and update the service
0 commit comments