Introduction

I’ve created a very minimalistc repository to show, how to deploy Go code to Heroku using GitLab CI.

Automatically triggered on push/merge:

How-To

  1. Create a new Heroku Pipeline.

    New Pipeline

  2. Set up as many Heroku apps in this pipeline as you need (e.g. staging and production).

    Pipeline

  3. git clone this repository or copy whatever you need.

  4. Get your Heroku API key found in your account.

    API Key

  5. Set the key as the variable HEROKU_API_KEY in your GitLab CI / CD Settings.

    CI/CD Variables

  6. Modify .gitlab-ci.yml and change the existing app name (-app=gitlab-heroku-deploy-*) to your newly created apps.

Hints

  • Heroku uses the $PORT environment variable (see main.go)
  • In this setup, Heroku knows what to deploy based on the modified Gopkg.toml (see buildpack for alternatives)

    [metadata.heroku]
    root-package = "gitlab.com/sj14/go-heroku"
    

Further Reading