How to get the most out of Heroku Pipelines

Reading Time: 3 minutes

A Pipeline is a collection of apps relating to a single codebase. This is a blog post on how to get the most out of your available tools and ensuring your review apps will remain in Heroku’s free tier.

 A Heroku Pipeline is a group of Heroku apps that have the same codebase; each one of these apps is in a different stage of a CI/CD workflow:

  • Review App
  • Staging
  • Production

Development

During development, a Review App can be configured to be deployed with each pull request. As a matter of fact, when a PR is created, Heroku will deploy a temporary app (A Review App) tied to it. Once the PR is closed, the review app will be deleted, ensuring you do not keep unnecessary dynos. Set a lifespan for Review apps on stale PRs to avoid consuming resources indefinitely.

By the way, you can configure Review Apps to use free dynos and add-ons, making them great for testing.

Note: During this stage, Heroku can start the process right away or wait for the CI to pass before deployment. This is only available with Heroku CI.

Staging

When a feature branch is merged into Development, Heroku will trigger the deployment in the staging app for further testing. In an Agile environment, this would be the place where you test that features from different tickets play nice with one another, ensuring the release candidate is perfect.

Production

You can manually promote a slug from staging to production, or you can trigger automatic deployments from the Main branch. Promoting a slug does not trigger a new build, so choose carefully.

Prerequisites

Git Workflow

Before being able to create a pipeline, you must adopt a Git Workflow. In fact, I found that the GitFlow Workflow works best with a pipeline. So, each branch of the workflow corresponds to a stage in the pipeline:

  • Feature to review apps
  • Development to staging
  • Main to production

Continuous Testing

You could have a pipeline without continuous testing, but… why would you?
You can seamlessly incorporate your favorite CI provider (mine is CircleCI) into the workflow to cut down on manual tests. So, configure the CI to run in your repo whenever a new PR is created!

Creating a Pipeline

For the initial setup see Heroku’s Docs. Once the pipeline is created, enable and configure the review apps:

Then, configure automatic deploys for staging and production:

Configure the review apps

Once you have created the apps, add an app.json file to the root of your repo. This file can be used to handle many aspects of your apps, but we will focus on just making sure your review apps are not costing you any money (example for a Rails app):


{
  "environments": {
    "review": {
      "addons": ["heroku-postgresql:hobby-dev"],
      "scripts": {
        "postdeploy": "bundle exec rake db:schema:load"
      },
    "formation": {
      "web": {
        "quantity": 1,
        "size": "free"
        }
      }
    }
  }
}

Put it into practice!

Now, you can leverage Heroku’s pipelines to streamline your CI/CD workflow, getting the most out of your available tools and ensuring your review apps will remain in Heroku’s free tier.

Thanks for reading! For Comments, questions, or follow-ups you can reach me on Twitter as @eduardo_gtzp.

0 Shares: