How to Deploy to Heroku With CircleCI
Authenticate with a Heroku API key, then heroku container:push and heroku container:release deploy the image to a named app.
Set HEROKU_API_KEY in a context, log in to the container registry, push the image, and release it to roll out the deploy.
Steps
- Store
HEROKU_API_KEYin a context. - Run
heroku container:login. - Push with
heroku container:push web -a <app>. - Release with
heroku container:release web -a <app>.
Config
.circleci/config.yml
version: 2.1
jobs:
deploy:
docker:
- image: cimg/base:2024.03
steps:
- checkout
- setup_remote_docker
- run:
name: Deploy to Heroku
command: |
curl https://cli-assets.heroku.com/install.sh | sh
heroku container:login
heroku container:push web -a "$HEROKU_APP"
heroku container:release web -a "$HEROKU_APP"
workflows:
ship:
jobs:
- deploy:
context: heroku
filters:
branches:
only: mainGotchas
container:loginreadsHEROKU_API_KEYfrom the environment, so never echo it into logs.- A push without a following
container:releasebuilds the slug but never goes live.
Related guides
How to Deploy to a VPS Over SSH With CircleCIDeploy to a remote VPS from CircleCI by adding a deploy SSH key, then running a remote script over ssh to pul…
How to Deploy to Google Cloud Run With CircleCIDeploy a container to Google Cloud Run from CircleCI by authenticating a service account, then running gcloud…