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

golang:1.10 mkdir /.cache/go-build/00: permission denied #225

Closed
wongoo opened this issue Jun 8, 2018 · 9 comments

Comments

Projects
None yet
5 participants
@wongoo
Copy link

commented Jun 8, 2018

FROM golang:1.10 will get the following error:

09:16:38 GOOS=linux go build -tags prod -ldflags='-w -s ' -o main
09:16:39 go: disabling cache (/.cache/go-build) due to initialization failure: mkdir /.cache/go-build/00: permission denied
@wglambert

This comment has been minimized.

Copy link

commented Jun 8, 2018

Could you give all the commands you ran and any relevant contextual information or files for reproducing the issue

@wglambert wglambert added the question label Jun 11, 2018

@wongoo

This comment has been minimized.

Copy link
Author

commented Jun 12, 2018

see test project

No error for directly running docker command:

docker run --rm \
  -w /go/src/$BASEDIR/$PROJECT \
  -v $(pwd):/go/src/$BASEDIR/$PROJECT \
  -it golang:1.10 \
  make build

The error occurs when running in jenkins:

docker.image('golang:1.10').inside {
  sh 'go version'
  sh 'pwd'
  sh 'env'
  sh 'mkdir -p $GOPATH/src/$BASEDIR; ln -sf `pwd` $GOPATH/src/$BASEDIR/$PROJECT'
  sh 'cd $GOPATH/src/$BASEDIR/* && make build'
}
@wglambert

This comment has been minimized.

Copy link

commented Jun 12, 2018

You could try Stack Overflow. This doesn't seem to be a golang problem but an issue with setting up jenkins, and you'd get better results by trying a forum for those questions.

@wongoo

This comment has been minimized.

Copy link
Author

commented Jun 15, 2018

@yosifkit

This comment has been minimized.

Copy link
Member

commented Jun 19, 2018

Closing since it seems to be related to jenkins setup and not the golang image.

@yosifkit yosifkit closed this Jun 19, 2018

@zevdg

This comment has been minimized.

Copy link

commented Jul 6, 2018

I'm not so sure this should be closed so fast. This is pretty easy to reproduce without jenkens. You just need try to build anything using the -u flag.

docker run -u $UID golang /bin/bash -c "cd /go/src/; mkdir hello; cd hello;
echo 'package main
import \"fmt\"
func main() {
    fmt.Println(\"hello world\")
}' > main.go; go run main.go"

The problem is that go assumes (not unreasonably) that you will have write access to $XDG_CACHE_HOME if it exists and $HOME/.cache if it does not
https://golang.org/src/cmd/go/internal/cache/default.go?s=2439:2657

It's even smart enough to turn off caching if $HOME=='', but unfortunately docker sets it to '/'

$ docker run -u $UID golang /bin/bash -c 'echo $HOME'
/

so go tries to mkdir /.cache (actually //.cache but the double slash gets cleaned up somewhere) and fails because you aren't running as root anymore.

The fix is to set XDG_CACHE_HOME to something that is universally writable like /tmp/.cache or something like that.

Alternatively, this could be fixed upstream if go were to disable caching when $HOME=='/' like it does for $HOME==''. I'll put in an issue to suggest it and see what they think.

@tianon

This comment has been minimized.

Copy link
Member

commented Jul 6, 2018

Good point and nice writeup, thanks; reopening.

@tianon

This comment has been minimized.

Copy link
Member

commented Jul 9, 2018

Just to follow up, the Go issue is at golang/go#26280, appears to be favorable by upstream, and has a CL now at https://golang.org/cl/122487. 🤘

@tianon

This comment has been minimized.

Copy link
Member

commented Jul 9, 2018

(Closing, since this is going to be resolved directly upstream. 👍)

@tianon tianon closed this Jul 9, 2018

@1138-4EB 1138-4EB referenced this issue Jan 1, 2019

Closed

[WIP] feat(BREAKING CH.): coding cleanup and v2.0.0 #575

47 of 48 tasks complete

fenxiong added a commit to fenxiong/amazon-ecs-agent that referenced this issue Apr 14, 2019

Fix broken make targets.
Go 1.12 enforces using cache and by default some of our build scripts will try to use /.cache as the cache directory which is not writable, and the scripts fail. See here for more details - docker-library/golang#225 (comment). Fixing by specifying Golang's cache directory to be under /tmp.

fenxiong added a commit to fenxiong/amazon-ecs-agent that referenced this issue Apr 14, 2019

Fix broken make target.
"make release" is failing because Go 1.12 enforces using cache and by default some of the build scripts will try to use /.cache as the cache directory which is not writable, and the scripts fail. See here for more details - docker-library/golang#225 (comment). Fixing by specifying Golang's cache directory to be under /tmp.

fenxiong added a commit to aws/amazon-ecs-agent that referenced this issue Apr 16, 2019

Fix broken make target.
"make release" is failing because Go 1.12 enforces using cache and by default some of the build scripts will try to use /.cache as the cache directory which is not writable, and the scripts fail. See here for more details - docker-library/golang#225 (comment). Fixing by specifying Golang's cache directory to be under /tmp.

proidiot added a commit to proidiot/pullcord that referenced this issue Apr 22, 2019

Changes golang build cache location
When using the golang Docker image as non-root, you don't have permissions to
create `/.cache/go-build` within the container. Presumably golang should check
have a more sane default build cache in such a situation. It sounds as though
this is indeed the behavior that has been pulled into upstream. However, it is
not clear why the behavior isn't fixed with current golang Docker image.
[Upstream bug](docker-library/golang#225)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.