I currently have two environments in which I work: development
locally and production
on Heroku.
I would like to add a staging
environment on Heroku to see that everything goes as expected before pushing the app live to users. Preferably, the staging
environment should have the exact same settings and data as the production
environment.
What are the steps needed to accomplish the above?
Note that the procedure explained by berislavbabic is not recommended according to the following guide on Heroku's site: https://devcenter.heroku.com/articles/multiple-environments#managing-staging-and-production-configurations
You can read in detail there, but the recommendation is to keep the staging environment the same as the production environment and simply use heroku fork to copy from production to staging.
I found the
heroku fork -a PRODUCTION_APP_NAME NEW_STAGE_APP_NAME
to be a faster, easier way to do it... it creates the new app, copies everything (including the postgres database). Then I went in and manually downgraded the addons to smaller plans when it made sense (for example, a starter tier database).In fact, we started using the relatively new
heroku pipeline:promote
to manage automatically (and VERY quickly) pushing a compiled slug from staging to production. (That assumes you have any env-specific settings via settings or environment variables, so the code slug is the same.)First the predispositions, i like to have my heroku git remotes set up as staging and production so you can easily use git push staging/production to deploy to each one of them. I'll be using that setup to explain how to make a staging env.
config/environments/staging.rb
which you will copy off `config/environments/production.rb'heroku plugins:install git://github.com/ddollar/heroku-config.git
heroku config:pull --remote production
RACK_ENV=staging RAILS_ENV=staging
so it will use the staging environment configuration.heroku fork -a production staging
(those are heroku appnames you want instead of production/staging)You can also read this tutorial, i think i used it to get started with multiple envs on heroku: https://devcenter.heroku.com/articles/multiple-environments#managing-staging-and-production-configurations