Introduction
This post is #4 of my Python Heroku Tutorial Series. In this Heroku tutorial, I will talk about how to setup Heroku pipeline and how to use it.
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
Heroku review app now only work with Github and it is not required in most cases (we can use different tests to make sure code work fine)
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 feature to master branch, we would push the code to Gitlab.
Gitlab CI would check code style, run unittests, live tests to make sure all feature works fine.
If commit pass the CI, the code would be deployed to
staging app
of Heroku pipelineWe 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 sould 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.
Conclusion
In this Heroku tutorial, I talked about how to use Heroku pipeline in your project and if you still have question, please feel free to contact.
Top comments (0)