Skip to content

Instantly share code, notes, and snippets.

@reedsa
Last active September 15, 2017 16:01
Show Gist options
  • Save reedsa/6ce22b9a1a271d73b2f1121cb58da464 to your computer and use it in GitHub Desktop.
Save reedsa/6ce22b9a1a271d73b2f1121cb58da464 to your computer and use it in GitHub Desktop.

Introduction to Heroku Pipelines

A pipeline in Heroku creates a continuous delivery workflow for a single application codebase. It creates a grouping of application instances for different environments that represent various stages of a continuous delivery workflow.

The explicit stages defined in a pipeline are:

  • Review
  • Development
  • Staging
  • Production

An application running multiple codebases might have multiple pipelines. For example, an application that involves a frontend user interface and a backend service would have one pipeline for the frontend and a separate pipeline for the backend.

Features

  • Connect with a GitHub Repository
  • Continuous Integration and Testing
  • Automatic Deployments
  • Review Apps
Costs

Each pipeline with CI enabled costs $10 per month, plus the cost of each dyno spun up to run tests. The cost of a dyno is prorated to the second so usually testing has minimal extra costs associated with them.

The number of apps in a pipeline is limited to the maximum allowed by your plan.

Create a Pipeline

Log into the Heroku dashboard, click the New menu and then click Create new pipeline.

  • Come up with a unique name for the pipeline
  • Make sure to select the correct owner
  • Connect the pipeline to a GitHub repository

Pipeline Dashboard

Now each stage of the pipeline is displayed and apps can be added at this time. The available stages defined by Heroku are:

  • Review Apps
  • Development (Hidden by default)
  • Staging
  • Production

You can add multiple apps to any stage to create as many running instances of the application as you like. This means a couple different apps can be running in the same stage with different configurations.

To add an app to one of the stages in the pipeline, click on "Add App...". If the app does not yet exist it can be created easily through this dashboard or through any other preferred method such as the CLI.

Configure Automatic Deploys and Testing

With an application configured with a particular stage in the pipeline, you can configure the pipeline to automatically deploy the app when changes are merged into a branch.

An app running in staging might automatically deploy master whenever something is merged. It is also useful to check the box that states "Wait for CI to pass before deploy". This will run your tests using the Continuous Integration service configured for your project and ensure they pass before deploying the branch to the app. CI is not limited to HerokuCI but can rely on any service that is configured with your GitHub repository.

Tests

The pipeline includes a tab for recent test runs associated with the apps in the pipeline. Each run includes the option to rerun the tests with or without caching if necessary.

Promote to Production

There are a couple of ways to push code to production. If deploying the latest commit on master is not a concern, manual deployments of master to the production app might work best for your workflow.

Heroku pipelines offers promotions between stages so that whatever was last deployed can easily be pushed to the downstream stage. In the case that you are running an app in staging and another app in production, a "Promote to production..." button will appear alongside the staging app. Heroku saves what is called a "slug" for a prepackaged copy of the latest deployment to the staging app. Promoting to production simply extracts the slug in the production environment.

Review Apps

Review apps are great for reviewing pull requests or quickly deploying a contained environment that offers a temporary URL to easily demonstrate new features to stakeholders. When enabled, review apps can create apps for all open pull requests automatically. It also has a nice feature to destroy stale apps when pull requests are left open and not deployed for longer than five days.

Debugging

You can start a debugging session through the CLI within your code repository. Run heroku ci:debug --pipeline pipeline-name but replace pipeline-name with the name of the pipeline.

Known Issues

I've encountered a few problems with Heroku Pipelines in the few months I've used it. It is still relatively new so I'm hoping it improves and gains more features as it matures.

  • There is no API that provides access to test results and other information.
  • Sometimes the pipeline dashboard gets out of sync. If that happens, usually refreshing the page fixes it.
  • I've had issues with GitHub and Heroku losing track of the webhook for tests. Sometimes I can simply go into the Heroku Pipeline Tests tab and rerun the test and GitHub will pick it back up and once again show the results in the pull request. At one point, I had to remove the webhook entirely and click the button to reconnect the GitHub project to the pipeline.

Alternatives

In general, HerokuCI is great for projects to quickly get set up with CI and CD. When it comes to customizing the runtime environment and debugging it seems to fall short. Continuous Integration and Deployment schemes can also be implemented using CircleCI, TravisCI, Jenkins, and so on.

For CircleCI, depending on the number of containers available you may experience bottlenecks when changes are being tested across many pull requests and projects. To my knowledge, CircleCI does not offer insight into what has been deployed to various environments. Even with these shortcomings, it may be a better solution for your specific use case.

Further Information

Look at the Documentation on Heroku's Dev Center for further details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment