Allow setting the platform of the image to download (#15)

This commit is contained in:
Itxaka 2023-05-17 10:04:20 +02:00 committed by GitHub
parent 60c5f9c587
commit 40db3d970e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

View File

@ -153,7 +153,7 @@ func NewBundleInstaller(bc BundleConfig) (BundleInstaller, error) {
type OCIImageExtractor struct{} type OCIImageExtractor struct{}
func (e OCIImageExtractor) Install(config *BundleConfig) error { func (e OCIImageExtractor) Install(config *BundleConfig) error {
return utils.ExtractOCIImage(config.Target, config.RootPath, config.LocalFile) return utils.ExtractOCIImage(config.Target, config.RootPath, utils.GetCurrentPlatform(), config.LocalFile)
} }
// OCIImageRunner will extract an OCI image and then run its run.sh // OCIImageRunner will extract an OCI image and then run its run.sh
@ -166,7 +166,7 @@ func (e OCIImageRunner) Install(config *BundleConfig) error {
} }
defer os.RemoveAll(tempDir) defer os.RemoveAll(tempDir)
err = utils.ExtractOCIImage(config.Target, tempDir, config.LocalFile) err = utils.ExtractOCIImage(config.Target, tempDir, utils.GetCurrentPlatform(), config.LocalFile)
if err != nil { if err != nil {
return err return err
} }

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. // 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 { func ExtractOCIImage(targetImage, targetDestination, targetPlatform string, isLocal bool) error {
platform, err := v1.ParsePlatform(fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)) var platform *v1.Platform
if err != nil { var err error
return err
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) ref, err := name.ParseReference(targetImage)

View File

@ -11,6 +11,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"runtime"
"strings" "strings"
"github.com/denisbrodbeck/machineid" "github.com/denisbrodbeck/machineid"
@ -246,3 +247,8 @@ func GetInterfaceIP(in string) string {
} }
return "" return ""
} }
// GetCurrentPlatform returns the current platform in docker style `linux/amd64` for use with image utils
func GetCurrentPlatform() string {
return fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
}