Skip to content
Latchkey

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_KEY in 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: main

Gotchas

  • container:login reads HEROKU_API_KEY from the environment, so never echo it into logs.
  • A push without a following container:release builds the slug but never goes live.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →