Skip to content

Templated Docker buildArgs work with useDockerCLI but not with the Docker Engine #2234

@sandhose

Description

@sandhose

Expected behavior

Templated field should work with build.artifacts[].docker.buildArgs.* for docker builds.

Actual behavior

They only work if build.local.useDockerCLI is set to true.

Information

  • Skaffold version: 0.31.0
  • Operating system: macOS 10.14.5
  • Contents of skaffold.yaml:
apiVersion: skaffold/v1beta11
kind: Config
build:
  tagPolicy:
    sha256: {}
  artifacts:
  - image: myimages
    docker:
      buildArgs:
        BUILD_DATE: '{{ .BUILD_DATE }}'
        COMMIT: '{{ .COMMIT }}'
        VERSION: '{{ .VERSION }}'
  local:
    useDockerCLI: true
deploy:
  kustomize:
    path: "k8s/"

Steps to reproduce the behavior

  1. Have a docker image that use build args
  2. Set that build arg with a template
  3. Run skaffold build with the environment variable set
  4. Inspect the built image label

Dockerfile:

FROM scratch

ARG MY_ARG
LABEL my_label=$MY_ARG

skaffold.yaml:

apiVersion: skaffold/v1beta11
kind: Config
build:
  tagPolicy:
    sha256: {}
  artifacts:
  - image: my_image
    docker:
      buildArgs:
        MY_ARG: '{{ .MY_ARG }}'
  local:
    useDockerCLI: true
$ MY_ARG=foo skaffold build
...
Successfully tagged my_image:latest
...
$ docker inspect my_image:latest -f '{{.ContainerConfig.Labels.my_label}}'
foo

After setting build.local.useDockerCLI to false in skaffold.yaml:

$ MY_ARG=foo skaffold build
...
Successfully tagged my_image:latest
...
$ docker inspect my_image:latest -f '{{.ContainerConfig.Labels.my_label}}'
{{ .MY_ARG }}

The code that does this for the docker CLI builder seems to be here:

for _, k := range keys {
args = append(args, "--build-arg")
v := a.BuildArgs[k]
if v == nil {
args = append(args, k)
} else {
value, err := evaluateBuildArgsValue(*v)
if err != nil {
return nil, errors.Wrapf(err, "unable to get value for build arg: %s", k)
}
args = append(args, fmt.Sprintf("%s=%s", k, value))
}
}

Metadata

Metadata

Assignees

Labels

help wantedWe would love to have this done, but don't have the bandwidth, need help from contributorskind/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions