Skip to content

Conversation

jedevc
Copy link
Collaborator

@jedevc jedevc commented May 9, 2023

🛠️ Fixes #1738 (can test and confirm with https://github.com/jedevc/bake-test)

Before:

docker buildx bake https://github.com/jedevc/bake-test.git#main foo --progress=plain
#1 [internal] load git source https://github.com/jedevc/bake-test.git#main
#1 0.502 d8471b53d9da6eaabd03504bb41ee1b633b31a90	refs/heads/main
#1 CACHED

#1 [internal] load git source https://github.com/jedevc/bake-test.git#main
#1 0.508 d8471b53d9da6eaabd03504bb41ee1b633b31a90	refs/heads/main
#1 DONE 1.0s

#2 set context to bar
#2 CACHED

#3 [1/1] COPY super-cool.txt /
#3 ERROR: "/super-cool.txt" not found: not found
------
 > [1/1] COPY super-cool.txt /:
------
ERROR: failed to solve: failed to compute cache key: "/super-cool.txt" not found: not found

After:

❯ docker buildx bake https://github.com/jedevc/bake-test.git#main foo --progress=plain
#1 [internal] load git source https://github.com/jedevc/bake-test.git#main
#1 0.547 d8471b53d9da6eaabd03504bb41ee1b633b31a90	refs/heads/main
#1 DONE 0.6s

#1 [internal] load git source https://github.com/jedevc/bake-test.git#main
#1 CACHED

#1 [internal] load git source https://github.com/jedevc/bake-test.git#main
#1 0.579 d8471b53d9da6eaabd03504bb41ee1b633b31a90	refs/heads/main
#1 DONE 1.1s

#2 set context to bar
#2 CACHED

#3 [1/1] COPY super-cool.txt /
#3 CACHED

#4 exporting to image
#4 exporting layers done
#4 writing image sha256:ba81439b7e84a4e100fb1ff002f31e6d660e00b2c32873642cbc465a59f90478 done
#4 DONE 0.0s

This PR has two patches:

  • The first patch just moves some of the logic around so that all the logic for doing path resolution on contexts and dockerfiles is grouped together
  • The second patch contains the actual fix:
    • Set CopyDirContentsOnly to copy the contents of the subdirectory into the root, instead of copying the directory. e.g. a file /abc/xyz should be copied in as /abc if xyz is set as the context.
    • Don't join the dockerfile path if we've performed this transformation.

cc @milas

jedevc added 2 commits May 9, 2023 17:15
Signed-off-by: Justin Chadwell <me@jedevc.com>
When resolving remote contexts locally in bake, then we need to ensure
that we properly unpack the contents of that context to the root
directory, instead of leaving it in the subdirectory.

Otherwise, any files will be found in the wrong location. Along with
this change, we also need a change to the dockerfile location lookup to
ensure that it is found at the root instead of in the subdirectory.

Signed-off-by: Justin Chadwell <me@jedevc.com>
@jedevc jedevc requested a review from tonistiigi May 9, 2023 16:28
@jedevc jedevc added this to the v0.11.0 milestone May 9, 2023
@jedevc jedevc merged commit 4a0a67d into docker:master May 11, 2023
@jedevc jedevc deleted the fix-bake-sub-dir-context branch May 11, 2023 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bake with remote docker-bake.hcl does not resolve custom target contexts
2 participants