pull_v2_unix.go 2.1 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. specs "github.com/opencontainers/image-spec/specs-go/v1"
  11. "github.com/sirupsen/logrus"
  12. )
  13. func (ld *v2LayerDescriptor) 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 specs.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. if m.Match(toOCIPlatform(desc.Platform)) {
  23. matches = append(matches, desc)
  24. logrus.Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
  25. }
  26. }
  27. sort.SliceStable(matches, func(i, j int) bool {
  28. return m.Less(toOCIPlatform(matches[i].Platform), toOCIPlatform(matches[j].Platform))
  29. })
  30. // deprecated: backwards compatibility with older versions that didn't compare variant
  31. if len(matches) == 0 && p.Architecture == "arm" {
  32. p = platforms.Normalize(p)
  33. for _, desc := range manifests {
  34. if desc.Platform.OS == p.OS && desc.Platform.Architecture == p.Architecture {
  35. matches = append(matches, desc)
  36. logrus.Debugf("found deprecated partial match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
  37. }
  38. }
  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 specs.Platform) specs.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 specs.Platform) string {
  58. if platform.OS == "" {
  59. platform = platforms.DefaultSpec()
  60. }
  61. return platforms.Format(platform)
  62. }