mirror of https://github.com/docker/buildx.git
build: fix multiple named contexts pointing to same bake target
Contexts using target: schema are replaced by input: pointing to previous build result before build request is sent. Currently this replacement did not work if multiple contexts pointed to the same target name. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
d4f088e689
commit
f8c6a97edc
|
@ -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 {
|
||||
m := map[string]string{}
|
||||
m := map[string][]string{}
|
||||
for k, v := range so.FrontendAttrs {
|
||||
if strings.HasPrefix(k, "context:") && strings.HasPrefix(v, "target:") {
|
||||
target := resultKey(index, strings.TrimPrefix(v, "target:"))
|
||||
m[target] = k
|
||||
m[target] = append(m[target], k)
|
||||
}
|
||||
}
|
||||
if len(m) == 0 {
|
||||
|
@ -801,7 +801,7 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
|
|||
return err
|
||||
}
|
||||
|
||||
for k, v := range m {
|
||||
for k, contexts := range m {
|
||||
r, ok := res[k]
|
||||
if !ok {
|
||||
continue
|
||||
|
@ -816,19 +816,45 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
|
|||
if so.FrontendInputs == nil {
|
||||
so.FrontendInputs = map[string]llb.State{}
|
||||
}
|
||||
if len(rr.Refs) > 0 {
|
||||
for platform, r := range rr.Refs {
|
||||
st, err := r.ToState()
|
||||
|
||||
for _, v := range contexts {
|
||||
if len(rr.Refs) > 0 {
|
||||
for platform, r := range rr.Refs {
|
||||
st, err := r.ToState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
so.FrontendInputs[k+"::"+platform] = st
|
||||
so.FrontendAttrs[v+"::"+platform] = "input:" + k + "::" + platform
|
||||
metadata := make(map[string][]byte)
|
||||
if dt, ok := rr.Metadata[exptypes.ExporterImageConfigKey+"/"+platform]; ok {
|
||||
metadata[exptypes.ExporterImageConfigKey] = dt
|
||||
}
|
||||
if dt, ok := rr.Metadata["containerimage.buildinfo/"+platform]; ok {
|
||||
metadata["containerimage.buildinfo"] = dt
|
||||
}
|
||||
if len(metadata) > 0 {
|
||||
dt, err := json.Marshal(metadata)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
so.FrontendAttrs["input-metadata:"+k+"::"+platform] = string(dt)
|
||||
}
|
||||
}
|
||||
delete(so.FrontendAttrs, v)
|
||||
}
|
||||
if rr.Ref != nil {
|
||||
st, err := rr.Ref.ToState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
so.FrontendInputs[k+"::"+platform] = st
|
||||
so.FrontendAttrs[v+"::"+platform] = "input:" + k + "::" + platform
|
||||
so.FrontendInputs[k] = st
|
||||
so.FrontendAttrs[v] = "input:" + k
|
||||
metadata := make(map[string][]byte)
|
||||
if dt, ok := rr.Metadata[exptypes.ExporterImageConfigKey+"/"+platform]; ok {
|
||||
if dt, ok := rr.Metadata[exptypes.ExporterImageConfigKey]; ok {
|
||||
metadata[exptypes.ExporterImageConfigKey] = dt
|
||||
}
|
||||
if dt, ok := rr.Metadata["containerimage.buildinfo/"+platform]; ok {
|
||||
if dt, ok := rr.Metadata["containerimage.buildinfo"]; ok {
|
||||
metadata["containerimage.buildinfo"] = dt
|
||||
}
|
||||
if len(metadata) > 0 {
|
||||
|
@ -836,32 +862,9 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
so.FrontendAttrs["input-metadata:"+k+"::"+platform] = string(dt)
|
||||
so.FrontendAttrs["input-metadata:"+k] = string(dt)
|
||||
}
|
||||
}
|
||||
delete(so.FrontendAttrs, v)
|
||||
}
|
||||
if rr.Ref != nil {
|
||||
st, err := rr.Ref.ToState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
so.FrontendInputs[k] = st
|
||||
so.FrontendAttrs[v] = "input:" + k
|
||||
metadata := make(map[string][]byte)
|
||||
if dt, ok := rr.Metadata[exptypes.ExporterImageConfigKey]; ok {
|
||||
metadata[exptypes.ExporterImageConfigKey] = dt
|
||||
}
|
||||
if dt, ok := rr.Metadata["containerimage.buildinfo"]; ok {
|
||||
metadata["containerimage.buildinfo"] = dt
|
||||
}
|
||||
if len(metadata) > 0 {
|
||||
dt, err := json.Marshal(metadata)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
so.FrontendAttrs["input-metadata:"+k] = string(dt)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue