Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 29 additions & 0 deletions command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ General Options:
Use the taskgroup count from the Nomad jobfile instead of the count that
is currently set in a running job.

-blue-green
Set the max-parallel and the canary count of each task group to the current
count for a blue-green type release

-ignore-no-changes
By default if no changes are detected when running a deployment Levant will
exit with a status 1 to indicate a deployment didn't happen. This behaviour
Expand Down Expand Up @@ -120,6 +124,7 @@ func (c *DeployCommand) Run(args []string) int {
flags.BoolVar(&config.Deploy.Force, "force", false, "")
flags.BoolVar(&config.Deploy.ForceBatch, "force-batch", false, "")
flags.BoolVar(&config.Deploy.ForceCount, "force-count", false, "")
flags.BoolVar(&config.Deploy.BlueGreen, "blue-green", false, "")
flags.BoolVar(&config.Plan.IgnoreNoChanges, "ignore-no-changes", false, "")
flags.StringVar(&level, "log-level", "INFO", "")
flags.StringVar(&format, "log-format", "HUMAN", "")
Expand Down Expand Up @@ -179,6 +184,18 @@ func (c *DeployCommand) Run(args []string) int {
}
}

if config.Deploy.BlueGreen {
if err = c.checkBlueGreen(config.Template.Job); err != nil {
c.UI.Error(fmt.Sprintf("[ERROR] levant/command: %v", err))
return 1
}
for _, taskGroup := range config.Template.Job.TaskGroups {
blueGreenCount := taskGroup.Count
taskGroup.Update.MaxParallel = blueGreenCount
taskGroup.Update.Canary = blueGreenCount
}
}

if !config.Deploy.Force {
p := levant.PlanConfig{
Client: config.Client,
Expand Down Expand Up @@ -230,3 +247,15 @@ func (c *DeployCommand) checkForceBatch(job *nomad.Job, forceBatch bool) error {

return fmt.Errorf("force-batch passed but job is not periodic")
}

func (c *DeployCommand) checkBlueGreen(job *nomad.Job) error {

if job.IsPeriodic() {
return fmt.Errorf("blue-green passed but job is periodic")
}
if *job.Type == "system" {
return fmt.Errorf(`blue-green passed but job type is "system"`)
}

return nil
}
2 changes: 2 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Levant supports a number of command line arguments which provide control over th

* **-force-count** (bool: false) Use the taskgroup count from the Nomad job file instead of the count that is obtained from the running job count.

* **-blue-green** (bool: false) Set the max-parallel and the canary count of each task group to the current count for a blue-green type release

* **-ignore-no-changes** (bool: false) By default if no changes are detected when running a deployment Levant will exit with a status 1 to indicate a deployment didn't happen. This behaviour can be changed using this flag so that Levant will exit cleanly ensuring CD pipelines don't fail when no changes are detected

* **-log-level** (string: "INFO") The level at which Levant will log to. Valid values are DEBUG, INFO, WARN, ERROR and FATAL.
Expand Down
4 changes: 4 additions & 0 deletions levant/structs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type DeployConfig struct {
// and force the count based on the rendered job file.
ForceCount bool

// BlueGreen is a boolean flag that can be used to run a blue-green release,
// overwriting the max-parallel and the canary count variables
BlueGreen bool

// EnvVault is a boolean flag that can be used to enable reading the VAULT_TOKEN
// from the enviromment.
EnvVault bool
Expand Down