Repository: GoogleContainerTools/skaffold
Pull request #7823 (2022-08-30 15:44:43)

fix: Remove the flag from deploy command
<!-- Include if applicable: -->
Fixes: #7819
**Merge before/after**: _Dependent or prerequisite PRs_

**Description**
Remove the `--platform` flag from the `deploy` command due to it doesn't influence the final result and could be confusing to have the flag available.

codecov[bot]: # [Codecov](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools) Report
> Merging [#7823](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools) (c5f17f5) into [main](https://codecov.io/gh/GoogleContainerTools/skaffold/commit/290280e8c6c19231e9ed5b5c027f2c01d22f75be?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools) (290280e) will **decrease** coverage by `3.90%`.
> The diff coverage is `53.59%`.

```diff
@@            Coverage Diff             @@
##             main    #7823      +/-   ##
==========================================
- Coverage   70.48%   66.58%   -3.91%     
==========================================
  Files         515      593      +78     
  Lines       23150    28682    +5532     
==========================================
+ Hits        16317    19097    +2780     
- Misses       5776     8174    +2398     
- Partials     1057     1411     +354     
```


| [Impacted Files](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools) | Coverage Δ | |
|---|---|---|
| [cmd/skaffold/app/cmd/credits/export.go](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvY3JlZGl0cy9leHBvcnQuZ28=) | `0.00% <0.00%> (ø)` | |
| [cmd/skaffold/app/cmd/deploy.go](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvZGVwbG95Lmdv) | `40.90% <0.00%> (-12.94%)` | :arrow_down: |
| [cmd/skaffold/app/cmd/test.go](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvdGVzdC5nbw==) | `44.44% <0.00%> (ø)` | |
| [cmd/skaffold/skaffold.go](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL3NrYWZmb2xkLmdv) | `0.00% <0.00%> (ø)` | |
| [cmd/skaffold/app/cmd/inspect\_tests.go](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvaW5zcGVjdF90ZXN0cy5nbw==) | `62.50% <14.28%> (-1.14%)` | :arrow_down: |
| [cmd/skaffold/app/cmd/render.go](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvcmVuZGVyLmdv) | `35.48% <18.18%> (-5.90%)` | :arrow_down: |
| [cmd/skaffold/app/cmd/lsp.go](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvbHNwLmdv) | `28.12% <28.12%> (ø)` | |
| [cmd/skaffold/app/cmd/run.go](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvcnVuLmdv) | `64.28% <33.33%> (-9.63%)` | :arrow_down: |
| [cmd/skaffold/app/cmd/fix.go](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvZml4Lmdv) | `56.41% <37.50%> (-20.07%)` | :arrow_down: |
| [cmd/skaffold/app/cmd/verify.go](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvdmVyaWZ5Lmdv) | `41.17% <41.17%> (ø)` | |
| ... and [363 more](https://codecov.io/gh/GoogleContainerTools/skaffold/pull/7823/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools) | |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools)


Patch:
diff --git a/cmd/skaffold/app/cmd/flags.go b/cmd/skaffold/app/cmd/flags.go
index af238350d..39148fe2d 100644
--- a/cmd/skaffold/app/cmd/flags.go
+++ b/cmd/skaffold/app/cmd/flags.go
@@ -401,7 +401,7 @@ var flagRegistry = []Flag{
 		Value:         &opts.Platforms,
 		DefValue:      []string{},
 		FlagAddMethod: "StringSliceVar",
-		DefinedOn:     []string{"build", "debug", "dev", "run", "deploy"},
+		DefinedOn:     []string{"build", "debug", "dev", "run"},
 	},
 	{
 		Name:          "minikube-profile",
diff --git a/docs/content/en/docs/references/cli/_index.md b/docs/content/en/docs/references/cli/_index.md
index a4f3934de..7821ee266 100644
--- a/docs/content/en/docs/references/cli/_index.md
+++ b/docs/content/en/docs/references/cli/_index.md
@@ -621,7 +621,6 @@ Options:
   -m, --module=[]: Filter Skaffold configs to only the provided named modules
       --mute-logs=[]: mute logs for specified stages in pipeline (build, deploy, status-check, none, all)
   -n, --namespace='': Runs deployments in the specified namespace. When used with 'render' command, renders manifests contain the namespace
-      --platform=[]: The platform to target for the build artifacts
       --port-forward=off: Port-forward exposes service ports and container ports within pods and other resources (off, user, services, debug, pods)
   -p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
       --profile-auto-activation=true: Set to false to disable profile auto activation
@@ -670,7 +669,6 @@ Env vars:
 * `SKAFFOLD_MODULE` (same as `--module`)
 * `SKAFFOLD_MUTE_LOGS` (same as `--mute-logs`)
 * `SKAFFOLD_NAMESPACE` (same as `--namespace`)
-* `SKAFFOLD_PLATFORM` (same as `--platform`)
 * `SKAFFOLD_PORT_FORWARD` (same as `--port-forward`)
 * `SKAFFOLD_PROFILE` (same as `--profile`)
 * `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)
diff --git a/integration/binpack/gcp.go b/integration/binpack/gcp.go
index 1704e8ea0..3ae226fe2 100644
--- a/integration/binpack/gcp.go
+++ b/integration/binpack/gcp.go
@@ -21,6 +21,7 @@ package binpack
 // GCPTimings contains the timings for tests marked with NeedsGcp
 var GCPTimings = []Timing{
 	{"TestBuildKanikoInsecureRegistry", 10.00},
+	{"TestBuildWithMultiPlatforms", 20.00},
 	{"TestBuildKanikoWithExplicitRepo", 10.00},
 	{"TestBuildInCluster", 10.00},
 	{"TestBuildGCBWithExplicitRepo", 10.00},
diff --git a/pkg/skaffold/build/docker/docker.go b/pkg/skaffold/build/docker/docker.go
index 07367d3ee..d7f17472a 100644
--- a/pkg/skaffold/build/docker/docker.go
+++ b/pkg/skaffold/build/docker/docker.go
@@ -93,7 +93,16 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact,
 
 func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string, workspace string, dockerfilePath string, a *latest.DockerArtifact, opts docker.BuildOptions, pl v1.Platform) (string, error) {
 	args := []string{"build", workspace, "--file", dockerfilePath, "-t", opts.Tag}
-	ba, err := docker.EvalBuildArgs(b.cfg.Mode(), workspace, a.DockerfilePath, a.BuildArgs, opts.ExtraBuildArgs)
+	imgRef, err := docker.ParseReference(opts.Tag)
+	if err != nil {
+		return "", fmt.Errorf("couldn't parse image tag: %w", err)
+	}
+	imageInfoEnv := map[string]string{
+		"IMAGE_REPO": imgRef.Repo,
+		"IMAGE_NAME": imgRef.Name,
+		"IMAGE_TAG":  imgRef.Tag,
+	}
+	ba, err := docker.EvalBuildArgsWithEnv(b.cfg.Mode(), workspace, a.DockerfilePath, a.BuildArgs, opts.ExtraBuildArgs, imageInfoEnv)
 	if err != nil {
 		return "", fmt.Errorf("unable to evaluate build args: %w", err)
 	}
diff --git a/pkg/skaffold/docker/image.go b/pkg/skaffold/docker/image.go
index 9e179326d..836543ce5 100644
--- a/pkg/skaffold/docker/image.go
+++ b/pkg/skaffold/docker/image.go
@@ -312,7 +312,16 @@ func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string
 	if err := l.CheckCompatible(a); err != nil {
 		return "", err
 	}
-	buildArgs, err := EvalBuildArgs(opts.Mode, workspace, a.DockerfilePath, a.BuildArgs, opts.ExtraBuildArgs)
+	imgRef, err := ParseReference(opts.Tag)
+	if err != nil {
+		return "", fmt.Errorf("couldn't parse image tag: %w", err)
+	}
+	imageInfoEnv := map[string]string{
+		"IMAGE_REPO": imgRef.Repo,
+		"IMAGE_NAME": imgRef.Name,
+		"IMAGE_TAG":  imgRef.Tag,
+	}
+	buildArgs, err := EvalBuildArgsWithEnv(opts.Mode, workspace, a.DockerfilePath, a.BuildArgs, opts.ExtraBuildArgs, imageInfoEnv)
 	if err != nil {
 		return "", fmt.Errorf("unable to evaluate build args: %w", err)
 	}


Test patch:
diff --git a/integration/build_test.go b/integration/build_test.go
index 22e315cf7..0dee0d98f 100644
--- a/integration/build_test.go
+++ b/integration/build_test.go
@@ -25,13 +25,16 @@ import (
 	"time"
 
 	"4d63.com/tz"
+	v1 "github.com/opencontainers/image-spec/specs-go/v1"
 
+	"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags"
 	"github.com/GoogleContainerTools/skaffold/integration/skaffold"
 	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/jib"
 	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
 	kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context"
 	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
 	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
+	"github.com/GoogleContainerTools/skaffold/testutil"
 )
 
 const imageName = "gcr.io/k8s-skaffold/simple-build:"
@@ -109,9 +112,79 @@ func TestBuild(t *testing.T) {
 	}
 }
 
+func TestBuildWithWithPlatform(t *testing.T) {
+	MarkIntegrationTest(t, CanRunWithoutGcp)
+
+	tests := []struct {
+		description       string
+		dir               string
+		args              []string
+		image             string
+		expectedPlatforms []v1.Platform
+	}{
+		{
+			description:       "docker build linux/amd64",
+			dir:               "testdata/build/docker-with-platform-amd",
+			args:              []string{"--platform", "linux/amd64"},
+			expectedPlatforms: []v1.Platform{{OS: "linux", Architecture: "amd64"}},
+		},
+		{
+			description:       "docker build linux/arm64",
+			dir:               "testdata/build/docker-with-platform-arm",
+			args:              []string{"--platform", "linux/arm64"},
+			expectedPlatforms: []v1.Platform{{OS: "linux", Architecture: "arm64"}},
+		},
+	}
+
+	for _, test := range tests {
+		t.Run(test.description, func(t *testing.T) {
+			tmpfile := testutil.TempFile(t, "", []byte{})
+			args := append(test.args, "--file-output", tmpfile)
+			skaffold.Build(args...).InDir(test.dir).RunOrFail(t)
+			bytes, err := os.ReadFile(tmpfile)
+			failNowIfError(t, err)
+			buildArtifacts, err := flags.ParseBuildOutput(bytes)
+			failNowIfError(t, err)
+			checkLocalImagePlatforms(t, buildArtifacts.Builds[0].Tag, test.expectedPlatforms)
+		})
+	}
+}
+
+func TestBuildWithMultiPlatforms(t *testing.T) {
+	MarkIntegrationTest(t, NeedsGcp)
+
+	tests := []struct {
+		description       string
+		dir               string
+		args              []string
+		image             string
+		expectedPlatforms []v1.Platform
+	}{
+		{
+			description:       "build cross platform images with gcb",
+			dir:               "testdata/build/gcb-with-platform",
+			args:              []string{"--platform", "linux/arm64,linux/amd64"},
+			expectedPlatforms: []v1.Platform{{OS: "linux", Architecture: "arm64"}, {OS: "linux", Architecture: "amd64"}},
+		},
+	}
+
+	for _, test := range tests {
+		t.Run(test.description, func(t *testing.T) {
+			tmpfile := testutil.TempFile(t, "", []byte{})
+			args := append(test.args, "--file-output", tmpfile)
+			skaffold.Build(args...).InDir(test.dir).RunOrFail(t)
+			bytes, err := os.ReadFile(tmpfile)
+			failNowIfError(t, err)
+			buildArtifacts, err := flags.ParseBuildOutput(bytes)
+			failNowIfError(t, err)
+			checkRemoteImagePlatforms(t, buildArtifacts.Builds[0].Tag, test.expectedPlatforms)
+		})
+	}
+}
+
 // TestExpectedBuildFailures verifies that `skaffold build` fails in expected ways
 func TestExpectedBuildFailures(t *testing.T) {
-	MarkIntegrationTest(t, CanRunWithoutGcp)
+	MarkIntegrationTest(t, NeedsGcp)
 	if !jib.JVMFound(context.Background()) {
 		t.Fatal("test requires Java VM")
 	}
@@ -142,6 +215,59 @@ func TestExpectedBuildFailures(t *testing.T) {
 	}
 }
 
+func checkLocalImagePlatforms(t *testing.T, image string, expected []v1.Platform) {
+	if expected == nil {
+		return
+	}
+	t.Helper()
+
+	cfg, err := kubectx.CurrentConfig()
+	failNowIfError(t, err)
+
+	client, err := docker.NewAPIClient(context.Background(), &runcontext.RunContext{
+		KubeContext: cfg.CurrentContext,
+	})
+	failNowIfError(t, err)
+	inspect, _, err := client.ImageInspectWithRaw(context.Background(), image)
+	failNowIfError(t, err)
+
+	actual := []v1.Platform{{Architecture: inspect.Architecture, OS: inspect.Os}}
+	checkPlatformsEqual(t, actual, expected)
+}
+
+func checkRemoteImagePlatforms(t *testing.T, image string, expected []v1.Platform) {
+	if expected == nil {
+		return
+	}
+	t.Helper()
+	actual, err := docker.GetPlatforms(image)
+	if err != nil {
+		t.Error(err)
+	}
+	checkPlatformsEqual(t, actual, expected)
+}
+
+func checkPlatformsEqual(t *testing.T, actual, expected []v1.Platform) {
+	expectedLen := len(expected)
+	actualLen := len(actual)
+
+	if expectedLen != actualLen {
+		t.Fatalf("length of the slices differ: Expected %d, but was %d", expectedLen, actualLen)
+	}
+	wmap := make(map[string]int)
+	for _, elem := range expected {
+		wmap[elem.OS+"/"+elem.Architecture]++
+	}
+	for _, elem := range actual {
+		wmap[elem.OS+"/"+elem.Architecture]--
+	}
+	for _, v := range wmap {
+		if v != 0 {
+			t.Fatalf("elements are missing (negative integers) or excess (positive integers): %#v", wmap)
+		}
+	}
+}
+
 // checkImageExists asserts that the given image is present
 func checkImageExists(t *testing.T, image string) {
 	t.Helper()
diff --git a/integration/testdata/build/docker-with-platform-amd/Dockerfile b/integration/testdata/build/docker-with-platform-amd/Dockerfile
new file mode 100644
index 000000000..8f6762484
--- /dev/null
+++ b/integration/testdata/build/docker-with-platform-amd/Dockerfile
@@ -0,0 +1,7 @@
+FROM golang:1.15-alpine as builder
+COPY main.go .
+RUN go build -o /app main.go
+
+FROM alpine:3
+CMD ["./app"]
+COPY --from=builder /app .
diff --git a/integration/testdata/build/docker-with-platform-amd/k8s/deployment.yaml b/integration/testdata/build/docker-with-platform-amd/k8s/deployment.yaml
new file mode 100644
index 000000000..f1c71fd8b
--- /dev/null
+++ b/integration/testdata/build/docker-with-platform-amd/k8s/deployment.yaml
@@ -0,0 +1,18 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: getting-started
+  labels:
+    app: getting-started
+spec:
+  selector:
+    matchLabels:
+      app: getting-started
+  template:
+    metadata:
+      labels:
+        app: getting-started
+    spec:
+      containers:
+      - name: getting-started
+        image: skaffold-hello
diff --git a/integration/testdata/build/docker-with-platform-amd/k8s/pod.yaml b/integration/testdata/build/docker-with-platform-amd/k8s/pod.yaml
new file mode 100644
index 000000000..f80ddcdf6
--- /dev/null
+++ b/integration/testdata/build/docker-with-platform-amd/k8s/pod.yaml
@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Pod
+metadata:
+  name: getting-started
+spec:
+  containers:
+  - name: getting-started
+    image: skaffold-hello
diff --git a/integration/testdata/build/docker-with-platform-amd/main.go b/integration/testdata/build/docker-with-platform-amd/main.go
new file mode 100644
index 000000000..8c3e45267
--- /dev/null
+++ b/integration/testdata/build/docker-with-platform-amd/main.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+	"fmt"
+	"time"
+)
+
+func main() {
+	for counter := 0; ; counter++ {
+		fmt.Println("Hello world!", counter)
+
+		time.Sleep(time.Second * 1)
+	}
+}
diff --git a/integration/testdata/build/docker-with-platform-amd/skaffold.yaml b/integration/testdata/build/docker-with-platform-amd/skaffold.yaml
new file mode 100644
index 000000000..8ed4fda2d
--- /dev/null
+++ b/integration/testdata/build/docker-with-platform-amd/skaffold.yaml
@@ -0,0 +1,15 @@
+apiVersion: skaffold/v3alpha1
+kind: Config
+build:
+  artifacts:
+  - image: docker-with-platform-amd
+
+profiles:
+  - name: pod
+    manifests:
+      rawYaml:
+      - k8s/pod.yaml
+  - name: deployment
+    manifests:
+      rawYaml:
+      - k8s/deployment.yaml
\ No newline at end of file
diff --git a/integration/testdata/build/docker-with-platform-arm/Dockerfile b/integration/testdata/build/docker-with-platform-arm/Dockerfile
new file mode 100644
index 000000000..8f6762484
--- /dev/null
+++ b/integration/testdata/build/docker-with-platform-arm/Dockerfile
@@ -0,0 +1,7 @@
+FROM golang:1.15-alpine as builder
+COPY main.go .
+RUN go build -o /app main.go
+
+FROM alpine:3
+CMD ["./app"]
+COPY --from=builder /app .
diff --git a/integration/testdata/build/docker-with-platform-arm/k8s/deployment.yaml b/integration/testdata/build/docker-with-platform-arm/k8s/deployment.yaml
new file mode 100644
index 000000000..f1c71fd8b
--- /dev/null
+++ b/integration/testdata/build/docker-with-platform-arm/k8s/deployment.yaml
@@ -0,0 +1,18 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: getting-started
+  labels:
+    app: getting-started
+spec:
+  selector:
+    matchLabels:
+      app: getting-started
+  template:
+    metadata:
+      labels:
+        app: getting-started
+    spec:
+      containers:
+      - name: getting-started
+        image: skaffold-hello
diff --git a/integration/testdata/build/docker-with-platform-arm/k8s/pod.yaml b/integration/testdata/build/docker-with-platform-arm/k8s/pod.yaml
new file mode 100644
index 000000000..f80ddcdf6
--- /dev/null
+++ b/integration/testdata/build/docker-with-platform-arm/k8s/pod.yaml
@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Pod
+metadata:
+  name: getting-started
+spec:
+  containers:
+  - name: getting-started
+    image: skaffold-hello
diff --git a/integration/testdata/build/docker-with-platform-arm/main.go b/integration/testdata/build/docker-with-platform-arm/main.go
new file mode 100644
index 000000000..8c3e45267
--- /dev/null
+++ b/integration/testdata/build/docker-with-platform-arm/main.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+	"fmt"
+	"time"
+)
+
+func main() {
+	for counter := 0; ; counter++ {
+		fmt.Println("Hello world!", counter)
+
+		time.Sleep(time.Second * 1)
+	}
+}
diff --git a/integration/testdata/build/docker-with-platform-arm/skaffold.yaml b/integration/testdata/build/docker-with-platform-arm/skaffold.yaml
new file mode 100644
index 000000000..2baaaf30d
--- /dev/null
+++ b/integration/testdata/build/docker-with-platform-arm/skaffold.yaml
@@ -0,0 +1,15 @@
+apiVersion: skaffold/v3alpha1
+kind: Config
+build:
+  artifacts:
+  - image: docker-with-platform-arm
+
+profiles:
+  - name: pod
+    manifests:
+      rawYaml:
+      - k8s/pod.yaml
+  - name: deployment
+    manifests:
+      rawYaml:
+      - k8s/deployment.yaml
\ No newline at end of file
diff --git a/integration/testdata/build/gcb-with-platform/Dockerfile b/integration/testdata/build/gcb-with-platform/Dockerfile
new file mode 100644
index 000000000..67f8c3cbb
--- /dev/null
+++ b/integration/testdata/build/gcb-with-platform/Dockerfile
@@ -0,0 +1,14 @@
+FROM golang:1.18 as builder
+WORKDIR /code
+COPY main.go .
+COPY go.mod .
+# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
+ARG SKAFFOLD_GO_GCFLAGS
+RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -trimpath -o /app main.go
+
+FROM alpine:3
+# Define GOTRACEBACK to mark this container as using the Go language runtime
+# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
+ENV GOTRACEBACK=single
+CMD ["./app"]
+COPY --from=builder /app .
diff --git a/integration/testdata/build/gcb-with-platform/go.mod b/integration/testdata/build/gcb-with-platform/go.mod
new file mode 100644
index 000000000..adee4fb0a
--- /dev/null
+++ b/integration/testdata/build/gcb-with-platform/go.mod
@@ -0,0 +1,3 @@
+module github.com/GoogleContainerTools/skaffold/examples/google-cloud-build
+
+go 1.18
diff --git a/integration/testdata/build/gcb-with-platform/k8s-pod.yaml b/integration/testdata/build/gcb-with-platform/k8s-pod.yaml
new file mode 100644
index 000000000..e8e559450
--- /dev/null
+++ b/integration/testdata/build/gcb-with-platform/k8s-pod.yaml
@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Pod
+metadata:
+  name: getting-started
+spec:
+  containers:
+  - name: getting-started
+    image: gcr.io/k8s-skaffold/skaffold-example-with-location
diff --git a/integration/testdata/build/gcb-with-platform/main.go b/integration/testdata/build/gcb-with-platform/main.go
new file mode 100644
index 000000000..593721cfe
--- /dev/null
+++ b/integration/testdata/build/gcb-with-platform/main.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+	"fmt"
+	"time"
+)
+
+func main() {
+	for {
+		fmt.Println("Hello world!")
+
+		time.Sleep(time.Second * 1)
+	}
+}
diff --git a/integration/testdata/build/gcb-with-platform/skaffold.yaml b/integration/testdata/build/gcb-with-platform/skaffold.yaml
new file mode 100644
index 000000000..79658f19a
--- /dev/null
+++ b/integration/testdata/build/gcb-with-platform/skaffold.yaml
@@ -0,0 +1,11 @@
+apiVersion: skaffold/v3alpha1
+kind: Config
+build:
+  artifacts:
+    - image: gcr.io/k8s-skaffold/gcb-with-platform
+  googleCloudBuild:
+    projectId: k8s-skaffold
+    region: asia-east1
+manifests:
+  rawYaml:
+    - k8s-*
\ No newline at end of file
diff --git a/pkg/skaffold/build/cache/retrieve_test.go b/pkg/skaffold/build/cache/retrieve_test.go
index 4d4ae6730..125aeb881 100644
--- a/pkg/skaffold/build/cache/retrieve_test.go
+++ b/pkg/skaffold/build/cache/retrieve_test.go
@@ -142,6 +142,9 @@ func TestCacheBuildLocal(t *testing.T) {
 		t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) {
 			return args, nil
 		})
+		t.Override(&docker.EvalBuildArgsWithEnv, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string, _ map[string]string) (map[string]*string, error) {
+			return args, nil
+		})
 
 		// Create cache
 		cfg := &mockConfig{
@@ -239,6 +242,9 @@ func TestCacheBuildRemote(t *testing.T) {
 		t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) {
 			return args, nil
 		})
+		t.Override(&docker.EvalBuildArgsWithEnv, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string, _ map[string]string) (map[string]*string, error) {
+			return args, nil
+		})
 
 		// Create cache
 		cfg := &mockConfig{
@@ -324,6 +330,9 @@ func TestCacheFindMissing(t *testing.T) {
 		t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) {
 			return args, nil
 		})
+		t.Override(&docker.EvalBuildArgsWithEnv, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string, _ map[string]string) (map[string]*string, error) {
+			return args, nil
+		})
 
 		// Create cache
 		cfg := &mockConfig{
diff --git a/pkg/skaffold/build/docker/docker_test.go b/pkg/skaffold/build/docker/docker_test.go
index b46212cc2..a7c4ec1cd 100644
--- a/pkg/skaffold/build/docker/docker_test.go
+++ b/pkg/skaffold/build/docker/docker_test.go
@@ -134,7 +134,7 @@ func TestDockerCLIBuild(t *testing.T) {
 		testutil.Run(t, test.description, func(t *testutil.T) {
 			t.NewTempDir().Touch("Dockerfile").Chdir()
 			dockerfilePath, _ := filepath.Abs("Dockerfile")
-			t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) {
+			t.Override(&docker.EvalBuildArgsWithEnv, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string, _ map[string]string) (map[string]*string, error) {
 				return args, nil
 			})
 			t.Override(&docker.DefaultAuthHelper, stubAuth{})
@@ -233,7 +233,7 @@ func TestDockerCLICheckCacheFromArgs(t *testing.T) {
 			a.Workspace = "."
 			a.DockerArtifact.DockerfilePath = dockerfilePath
 			t.Override(&docker.DefaultAuthHelper, stubAuth{})
-			t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) {
+			t.Override(&docker.EvalBuildArgsWithEnv, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string, _ map[string]string) (map[string]*string, error) {
 				return args, nil
 			})
 
diff --git a/pkg/skaffold/build/docker/errors_test.go b/pkg/skaffold/build/docker/errors_test.go
index ccc694698..6f92bdad2 100644
--- a/pkg/skaffold/build/docker/errors_test.go
+++ b/pkg/skaffold/build/docker/errors_test.go
@@ -53,7 +53,7 @@ Refer https://skaffold.dev/docs/references/yaml/#build-artifacts-docker for deta
 		testutil.Run(t, test.description, func(t *testutil.T) {
 			t.NewTempDir().Touch("Dockerfile").Chdir()
 			dockerfilePath, _ := filepath.Abs("Dockerfile")
-			t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) {
+			t.Override(&docker.EvalBuildArgsWithEnv, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string, _ map[string]string) (map[string]*string, error) {
 				return args, nil
 			})
 			t.Override(&util.DefaultExecCommand, testutil.CmdRun(
diff --git a/pkg/skaffold/build/local/local_test.go b/pkg/skaffold/build/local/local_test.go
index 8cd330e73..b9bc45b17 100644
--- a/pkg/skaffold/build/local/local_test.go
+++ b/pkg/skaffold/build/local/local_test.go
@@ -228,7 +228,7 @@ func TestLocalRun(t *testing.T) {
 			t.Override(&docker.NewAPIClient, func(context.Context, docker.Config) (docker.LocalDaemon, error) {
 				return fakeLocalDaemon(test.api), nil
 			})
-			t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) {
+			t.Override(&docker.EvalBuildArgsWithEnv, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string, _ map[string]string) (map[string]*string, error) {
 				return args, nil
 			})
 			testEvent.InitializeState([]latest.Pipeline{{
@@ -402,7 +402,7 @@ func TestGetArtifactBuilder(t *testing.T) {
 			t.Override(&docker.NewAPIClient, func(context.Context, docker.Config) (docker.LocalDaemon, error) {
 				return fakeLocalDaemon(&testutil.FakeAPIClient{}), nil
 			})
-			t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) {
+			t.Override(&docker.EvalBuildArgsWithEnv, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string, _ map[string]string) (map[string]*string, error) {
 				return args, nil
 			})
 
diff --git a/pkg/skaffold/docker/image_test.go b/pkg/skaffold/docker/image_test.go
index 7467a86d9..8a6e4090d 100644
--- a/pkg/skaffold/docker/image_test.go
+++ b/pkg/skaffold/docker/image_test.go
@@ -195,7 +195,7 @@ func TestBuild(t *testing.T) {
 	for _, test := range tests {
 		testutil.Run(t, test.description, func(t *testutil.T) {
 			t.Override(&DefaultAuthHelper, testAuthHelper{})
-			t.Override(&EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) {
+			t.Override(&EvalBuildArgsWithEnv, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string, _ map[string]string) (map[string]*string, error) {
 				return util.EvaluateEnvTemplateMap(args)
 			})
 			t.SetEnvs(test.env)