Yesterday I was setting up a Gitlab CI/CD pipeline to deploy Docker containers to Heroku. Whilst it’s a fairly straightforward task, there are a few pitfalls, and I was surprised by the dearth of good tutorials which explained them.
So to successfully deploy a Docker container to Heroku, we have to do a number of things:
The Docker image needs to be built.
The Docker image needs to be pushed to Heroku.
The container needs to be released, at which point the new image will replace the existing service running on Heroku.
All of these steps are described in a .gitlab-ci.yml file, which is shown in full at the end of this document. The CI file breaks up the deployment logically into the three steps above:
Building the Docker image
The first thing that we need to do is create a Docker image. To do so, we first have to log in to the Gitlab registry, which is a store of Docker images. Having done so, we build the image, and then tag the image as “latest”.
The “image” entry in the code above refers to the base image of the environment which will be spun up in order to build our image. So we’re spinning up a Docker container, and then building the image inside it, before pusing it to the Gitlab registry. Got that?
The “docker:dind” service which is specified under “services” allows us to run the full Docker toolset from within a docker container. “DinD” stands for “Docker in Docker”.
Pushing our container to Heroku
Releasing our container
Here’s the full .gitlab-ci.yml file:
Hi! Welcome to the site. I'm an IT solutions specialist and technology lead from the UK.
This site is mostly a collection of articles on technical subjects - from reflections on topics which have come up during consultancy to blogs on projects which I've been working on in my spare time.
I also throw in fun stuff from time to time, like retrocomputing or hardware development.