Git workflow for a staging environment with Heroku and GitHub
May 12, 2011
Having a staging environment to verify changes adds an extra measure of confidence to each deployment. Git is the primary means for deploying apps to Heroku. For Heroku, a staging environment corresponds to another app. For Git, it is just a branch.
Thomas Balthazar has written a full outline of how to deploy multiple environments on Heroku and still host your code on GitHub. With the Heroku and GitHub repos thus configured, our local repo has three branches:
- work
- staging
- production (master)
Why do we use Git?
We build and test all changes in the work branch before merging with the production master. Our workflow to deploy a tested change from work through staging to production:
# standing in /rails_app_root
git checkout -b work
# after committing a change
git status
# nothing to commit (working directory clean)
git checkout staging
git merge working
# 'see' Fast forward
git push heroku_staging staging:master
heroku maintenance:off --app staging_app_name
# exercise the staging app to verify change
heroku maintenance:on --app staging_app_name
git push # to GitHub
git checkout master
git merge staging
# 'see' Fast forward
heroku maintenance:on --app production_app_name
git push heroku_production
heroku maintenance:off --app production_app_name
git push # to GitHub
git checkout work
# go forth and make more changes
Witness the ease with which a local Git repo operates with remotes on GitHub and Heroku. Those who have not yet tried Git may not know what they have been missing.