From f51c5e1a5ce2ac6aa73cc78ddc8be6c2c41ec0e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 22 Sep 2023 13:17:29 +0200 Subject: [PATCH] c8d/save: Don't save name if exported by digest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- daemon/containerd/image_exporter.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/daemon/containerd/image_exporter.go b/daemon/containerd/image_exporter.go index 55fc09cf28..27c0ff8b15 100644 --- a/daemon/containerd/image_exporter.go +++ b/daemon/containerd/image_exporter.go @@ -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 }