Browse Source

Merge pull request #46513 from vvoland/c8d-pull-pretty-jws

c8d/pull: Support legacy schema1 prettyjws manifests
Sebastiaan van Stijn 1 year ago
parent
commit
1c34831291
3 changed files with 16 additions and 3 deletions
  1. 10 1
      daemon/containerd/image_pull.go
  2. 4 0
      distribution/errors.go
  3. 2 2
      distribution/pull_v2.go

+ 10 - 1
daemon/containerd/image_pull.go

@@ -13,6 +13,7 @@ import (
 	"github.com/distribution/reference"
 	"github.com/docker/docker/api/types/events"
 	"github.com/docker/docker/api/types/registry"
+	"github.com/docker/docker/distribution"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/pkg/progress"
 	"github.com/docker/docker/pkg/streamformatter"
@@ -73,8 +74,12 @@ func (i *ImageService) PullImage(ctx context.Context, image, tagOrDigest string,
 	finishProgress := jobs.showProgress(ctx, out, pp)
 	defer finishProgress()
 
-	var sentPullingFrom bool
+	var sentPullingFrom, sentSchema1Deprecation bool
 	ah := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
+		if desc.MediaType == images.MediaTypeDockerSchema1Manifest && !sentSchema1Deprecation {
+			progress.Message(out, "", distribution.DeprecatedSchema1ImageMessage(ref))
+			sentSchema1Deprecation = true
+		}
 		if images.IsManifestType(desc.MediaType) {
 			if !sentPullingFrom {
 				progress.Message(out, tagOrDigest, "Pulling from "+reference.Path(ref))
@@ -104,6 +109,10 @@ func (i *ImageService) PullImage(ctx context.Context, image, tagOrDigest string,
 	infoHandler := snapshotters.AppendInfoHandlerWrapper(ref.String())
 	opts = append(opts, containerd.WithImageHandlerWrapper(infoHandler))
 
+	// Allow pulling application/vnd.docker.distribution.manifest.v1+prettyjws images
+	// by converting them to OCI manifests.
+	opts = append(opts, containerd.WithSchema1Conversion)
+
 	img, err := i.client.Pull(ctx, ref.String(), opts...)
 	if err != nil {
 		return err

+ 4 - 0
distribution/errors.go

@@ -212,3 +212,7 @@ func (e reservedNameError) Error() string {
 }
 
 func (e reservedNameError) Forbidden() {}
+
+func DeprecatedSchema1ImageMessage(ref reference.Named) string {
+	return fmt.Sprintf("[DEPRECATION NOTICE] Docker Image Format v1, and Docker Image manifest version 2, schema 1 support will be removed in an upcoming release. Suggest the author of %s to upgrade the image to the OCI Format, or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/", ref)
+}

+ 2 - 2
distribution/pull_v2.go

@@ -435,7 +435,7 @@ func (p *puller) pullTag(ctx context.Context, ref reference.Named, platform *oci
 
 	switch v := manifest.(type) {
 	case *schema1.SignedManifest:
-		msg := fmt.Sprintf("[DEPRECATION NOTICE] Docker Image Format v1, and Docker Image manifest version 2, schema 1 support will be removed in an upcoming release. Suggest the author of %s to upgrade the image to the OCI Format, or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/", ref)
+		msg := DeprecatedSchema1ImageMessage(ref)
 		log.G(ctx).Warn(msg)
 		progress.Message(p.config.ProgressOutput, "", msg)
 
@@ -868,7 +868,7 @@ func (p *puller) pullManifestList(ctx context.Context, ref reference.Named, mfst
 
 		switch v := manifest.(type) {
 		case *schema1.SignedManifest:
-			msg := fmt.Sprintf("[DEPRECATION NOTICE] Docker Image Format v1, and Docker Image manifest version 2, schema 1 support will be removed in an upcoming release. Suggest the author of %s to upgrade the image to the OCI Format, or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/", ref)
+			msg := DeprecatedSchema1ImageMessage(ref)
 			log.G(ctx).Warn(msg)
 			progress.Message(p.config.ProgressOutput, "", msg)