Skip to content

Commit

Permalink
comapre host and target platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaytee-fn committed Jul 29, 2023
1 parent e508866 commit 885deda
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"runtime"
"strings"
"time"
"unicode"


"github.com/coreos/go-semver/semver"
"github.com/fatih/color"
"github.com/fnproject/cli/config"
Expand Down Expand Up @@ -67,6 +69,12 @@ var ShapeMap = map[string][]string{
modelsv2.AppShapeGENERICX86ARM: {"linux/amd64", "linux/arm64"},
}

var TargetPlatformMap = map[string][] string{
modelsv2.AppShapeGENERICX86: {"amd64"},
modelsv2.AppShapeGENERICARM: {"arm64"},
modelsv2.AppShapeGENERICX86ARM: {"multiarch"},
}

func IsVerbose() bool {
return GlobalVerbose || CommandVerbose
}
Expand Down Expand Up @@ -513,6 +521,12 @@ func RunBuild(verbose bool, dir, imageName, dockerfile string, buildArgs []strin
var dockerBuildCmdArgs []string
// Depending whether architecture list is passed or not trigger docker buildx or docker build accordingly
var mappedArchitectures []string
var hostedPlatform = runtime.GOARCH
if targetPlatform, ok := TargetPlatformMap[shape]; ok {
fmt.Printf("hostedPlatform %v targetPlatform %v", hostedPlatform, targetPlatform)
// compare target platform and hosted platform
// perform docker buildx if they don't match
}
if arch, ok := ShapeMap[shape]; ok {
mappedArchitectures = append(mappedArchitectures, arch...)
if containerEngineType == ContainerEngineType {
Expand All @@ -522,7 +536,6 @@ func RunBuild(verbose bool, dir, imageName, dockerfile string, buildArgs []strin
return
}
}

dockerBuildCmdArgs = buildXDockerCommand(imageName, dockerfile, buildArgs, noCache, mappedArchitectures)
// perform cleanup
defer cleanupContainerBuilder(containerEngineType)
Expand Down

0 comments on commit 885deda

Please sign in to comment.