Created
December 17, 2020 16:42
-
-
Save adefemi171/d45d516d3d5a6cfc289ad7e9b5abfdd8 to your computer and use it in GitHub Desktop.
GitLab config for Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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