Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitlab ci cache/keep golang packages between stages

I use gitlab-ci to test, compile and deploy a small golang application but the problem is that the stages take longer than necessary because they have to fetch all of the dependencies every time.

How can I keep the golang dependencies between two stages (test and build)?

This is part of my current gitlab-ci config:

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
like image 235
irgendwr Avatar asked Aug 06 '17 22:08

irgendwr


1 Answers

As mentioned by Yan Foto, you can only use paths that are within the project workspace. But you can move the $GOPATH to be inside your project, as suggested by extrawurst blog.

test:
  image: golang:1.11
  cache:
    paths:
      - .cache
  script:
    - mkdir -p .cache
    - export GOPATH="$CI_PROJECT_DIR/.cache"
    - make test
like image 199
voiski Avatar answered Sep 22 '22 11:09

voiski