Skip to content

Commit 885deda

Browse files
committed
comapre host and target platform
1 parent e508866 commit 885deda

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

common/common.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ import (
3232
"os/exec"
3333
"os/signal"
3434
"path/filepath"
35+
"runtime"
3536
"strings"
3637
"time"
3738
"unicode"
3839

40+
3941
"github.com/coreos/go-semver/semver"
4042
"github.com/fatih/color"
4143
"github.com/fnproject/cli/config"
@@ -67,6 +69,12 @@ var ShapeMap = map[string][]string{
6769
modelsv2.AppShapeGENERICX86ARM: {"linux/amd64", "linux/arm64"},
6870
}
6971

72+
var TargetPlatformMap = map[string][] string{
73+
modelsv2.AppShapeGENERICX86: {"amd64"},
74+
modelsv2.AppShapeGENERICARM: {"arm64"},
75+
modelsv2.AppShapeGENERICX86ARM: {"multiarch"},
76+
}
77+
7078
func IsVerbose() bool {
7179
return GlobalVerbose || CommandVerbose
7280
}
@@ -513,6 +521,12 @@ func RunBuild(verbose bool, dir, imageName, dockerfile string, buildArgs []strin
513521
var dockerBuildCmdArgs []string
514522
// Depending whether architecture list is passed or not trigger docker buildx or docker build accordingly
515523
var mappedArchitectures []string
524+
var hostedPlatform = runtime.GOARCH
525+
if targetPlatform, ok := TargetPlatformMap[shape]; ok {
526+
fmt.Printf("hostedPlatform %v targetPlatform %v", hostedPlatform, targetPlatform)
527+
// compare target platform and hosted platform
528+
// perform docker buildx if they don't match
529+
}
516530
if arch, ok := ShapeMap[shape]; ok {
517531
mappedArchitectures = append(mappedArchitectures, arch...)
518532
if containerEngineType == ContainerEngineType {
@@ -522,7 +536,6 @@ func RunBuild(verbose bool, dir, imageName, dockerfile string, buildArgs []strin
522536
return
523537
}
524538
}
525-
526539
dockerBuildCmdArgs = buildXDockerCommand(imageName, dockerfile, buildArgs, noCache, mappedArchitectures)
527540
// perform cleanup
528541
defer cleanupContainerBuilder(containerEngineType)

0 commit comments

Comments
 (0)