11

Deploy Go code to Heroku with GitLab CI

 3 years ago
source link: https://sj14.gitlab.io/post/2018/06-19-go-gitlab-heroku/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
2018-06-19

Introduction

Updated on 2019-03-09: Using go mod instead of dep.

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

Automatically triggered on push/merge:

  • golint
  • go tool vet
  • go test -race
  • deploy to staging (automatically)
  • deploy to production (manually)

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 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 ..

  • The Procfile decides 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).

    web: go-heroku
    

Older approach using godep

See the using-godep branch for an example using dep instead of go modules.

Further Reading


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK