pull_v2_unix.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 = platforms.Normalize(withDefault(p))
  17. m := platforms.NewMatcher(p)
  18. var matches []manifestlist.ManifestDescriptor
  19. for _, desc := range manifests {
  20. if m.Match(toOCIPlatform(desc.Platform)) {
  21. matches = append(matches, desc)
  22. logrus.Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
  23. }
  24. }
  25. // deprecated: backwards compatibility with older versions that didn't compare variant
  26. if len(matches) == 0 && p.Architecture == "arm" {
  27. p = platforms.Normalize(p)
  28. for _, desc := range manifests {
  29. if desc.Platform.OS == p.OS && desc.Platform.Architecture == p.Architecture {
  30. matches = append(matches, desc)
  31. logrus.Debugf("found deprecated partial match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
  32. }
  33. }
  34. }
  35. return matches
  36. }
  37. // checkImageCompatibility is a Windows-specific function. No-op on Linux
  38. func checkImageCompatibility(imageOS, imageOSVersion string) error {
  39. return nil
  40. }
  41. func withDefault(p specs.Platform) specs.Platform {
  42. def := platforms.DefaultSpec()
  43. if p.OS == "" {
  44. p.OS = def.OS
  45. }
  46. if p.Architecture == "" {
  47. p.Architecture = def.Architecture
  48. p.Variant = def.Variant
  49. }
  50. return p
  51. }
  52. func formatPlatform(platform specs.Platform) string {
  53. if platform.OS == "" {
  54. platform = platforms.DefaultSpec()
  55. }
  56. return platforms.Format(platform)
  57. }