pull_v2_unix.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // +build !windows
  2. package distribution // import "github.com/docker/docker/distribution"
  3. import (
  4. "context"
  5. "github.com/containerd/containerd/platforms"
  6. "github.com/docker/distribution"
  7. "github.com/docker/distribution/manifest/manifestlist"
  8. specs "github.com/opencontainers/image-spec/specs-go/v1"
  9. "github.com/sirupsen/logrus"
  10. )
  11. func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) {
  12. blobs := ld.repo.Blobs(ctx)
  13. return blobs.Open(ctx, ld.digest)
  14. }
  15. func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platform) []manifestlist.ManifestDescriptor {
  16. p = withDefault(p)
  17. var matches []manifestlist.ManifestDescriptor
  18. for _, desc := range manifests {
  19. if compareNormalized(toOCIPlatform(desc.Platform), p) {
  20. matches = append(matches, desc)
  21. logrus.Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
  22. }
  23. }
  24. // deprecated: backwards compatibility with older versions that didn't compare variant
  25. if len(matches) == 0 && p.Architecture == "arm" {
  26. p = normalize(p)
  27. for _, desc := range manifests {
  28. if desc.Platform.OS == p.OS && desc.Platform.Architecture == p.Architecture {
  29. matches = append(matches, desc)
  30. logrus.Debugf("found deprecated partial match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
  31. }
  32. }
  33. }
  34. return matches
  35. }
  36. // checkImageCompatibility is a Windows-specific function. No-op on Linux
  37. func checkImageCompatibility(imageOS, imageOSVersion string) error {
  38. return nil
  39. }
  40. func withDefault(p specs.Platform) specs.Platform {
  41. def := platforms.DefaultSpec()
  42. if p.OS == "" {
  43. p.OS = def.OS
  44. }
  45. if p.Architecture == "" {
  46. p.Architecture = def.Architecture
  47. p.Variant = def.Variant
  48. }
  49. return p
  50. }
  51. func compareNormalized(p1, p2 specs.Platform) bool {
  52. // remove after https://github.com/containerd/containerd/pull/2414
  53. return p1.OS == p2.OS &&
  54. p1.Architecture == p2.Architecture &&
  55. p1.Variant == p2.Variant
  56. }
  57. func normalize(p specs.Platform) specs.Platform {
  58. p = platforms.Normalize(p)
  59. // remove after https://github.com/containerd/containerd/pull/2414
  60. if p.Architecture == "arm" {
  61. if p.Variant == "" {
  62. p.Variant = "v7"
  63. }
  64. }
  65. if p.Architecture == "arm64" {
  66. if p.Variant == "" {
  67. p.Variant = "v8"
  68. }
  69. }
  70. return p
  71. }