Pārlūkot izejas kodu

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

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 1 gadu atpakaļ
vecāks
revīzija
f51c5e1a5c
1 mainītis faili ar 17 papildinājumiem un 0 dzēšanām
  1. 17 0
      daemon/containerd/image_exporter.go

+ 17 - 0
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
 		}