Skip to content

Instantly share code, notes, and snippets.

@bhattisatish
Created February 23, 2012 07:53
Show Gist options
  • Select an option

  • Save bhattisatish/1891399 to your computer and use it in GitHub Desktop.

Select an option

Save bhattisatish/1891399 to your computer and use it in GitHub Desktop.
Makefile to create a staging environment that is a replica of prod on Heroku
# Original Source: http://illuminatedcomputing.com/posts/2011/11/disposable-staging-site-on-heroku/
# We use this Makefile to destroy the staging site
# and re-create it based on production.
# This is useful to keep staging current,
# and it's especially nice so we can rehearse deployments.
# If we nuke staging and then deploy the latest code there,
# we can be more confident that the production deploy
# will run smoothly.
PRODUCTION_APP=example
STAGING_APP=example-staging
initialize_staging: destroy_staging create_staging populate_staging_database
populate_staging_database:
heroku pgbackups:capture --expire --app=${PRODUCTION_APP}
heroku pgbackups:restore DATABASE `heroku pgbackups:url --app=${PRODUCTION_APP}` --app=${STAGING_APP} --confirm ${STAGING_APP}
# We use these next two Rake tasks so it's easy to get consistent
# indexes and foreign keys on all systems,
# and they are all listed in one place.
# This is especially handy for foreign keys,
# because Heroku's db:{push,pull} commands don't transfer them.
heroku rake db:add_indexes --app=${STAGING_APP}
heroku rake db:add_foreign_keys --app=${STAGING_APP}
heroku ps:restart --app=${STAGING_APP}
create_staging:
heroku apps:create --remote staging --stack bamboo-mri-1.9.2 ${STAGING_APP}
git push staging master
heroku sharing:add someone@example.com --app=${STAGING_APP}
# We run staging as its own Rails environment:
heroku config:add RACK_ENV=staging --app=${STAGING_APP}
# Uncomment this line if you want a bigger database on staging:
# heroku addons:upgrade shared-database:20gb --app=electnext-staging
heroku addons:add releases:basic --app=${STAGING_APP}
heroku addons:add pgbackups:basic --app=${STAGING_APP}
heroku addons:add custom_domains:basic --app=${STAGING_APP}
heroku addons:add newrelic:standard --app=${STAGING_APP}
heroku addons:upgrade logging:expanded --app=${STAGING_APP}
heroku domains:add staging.example.com --app=${STAGING_APP}
heroku addons:add memcache:5mb --app=${STAGING_APP}
# ...
heroku ps:restart --app=${STAGING_APP}
destroy_staging:
heroku apps:destroy --app=${STAGING_APP} --confirm ${STAGING_APP}
# vim: set filetype=make :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment