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

cmd/go: go1.11 failed to derive $GOPATH in container environment #27468

Closed
rockmenjack opened this issue Sep 3, 2018 · 5 comments
Closed

cmd/go: go1.11 failed to derive $GOPATH in container environment #27468

rockmenjack opened this issue Sep 3, 2018 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rockmenjack
Copy link

What version of Go are you using (go version)?

go 1.11

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

linux amd64

What did you do?

go test/build a module in a container

What did you expect to see?

command shall run without any issue

What did you see instead?

go complains "missing $GOPATH"

I have checked go env output in the container:

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""             <--  empty here!!!
GOPROXY=""
GORACE=""
GOROOT="/root/go"
GOTMPDIR=""
GOTOOLDIR="/root/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build579993932=/tmp/go-build -gno-record-gcc-switches"

go env looks ok in the host:

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/rockmen1/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/rockmen1/go"    <--   however this dir does not exist
GOPROXY=""
GORACE=""
GOROOT="/tmp/go"
GOTMPDIR=""
GOTOOLDIR="/tmp/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-build691156100=/tmp/go-build -gno-record-gcc-switches"

Can be easily reproduce with below Dockerfile:

#FROM centos:7
FROM debian:9

ADD go1.11.linux-amd64.tar.gz /root

CMD GOROOT=/root/go /root/go/bin/go env

older go version runs fine.

@mfrw
Copy link
Contributor

mfrw commented Sep 3, 2018

The issue #17262 might help you in understanding why host shows $GOPATH as a non-existent directory.

@andybons andybons changed the title go1.11 failed to derive $GOPATH in container environment cmd/go: go1.11 failed to derive $GOPATH in container environment Sep 5, 2018
@andybons
Copy link
Member

andybons commented Sep 5, 2018

@bcmills

@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 5, 2018
@andybons andybons added this to the Unplanned milestone Sep 5, 2018
@bcmills
Copy link
Contributor

bcmills commented Sep 5, 2018

go test/build a module in a container

older go version runs fine.

These can't both hold, can they? Older go versions don't support modules.

@rockmenjack
Copy link
Author

These can't both hold, can they? Older go versions don't support modules.

True. That's why go 1.11 shall not complain missing $GOPATH when modules is used, but it did in the container case where GOPATH is empty.

@bcmills
Copy link
Contributor

bcmills commented Jan 17, 2019

In Go 1.12, you will need to set either $HOME, or both $GOCACHE and $GOPATH (see #29267).

Environments without $HOME are pretty clearly in power-user territory, so the need for a bit of configuration should not come as a big surprise.

@bcmills bcmills closed this as completed Jan 17, 2019
@golang golang locked and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants