Updated on 2019-03-09: Using
go mod instead of
I’ve created a very minimalistc repository to show, how to deploy Go code to Heroku using GitLab CI.
Automatically triggered on push/merge:
Create a new Heroku Pipeline.
Set up as many Heroku apps in this pipeline as you need (e.g. staging and production).
git clone this repository or copy whatever you need.
Get your Heroku API key found in your account.
Set the key as the variable
HEROKU_API_KEY in your GitLab CI / CD Settings.
.gitlab-ci.yml and change the existing app name (
-app=gitlab-heroku-deploy-*) to your newly created apps.
In this setup, Heroku knows what to deploy based on the modified
go.mod file (see buildpack for alternatives):
// +heroku install .
This is not required here, and
. is the default, but when your main file is in a different folder, you have to give the corresponding path instead of the
Procfiledecides which command should be run. Again, in this setup it’s not required as the binary is the same as the project name. When you have to run another command, change the command after
web:accordingly (The Procfile).
See the using-godep branch for an example using
dep instead of go modules.