Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require confirmation if rolling back more than 9 releases #975

Merged
merged 2 commits into from
Aug 18, 2016
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
* The log level within empire can now be configured when starting the service. [#929](https://github.com/remind101/empire/issues/929)
* The CloudFormation backend now has experimental support for a `Custom::ECSTaskDefinition` resource that greatly reduces the size of generated templates. [#935](https://github.com/remind101/empire/pull/935)
* The Scheduler now has a `Restart` method which will trigger a restart of all the processes within an app. Previously, a "Restart" just re-released the app. Now schedulers like the cloudformation backend can optimize how the restart is handled. [#697](https://github.com/remind101/empire/issues/697)
* `emp run` now publishes an event when it is ran [#954](https://github.com/remind101/empire/pull/954)
* `emp run` now publishes an event when it is ran. [#954](https://github.com/remind101/empire/pull/954)
* `emp rollback` requires confirmation if rolling back more than 9 versions. [#975](https://github.com/remind101/empire/pull/975)

**Bugs**

Expand Down
23 changes: 23 additions & 0 deletions cmd/emp/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"sort"
"strconv"
"strings"
"text/tabwriter"
"time"
Expand Down Expand Up @@ -226,7 +227,29 @@ func runRollback(cmd *Command, args []string) {
os.Exit(2)
}
ver := strings.TrimPrefix(args[0], "v")
rollbackSafetyCheck(ver, appname)

rel, err := client.ReleaseRollback(appname, ver, message)
must(err)
log.Printf("Rolled back %s to v%s as v%d.\n", appname, ver, rel.Version)
}

func rollbackSafetyCheck(verStr, appname string) {
// Grab head release to get the current version
hrels, err := client.ReleaseList(appname, &heroku.ListRange{
Field: "version",
Max: 1,
Descending: true,
})
must(err)

currVer := hrels[0].Version
verNum, err := strconv.Atoi(verStr)
must(err)

diff := currVer - verNum
if diff >= 10 {
warning := fmt.Sprintf("Attempting to rollback %d versions from v%d to v%d. Type v%d to continue:", diff, currVer, verNum, verNum)
mustConfirm(warning, fmt.Sprintf("v%s", verStr))
}
}