github.com/rawahars/moby@v24.0.4+incompatible/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 "sort" 9 10 "github.com/containerd/containerd/platforms" 11 "github.com/docker/distribution" 12 "github.com/docker/distribution/manifest/manifestlist" 13 ocispec "github.com/opencontainers/image-spec/specs-go/v1" 14 "github.com/sirupsen/logrus" 15 ) 16 17 func (ld *layerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) { 18 blobs := ld.repo.Blobs(ctx) 19 return blobs.Open(ctx, ld.digest) 20 } 21 22 func filterManifests(manifests []manifestlist.ManifestDescriptor, p ocispec.Platform) []manifestlist.ManifestDescriptor { 23 p = platforms.Normalize(withDefault(p)) 24 m := platforms.Only(p) 25 var matches []manifestlist.ManifestDescriptor 26 for _, desc := range manifests { 27 descP := toOCIPlatform(desc.Platform) 28 if descP == nil || m.Match(*descP) { 29 matches = append(matches, desc) 30 if descP != nil { 31 logrus.Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String()) 32 } 33 } 34 } 35 36 sort.SliceStable(matches, func(i, j int) bool { 37 p1 := toOCIPlatform(matches[i].Platform) 38 if p1 == nil { 39 return false 40 } 41 p2 := toOCIPlatform(matches[j].Platform) 42 if p2 == nil { 43 return true 44 } 45 return m.Less(*p1, *p2) 46 }) 47 48 return matches 49 } 50 51 // checkImageCompatibility is a Windows-specific function. No-op on Linux 52 func checkImageCompatibility(imageOS, imageOSVersion string) error { 53 return nil 54 } 55 56 func withDefault(p ocispec.Platform) ocispec.Platform { 57 def := maximumSpec() 58 if p.OS == "" { 59 p.OS = def.OS 60 } 61 if p.Architecture == "" { 62 p.Architecture = def.Architecture 63 p.Variant = def.Variant 64 } 65 return p 66 } 67 68 func formatPlatform(platform ocispec.Platform) string { 69 if platform.OS == "" { 70 platform = platforms.DefaultSpec() 71 } 72 return platforms.Format(platform) 73 }