Skip to content

Commit 4065831

Browse files
committed
archive: consistently respect value of WithSkipDockerManifest
It was possible to still export the docker-compatible manifest.json file, if a single platform image (as a standalone manifest) was exported, even if the WithSkipDockerManifest option was explicitly set. To resolve this, we remove all references to skipDockerManifest to, adding it instead to the point-of-writing, simplifying the earlier logic and making it clear exactly when this manifest file should be written. Signed-off-by: Justin Chadwell <[email protected]>
1 parent 5da7e2c commit 4065831

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

images/archive/exporter.go

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func Export(ctx context.Context, store content.Provider, writer io.Writer, opts
188188
}
189189

190190
name := desc.Annotations[images.AnnotationImageName]
191-
if name != "" && !eo.skipDockerManifest {
191+
if name != "" {
192192
mt.names = append(mt.names, name)
193193
}
194194
case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex:
@@ -227,26 +227,24 @@ func Export(ctx context.Context, store content.Provider, writer io.Writer, opts
227227
records = append(records, r...)
228228
}
229229

230-
if !eo.skipDockerManifest {
231-
if len(manifests) >= 1 {
232-
if len(manifests) > 1 {
233-
sort.SliceStable(manifests, func(i, j int) bool {
234-
if manifests[i].Platform == nil {
235-
return false
236-
}
237-
if manifests[j].Platform == nil {
238-
return true
239-
}
240-
return eo.platform.Less(*manifests[i].Platform, *manifests[j].Platform)
241-
})
242-
}
243-
d = manifests[0].Digest
244-
dManifests[d] = &exportManifest{
245-
manifest: manifests[0],
246-
}
247-
} else if eo.platform != nil {
248-
return fmt.Errorf("no manifest found for platform: %w", errdefs.ErrNotFound)
230+
if len(manifests) >= 1 {
231+
if len(manifests) > 1 {
232+
sort.SliceStable(manifests, func(i, j int) bool {
233+
if manifests[i].Platform == nil {
234+
return false
235+
}
236+
if manifests[j].Platform == nil {
237+
return true
238+
}
239+
return eo.platform.Less(*manifests[i].Platform, *manifests[j].Platform)
240+
})
241+
}
242+
d = manifests[0].Digest
243+
dManifests[d] = &exportManifest{
244+
manifest: manifests[0],
249245
}
246+
} else if eo.platform != nil {
247+
return fmt.Errorf("no manifest found for platform: %w", errdefs.ErrNotFound)
250248
}
251249
resolvedIndex[desc.Digest] = d
252250
}
@@ -262,7 +260,7 @@ func Export(ctx context.Context, store content.Provider, writer io.Writer, opts
262260
}
263261
}
264262

265-
if len(dManifests) > 0 {
263+
if !eo.skipDockerManifest && len(dManifests) > 0 {
266264
tr, err := manifestsRecord(ctx, store, dManifests)
267265
if err != nil {
268266
return fmt.Errorf("unable to create manifests file: %w", err)

0 commit comments

Comments
 (0)