Skip to content

Commit

Permalink
Add force flag to trigger a deployment even without changes
Browse files Browse the repository at this point in the history
In some cases it is necessary to deploy a version that was already
deployed. For example, when something unexpected happened
on the Nomad side and not all allocations come up.
To mitigate that, the `force` flag triggers a deployment without
running `plan` before and just blindly forwards the command
to Nomad.
  • Loading branch information
mre committed Jul 26, 2019
1 parent 1af56e6 commit 44ed906
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 0.2.8 (Unreleased)

* Add `-force` flag to deploy CLI command which allows for forcing a deployment even if Levant detects 0 changes on plan [GH-296](https://github.com/jrasell/levant/pull/296)

## 0.2.7 (19 March 2019)

IMPROVEMENTS:
Expand Down
4 changes: 4 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
default: check test build

.PHONY: tools
tools: ## Install the tools used to test and build
@echo "==> Installing build tools"
go get github.com/ahmetb/govvv
go get github.com/alecthomas/gometalinter
gometalinter --install

.PHONY: build
build: ## Build Levant for development purposes
@echo "==> Running $@..."
govvv build -o levant-local . -version local

.PHONY: test
test: ## Run the Levant test suite with coverage
@echo "==> Running $@..."
@go test -cover -v -tags -race \
"$(BUILDTAGS)" $(shell go list ./... | grep -v vendor)

.PHONY: release
release: ## Trigger the release build script
@echo "==> Running $@..."
@goreleaser --rm-dist
Expand Down
26 changes: 16 additions & 10 deletions command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ General Options:
The Consul host and port to use when making Consul KeyValue lookups for
template rendering.
-force
Execute deployment even though there were no changes.
-force-batch
Forces a new instance of the periodic job. A new instance will be created
even if it violates the job's prohibit_overlap settings.
Expand Down Expand Up @@ -114,6 +117,7 @@ func (c *DeployCommand) Run(args []string) int {
flags.BoolVar(&config.Client.AllowStale, "allow-stale", false, "")
flags.IntVar(&config.Deploy.Canary, "canary-auto-promote", 0, "")
flags.StringVar(&config.Client.ConsulAddr, "consul-address", "", "")
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.Plan.IgnoreNoChanges, "ignore-no-changes", false, "")
Expand Down Expand Up @@ -175,17 +179,19 @@ func (c *DeployCommand) Run(args []string) int {
}
}

p := levant.PlanConfig{
Client: config.Client,
Plan: config.Plan,
Template: config.Template,
}
if !config.Deploy.Force {
p := levant.PlanConfig{
Client: config.Client,
Plan: config.Plan,
Template: config.Template,
}

planSuccess, changes := levant.TriggerPlan(&p)
if !planSuccess {
return 1
} else if !changes && p.Plan.IgnoreNoChanges {
return 0
planSuccess, changes := levant.TriggerPlan(&p)
if !planSuccess {
return 1
} else if !changes && p.Plan.IgnoreNoChanges {
return 0
}
}

success := levant.TriggerDeployment(config, nil)
Expand Down
2 changes: 2 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Levant supports a number of command line arguments which provide control over th

* **-consul-address** (string: "localhost:8500") The Consul host and port to use when making Consul KeyValue lookups for template rendering.

* **-force** (bool: false) Execute deployment even though there were no changes.

* **-force-batch** (bool: false) Forces a new instance of the periodic job. A new instance will be created even if it violates the job's prohibit_overlap settings.

* **-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.
Expand Down
4 changes: 4 additions & 0 deletions levant/structs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type DeployConfig struct {
// until attempting to perform autopromote.
Canary int

// Force is a boolean flag that can be used to force a deployment
// even though levant didn't detect any changes.
Force bool

// ForceBatch is a boolean flag that can be used to force a run of a periodic
// job upon registration.
ForceBatch bool
Expand Down

0 comments on commit 44ed906

Please sign in to comment.