Skaffold does not cope well with buildkit used with --output (invalid reference format) #7024
Closed
Description
Expected behavior
When using buildkit in conjunction with --output skaffold should not expect that docker will tag the build.
Actual behavior
Docker buildkit used with --output does not produce any tag for the build. Skaffold on the other hand is not aware about this behavior and expects a tag failing the process.
Error parsing reference: "" is not a valid repository/tag: invalid reference format
Information
- Skaffold version:
v1.35.2
- Operating system:
Running from a docker container based on:
CentOS Linux release 7.9.2009 (Core) (Linux 6e75c71d7fd8 4.18.0-348.7.1.el8_5.x86_64
- Installed via:
skaffold.dev
- Contents of skaffold.yaml:
---
apiVersion: skaffold/v2beta26
kind: Config
build:
local:
push: false
tryImportMissing: true
useBuildkit: true
useDockerCLI: true
tagPolicy:
envTemplate:
template: '{{.GIT_COMMIT}}'
artifacts:
- image: my-docker-image
context: source/my-docker-image
docker:
buildArgs:
GIT_COMMIT: 75c25fd
GIT_BRANCH: <branch_name>
noCache: false
target: export-test-results
cliFlags:
- --output
- /tmp/output_dir
Steps to reproduce the behavior
- Using a multistage docker build with a target and running skaffold on that target to get the output files (unit tests at build time)
https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs
FROM scratch as export-test-results
COPY --from=build /my-app/build/reports/jacoco/* /
From skaffold perspective this will resume to following skaffold build execution:
skaffold build -f /tmp/skaffold-my-image-export-test-results.yaml --quiet=false --cache-artifacts=false --default-repo=my-docker.repository
Which will fail with:
Error parsing reference: "" is not a valid repository/tag: invalid reference format
By using vdebug I got the command that was executed de-facto by skaffold.
DOCKER_BUILDKIT=1 docker build source/my-docker-image --file /my_image_dir/source/my-docker-image/Dockerfile -t my-docker-image:1.0.0 --build-arg GIT_BRANCH=feature/random-branch-name --build-arg GIT_COMMIT=0895bd5 --output /tmp/my_custom_dir3 --target export-test-results --force-rm
Basically what happens in behind is when using DOCKER_BUILDKIT=1 with --output the normal behaviour is not to tag the image.
Skaffold doesn't take this in consideration and expects a tag, failing with the error message from above which in this case isn't the correct behavior.