Allow setting the platform of the image to download

Default to current platform

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
Itxaka
2023-05-17 00:11:19 +02:00
parent ee38ccde54
commit c76b4bd81f
3 changed files with 22 additions and 6 deletions

View File

@@ -15,10 +15,20 @@ import (
)
// ExtractOCIImage will extract a given targetImage into a given targetDestination and pull from the local repo if set.
func ExtractOCIImage(targetImage, targetDestination string, isLocal bool) error {
platform, err := v1.ParsePlatform(fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
if err != nil {
return err
func ExtractOCIImage(targetImage, targetDestination, targetPlatform string, isLocal bool) error {
var platform *v1.Platform
var err error
if targetPlatform != "" {
platform, err = v1.ParsePlatform(targetPlatform)
if err != nil {
return err
}
} else {
platform, err = v1.ParsePlatform(fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
if err != nil {
return err
}
}
ref, err := name.ParseReference(targetImage)