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 <me@jedevc.com>
This commit is contained in:
Justin Chadwell 2023-03-06 16:16:57 +00:00
parent 5da7e2c097
commit 4065831652

View File

@ -188,7 +188,7 @@ func Export(ctx context.Context, store content.Provider, writer io.Writer, opts
} }
name := desc.Annotations[images.AnnotationImageName] name := desc.Annotations[images.AnnotationImageName]
if name != "" && !eo.skipDockerManifest { if name != "" {
mt.names = append(mt.names, name) mt.names = append(mt.names, name)
} }
case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex: case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex:
@ -227,26 +227,24 @@ func Export(ctx context.Context, store content.Provider, writer io.Writer, opts
records = append(records, r...) records = append(records, r...)
} }
if !eo.skipDockerManifest { if len(manifests) >= 1 {
if len(manifests) >= 1 { if len(manifests) > 1 {
if len(manifests) > 1 { sort.SliceStable(manifests, func(i, j int) bool {
sort.SliceStable(manifests, func(i, j int) bool { if manifests[i].Platform == nil {
if manifests[i].Platform == nil { return false
return false }
} if manifests[j].Platform == nil {
if manifests[j].Platform == nil { return true
return true }
} return eo.platform.Less(*manifests[i].Platform, *manifests[j].Platform)
return eo.platform.Less(*manifests[i].Platform, *manifests[j].Platform) })
})
}
d = manifests[0].Digest
dManifests[d] = &exportManifest{
manifest: manifests[0],
}
} else if eo.platform != nil {
return fmt.Errorf("no manifest found for platform: %w", errdefs.ErrNotFound)
} }
d = manifests[0].Digest
dManifests[d] = &exportManifest{
manifest: manifests[0],
}
} else if eo.platform != nil {
return fmt.Errorf("no manifest found for platform: %w", errdefs.ErrNotFound)
} }
resolvedIndex[desc.Digest] = d resolvedIndex[desc.Digest] = d
} }
@ -262,7 +260,7 @@ func Export(ctx context.Context, store content.Provider, writer io.Writer, opts
} }
} }
if len(dManifests) > 0 { if !eo.skipDockerManifest && len(dManifests) > 0 {
tr, err := manifestsRecord(ctx, store, dManifests) tr, err := manifestsRecord(ctx, store, dManifests)
if err != nil { if err != nil {
return fmt.Errorf("unable to create manifests file: %w", err) return fmt.Errorf("unable to create manifests file: %w", err)