Skip to content

Commit

Permalink
Support normalizing any arm64/v9.x variants
Browse files Browse the repository at this point in the history
Cap arm64 v8 variants at v8.9

Signed-off-by: Chongyi Zheng <[email protected]>
Signed-off-by: Samuel Karp <[email protected]>
  • Loading branch information
harryzcy authored and samuelkarp committed Nov 4, 2024
1 parent f0e7837 commit 139c8d7
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 8 deletions.
5 changes: 4 additions & 1 deletion compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ func platformVector(platform specs.Platform) []specs.Platform {
})
}

// v9.0 diverged from v8.5, meaning that v9.x is compatible with v8.{x+5}
// v9.0 diverged from v8.5, meaning that v9.x is compatible with v8.{x+5} until v9.4/v8.9
armMinor = armMinor + 5
if armMinor > 9 {
armMinor = 9
}
armMajor = 8
vector = append(vector, specs.Platform{
Architecture: platform.Architecture,
Expand Down
62 changes: 62 additions & 0 deletions compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,44 @@ func TestOnly(t *testing.T) {
},
},
},
{
platform: "linux/arm64/v9.6",
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/v8.6",
"linux/arm64/v8.7",
"linux/arm64/v8.8",
"linux/arm64/v8.9",
"linux/arm64/v9",
"linux/arm64/v9.0",
"linux/arm64/v9.1",
"linux/arm64/v9.2",
"linux/arm64/v9.3",
"linux/arm64/v9.4",
"linux/arm64/v9.5",
"linux/arm64/v9.6",
},
false: {
"linux/amd64",
"linux/arm/v4",
"windows/amd64",
"windows/arm",
"linux/arm64/v8.10", // there's no v8.10
},
},
},
{
platform: "linux/arm64/v9",
matches: map[bool][]string{
Expand Down Expand Up @@ -441,6 +479,30 @@ func TestOnlyStrict(t *testing.T) {
},
},
},
{
platform: "linux/arm64/v9.5",
matches: map[bool][]string{
true: {
"linux/arm64/v9.5",
},
false: {
"linux/arm",
"linux/arm/v5",
"linux/arm/v6",
"linux/arm/v7",
"linux/arm/v8",
"linux/amd64",
"linux/arm/v4",
"linux/arm64/v8",
"linux/arm64/v8.1",
"linux/arm64/v9",
"linux/arm64/v9.1",
"linux/arm64/v9.4",
"windows/amd64",
"windows/arm",
},
},
},
{
platform: "linux/arm64/v9",
matches: map[bool][]string{
Expand Down
22 changes: 15 additions & 7 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,22 @@ func normalizeArch(arch, variant string) (string, string) {
}
case "aarch64", "arm64":
arch = "arm64"
switch variant {
case "8", "v8", "8.0", "v8.0":
majorVariant, minorVariant, hasMinor := strings.Cut(variant, ".")
majorVariant = strings.TrimPrefix(majorVariant, "v")
if minorVariant == "0" {
minorVariant = ""
hasMinor = false
}

if (majorVariant == "" || majorVariant == "8") && !hasMinor {
// normalize v8 to empty string
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
} else {
// otherwise to v8.x or v9 or v9.x
variant = "v" + majorVariant
if hasMinor {
variant = variant + "." + minorVariant
}
}
case "armhf":
arch = "arm"
Expand Down

0 comments on commit 139c8d7

Please sign in to comment.