Skip to content

Commit 32ee63f

Browse files
committed
fix: clone exports before modifying for save
1 parent f9dd800 commit 32ee63f

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

pkg/registry/cli.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,24 @@ func WithDepotSave(buildOpts map[string]buildx.Options, opts SaveOptions) map[st
3535
}
3636
}
3737

38+
exports := deepCloneExports(buildOpt.Exports)
39+
3840
for _, i := range imageExportIndices {
39-
_, ok := buildOpt.Exports[i].Attrs["push"]
41+
_, ok := exports[i].Attrs["push"]
4042
hadPush = hadPush || ok
41-
buildOpt.Exports[i].Attrs["push"] = "true"
43+
exports[i].Attrs["push"] = "true"
4244
}
4345

4446
if len(imageExportIndices) == 0 {
4547
exportImage := client.ExportEntry{
4648
Type: "image",
4749
Attrs: map[string]string{"push": "true"},
4850
}
49-
buildOpt.Exports = append(buildOpt.Exports, exportImage)
51+
exports = append(exports, exportImage)
5052
}
5153

54+
buildOpt.Exports = exports
55+
5256
additionalTags := slices.Clone(opts.AdditionalTags)
5357
for i, tag := range additionalTags {
5458
if opts.AddTargetSuffix {
@@ -68,3 +72,23 @@ func WithDepotSave(buildOpts map[string]buildx.Options, opts SaveOptions) map[st
6872

6973
return buildOpts
7074
}
75+
76+
func deepCloneExports(original []client.ExportEntry) []client.ExportEntry {
77+
if original == nil {
78+
return nil
79+
}
80+
81+
exports := make([]client.ExportEntry, len(original))
82+
for i := range original {
83+
clone := original[i]
84+
// Attrs is the only field with references
85+
clone.Attrs = make(map[string]string, len(original[i].Attrs))
86+
for k, v := range original[i].Attrs {
87+
clone.Attrs[k] = v
88+
}
89+
90+
exports[i] = clone
91+
}
92+
93+
return exports
94+
}

0 commit comments

Comments
 (0)