Multiple Environments on Heroku

Multiple Environments on Heroku

Simple and quick deep dive into how to obtain multiple hosting environments on Heroku

2022-11-10T00:00:00.000Z


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.

Staging

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

staging.png

Production

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

production.png

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

Untitled

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:

Untitled

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:

Untitled

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 if you wanna chat more on this.