Why?
Running the Heroku CLI on Docker gives us access to the CLI without needing to install Node and the associated packages on a personal computer.
How does it work?
Using the dickeyxxx/heroku-cli image we can run the CLI as follows:
docker run --envfile=.env dickeyxxx/heroku-cli heroku <cmd> -a $HEROKU_APP_NAME
Using it on Bitbucket
Using the Heroku CLI in a Bitbucket pipeline will allow additional commands to be run for apps. The deploy pipe doesn’t support running these additional commands.
Let’s say in the latest commit to a Django project there may have been model
changes. This means the migrate command needs to be run to update the
database tables. We can use dickeyxxx/heroku-cli to run the command as follows:
step:
script:
...
- docker run -e HEROKU_API_KEY=$HEROKU_API_KEY dickeyxxx/heroku-cli heroku run python manage.py migrate -a $HEROKU_APP_NAME
services:
- docker
What about image size?
The compressed image is 360MB in size. While not huge for a Docker image, it would be nice to have it smaller to reduce the amount of bandwidth used which will make the builds more energy efficient.
I tried to build a smaller image first using the alpine flavour of Node, but it didn’t
have the required pgp packages, so I tried the slim flavour instead. The compressed
image size was 330MB, so there was very little saving.
Hosting the image
If we wanted to use that new image we’d need to host the image on a publicly available URL.
My first thought was Docker Hub, but it has a restricition that only allows one access key to be generated for free accounts. I then took a look into GitHub Container Registry (GCR).
By following the documentation it was easy to get the image into the registry. However, due to the small reduction in image size I decided against this as a long term solution.