Contributing guidelines and issue reporting guide
Well-formed report checklist
Description of bug
Bug description
Passing --opt build-arg:IMAGE to buildctl build results in an error:
error: invalid opt: invalid value build-arg:IMAGE
even though the environment variable IMAGE is set.
Given that BuildKit's own documentation of build-arg handling is fairly sparse,
a reasonable expectation is that the original Docker/Buildx behavior would be followed.
The simple workaround of passing --opt build-arg:IMAGE=$IMAGE avoids the error,
but that should not be necessary.
Reproduction
$ docker run --rm -it --entrypoint sh --privileged -w /root moby/buildkit
~ # printf 'ARG IMAGE\nFROM $IMAGE\nRUN echo working\n' > Dockerfile
~ # export IMAGE=alpine
~ # buildctl-daemonless.sh build --frontend dockerfile.v0 --local dockerfile=. --opt build-arg:IMAGE
error: invalid opt: invalid value build-arg:IMAGE
~ #
$
Version information
$ docker run --rm moby/buildkit --version
buildkitd github.com/moby/buildkit v0.32.2 991535e0973488b6a429096d21fa13f81f2d89d8
$
Additional notes
I tracked down the issue to BuildKit's unifrom handling of ALL --opt arguments,
via ParseOpt and attrMap in opt.go and build.go, respectively.
Contrast that with Buildx's listToMap function that optionally references environment variables:
https://github.com/docker/buildx/blob/556e63ede01ff0321cb5dda26826accfec9374f6/commands/build.go#L782-L800
As expected, build-arg processing turns that on:
https://github.com/docker/buildx/blob/556e63ede01ff0321cb5dda26826accfec9374f6/commands/build.go#L115
Contributing guidelines and issue reporting guide
Well-formed report checklist
Description of bug
Bug description
Passing
--opt build-arg:IMAGEtobuildctl buildresults in an error:even though the environment variable
IMAGEis set.Given that BuildKit's own documentation of
build-arghandling is fairly sparse,a reasonable expectation is that the original Docker/Buildx behavior would be followed.
The simple workaround of passing
--opt build-arg:IMAGE=$IMAGEavoids the error,but that should not be necessary.
Reproduction
Version information
Additional notes
I tracked down the issue to BuildKit's unifrom handling of ALL
--optarguments,via
ParseOptandattrMapin opt.go and build.go, respectively.Contrast that with Buildx's
listToMapfunction that optionally references environment variables:https://github.com/docker/buildx/blob/556e63ede01ff0321cb5dda26826accfec9374f6/commands/build.go#L782-L800
As expected,
build-argprocessing turns that on:https://github.com/docker/buildx/blob/556e63ede01ff0321cb5dda26826accfec9374f6/commands/build.go#L115