Skip to content

Commit 826a49c

Browse files
Merge pull request #398 from depot/merge-annotations
Fix annotations when merging multi-platform manifests
2 parents 761e6ba + 5ebb807 commit 826a49c

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

pkg/buildx/build/build.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,12 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
12521252
}
12531253
}
12541254

1255-
dt, desc, err := itpull.Combine(ctx, srcs, nil)
1255+
indexAnnotations, err := extractIndexAnnotations(opt.Exports)
1256+
if err != nil {
1257+
return err
1258+
}
1259+
1260+
dt, desc, err := itpull.Combine(ctx, srcs, indexAnnotations)
12561261
if err != nil {
12571262
return err
12581263
}
@@ -1332,6 +1337,23 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
13321337
return resp, nil
13331338
}
13341339

1340+
// extractIndexAnnotations extracts annotations for the OCI index from export attributes
1341+
func extractIndexAnnotations(exports []client.ExportEntry) ([]string, error) {
1342+
var annotations []string
1343+
for _, exp := range exports {
1344+
for k, v := range exp.Attrs {
1345+
if key, ok := strings.CutPrefix(k, "annotation-index."); ok {
1346+
annotations = append(annotations, fmt.Sprintf("index:%s=%s", key, v))
1347+
} else if key, ok := strings.CutPrefix(k, "annotation-manifest-descriptor."); ok {
1348+
annotations = append(annotations, fmt.Sprintf("manifest-descriptor:%s=%s", key, v))
1349+
} else if key, ok := strings.CutPrefix(k, "annotation."); ok && !strings.Contains(k, "-") {
1350+
annotations = append(annotations, fmt.Sprintf("%s=%s", key, v))
1351+
}
1352+
}
1353+
}
1354+
return annotations, nil
1355+
}
1356+
13351357
func pushWithMoby(ctx context.Context, d driver.Driver, name string, l progress.SubLogger) error {
13361358
api := d.Config().DockerAPI
13371359
if api == nil {

0 commit comments

Comments
 (0)