I built a CLI to deploy to Heroku Container Registry
TL;DR: After copying and pasting the same bash script over and over, I decided to build a simple CLI to deploy my back-end services to Heroku Container Registry. The codebase is hosted on Github and you can find more details here.
As Software Engineers we try to automate as much as possible in order to remove repetitive tasks out of our way and be more productive. And deploying an application to production is certainly one of them.
Heroku deployment is rather easy once a repository is hosted on GitHub. But as most of my apps were kept in GitLab I lost that ease of deployment and had to build things myself.
When building a back-end service, my go-to is to encapsulate it in a Dockerfile so I can abstract infrastructure code while having the ability to run it in the same environment as I’d run once it is live. And I found it convenient to use Docker alongside Heroku Container Registry to deploy such services.
It’s important to say that most of my deployments to Heroku lived in a bash file which ran the following steps:
- Store app name, Heroku API keys, Docker image names in environment variables
- Login to Heroku container registry
- Build Docker image
- Tag and push Docker images to Heroku container registry
- Deploy new Heroku app via API call with new Docker image created in the previous step
Some of these steps are described and explained with more details in the Heroku Container Registry and Runtime docs and the only decision I made was to not use Heroku CLI on my deployments.
It would make sense to use it for one or two applications, but as of the time of this writing I’m currently hosting 26 services. Needless to say that copying and pasting the same script and storing all of those credentials simply doesn’t scale.
As I have mentioned in the beginning of this blog post:
we (Software Engineers) try to automate as much as possible in order to remove repetitive tasks out of our way and be more productive.
I would be lying if I say I’m no different. In fact, I actually like to build tools and libs that make my life easier :)
And for that reason, I created a simple CLI script that takes care of deploying any application contained in a Dockerfile to Heroku Container Registry.
The steps are relatively simple and I only need to set configuration variables:
npx mersocarlin-deployer \ --provider heroku \ --container-registry-host registry.heroku.com \ --container-registry-username <heroku-registry-username> \ --container-registry-password <heroku-registry-password> \ --dockerfile-path <path-to-Dockerfile> \ --heroku-app-name <heroku-app-name> \ --heroku-api-key <heroku-api-key>
The code is hosted on GitHub, feel free to check it out!
I hope that's helpful and interesting to you. 👋🏼
Did you know you can help me with this page?
Hemerson Carlin, also known as mersocarlin, is passionate and resourceful full-stack Software Engineer with 10+ years of experience focused on agile development, architecture and team building.
This is the space to share the things he likes, a couple of ideas and some of his work.