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 6e96ab1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions 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 @@ -512,17 +520,23 @@ func RunBuild(verbose bool, dir, imageName, dockerfile string, buildArgs []strin
go func(done chan<- error) {
var dockerBuildCmdArgs []string
// Depending whether architecture list is passed or not trigger docker buildx or docker build accordingly
var mappedArchitectures []string

if arch, ok := ShapeMap[shape]; ok {
var mappedArchitectures []string
mappedArchitectures = append(mappedArchitectures, arch...)
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 containerEngineType == ContainerEngineType {
err := initializeContainerBuilder(containerEngineType, mappedArchitectures)
if err != nil {
done <- err
return
}
}

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

0 comments on commit 6e96ab1

Please sign in to comment.