Skip to content

Commit 6e96ab1

Browse files
committed
comapre host and target platform
1 parent e508866 commit 6e96ab1

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

common/common.go

Lines changed: 16 additions & 2 deletions
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
}
@@ -512,17 +520,23 @@ func RunBuild(verbose bool, dir, imageName, dockerfile string, buildArgs []strin
512520
go func(done chan<- error) {
513521
var dockerBuildCmdArgs []string
514522
// Depending whether architecture list is passed or not trigger docker buildx or docker build accordingly
515-
var mappedArchitectures []string
523+
516524
if arch, ok := ShapeMap[shape]; ok {
525+
var mappedArchitectures []string
517526
mappedArchitectures = append(mappedArchitectures, arch...)
527+
var hostedPlatform = runtime.GOARCH
528+
if targetPlatform, ok := TargetPlatformMap[shape]; ok {
529+
fmt.Printf("hostedPlatform %v targetPlatform %v", hostedPlatform, targetPlatform)
530+
// compare target platform and hosted platform
531+
// perform docker buildx if they don't match
532+
}
518533
if containerEngineType == ContainerEngineType {
519534
err := initializeContainerBuilder(containerEngineType, mappedArchitectures)
520535
if err != nil {
521536
done <- err
522537
return
523538
}
524539
}
525-
526540
dockerBuildCmdArgs = buildXDockerCommand(imageName, dockerfile, buildArgs, noCache, mappedArchitectures)
527541
// perform cleanup
528542
defer cleanupContainerBuilder(containerEngineType)

0 commit comments

Comments
 (0)