Merge pull request #43434 from tonistiigi/amd64-variant-support

distribution: fix matching amd64 variants
This commit is contained in:
Sebastiaan van Stijn 2022-04-02 00:12:33 +02:00 committed by GitHub
commit 99b2894e17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 4 deletions

View file

@ -22,6 +22,7 @@ import (
"github.com/opencontainers/selinux/go-selinux"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
archvariant "github.com/tonistiigi/go-archvariant"
)
type createOpts struct {
@ -68,7 +69,7 @@ func (daemon *Daemon) containerCreate(opts createOpts) (containertypes.Container
if opts.params.Platform == nil && opts.params.Config.Image != "" {
if img, _ := daemon.imageService.GetImage(opts.params.Config.Image, opts.params.Platform); img != nil {
p := platforms.DefaultSpec()
p := maximumSpec()
imgPlat := v1.Platform{
OS: img.OS,
Architecture: img.Architecture,
@ -319,3 +320,12 @@ func verifyNetworkingConfig(nwConfig *networktypes.NetworkingConfig) error {
}
return nil
}
// maximumSpec returns the distribution platform with maximum compatibility for the current node.
func maximumSpec() v1.Platform {
p := platforms.DefaultSpec()
if p.Architecture == "amd64" {
p.Variant = archvariant.AMD64Variant()
}
return p
}

View file

@ -33,6 +33,7 @@ import (
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
archvariant "github.com/tonistiigi/go-archvariant"
)
var (
@ -1027,3 +1028,12 @@ func toOCIPlatform(p manifestlist.PlatformSpec) specs.Platform {
OSVersion: p.OSVersion,
}
}
// maximumSpec returns the distribution platform with maximum compatibility for the current node.
func maximumSpec() specs.Platform {
p := platforms.DefaultSpec()
if p.Architecture == "amd64" {
p.Variant = archvariant.AMD64Variant()
}
return p
}

View file

@ -5,6 +5,7 @@ package distribution // import "github.com/docker/docker/distribution"
import (
"context"
"sort"
"github.com/containerd/containerd/platforms"
"github.com/docker/distribution"
@ -20,7 +21,7 @@ func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekClo
func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platform) []manifestlist.ManifestDescriptor {
p = platforms.Normalize(withDefault(p))
m := platforms.NewMatcher(p)
m := platforms.Only(p)
var matches []manifestlist.ManifestDescriptor
for _, desc := range manifests {
if m.Match(toOCIPlatform(desc.Platform)) {
@ -29,6 +30,10 @@ func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platfo
}
}
sort.SliceStable(matches, func(i, j int) bool {
return m.Less(toOCIPlatform(matches[i].Platform), toOCIPlatform(matches[j].Platform))
})
// deprecated: backwards compatibility with older versions that didn't compare variant
if len(matches) == 0 && p.Architecture == "arm" {
p = platforms.Normalize(p)
@ -49,7 +54,7 @@ func checkImageCompatibility(imageOS, imageOSVersion string) error {
}
func withDefault(p specs.Platform) specs.Platform {
def := platforms.DefaultSpec()
def := maximumSpec()
if p.OS == "" {
p.OS = def.OS
}

View file

@ -74,6 +74,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/tchap/go-patricia v2.3.0+incompatible
github.com/tonistiigi/fsutil v0.0.0-20220115021204-b19f7f9cb274
github.com/tonistiigi/go-archvariant v1.0.0
github.com/vbatts/tar-split v0.11.2
github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f
@ -137,7 +138,6 @@ require (
github.com/rexray/gocsi v1.2.2 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/tinylib/msgp v1.1.0 // indirect
github.com/tonistiigi/go-archvariant v1.0.0 // indirect
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.2 // indirect