@@ -37,7 +37,6 @@ import (
3737 "time"
3838 "unicode"
3939
40-
4140 "github.com/coreos/go-semver/semver"
4241 "github.com/fatih/color"
4342 "github.com/fnproject/cli/config"
@@ -69,7 +68,7 @@ var ShapeMap = map[string][]string{
6968 modelsv2 .AppShapeGENERICX86ARM : {"linux/amd64" , "linux/arm64" },
7069}
7170
72- var TargetPlatformMap = map [string ][] string {
71+ var TargetPlatformMap = map [string ][]string {
7372 modelsv2 .AppShapeGENERICX86 : {"amd64" },
7473 modelsv2 .AppShapeGENERICARM : {"arm64" },
7574 modelsv2 .AppShapeGENERICX86ARM : {"multiarch" },
@@ -525,23 +524,26 @@ func RunBuild(verbose bool, dir, imageName, dockerfile string, buildArgs []strin
525524 var mappedArchitectures []string
526525 mappedArchitectures = append (mappedArchitectures , arch ... )
527526 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- }
533- if containerEngineType == ContainerEngineType {
534- err := initializeContainerBuilder (containerEngineType , mappedArchitectures )
535- if err != nil {
536- done <- err
537- return
527+ if platform , ok := TargetPlatformMap [shape ]; ok {
528+ targetPlatform := strings .Join (platform ," " )
529+ if targetPlatform != hostedPlatform {
530+ fmt .Println ("TargetedPlatform and hostPlatform are not same" )
531+ if containerEngineType == ContainerEngineType {
532+ err := initializeContainerBuilder (containerEngineType , mappedArchitectures )
533+ if err != nil {
534+ done <- err
535+ return
536+ }
537+ }
538+ dockerBuildCmdArgs = buildXDockerCommand (imageName , dockerfile , buildArgs , noCache , mappedArchitectures )
539+ // perform cleanup
540+ defer cleanupContainerBuilder (containerEngineType )
541+ } else {
542+ fmt .Println ("TargetedPlatform and hostPlatform are same" )
543+ dockerBuildCmdArgs = buildDockerCommand (imageName , dockerfile , buildArgs , noCache )
538544 }
539545 }
540- dockerBuildCmdArgs = buildXDockerCommand (imageName , dockerfile , buildArgs , noCache , mappedArchitectures )
541- // perform cleanup
542- defer cleanupContainerBuilder (containerEngineType )
543- } else {
544- dockerBuildCmdArgs = buildDockerCommand (imageName , dockerfile , buildArgs , noCache )
546+
545547 }
546548
547549 cmd := exec .Command (containerEngineType , dockerBuildCmdArgs ... )
0 commit comments