pull_v2_unix.go 1.8 KB

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