Merge pull request #2444 from tonistiigi/fix-base-duplicate-target-ref

build: fix multiple named contexts pointing to same bake target
This commit is contained in:
Tõnis Tiigi
2024-05-13 08:48:55 -07:00
committed by GitHub

View File

@@ -782,11 +782,11 @@ func calculateChildTargets(reqs map[string][]*reqForNode, opt map[string]Options
} }
func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *client.SolveOpt) error { func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *client.SolveOpt) error {
m := map[string]string{} m := map[string][]string{}
for k, v := range so.FrontendAttrs { for k, v := range so.FrontendAttrs {
if strings.HasPrefix(k, "context:") && strings.HasPrefix(v, "target:") { if strings.HasPrefix(k, "context:") && strings.HasPrefix(v, "target:") {
target := resultKey(index, strings.TrimPrefix(v, "target:")) target := resultKey(index, strings.TrimPrefix(v, "target:"))
m[target] = k m[target] = append(m[target], k)
} }
} }
if len(m) == 0 { if len(m) == 0 {
@@ -801,7 +801,7 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
return err return err
} }
for k, v := range m { for k, contexts := range m {
r, ok := res[k] r, ok := res[k]
if !ok { if !ok {
continue continue
@@ -816,6 +816,8 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
if so.FrontendInputs == nil { if so.FrontendInputs == nil {
so.FrontendInputs = map[string]llb.State{} so.FrontendInputs = map[string]llb.State{}
} }
for _, v := range contexts {
if len(rr.Refs) > 0 { if len(rr.Refs) > 0 {
for platform, r := range rr.Refs { for platform, r := range rr.Refs {
st, err := r.ToState() st, err := r.ToState()
@@ -864,6 +866,7 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
} }
} }
} }
}
return nil return nil
} }