diff --git a/docs/content/en/schemas/v2beta16.json b/docs/content/en/schemas/v2beta16.json index 283f0081f80..dd09e4f682a 100755 --- a/docs/content/en/schemas/v2beta16.json +++ b/docs/content/en/schemas/v2beta16.json @@ -1111,7 +1111,7 @@ "x-intellij-html-description": "arguments passed to the docker build.", "default": "{}", "examples": [ - "{\"key1\": \"value1\", \"key2\": \"value2\"}" + "{\"key1\": \"value1\", \"key2\": \"{{ .ENV_VAR }}\"}" ] }, "cacheFrom": { diff --git a/pkg/skaffold/docker/build_args_test.go b/pkg/skaffold/docker/build_args_test.go index aee2d1291b0..120d5b9df0e 100644 --- a/pkg/skaffold/docker/build_args_test.go +++ b/pkg/skaffold/docker/build_args_test.go @@ -245,6 +245,43 @@ func TestCreateBuildArgsFromArtifacts(t *testing.T) { } } +func TestBuildArgTemplating(t *testing.T) { + envs := map[string]string{ + "MY_KEY": "abc123", + "SO_SECRET": "do not say it", + } + + args := map[string]*string{ + "MY_KEY": util.StringPtr("{{ .MY_KEY}}"), + "SO_SECRET": util.StringPtr("{{ .SO_SECRET}}"), + } + + dockerFile := ` + ARG MY_KEY + ARG SO_SECRET + ARG foo3 + ARG SKAFFOLD_GO_GCFLAGS + FROM bar1` + + testutil.Run(t, "test_templating_from_env_variables", func(t *testutil.T) { + t.SetEnvs(envs) + artifact := &latestV1.DockerArtifact{ + DockerfilePath: "Dockerfile", + BuildArgs: args, + } + + tmpDir := t.NewTempDir() + tmpDir.Write("./Dockerfile", dockerFile) + workspace := tmpDir.Path(".") + + filledMap, err := EvalBuildArgs(config.RunModes.Dev, workspace, artifact.DockerfilePath, artifact.BuildArgs, nil) + + t.CheckNil(err) + t.CheckMatches(*filledMap["MY_KEY"], "abc123") + t.CheckMatches(*filledMap["SO_SECRET"], "do not say it") + }) +} + type mockArtifactResolver struct { m map[string]string } diff --git a/pkg/skaffold/schema/latest/v1/config.go b/pkg/skaffold/schema/latest/v1/config.go index 173816ec41e..a71b68f5706 100644 --- a/pkg/skaffold/schema/latest/v1/config.go +++ b/pkg/skaffold/schema/latest/v1/config.go @@ -1205,7 +1205,7 @@ type DockerArtifact struct { Target string `yaml:"target,omitempty"` // BuildArgs are arguments passed to the docker build. - // For example: `{"key1": "value1", "key2": "value2"}`. + // For example: `{"key1": "value1", "key2": "{{ .ENV_VAR }}"}`. BuildArgs map[string]*string `yaml:"buildArgs,omitempty"` // NetworkMode is passed through to docker and overrides the