Django Heroku Tutorial Series:
- Heroku vs AWS Which is Best for Your Django project
- How to deploy Django project to Heroku using Docker
- How to deploy Python project to Heroku in Gitlab CI
- How to use Heroku Pipeline
- Heroku Logs Tutorial
- How to monitor Heroku Postgres using heroku-pg-extras
Django Dokku Tutorial Series:
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.
- When we merge some merge request to main branch, we would push the code to Gitlab.
- Gitlab CI would check code style, run tests to make sure all feature works fine.
- If commit pass the CI, the code would be deployed to
staging app
of Heroku pipeline - We can do some manual tests and check if the function work fine (this step is not required in some cases)
- If we think the commit is good to go, we can promote the code from
staging app
toproduction 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:
- Heroku vs AWS Which is Best for Your Django project
- How to deploy Django project to Heroku using Docker
- How to deploy Python project to Heroku in Gitlab CI
- How to use Heroku Pipeline
- Heroku Logs Tutorial
- How to monitor Heroku Postgres using heroku-pg-extras
Django Dokku Tutorial Series: