我使用gitlab-ci来测试,编译和部署一个小型golang应用程序,但问题是阶段花费的时间比必要的长,因为它们每次都必须获取所有依赖项。
如何在两个阶段(测试和构建)之间保持golang依赖关系?
这是我当前的gitlab-ci配置的一部分:
test:
stage: test
script:
# get dependencies
- go get github.com/foobar/...
- go get github.com/foobar2/...
# ...
- go tool vet -composites=false -shadow=true *.go
- go test -race $(go list ./... | grep -v /vendor/)
compile:
stage: build
script:
# getting the same dependencies again
- go get github.com/foobar/...
- go get github.com/foobar2/...
# ...
- go build -race -ldflags "-extldflags '-static'" -o foobar
artifacts:
paths:
- foobar
Run Code Online (Sandbox Code Playgroud)