
For supporting selection of images and runtimes in the containerized world, there is thin support for selecting objects by platform. This package defines a syntax to display to users that can express specific platforms in addition to wild cards for matching platforms. The plan is to extend this to provide support for parsing flag arguments and displaying platform types for images. This package will also provide a configurable matcher to allow match of platforms against arbitrary targets, invariant to the Go compilation. The internals are based the OCI Image Spec model. This changeset is being submitted for feedback on the approach before this gets larger. Specifically, review the unit tests and raise any concerns. Signed-off-by: Stephen J Day <stephen.day@docker.com>
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package platforms
|
|
|
|
import (
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
// These function are generated from from https://golang.org/src/go/build/syslist.go.
|
|
//
|
|
// We use switch statements because they are slightly faster than map lookups
|
|
// and use a little less memory.
|
|
|
|
// isKnownOS returns true if we know about the operating system.
|
|
//
|
|
// The OS value should be normalized before calling this function.
|
|
func isKnownOS(os string) bool {
|
|
switch os {
|
|
case "android", "darwin", "dragonfly", "freebsd", "linux", "nacl", "netbsd", "openbsd", "plan9", "solaris", "windows", "zos":
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// isKnownArch returns true if we know about the architecture.
|
|
//
|
|
// The arch value should be normalized before being passed to this function.
|
|
func isKnownArch(arch string) bool {
|
|
switch arch {
|
|
case "386", "amd64", "amd64p32", "arm", "armbe", "arm64", "arm64be", "ppc64", "ppc64le", "mips", "mipsle", "mips64", "mips64le", "mips64p32", "mips64p32le", "ppc", "s390", "s390x", "sparc", "sparc64":
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func normalizeOS(os string) string {
|
|
if os == "" {
|
|
return runtime.GOOS
|
|
}
|
|
os = strings.ToLower(os)
|
|
|
|
switch os {
|
|
case "macos":
|
|
os = "darwin"
|
|
}
|
|
return os
|
|
}
|
|
|
|
// normalizeArch normalizes the architecture.
|
|
func normalizeArch(arch, variant string) (string, string) {
|
|
arch, variant = strings.ToLower(arch), strings.ToLower(variant)
|
|
switch arch {
|
|
case "i386":
|
|
arch = "386"
|
|
variant = ""
|
|
case "x86_64", "x86-64":
|
|
arch = "amd64"
|
|
variant = ""
|
|
case "aarch64":
|
|
arch = "arm64"
|
|
variant = "" // v8 is implied
|
|
case "armhf":
|
|
arch = "arm"
|
|
variant = ""
|
|
case "armel":
|
|
arch = "arm"
|
|
variant = "v6"
|
|
case "arm":
|
|
switch variant {
|
|
case "v7", "7":
|
|
variant = "v7"
|
|
case "5", "6", "8":
|
|
variant = "v" + variant
|
|
}
|
|
}
|
|
|
|
return arch, variant
|
|
}
|