Created
May 13, 2021 17:36
-
-
Save CypherpunkSamurai/3c7da6b45511e1ba8dd1105513c8091f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# CI-CD Quickstart | |
## GitLab | |
* Go: | |
**Default CI:** | |
```yml | |
# This file is a template, and might need editing before it works on your project. | |
image: golang:latest | |
variables: | |
# Please edit to your GitLab project | |
REPO_NAME: gitlab.com/namespace/project | |
# The problem is that 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: | |
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME) | |
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME | |
- cd $GOPATH/src/$REPO_NAME | |
stages: | |
- test | |
- build | |
- deploy | |
format: | |
stage: test | |
script: | |
- go fmt $(go list ./... | grep -v /vendor/) | |
- go vet $(go list ./... | grep -v /vendor/) | |
- go test -race $(go list ./... | grep -v /vendor/) | |
compile: | |
stage: build | |
script: | |
- go build -race -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/mybinary | |
artifacts: | |
paths: | |
- mybinary | |
``` | |
**Go Build and Run CI:** | |
```yml | |
stages: | |
- build | |
build: | |
stage: build | |
image: golang:1.9.2 | |
before_script: | |
# Create a symbolic link under $GOPATH, this is needed for local build | |
# i.e. /go/src/gitlab.com/ykyuen/gitlab-ci-go-build | |
- cd $GOPATH/src | |
- mkdir -p gitlab.com/$CI_PROJECT_NAMESPACE | |
- cd gitlab.com/$CI_PROJECT_NAMESPACE | |
- ln -s $CI_PROJECT_DIR | |
- cd $CI_PROJECT_NAME | |
script: | |
# Compile and name the binary as `hello` | |
- go build -o hello | |
# Execute the binary | |
- ./hello | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment