moby/distribution/pull_v2_unix.go
Tianon Gravi 5bc17c3e54 Remove long-deprecated "arm" fallback
This fallback is used when we filter the manifest list by the user-provided platform and find no matches such that we match the previous Docker behavior (before it supported variant matching).  This has been deprecated long enough that I think it's time we finally stop supporting this weird fallback, especially since it makes for buggy behavior like `docker pull --platform linux/arm/v5 alpine:3.16` leading to a `linux/arm/v6` image being pulled (I specified a variant, every manifest list entry specifies a variant, so clearly the only behavior I as a user could reasonably expect is an error that `linux/arm/v5` is not supported, but instead I get an explicitly incompatible image despite doing everything I as a user can to prevent that situation).

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
2022-11-01 15:31:07 -07:00

73 lines
1.8 KiB
Go

//go:build !windows
// +build !windows
package distribution // import "github.com/docker/docker/distribution"
import (
"context"
"sort"
"github.com/containerd/containerd/platforms"
"github.com/docker/distribution"
"github.com/docker/distribution/manifest/manifestlist"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
)
func (ld *layerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) {
blobs := ld.repo.Blobs(ctx)
return blobs.Open(ctx, ld.digest)
}
func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platform) []manifestlist.ManifestDescriptor {
p = platforms.Normalize(withDefault(p))
m := platforms.Only(p)
var matches []manifestlist.ManifestDescriptor
for _, desc := range manifests {
descP := toOCIPlatform(desc.Platform)
if descP == nil || m.Match(*descP) {
matches = append(matches, desc)
if descP != nil {
logrus.Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
}
}
}
sort.SliceStable(matches, func(i, j int) bool {
p1 := toOCIPlatform(matches[i].Platform)
if p1 == nil {
return false
}
p2 := toOCIPlatform(matches[j].Platform)
if p2 == nil {
return true
}
return m.Less(*p1, *p2)
})
return matches
}
// checkImageCompatibility is a Windows-specific function. No-op on Linux
func checkImageCompatibility(imageOS, imageOSVersion string) error {
return nil
}
func withDefault(p specs.Platform) specs.Platform {
def := maximumSpec()
if p.OS == "" {
p.OS = def.OS
}
if p.Architecture == "" {
p.Architecture = def.Architecture
p.Variant = def.Variant
}
return p
}
func formatPlatform(platform specs.Platform) string {
if platform.OS == "" {
platform = platforms.DefaultSpec()
}
return platforms.Format(platform)
}