-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
macOS podman build fails with Dockerfile not in context #13561
Comments
I did a bit of digging myself and I believe the issue is related to the podman/pkg/bindings/images/build.go Line 566 in 4966add
I tried out this code and it seems to make the build work now: diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index c508cb767..cfba1efe0 100644
--- a/pkg/bindings/images/build.go
+++ b/pkg/bindings/images/build.go
@@ -557,6 +557,57 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
return
}
+ // define add file link process to be shared by walk process and single file processor
+ addFileLink := func(info os.FileInfo, filename string) error {
+ di, isHardLink := checkHardLink(info)
+ hdr, err := tar.FileInfoHeader(info, "")
+ if err != nil {
+ return err
+ }
+ hdr.Uid, hdr.Gid = 0, 0
+ orig, ok := seen[di]
+ if ok {
+ hdr.Typeflag = tar.TypeLink
+ hdr.Linkname = orig
+ hdr.Size = 0
+ hdr.Name = filename
+ return tw.WriteHeader(hdr)
+ }
+ f, err := os.Open(filename)
+ if err != nil {
+ return err
+ }
+
+ hdr.Name = filename
+ if err := tw.WriteHeader(hdr); err != nil {
+ f.Close()
+ return err
+ }
+
+ _, err = io.Copy(tw, f)
+ f.Close()
+ if err == nil && isHardLink {
+ seen[di] = filename
+ }
+ return err
+ }
+
+ // if source is a regular file, skip to process it
+ if info, err := os.Stat(s); err == nil && info.Mode().IsRegular() {
+ err = func() error {
+ excluded, err := pm.Matches(s) // nolint:staticcheck
+ if err != nil {
+ return err
+ }
+ if excluded {
+ return nil
+ }
+ return addFileLink(info, s)
+ }()
+ merr = multierror.Append(merr, err)
+ continue
+ }
+
err = filepath.Walk(s, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
@@ -577,41 +628,10 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
}
if info.Mode().IsRegular() { // add file item
- di, isHardLink := checkHardLink(info)
- if err != nil {
- return err
- }
-
- hdr, err := tar.FileInfoHeader(info, "")
+ err := addFileLink(info, name)
if err != nil {
return err
}
- hdr.Uid, hdr.Gid = 0, 0
- orig, ok := seen[di]
- if ok {
- hdr.Typeflag = tar.TypeLink
- hdr.Linkname = orig
- hdr.Size = 0
- hdr.Name = name
- return tw.WriteHeader(hdr)
- }
- f, err := os.Open(path)
- if err != nil {
- return err
- }
-
- hdr.Name = name
- if err := tw.WriteHeader(hdr); err != nil {
- f.Close()
- return err
- }
-
- _, err = io.Copy(tw, f)
- f.Close()
- if err == nil && isHardLink {
- seen[di] = name
- }
- return err
} else if info.Mode().IsDir() { // add folders
hdr, lerr := tar.FileInfoHeader(info, name)
if lerr != nil { Not sure if there would be other implications with this change though with other systems. |
before changes:
after changes:
|
thanks for the suggestion @Cameron-Kurotori I have a similar solution on my end and will push it to #13531 soon the issue is, we do want to skip the root dir sometimes but the way nTar is written we are skipping basically everything so I just made a quick patch to check for some particular cases. |
Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)
/kind bug
Description
On OSX (darwin) running
podman build
with the-f
pointing to a file that's outside the context directory tree, the build fails withno such file or directory
error. This issue also affects building from stdin (-f-
) for the same reason (since stdin is written to a tmp file)Steps to reproduce the issue:
Describe the results you received:
Describe the results you expected:
The image to build
Additional information you deem important (e.g. issue happens only occasionally):
Output of
podman version
:Output of
podman info --debug
:Package info (e.g. output of
rpm -q podman
orapt list podman
):Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/main/troubleshooting.md)
Yes
Additional environment details (AWS, VirtualBox, physical, etc.):
The text was updated successfully, but these errors were encountered: