Skip to content

Commit

Permalink
Add support for CPU variants (#1676)
Browse files Browse the repository at this point in the history
Signed-off-by: Silvano Cirujano Cuesta <silvano.cirujano-cuesta@siemens.com>
Inspired-by: mickkael 19755421+mickkael@users.noreply.github.com
  • Loading branch information
Silvanoc authored Jul 8, 2021
1 parent 9997cd4 commit 1d9bc17
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand Down
12 changes: 9 additions & 3 deletions pkg/image/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1d9bc17

Please sign in to comment.