Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set GOCACHE and fix perms to avoid permissions errors #261

Closed
wants to merge 2 commits into from
Closed

Set GOCACHE and fix perms to avoid permissions errors #261

wants to merge 2 commits into from

Conversation

crazy-max
Copy link

On some CI environments like Jenkins, cache could not be used due to permission errors. Here is a simple POC with a pipeline stage :

stage("Test") {
  docker.image('golang:1.11.5').inside {
    sh '''
    go version
    go mod download
    go get -u github.com/jstemmer/go-junit-report
    go get -u github.com/t-yuki/gocover-cobertura
    go test -coverprofile=bin/coverage.out -v ./...
    go test -json ./... > bin/report.json
    go test -v ./... 2>&1 | go-junit-report > bin/junit.xml
    gocover-cobertura < bin/coverage.out > bin/cobertura.xml
    '''
  }
}

This stage leads to :

[Pipeline] sh
+ go version
go version go1.11.5 linux/amd64
+ go mod download
go: disabling cache (/.cache/go-build) due to initialization failure: mkdir /.cache: permission denied
go: cannot use modules with build cache disabled
[Pipeline] }
$ docker top b511f686685e39732d3aad9486a66380632397aafe1ca3bf6eb2ce918e0aeba3 -eo pid,comm
$ docker stop --time=1 b511f686685e39732d3aad9486a66380632397aafe1ca3bf6eb2ce918e0aeba3
$ docker rm -f b511f686685e39732d3aad9486a66380632397aafe1ca3bf6eb2ce918e0aeba3

My current workaround sets GOCACHE to /tmp :

stage("Test") {
  docker.image('golang:1.11.5').inside('-e "GOCACHE=/tmp"') { c ->
    sh '''
    go version
    go mod download
    go get -u github.com/jstemmer/go-junit-report
    go get -u github.com/t-yuki/gocover-cobertura
    go test -coverprofile=bin/coverage.out -v ./...
    go test -json ./... > bin/report.json
    go test -v ./... 2>&1 | go-junit-report > bin/junit.xml
    gocover-cobertura < bin/coverage.out > bin/cobertura.xml
    '''
  }
}

@tianon
Copy link
Member

tianon commented Jan 25, 2019

Hmm, I hesitate to set a default here because it could mess up users, especially if they're already relying on the default of it being based on the value of $HOME (which would change depending on what user they run or build the image as).

@crazy-max
Copy link
Author

@tianon Maybe we can rely on go env to take the default value ?

$ env

HOSTNAME=128fa8ec9532
HOME=/root
TERM=xterm
PATH=/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
GOPATH=/go
PWD=/go
GOLANG_VERSION=1.11.5

$ go env

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build206706691=/tmp/go-build -gno-record-gcc-switches"

@tao12345666333
Copy link
Contributor

tao12345666333 commented Feb 26, 2019

Hmm, I hesitate to set a default here because it could mess up users, especially if they're already relying on the default of it being based on the value of $HOME (which would change depending on what user they run or build the image as).

+1 👍

I don't think we should add default values to the base image.Users can set it up as needed.

xref: golang/go#29267
golang/go#29267 (comment)

@crazy-max crazy-max closed this May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants