bake: fix remote named context subdir handling

Fix using CopyDirContentsOnly when projecting remote named contexts so
subdir contexts keep the same root semantics as local bake runs.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2026-02-27 17:06:32 -08:00
parent 22074cd400
commit d39a81e456
2 changed files with 80 additions and 1 deletions
+4 -1
View File
@@ -1299,6 +1299,7 @@ func updateContext(t *build.Inputs, inp *Input) {
for k, v := range t.NamedContexts {
if v.Path == "." {
t.NamedContexts[k] = build.NamedContext{Path: inp.URL}
continue
}
if strings.HasPrefix(v.Path, "cwd://") || strings.HasPrefix(v.Path, "target:") || strings.HasPrefix(v.Path, "docker-image:") {
continue
@@ -1306,7 +1307,9 @@ func updateContext(t *build.Inputs, inp *Input) {
if urlutil.IsRemoteURL(v.Path) {
continue
}
st := llb.Scratch().File(llb.Copy(*inp.State, v.Path, "/"), llb.WithCustomNamef("set context %s to %s", k, v.Path))
st := llb.Scratch().File(llb.Copy(*inp.State, v.Path, "/", &llb.CopyInfo{
CopyDirContentsOnly: true,
}), llb.WithCustomNamef("set context %s to %s", k, v.Path))
t.NamedContexts[k] = build.NamedContext{State: &st, Path: inp.URL}
}