Skip to content

Commit 12b6a3a

Browse files
committed
bake: copy remote context contents to root
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 <[email protected]>
1 parent 22e1901 commit 12b6a3a

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

bake/bake.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,12 @@ func updateContext(t *build.Inputs, inp *Input) {
951951
if build.IsRemoteURL(t.ContextPath) {
952952
return
953953
}
954-
st := llb.Scratch().File(llb.Copy(*inp.State, t.ContextPath, "/"), llb.WithCustomNamef("set context to %s", t.ContextPath))
954+
st := llb.Scratch().File(
955+
llb.Copy(*inp.State, t.ContextPath, "/", &llb.CopyInfo{
956+
CopyDirContentsOnly: true,
957+
}),
958+
llb.WithCustomNamef("set context to %s", t.ContextPath),
959+
)
955960
t.ContextState = &st
956961
}
957962

@@ -1027,9 +1032,6 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
10271032
if t.Dockerfile != nil {
10281033
dockerfilePath = *t.Dockerfile
10291034
}
1030-
if !build.IsRemoteURL(contextPath) && !path.IsAbs(dockerfilePath) {
1031-
dockerfilePath = path.Join(contextPath, dockerfilePath)
1032-
}
10331035

10341036
bi := build.Inputs{
10351037
ContextPath: contextPath,
@@ -1040,6 +1042,9 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
10401042
bi.DockerfileInline = *t.DockerfileInline
10411043
}
10421044
updateContext(&bi, inp)
1045+
if !build.IsRemoteURL(bi.ContextPath) && bi.ContextState == nil && !path.IsAbs(bi.DockerfilePath) {
1046+
bi.DockerfilePath = path.Join(bi.ContextPath, bi.DockerfilePath)
1047+
}
10431048
if strings.HasPrefix(bi.ContextPath, "cwd://") {
10441049
bi.ContextPath = path.Clean(strings.TrimPrefix(bi.ContextPath, "cwd://"))
10451050
}

0 commit comments

Comments
 (0)