From 1d9bc175c2070680c0d2d5b1d7531ffe53d713f7 Mon Sep 17 00:00:00 2001 From: Silvano Cirujano Cuesta Date: Thu, 8 Jul 2021 21:05:38 +0200 Subject: [PATCH] Add support for CPU variants (#1676) Signed-off-by: Silvano Cirujano Cuesta Inspired-by: mickkael 19755421+mickkael@users.noreply.github.com --- README.md | 7 ++++++- pkg/image/remote/remote.go | 12 +++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8771ff037..3019539e8 100644 --- a/README.md +++ b/README.md @@ -593,7 +593,12 @@ and you want to build one of its subfolders instead of the root folder. #### --customPlatform Allows to build with another default platform than the host, similarly to docker build --platform xxx -the value has to be on the form `--customPlatform=linux/arm` , with acceptable values listed here: [GOOS/GOARCH](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63) +the value has to be on the form `--customPlatform=linux/arm`, with acceptable values listed here: [GOOS/GOARCH](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63). + +It's also possible specifying CPU variants adding it as a third parameter (like `--customPlatform=linux/arm/v5`). +Currently CPU variants are only known to be used for the ARM architecture as listed here: [GOARM](https://github.com/golang/go/wiki/GoArm#supported-architectures) + +_The resulting images cannot provide any metadata about CPU variant due to a limitation of the OCI-image specification._ _This is not virtualization and cannot help to build an architecture not natively supported by the build host. This is used to build i386 on an amd64 Host for example, or arm32 on an arm64 host._ diff --git a/pkg/image/remote/remote.go b/pkg/image/remote/remote.go index ea40b2733..990a7a1db 100644 --- a/pkg/image/remote/remote.go +++ b/pkg/image/remote/remote.go @@ -138,10 +138,16 @@ func remoteOptions(registryName string, opts config.RegistryOptions, customPlatf // CurrentPlatform returns the v1.Platform on which the code runs func currentPlatform(customPlatform string) v1.Platform { if customPlatform != "" { - return v1.Platform{ - OS: strings.Split(customPlatform, "/")[0], - Architecture: strings.Split(customPlatform, "/")[1], + customPlatformArray := strings.Split(customPlatform, "/") + imagePlatform := v1.Platform{} + imagePlatform.OS = customPlatformArray[0] + if len(customPlatformArray) > 1 { + imagePlatform.Architecture = customPlatformArray[1] + if len(customPlatformArray) > 2 { + imagePlatform.Variant = customPlatformArray[2] + } } + return imagePlatform } return v1.Platform{ OS: runtime.GOOS,