Skip to content

Instantly share code, notes, and snippets.

@jcloutz
Last active December 6, 2022 11:20
Show Gist options
  • Save jcloutz/a9831d60aefb5e6ca29fd7848a230467 to your computer and use it in GitHub Desktop.
Save jcloutz/a9831d60aefb5e6ca29fd7848a230467 to your computer and use it in GitHub Desktop.
Example Gitlab CI setup for Go using the official golang docker image
image: golang:1.7
stages:
- build
- test
before_script:
- go get github.com/tools/godep
- cp -r /builds/user /go/src/github.com/user/
- cd /go/src/github.com/user/repo
build-my-project:
stage: build
script:
- godep restore
- godep go build
test-my-project:
stage: test
script:
- godep restore
- godep go test -v -cover ./...
@maestrofx
Copy link

Hi @jcloutz, instead of using golang images (golang:1.7) which is derived from Debian source giving you 255 MB in size every build and test based on new commit, I recommend you use golang alpine (golang:1.7-alpine), contrast in size (73MB).
You can compare which image fit in you here: https://hub.docker.com/r/library/golang/tags/

Thank you.

@aurelienrb
Copy link

aurelienrb commented Jul 25, 2017

If you use the Alpine image then also you need to install git (required by go get):

before_script:
  - apk add --update git

@jgillich
Copy link

A better solution is to use a soft link:

    - ln -s /builds /go/src/gitlab.com

@kingcrunch
Copy link

You should indeed use symlinks instead of cp, else artifacts and cache are more difficult to use reliable.

Additionally:

  - cd /go/src/gitlab.com/${CI_PROJECT_PATH}

Makes it easier to reuse and it still works after moving a project.

@sandipb
Copy link

sandipb commented Feb 15, 2018

Don't use symlinks. Various tools like go test, etc. ignore symlinks

@BimaPanduW
Copy link

anyone has deployment job example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment