c8d/save: Don't save name if exported by digest

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2023-09-22 13:17:29 +02:00
parent b5f5987959
commit f51c5e1a5c
No known key found for this signature in database
GPG key ID: B85EFCFE26DEF92A

View file

@ -108,6 +108,19 @@ func (i *ImageService) ExportImage(ctx context.Context, names []string, outStrea
"name": ref,
}).Debug("export image")
} else {
orgTarget := target
target.Annotations = make(map[string]string)
for k, v := range orgTarget.Annotations {
switch k {
case containerdimages.AnnotationImageName, ocispec.AnnotationRefName:
// Strip image name/tag annotations from the descriptor.
// Otherwise containerd will use it as name.
default:
target.Annotations[k] = v
}
}
opts = append(opts, archive.WithManifest(target))
log.G(ctx).WithFields(log.Fields{
@ -187,6 +200,10 @@ func (i *ImageService) ExportImage(ctx context.Context, names []string, outStrea
return refErr
}
// If user exports a specific digest, it shouldn't have a tag.
if specificDigestResolved {
ref = nil
}
if err := exportImage(ctx, target, ref); err != nil {
return err
}