github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/distribution/pull_v2_unix.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  package distribution // import "github.com/docker/docker/distribution"
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/containerd/containerd/platforms"
    10  	"github.com/docker/distribution"
    11  	"github.com/docker/distribution/manifest/manifestlist"
    12  	specs "github.com/opencontainers/image-spec/specs-go/v1"
    13  	"github.com/sirupsen/logrus"
    14  )
    15  
    16  func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) {
    17  	blobs := ld.repo.Blobs(ctx)
    18  	return blobs.Open(ctx, ld.digest)
    19  }
    20  
    21  func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platform) []manifestlist.ManifestDescriptor {
    22  	p = platforms.Normalize(withDefault(p))
    23  	m := platforms.NewMatcher(p)
    24  	var matches []manifestlist.ManifestDescriptor
    25  	for _, desc := range manifests {
    26  		if m.Match(toOCIPlatform(desc.Platform)) {
    27  			matches = append(matches, desc)
    28  			logrus.Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
    29  		}
    30  	}
    31  
    32  	// deprecated: backwards compatibility with older versions that didn't compare variant
    33  	if len(matches) == 0 && p.Architecture == "arm" {
    34  		p = platforms.Normalize(p)
    35  		for _, desc := range manifests {
    36  			if desc.Platform.OS == p.OS && desc.Platform.Architecture == p.Architecture {
    37  				matches = append(matches, desc)
    38  				logrus.Debugf("found deprecated partial match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
    39  			}
    40  		}
    41  	}
    42  
    43  	return matches
    44  }
    45  
    46  // checkImageCompatibility is a Windows-specific function. No-op on Linux
    47  func checkImageCompatibility(imageOS, imageOSVersion string) error {
    48  	return nil
    49  }
    50  
    51  func withDefault(p specs.Platform) specs.Platform {
    52  	def := platforms.DefaultSpec()
    53  	if p.OS == "" {
    54  		p.OS = def.OS
    55  	}
    56  	if p.Architecture == "" {
    57  		p.Architecture = def.Architecture
    58  		p.Variant = def.Variant
    59  	}
    60  	return p
    61  }
    62  
    63  func formatPlatform(platform specs.Platform) string {
    64  	if platform.OS == "" {
    65  		platform = platforms.DefaultSpec()
    66  	}
    67  	return platforms.Format(platform)
    68  }