Create a CI/CD pipeline to automate testing and bringing our cube app to production, because this thing just has to be shared with the whole world:
- Install Docker
- Open a Heroku account
- Install Heroku's CLI
This repository contains:
- A basic Express application
- A prepared Dockerfile which contains said application and its dependencies
- Basic tests that can be ran with
npm test
- Two YAML definitions with placeholders for the workflows we will be creating, under .github/workflows
The two workflows you need to create are:
- When a pull request is opened, run tests – pr-workflow.yaml
- When pushing to master, repeat the pull request steps + deploy to Heroku – on-merge-workflow.yaml
- We want to protect our master branch from code that fails tests. Make the pr-workflow required!
- Create an additional app in Heroku, "cube-staging", and deploy to it only if the PR title includes a
[stage]
prefix
For your GitHub workflows to work with Heroku, they will need to authenticate against Heroku's API. To generate a token, run heroku login
and then heroku auth:token
.
We suggest following security best practices and storing this token as an encrypted secret and not hardcoding it in the workflow YAML definitions. The same article includes instructions on how to access secrets from within workflows.
You might want to combine this functionality with the fact that Heroku's CLI first looks for an environment variable called HEROKU_API_KEY.
A quick Google search will reveal that there are multiple ways of deploying a Dockerfile to Heroku. One straigthforward solution is to simply use the commands provided inside the Container Registry section, under the application's Deploy tab:
You can search for steps to include in your workflows here: https://github.com/marketplace?type=actions