Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit 44ed906

Browse files
committed
Add force flag to trigger a deployment even without changes
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.
1 parent 1af56e6 commit 44ed906

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 0.2.8 (Unreleased)
22

3+
* 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)
4+
35
## 0.2.7 (19 March 2019)
46

57
IMPROVEMENTS:

GNUmakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
default: check test build
22

3+
.PHONY: tools
34
tools: ## Install the tools used to test and build
45
@echo "==> Installing build tools"
56
go get github.com/ahmetb/govvv
67
go get github.com/alecthomas/gometalinter
78
gometalinter --install
89

10+
.PHONY: build
911
build: ## Build Levant for development purposes
1012
@echo "==> Running $@..."
1113
govvv build -o levant-local . -version local
1214

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

21+
.PHONY: release
1822
release: ## Trigger the release build script
1923
@echo "==> Running $@..."
2024
@goreleaser --rm-dist

command/deploy.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ General Options:
5151
The Consul host and port to use when making Consul KeyValue lookups for
5252
template rendering.
5353
54+
-force
55+
Execute deployment even though there were no changes.
56+
5457
-force-batch
5558
Forces a new instance of the periodic job. A new instance will be created
5659
even if it violates the job's prohibit_overlap settings.
@@ -114,6 +117,7 @@ func (c *DeployCommand) Run(args []string) int {
114117
flags.BoolVar(&config.Client.AllowStale, "allow-stale", false, "")
115118
flags.IntVar(&config.Deploy.Canary, "canary-auto-promote", 0, "")
116119
flags.StringVar(&config.Client.ConsulAddr, "consul-address", "", "")
120+
flags.BoolVar(&config.Deploy.Force, "force", false, "")
117121
flags.BoolVar(&config.Deploy.ForceBatch, "force-batch", false, "")
118122
flags.BoolVar(&config.Deploy.ForceCount, "force-count", false, "")
119123
flags.BoolVar(&config.Plan.IgnoreNoChanges, "ignore-no-changes", false, "")
@@ -175,17 +179,19 @@ func (c *DeployCommand) Run(args []string) int {
175179
}
176180
}
177181

178-
p := levant.PlanConfig{
179-
Client: config.Client,
180-
Plan: config.Plan,
181-
Template: config.Template,
182-
}
182+
if !config.Deploy.Force {
183+
p := levant.PlanConfig{
184+
Client: config.Client,
185+
Plan: config.Plan,
186+
Template: config.Template,
187+
}
183188

184-
planSuccess, changes := levant.TriggerPlan(&p)
185-
if !planSuccess {
186-
return 1
187-
} else if !changes && p.Plan.IgnoreNoChanges {
188-
return 0
189+
planSuccess, changes := levant.TriggerPlan(&p)
190+
if !planSuccess {
191+
return 1
192+
} else if !changes && p.Plan.IgnoreNoChanges {
193+
return 0
194+
}
189195
}
190196

191197
success := levant.TriggerDeployment(config, nil)

docs/commands.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Levant supports a number of command line arguments which provide control over th
1414

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

17+
* **-force** (bool: false) Execute deployment even though there were no changes.
18+
1719
* **-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.
1820

1921
* **-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.

levant/structs/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ type DeployConfig struct {
2727
// until attempting to perform autopromote.
2828
Canary int
2929

30+
// Force is a boolean flag that can be used to force a deployment
31+
// even though levant didn't detect any changes.
32+
Force bool
33+
3034
// ForceBatch is a boolean flag that can be used to force a run of a periodic
3135
// job upon registration.
3236
ForceBatch bool

0 commit comments

Comments
 (0)