github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/distribution/pull_v2_unix.go (about) 1 //go:build !windows 2 3 package distribution // import "github.com/Prakhar-Agarwal-byte/moby/distribution" 4 5 import ( 6 "context" 7 "sort" 8 9 "github.com/containerd/containerd/platforms" 10 "github.com/containerd/log" 11 "github.com/docker/distribution" 12 "github.com/docker/distribution/manifest/manifestlist" 13 ocispec "github.com/opencontainers/image-spec/specs-go/v1" 14 ) 15 16 func (ld *layerDescriptor) 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 ocispec.Platform) []manifestlist.ManifestDescriptor { 22 p = platforms.Normalize(withDefault(p)) 23 m := platforms.Only(p) 24 var matches []manifestlist.ManifestDescriptor 25 for _, desc := range manifests { 26 descP := toOCIPlatform(desc.Platform) 27 if descP == nil || m.Match(*descP) { 28 matches = append(matches, desc) 29 if descP != nil { 30 log.G(context.TODO()).Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String()) 31 } 32 } 33 } 34 35 sort.SliceStable(matches, func(i, j int) bool { 36 p1 := toOCIPlatform(matches[i].Platform) 37 if p1 == nil { 38 return false 39 } 40 p2 := toOCIPlatform(matches[j].Platform) 41 if p2 == nil { 42 return true 43 } 44 return m.Less(*p1, *p2) 45 }) 46 47 return matches 48 } 49 50 // checkImageCompatibility is a Windows-specific function. No-op on Linux 51 func checkImageCompatibility(imageOS, imageOSVersion string) error { 52 return nil 53 } 54 55 func withDefault(p ocispec.Platform) ocispec.Platform { 56 def := maximumSpec() 57 if p.OS == "" { 58 p.OS = def.OS 59 } 60 if p.Architecture == "" { 61 p.Architecture = def.Architecture 62 p.Variant = def.Variant 63 } 64 return p 65 } 66 67 func formatPlatform(platform ocispec.Platform) string { 68 if platform.OS == "" { 69 platform = platforms.DefaultSpec() 70 } 71 return platforms.Format(platform) 72 }