pull_v2_unix.go 1.8 KB

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