Skip to content

Commit

Permalink
Halt Deploys With release script if ENV variable DEPLOY_STATUS is set…
Browse files Browse the repository at this point in the history
… to blocked (forem#5510) [deploy]
  • Loading branch information
mstruve authored Jan 15, 2020
1 parent 7bfb255 commit ddb54d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
23 changes: 15 additions & 8 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ Upon deploy, the app installs dependencies, bundles assets, and gets the app
ready for launch. However, before it launches and releases the app Heroku runs a
release script on a one-off dyno. If that release script/step succeeds the new
app is released on all of the dynos. If that release script/step fails then the
deploy is halted and we are notified. During this release step, we first run any
outstanding migrations. This ensures that a migration finishes successfully
before the code that uses it goes live. After running migrations, we use the
rails runner to output a simple string. Executing a Rails runner command allows
us to ensure that we can boot up the entire app successfully before it is
deployed. We deploy asynchronously, so the website is running the new code a few
minutes after deploy. A new instance of Heroku Rails console will immediately
run a new code.
deploy is halted and we are notified. During this release step, we first check
the DEPLOY_STATUS environment variable. In the event that we want to prevent
deploys, for example after a rollback, we will set DEPLOY_STATUS to "blocked".
This will cause the release script to exit with a code of 1 which will halt the
deploy. This ensures that we don't accidentally push out code while we are
waiting for a fix or running other tasks. Next, we run any outstanding
migrations. This ensures that a migration finishes successfully before the code
that uses it goes live. After running migrations, we use the Rails runner to
output a simple string. Executing a Rails runner command ensures that we can
boot up the entire app successfully before it is deployed. We deploy
asynchronously, so the website is running the new code a few minutes after
deploy. A new instance of Heroku Rails console will immediately run a new code.
We deploy asynchronously, so the website is running the new code a few minutes
after deploy. A new instance of Heroku Rails console will immediately run a new
code.

![](https://devcenter0.assets.heroku.com/article-images/1494371187-release-phase-diagram-3.png)
10 changes: 9 additions & 1 deletion release-tasks.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#!/bin/bash

STATEMENT_TIMEOUT=180000 bundle exec rails db:migrate && rails runner "puts 'app load success'"
# enable echo mode
set -x

# abort release if deploy status equals "blocked"
[[ $DEPLOY_STATUS = "blocked" ]] && echo "Deploy blocked" && exit 1

# runs migration and boots the app to check there are no errors
STATEMENT_TIMEOUT=180000 bundle exec rails db:migrate && \
bundle exec rails runner "puts 'app load success'"

0 comments on commit ddb54d0

Please sign in to comment.