@@ -32,6 +32,7 @@ import (
32
32
"os/exec"
33
33
"os/signal"
34
34
"path/filepath"
35
+ "runtime"
35
36
"strings"
36
37
"time"
37
38
"unicode"
@@ -67,6 +68,12 @@ var ShapeMap = map[string][]string{
67
68
modelsv2 .AppShapeGENERICX86ARM : {"linux/amd64" , "linux/arm64" },
68
69
}
69
70
71
+ var TargetPlatformMap = map [string ][]string {
72
+ modelsv2 .AppShapeGENERICX86 : {"amd64" },
73
+ modelsv2 .AppShapeGENERICARM : {"arm64" },
74
+ modelsv2 .AppShapeGENERICX86ARM : {"multiarch" },
75
+ }
76
+
70
77
func IsVerbose () bool {
71
78
return GlobalVerbose || CommandVerbose
72
79
}
@@ -512,22 +519,31 @@ func RunBuild(verbose bool, dir, imageName, dockerfile string, buildArgs []strin
512
519
go func (done chan <- error ) {
513
520
var dockerBuildCmdArgs []string
514
521
// Depending whether architecture list is passed or not trigger docker buildx or docker build accordingly
515
- var mappedArchitectures [] string
522
+
516
523
if arch , ok := ShapeMap [shape ]; ok {
524
+ var mappedArchitectures []string
517
525
mappedArchitectures = append (mappedArchitectures , arch ... )
518
- if containerEngineType == ContainerEngineType {
519
- err := initializeContainerBuilder (containerEngineType , mappedArchitectures )
520
- if err != nil {
521
- done <- err
522
- return
526
+ var hostedPlatform = runtime .GOARCH
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 )
523
544
}
524
545
}
525
546
526
- dockerBuildCmdArgs = buildXDockerCommand (imageName , dockerfile , buildArgs , noCache , mappedArchitectures )
527
- // perform cleanup
528
- defer cleanupContainerBuilder (containerEngineType )
529
- } else {
530
- dockerBuildCmdArgs = buildDockerCommand (imageName , dockerfile , buildArgs , noCache )
531
547
}
532
548
533
549
cmd := exec .Command (containerEngineType , dockerBuildCmdArgs ... )
0 commit comments