Multiple Environments on Heroku

Published 07 April 2022

Multiple Environments on Heroku Cover Image

Staging environments are important when building software to enable you to rapidly prototype and release software. This is one of the methodologies employed in large teams but it's also good practice when working on side projects.
If you are a Ruby on Rails engineer, you have most likely heard or even used Heroku, a platform as a service (PaaS), a cloud platform that lets companies build, deliver, monitor and scale apps. I have been using Heroku for a while now and it's a pleasure to work with.
Instead of going the longer route and setting up Circle CI or GitHub Actions, we can set up different environments on Heroku. Let's assume our app's name is called carpooler.

This is how you can create a staging environment on Heroku.
Create Heroku staging env

This is how you can create a production environment on Heroku.
Create Heroku production env

You can easily validate if these two new remotes were added to your git config file (.git) by running this command:
Validate Heroku environments

Because we haven't set up a more robust CI/CD pipeline, we will do manual pushes to our different environments. To do this for staging, you can run:
Push to staging

Main is the branch name which can be anything (here's an article on why the default branch was renamed from 'master').

In order to push to production after you've done your QA and validated everything on Staging, you can run an almost similar command:
Push to production

And there you have it, different environments. Of course, there could be a better way but this works fine as well. You can catch me on Twitter (@ThubaMamba) if you wanna chat more on this. 


devops, cloud engineering, Heroku