diff --git a/compare.go b/compare.go index 3913ef6..d25b412 100644 --- a/compare.go +++ b/compare.go @@ -72,6 +72,61 @@ func platformVector(platform specs.Platform) []specs.Platform { if variant == "" { variant = "v8" } + + if armMajor, err := strconv.Atoi(strings.TrimPrefix(variant[:2], "v")); err == nil && armMajor >= 8 { + armMinor := 0 + if len(variant) == 4 { + if minor, err := strconv.Atoi(variant[3:]); err == nil && variant[2] == '.' { + armMinor = minor + } + } + + if armMajor == 9 { + for minor := armMinor - 1; minor >= 0; minor-- { + arm64Variant := "v" + strconv.Itoa(armMajor) + "." + strconv.Itoa(minor) + if minor == 0 { + arm64Variant = "v" + strconv.Itoa(armMajor) + } + vector = append(vector, specs.Platform{ + Architecture: platform.Architecture, + OS: platform.OS, + OSVersion: platform.OSVersion, + OSFeatures: platform.OSFeatures, + Variant: arm64Variant, + }) + } + + // v9.0 diverged from v8.5, meaning that v9.x is compatible with v8.{x+5} + armMinor = armMinor + 5 + armMajor = 8 + vector = append(vector, specs.Platform{ + Architecture: platform.Architecture, + OS: platform.OS, + OSVersion: platform.OSVersion, + OSFeatures: platform.OSFeatures, + Variant: "v8." + strconv.Itoa(armMinor), + }) + } + + for minor := armMinor - 1; minor >= 0; minor-- { + arm64Variant := "v" + strconv.Itoa(armMajor) + "." + strconv.Itoa(minor) + if minor == 0 { + arm64Variant = "v" + strconv.Itoa(armMajor) + } + vector = append(vector, specs.Platform{ + Architecture: platform.Architecture, + OS: platform.OS, + OSVersion: platform.OSVersion, + OSFeatures: platform.OSFeatures, + Variant: arm64Variant, + }) + } + } + + if strings.HasPrefix(variant, "v8.") || strings.HasPrefix(variant, "v9.") { + variant = "v8" + } + vector = append(vector, platformVector(specs.Platform{ Architecture: "arm", OS: platform.OS, @@ -87,6 +142,8 @@ func platformVector(platform specs.Platform) []specs.Platform { // Only returns a match comparer for a single platform // using default resolution logic for the platform. // +// For arm64/v9.x, will also match arm64/v9.{0..x-1} and arm64/v8.{0..x+5} +// For arm64/v8.x, will also match arm64/v8.{0..x-1} // For arm/v8, will also match arm/v7, arm/v6 and arm/v5 // For arm/v7, will also match arm/v6 and arm/v5 // For arm/v6, will also match arm/v5 diff --git a/compare_test.go b/compare_test.go index cbe90de..654a8b3 100644 --- a/compare_test.go +++ b/compare_test.go @@ -182,6 +182,57 @@ func TestOnly(t *testing.T) { }, }, }, + { + platform: "linux/arm64/v9", + matches: map[bool][]string{ + true: { + "linux/arm", + "linux/arm/v5", + "linux/arm/v6", + "linux/arm/v7", + "linux/arm/v8", + "linux/arm64", + "linux/arm64/v8", + "linux/arm64/v8.1", + "linux/arm64/v8.2", + "linux/arm64/v8.3", + "linux/arm64/v8.4", + "linux/arm64/v8.5", + "linux/arm64/v9", + "linux/arm64/v9.0", + }, + false: { + "linux/amd64", + "linux/arm/v4", + "windows/amd64", + "windows/arm", + "linux/arm64/v8.6", + }, + }, + }, + { + platform: "linux/arm64/v8.1", + matches: map[bool][]string{ + true: { + "linux/arm", + "linux/arm/v5", + "linux/arm/v6", + "linux/arm/v7", + "linux/arm/v8", + "linux/arm64", + "linux/arm64/v8", + "linux/arm64/v8.1", + }, + false: { + "linux/amd64", + "linux/arm/v4", + "linux/arm/v9", + "linux/arm64/v9", + "windows/amd64", + "windows/arm", + }, + }, + }, { platform: "linux/arm64", matches: map[bool][]string{ @@ -369,6 +420,51 @@ func TestOnlyStrict(t *testing.T) { }, }, }, + { + platform: "linux/arm64/v9", + matches: map[bool][]string{ + true: { + "linux/arm64/v9", + "linux/arm64/v9.0", + }, + false: { + "linux/arm", + "linux/arm/v5", + "linux/arm/v6", + "linux/arm/v7", + "linux/arm/v8", + "linux/amd64", + "linux/arm/v4", + "linux/arm/v9", + "linux/arm64/v8", + "linux/arm64/v8.1", + "windows/amd64", + "windows/arm", + }, + }, + }, + { + platform: "linux/arm64/v8.1", + matches: map[bool][]string{ + true: { + "linux/arm64/v8.1", + }, + false: { + "linux/arm", + "linux/arm/v5", + "linux/arm/v6", + "linux/arm/v7", + "linux/arm/v8", + "linux/amd64", + "linux/arm/v4", + "linux/arm/v9", + "linux/arm64/v8", + "linux/arm64/v9", + "windows/amd64", + "windows/arm", + }, + }, + }, { platform: "linux/arm64", matches: map[bool][]string{ diff --git a/database.go b/database.go index 2e26fd3..113bbab 100644 --- a/database.go +++ b/database.go @@ -87,8 +87,13 @@ func normalizeArch(arch, variant string) (string, string) { case "aarch64", "arm64": arch = "arm64" switch variant { - case "8", "v8": + case "8", "v8", "8.0", "v8.0": variant = "" + case "9", "9.0", "v9.0": + variant = "v9" + case "8.1", "8.2", "8.3", "8.4", "8.5", "8.6", "8.7", "8.8", "8.9", + "9.1", "9.2", "9.3", "9.4", "9.5": + variant = "v" + variant } case "armhf": arch = "arm" diff --git a/go.mod b/go.mod index aea1e57..81aa215 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,11 @@ module github.com/containerd/platforms go 1.20 require ( - github.com/Microsoft/hcsshim v0.12.0-rc.2 + github.com/Microsoft/hcsshim v0.10.0 github.com/containerd/log v0.1.0 github.com/opencontainers/image-spec v1.1.0-rc5 github.com/stretchr/testify v1.8.4 - golang.org/x/sys v0.16.0 + golang.org/x/sys v0.10.0 ) require ( diff --git a/go.sum b/go.sum index fb58376..a28ca24 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/Microsoft/hcsshim v0.12.0-rc.2 h1:gfKebjq3Mq17Ys+4cjE8vc2h6tZVeqCGb9a7vBVqpAk= -github.com/Microsoft/hcsshim v0.12.0-rc.2/go.mod h1:G2TZhBED5frlh/hsuxV5CDh/ylkSFknPAMPpQg9owQw= +github.com/Microsoft/hcsshim v0.10.0 h1:PbvoxdUGgXxyirmN5Oncp3POLkxEG5LbWCEBfWmHTGA= +github.com/Microsoft/hcsshim v0.10.0/go.mod h1:3j1trOamcUdi86J5Tr5+1BpqMjSv/QeRWkX2whBF6dY= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -18,8 +18,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/platforms.go b/platforms.go index 43e4ad3..091846d 100644 --- a/platforms.go +++ b/platforms.go @@ -121,7 +121,7 @@ import ( ) var ( - specifierRe = regexp.MustCompile(`^[A-Za-z0-9_-]+$`) + specifierRe = regexp.MustCompile(`^[\.A-Za-z0-9_-]+$`) ) // Platform is a type alias for convenience, so there is no need to import image-spec package everywhere.