containers / buildah

A tool that facilitates building OCI images.
https://buildah.io
Apache License 2.0
7.37k stars 781 forks source link

Match docker behavior for `ADD` and `COPY` with globs if no file matches #5742

Open thmo opened 1 month ago

thmo commented 1 month ago

Trying to build with this Dockerfile:

from scratch
COPY non[e]xistant .

Describe the results you received:

$ buildah bud
STEP 1/2: FROM scratch
STEP 2/2: COPY non[e]xistant .
Error: building at STEP "COPY non[e]xistant .": checking on sources under "/tmp/u": Rel: can't make  relative to /tmp/u; copier: stat: ["/non[e]xistant"]: no such file or directory

Describe the results you expected:

Match current Docker behavior: COPY should not fail if there is not at least one file to copy.

Output of rpm -q buildah or apt list buildah: buildah-1.37.1-1.fc40.x86_64

Output of buildah version:

Version:         1.37.1
Go Version:      go1.22.6
Image Spec:      1.1.0
Runtime Spec:    1.2.0
CNI Spec:        1.1.0
libcni Version:  
image Version:   5.33.1
Git Commit:      
Built:           Thu Aug 15 21:59:01 2024
OS/Arch:         linux/amd64
BuildPlatform:   linux/amd64
nalind commented 1 month ago

Yeah, this one's a surprise. Note to self: need to check if the docker build behavior depends on whether or not the glob includes wildcards or metacharacters, or if it's just always like that now.

github-actions[bot] commented 1 week ago

A friendly reminder that this issue had no activity for 30 days.

rhatdan commented 6 days ago

@nalind What should we do with this one? Is there a difference between docker with and without buildkit?

nalind commented 5 days ago

@rhatdan yes, depending on whether I set DOCKER_BUILDKIT to 0 or 1, this may or may not produce an error:

mkdir /tmp/glob; (echo FROM scratch; echo 'COPY b* .') > /tmp/glob/Dockerfile
docker build /tmp/glob
rhatdan commented 5 days ago

Since we only want to match BUILDKIT, behavior, I take it Buildkit ignores no match?

nalind commented 5 days ago

I tend to prefer offering an API toggle for the sake of tools that use us as a library. In this case, in my experience, if the source does not include any characters which would be treated as special (e.g., replace b* with b in the above example), an error is still produced.

mhkarimi1383 commented 1 day ago

Hi

I'm having the same problem while trying to copy files that my not exists