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 Aug 7, 2023
1 parent e508866 commit fae33f2
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"runtime"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -67,6 +68,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,22 +519,31 @@ 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...)
if containerEngineType == ContainerEngineType {
err := initializeContainerBuilder(containerEngineType, mappedArchitectures)
if err != nil {
done <- err
return
var hostedPlatform = runtime.GOARCH
if platform, ok := TargetPlatformMap[shape]; ok {
targetPlatform := strings.Join(platform," ")
if targetPlatform != hostedPlatform {
fmt.Println("TargetedPlatform and hostPlatform are not same")
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)
} else {
fmt.Println("TargetedPlatform and hostPlatform are same")
dockerBuildCmdArgs = buildDockerCommand(imageName, dockerfile, buildArgs, noCache)
}
}

dockerBuildCmdArgs = buildXDockerCommand(imageName, dockerfile, buildArgs, noCache, mappedArchitectures)
// perform cleanup
defer cleanupContainerBuilder(containerEngineType)
} else {
dockerBuildCmdArgs = buildDockerCommand(imageName, dockerfile, buildArgs, noCache)
}

cmd := exec.Command(containerEngineType, dockerBuildCmdArgs...)
Expand Down

0 comments on commit fae33f2

Please sign in to comment.