Bladeren bron

feat: allow users the ability to override the --platform flag as desired (#4014)

jose-fully-ported 2 jaren geleden
bovenliggende
commit
e82e1d20ba
1 gewijzigde bestanden met toevoegingen van 15 en 1 verwijderingen
  1. 15 1
      cli/cmd/docker/builder.go

+ 15 - 1
cli/cmd/docker/builder.go

@@ -206,7 +206,6 @@ func buildLocalWithBuildkit(ctx context.Context, opts BuildOpts) error {
 	commandArgs := []string{
 		"build",
 		"-f", dockerfileName,
-		"--platform", "linux/amd64",
 		"--tag", fmt.Sprintf("%s:%s", opts.ImageRepo, opts.Tag),
 		"--cache-from", fmt.Sprintf("%s:%s", opts.ImageRepo, opts.CurrentTag),
 	}
@@ -214,6 +213,10 @@ func buildLocalWithBuildkit(ctx context.Context, opts BuildOpts) error {
 		commandArgs = append(commandArgs, "--build-arg", fmt.Sprintf("%s=%s", key, val))
 	}
 
+	if !sliceContainsString(extraDockerArgs, "--platform") {
+		commandArgs = append(commandArgs, "--platform", "linux/amd64")
+	}
+
 	commandArgs = append(commandArgs, extraDockerArgs...)
 	// note: the path _must_ be the last argument
 	commandArgs = append(commandArgs, opts.BuildContext)
@@ -299,3 +302,14 @@ func injectDockerfileIntoBuildContext(buildContext string, dockerfilePath string
 
 	return randomName, nil
 }
+
+// sliceContainsString implements slice.Contains and should be removed on upgrade to golang 1.21
+func sliceContainsString(haystack []string, needle string) bool {
+	for _, value := range haystack {
+		if value == needle {
+			return true
+		}
+	}
+
+	return false
+}