Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation of docker buildArgs (#5871) #5901

Merged
merged 2 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/en/schemas/v2beta16.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
37 changes: 37 additions & 0 deletions pkg/skaffold/docker/build_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/schema/latest/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down