Skip to content

Instantly share code, notes, and snippets.

@adefemi171
Created December 17, 2020 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adefemi171/d45d516d3d5a6cfc289ad7e9b5abfdd8 to your computer and use it in GitHub Desktop.
Save adefemi171/d45d516d3d5a6cfc289ad7e9b5abfdd8 to your computer and use it in GitHub Desktop.
GitLab config for Golang
# using Golang as the image
image: golang:latest
variables:
# Please edit to your GitLab project
REPO_NAME: gitlab.com/adefemi171/golang-webserver
# This section run before the job
# to be able to use go get, one needs to put
# the repository in the $GOPATH. So for example if your gitlab domain
# is gitlab.com, and that your repository is namespace/project, and
# the default GOPATH being /go, then you'd need to have your
# repository in /go/src/gitlab.com/namespace/project
# Thus, making a symbolic link corrects this.
before_script:
- echo "simple Golang Webserver"
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME
# Define a job stage and for this proj I have three stages
stages:
- build
- test
- run
# test-server is the job name and can be anything
test-server:
stage: test
script:
- go fmt $(go list ./... | grep -v /vendor/)
tags:
- docker
run-server:
stage: run
script:
- go run $(go list ./... | grep -v /vendor/)
tags:
- docker
server-build:
stage: build
script:
- go build -race -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/webserver
artifacts:
expire_in: 1 days
when: on_success
paths:
- webserver
tags:
- docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment