Skip to content

Commit

Permalink
Merge pull request #975 from remind101/jl-safer-rollback
Browse files Browse the repository at this point in the history
Require confirmation if rolling back more than 9 releases
  • Loading branch information
ejholmes authored Aug 18, 2016
2 parents 66a68e1 + 3e2bba8 commit 38f1028
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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))
}
}

0 comments on commit 38f1028

Please sign in to comment.