Commit 65fd3367 authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Léo-Paul Géneau

golang: Fix it to keep per-workspace bits inside go.work/

And not globally inside slapuser $HOME (which is go builtin default).

`go env` output: before:

    (go.work) slapuser34@vifibcloud-rapidspace-hosting-007:~/srv/runner$ go env
    GO111MODULE=""
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/srv/slapgrid/slappart34/.cache/go-build"
    GOENV="/srv/slapgrid/slappart34/.config/go/env"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOINSECURE=""
    GONOPROXY=""
    GONOSUMDB=""
    GOOS="linux"
    GOPATH="/srv/slapgrid/slappart34/srv/runner/software/09b17891535725b7c44e64fb2e856ebe/go.work"
    GOPRIVATE=""
    GOPROXY="https://proxy.golang.org,direct"
    GOROOT="/srv/slapgrid/slappart34/srv/runner/shared/golang1.14/da4c5c8222d5573da4d0e547cfc1793e"
    GOSUMDB="sum.golang.org"
    GOTMPDIR=""
    GOTOOLDIR="/srv/slapgrid/slappart34/srv/runner/shared/golang1.14/da4c5c8222d5573da4d0e547cfc1793e/pkg/tool/linux_amd64"
    GCCGO="gccgo"
    AR="ar"
    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-build196479275=/tmp/go-build -gno-record-gcc-switches"

after:

    (go.work) slapuser34@vifibcloud-rapidspace-hosting-007:~/srv/runner$ go env
    GO111MODULE=""
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/srv/slapgrid/slappart34/srv/runner/software/09b17891535725b7c44e64fb2e856ebe/go.work/cache"
    GOENV="/srv/slapgrid/slappart34/srv/runner/software/09b17891535725b7c44e64fb2e856ebe/go.work/goenv"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOINSECURE=""
    GONOPROXY=""
    GONOSUMDB=""
    GOOS="linux"
    GOPATH="/srv/slapgrid/slappart34/srv/runner/software/09b17891535725b7c44e64fb2e856ebe/go.work"
    GOPRIVATE=""
    GOPROXY="https://proxy.golang.org,direct"
    GOROOT="/srv/slapgrid/slappart34/srv/runner/shared/golang1.14/da4c5c8222d5573da4d0e547cfc1793e"
    GOSUMDB="sum.golang.org"
    GOTMPDIR=""
    GOTOOLDIR="/srv/slapgrid/slappart34/srv/runner/shared/golang1.14/da4c5c8222d5573da4d0e547cfc1793e/pkg/tool/linux_amd64"
    GCCGO="gccgo"
    AR="ar"
    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-build233719895=/tmp/go-build -gno-record-gcc-switches"

i.e. we change $GOCACHE and $GOENV to be per-workspace:

    --- a/goenv.before
    +++ b/goenv.after
    @@ -1,8 +1,8 @@
     GO111MODULE=""
     GOARCH="amd64"
     GOBIN=""
    -GOCACHE="/srv/slapgrid/slappart34/.cache/go-build"
    -GOENV="/srv/slapgrid/slappart34/.config/go/env"
    +GOCACHE="/srv/slapgrid/slappart34/srv/runner/software/09b17891535725b7c44e64fb2e856ebe/go.work/cache"
    +GOENV="/srv/slapgrid/slappart34/srv/runner/software/09b17891535725b7c44e64fb2e856ebe/go.work/goenv"
     GOEXE=""
     GOFLAGS=""
     GOHOSTARCH="amd64"

Explanation:

- Starting from Go1.10 the go command maintains cache for built packages, test results, etc:

  https://golang.org/doc/go1.10#build

  while this cache tries to remember by which go version and in which
  environment a package was built, and reusing the cached entry only when it is
  indeed correct to do so, by keeping this cache in a shared place - not per go
  workspace - we expose it to interactions with other go installments, which,
  due to e.g. software bugs might misbehave.

  -> keeping the build cache inside go workspace makes things more safe.

- Starting from Go1.13 the go command allows to keep its configuration and environment inside a file:

  https://golang.org/doc/go1.13#go-env-w
  https://go.googlesource.com/proposal/+/master/design/30411-env.md

  The default location for such file is per-user, which can bring
  misinteraction among several go workspace installments and wrt system go
  installment.

  -> move this configuration file into inside go workspace.

/reviewed-by: TrustMe
parent abecf223
......@@ -111,7 +111,7 @@ recipe = slapos.recipe.template
url = ${:_profile_base_location_}/goenv.sh.in
output = ${gowork:directory}/env.sh
depends = ${gowork.mkdir:recipe}
md5sum = 6bcf96cf18ea68ce6e378ed8d49346a3
md5sum = f89553711ea95ad1f6727b76747a62bf
[gowork.mkdir]
# NOTE do not use slapos.cookbook:mkdirectory here - if anything in software (not instance)
......
......@@ -12,6 +12,8 @@ export PKG_CONFIG_PATH=$(echo -n "${gowork:cpkgpath}" |tr '\n' ':'):$PKG_CONFIG_
export GOPATH=$X:$GOPATH
export PATH=$X/bin:$PATH
export PS1="(`basename $X`) $PS1"
export GOCACHE=$X/cache
export GOENV=$X/goenv
# strip trailing : from $GOPATH, $PKG_CONFIG_PATH
GOPATH=$${GOPATH%:}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment