-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: embed directory fails when at / #49570
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
Comments
This fails for 1.18rc1 as well (using root directory). Trying to learn a little here, seems to fail almost immediately in the build process. Shows truncating the leading / if it is in root. Here we are in "/ (root)":
Symlink fixes it.
I have been digging around, this code seems to fail when the pkgdir is "/".
I had thought I caused "go list all" to also fail, but after cleaning things up its seems to no longer fail in the same way. |
Hi, I have investigated about this issue. My guess:This issue would be caused by Detail:Reproduce and check the problem:First of all, I had confirmed ./
|- Dockerfile
|- main.go
|- go.mod
|- foo/
|- foo.txt main.go package main
import (
"embed"
"fmt"
)
//go:embed foo
var foo embed.FS
func main() {
// do something
} Dockerfile FROM golang:1.18-alpine
# git is required to run `go list`
RUN apk add git --no-cache
WORKDIR /
COPY ./ ./
CMD ["go", "list", "-f", "'pattern: {{.EmbedPatterns}}, files: {{.EmbedFiles}}'"] Result: EmbedPatterns are same in both cases. But EmbedFiles is different. So, some codes generating EmbedFiles would have a problem.
Read codes:I found a suspicious part in err := fsys.Walk(file, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
rel := filepath.ToSlash(path[len(pkgdir)+1:]) This function recursively walks around in the working directory, then picks up files. The files' paths are stored as Here, if dir == "" {
dir = base.Cwd()
}
dir, err = filepath.Abs(dir)
if err != nil {
base.Fatalf("%s", err)
}
bp, err := ctxt.ImportDir(dir, 0) The
Considering all above, the
https://go.dev/play/p/ySwcRSEYVd9 Solution (guess):So, solution could be adding an exception when If I have a time, I will challenge a bugfix. But it's the first time to try, so it will take a little long... |
I have fixed |
Change https://go.dev/cl/396694 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
I do not know
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Training for docker with go, I forked
github.com/olliefr/docker-gs-ping
and addedembed
directiveit worked fined in my working directory.
But when I configured Dockerfile for having everything at root, it did not work.
To reproduce the bug
What did you expect to see?
a successfull go build
What did you see instead?
A workaround is to have the WORKDIR different from "/"
The text was updated successfully, but these errors were encountered: