github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/distribution/pull_v2_unix.go (about)

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