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

COPY ./.git X command errors in buildx v0.13.1 #4777

Closed
dhedey opened this issue Mar 18, 2024 · 2 comments · Fixed by #4849
Closed

COPY ./.git X command errors in buildx v0.13.1 #4777

dhedey opened this issue Mar 18, 2024 · 2 comments · Fixed by #4849

Comments

@dhedey
Copy link

dhedey commented Mar 18, 2024

Summary

Until a recent upgrade, a command such as COPY ./.git /build-dir/.git was working fine. It's perhaps a little questionable copying a git folder into a docker image, but we were using it for builds, and our build script reads tag information from the git directory - so it's certainly defensible.

Now it errors with:

ERROR: failed to solve: source can't be a git ref for COPY
Error: buildx failed with: ERROR: failed to solve: source can't be a git ref for COPY

Using

/usr/bin/docker buildx version
  github.com/docker/buildx v0.13.1 788433953af10f2a698f5c07611dddce2e08c7a0

Likely cause

I believe this relates to #4142 - although I'm not sure why we've only just seen the issue now. Maybe it's taken a while for the release to hit our CI server, or maybe there's some other more recent update which has triggered this code path.

Specifically:

I think the fallback assumption that a path is https:// is too excessive. Basically any path ending .git would hit this issue.

As a workaround in our case, we might be able to do something like this: COPY ./.git/* /build-dir/.git/ but I still need to test this (cf moby/moby#15771)

@dhedey dhedey changed the title COPY of ./.git folder now errors COPY ./.git X command now errors Mar 18, 2024
@dhedey dhedey changed the title COPY ./.git X command now errors COPY ./.git X command now errors in buildx v0.13.1 Mar 18, 2024
@dhedey dhedey changed the title COPY ./.git X command now errors in buildx v0.13.1 COPY ./.git X command errors in buildx v0.13.1 Mar 18, 2024
@tonistiigi
Copy link
Member

#4776

@raylu
Copy link

raylu commented Mar 29, 2024

I don't think the above fixes it in general. we have a build context with an absolute path (/src.git)
so when we build

$ cat Dockerfile 
FROM alpine

COPY --from=src file /

this still breaks. it used to work in docker 24.0.5:

$ docker buildx version
github.com/docker/buildx v0.11.2 9872040b6626fb7d87ef7296fd5b832e8cc2ad17

but in docker 24.0.9 and 25.0.3,

 $ docker buildx version
github.com/docker/buildx v0.13.1 788433953af10f2a698f5c07611dddce2e08c7a0
~ $ docker buildx build --build-context src=/src.git .
[+] Building 0.2s (4/4) FINISHED                                                                                   docker:default
 => [internal] load local bake definitions                                                                                   0.0s
 => => reading Bakefile 246B / 246B                                                                                          0.0s
 => [internal] load build definition from Dockerfile                                                                         0.0s
 => => transferring dockerfile: 73B                                                                                          0.0s
 => [internal] load .dockerignore                                                                                            0.0s
 => => transferring context: 2B                                                                                              0.0s
 => CANCELED [internal] load metadata for docker.io/library/alpine:latest                                                    0.0s
Dockerfile:3
--------------------
   1 |     FROM alpine
   2 |     
   3 | >>> COPY --from=src file /
   4 |     
--------------------
ERROR: failed to solve: invalid context specifier /src.git for src

the fix in eb41916 only works if the path starts with ./ or ../, which our absolute paths don't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants