How to use Heroku Pipeline

Table of Contents

Django Heroku Tutorial Series:

  1. Heroku vs AWS Which is Best for Your Django project
  2. How to deploy Django project to Heroku using Docker
  3. How to deploy Python project to Heroku in Gitlab CI
  4. How to use Heroku Pipeline
  5. Heroku Logs Tutorial
  6. How to monitor Heroku Postgres using heroku-pg-extras

Django Dokku Tutorial Series:

  1. How to deploy Django project to Dokku
  2. How to deploy Django project to Dokku with Docker

Introduction

A Heroku pipeline is a group of Heroku apps that share the same codebase. Each app in a pipeline represents one of the following stages in a continuous delivery workflow

  • Development
  • Review
  • Staging
  • Production

Workflow with Gitlab

There are some different ways to use Heroku pipeline, here is my workflow and hope it can inspire you.

  1. When we merge some merge request to main branch, we would push the code to Gitlab.
  2. Gitlab CI would check code style, run tests to make sure all feature works fine.
  3. If commit pass the CI, the code would be deployed to staging app of Heroku pipeline
  4. We can do some manual tests and check if the function work fine (this step is not required in some cases)
  5. If we think the commit is good to go, we can promote the code from staging app to production app

staging app and production app share the same code (in some cases, code version in staging app might be a little newer), but they have different env resources (database, AWS S3 bucket, domain name and other config vars)

Create Heroku Pipeline in Heroku dashboard

In heroku dashboard, make sure you already have Heroku app, then add it to a new Heroku pipeline you can do that in app's Deploy tab

After you are done, you can see the pipeline in your Heroku Dashboard and you can keep adding a new Heroku app to pipeline as production app

Create Heroku Pipeline in Heroku CLI

$ heroku pipelines:create -a django-heroku-docker

? Pipeline name django-heroku
? Stage of django-heroku-docker staging
Creating django-heroku pipeline... done
Adding ⬢ django-heroku-docker to django-heroku pipeline as staging... done

If you want to add Heroku app to pipeline

$ heroku pipelines:add django-heroku -a django-heroku-docker-production

How to promote staging app

When you test the version on your staging app and seems it is good to deploy to production app, you can just click Promote to production... on pipeline page.

The code would be deployed to production app automatically.

Please note that if you are using docker to deploy your project, the above promote button might not work in some cases. To solve this problem, you can define the promote work as manual work in CI. (or let CI auto deploy prod branch to production app)

Some tips

To avoid operation mistake, it is better to make your Heroku app have the right suffix.

For example, you are developing a project whitewave, the staging app has name whitewave-staging and production app has name whitewave-prod.

What you should keep in mind

When you start using Heroku pipelines, you should know two Heroku apps and relevant resources could cost you more money than single Heroku app.

But the pipeline can make sure every commit has been tested before deployed to your production site, it reduced the risk, that is why I recommend you to give it a try.

Django Heroku Tutorial Series:

  1. Heroku vs AWS Which is Best for Your Django project
  2. How to deploy Django project to Heroku using Docker
  3. How to deploy Python project to Heroku in Gitlab CI
  4. How to use Heroku Pipeline
  5. Heroku Logs Tutorial
  6. How to monitor Heroku Postgres using heroku-pg-extras

Django Dokku Tutorial Series:

  1. How to deploy Django project to Dokku
  2. How to deploy Django project to Dokku with Docker
Launch Products Faster with Django

SaaS Hammer helps you launch products in faster way. It contains all the foundations you need so you can focus on your product.

Michael Yin

Michael is a Full Stack Developer from China who loves writing code, tutorials about Django, and modern frontend tech.

He has published some ebooks on leanpub and tech course on testdriven.io.

He is also the founder of the AccordBox which provides the web development services.

Django SaaS Template

It aims to save your time and money building your product

Learn More

Hotwire is the default frontend solution shipped in Rails, this book will teach you how to make it work with Django, you will learn building modern web applications without using much JavaScript.

Read More
© 2018 - 2024 AccordBox