-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Templated Docker buildArgs work with useDockerCLI but not with the Docker Engine #2234
Copy link
Copy link
Closed
Labels
help wantedWe would love to have this done, but don't have the bandwidth, need help from contributorsWe would love to have this done, but don't have the bandwidth, need help from contributorskind/bugSomething isn't workingSomething isn't working
Description
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
- Have a docker image that use build args
- Set that build arg with a template
- Run
skaffold buildwith the environment variable set - Inspect the built image label
Dockerfile:
FROM scratch
ARG MY_ARG
LABEL my_label=$MY_ARGskaffold.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}}'
fooAfter 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:
skaffold/pkg/skaffold/docker/image.go
Lines 345 to 358 in 6cb1d51
| 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)) | |
| } | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
help wantedWe would love to have this done, but don't have the bandwidth, need help from contributorsWe would love to have this done, but don't have the bandwidth, need help from contributorskind/bugSomething isn't workingSomething isn't working