The `BUILDX_COMMIT` variable was set as a Make variable,
which isn't exported, and thus not available in scripts,
unless referenced through `$(VAR)` (non-curly-brackets).
As a result `--build-arg BUILDX_COMMIT` did not set the
`BUILDX_COMMIT` build-arg, and the default from the Dockerfile
(`master`) was used instead.
This patch exports the default version that's set in the
Makefile, so that it can be used as a regular environment
variable. The script was also slighly modified to no longer
use the `Make` variable.
In addition, the `buildx` target now calls `buildx version`,
which is useful to confirm if the binary was successfully built
(and with the correct version).
Before:
rm -f bundles/buildx && make buildx && ./bundles/buildx version
# => => naming to docker.io/library/moby-buildx:v0.3.0
github.com/docker/buildx v0.3.1 6db68d0
# using a make variable:
rm -f bundles/buildx && make BUILDX_COMMIT=v0.2.1 buildx && ./bundles/buildx version
# => => naming to docker.io/library/moby-buildx:v0.2.1
github.com/docker/buildx v0.3.1 6db68d0
# using an environment variable:
rm -f bundles/buildx && BUILDX_COMMIT=v0.2.2 make buildx && ./bundles/buildx version
# => => naming to docker.io/library/moby-buildx:v0.2.2
github.com/docker/buildx v0.3.1 6db68d0
After:
# default
rm -f bundles/buildx && make buildx
# => => naming to docker.io/library/moby-buildx:v0.3.0
github.com/docker/buildx v0.3.0 c967f1d
# using a make variable:
rm -f bundles/buildx && make BUILDX_COMMIT=v0.2.1 buildx
# => => naming to docker.io/library/moby-buildx:v0.2.1
github.com/docker/buildx v0.2.1 0eb2df5
# using an environment variable:
rm -f bundles/buildx && BUILDX_COMMIT=v0.2.2 make buildx
# => => naming to docker.io/library/moby-buildx:v0.2.2
github.com/docker/buildx v0.2.2 ab5fe3d
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
... | ... |
@@ -252,16 +252,25 @@ else |
252 | 252 |
buildx: |
253 | 253 |
endif |
254 | 254 |
|
255 |
+BUILDX_COMMIT ?= v0.3.0 |
|
256 |
+export BUILDX_COMMIT |
|
257 |
+ |
|
255 | 258 |
bundles/buildx: BUILDX_DOCKERFILE ?= Dockerfile.buildx |
256 |
-bundles/buildx: BUILDX_COMMIT ?= v0.3.0 |
|
257 | 259 |
bundles/buildx: bundles ## build buildx CLI tool |
258 | 260 |
# This intetionally is not using the `--output` flag from the docker CLI which is a buildkit option |
259 | 261 |
# The idea here being that if buildx is being used, it's because buildkit is not supported natively |
260 |
- docker build -f $(BUILDX_DOCKERFILE) -t "moby-buildx:$(BUILDX_COMMIT)" \ |
|
262 |
+ docker build -f $(BUILDX_DOCKERFILE) -t "moby-buildx:$${BUILDX_COMMIT:-latest}" \ |
|
261 | 263 |
--build-arg BUILDX_COMMIT \ |
262 | 264 |
--build-arg BUILDX_REPO \ |
263 | 265 |
--build-arg GOOS=$$(if [ -n "$(GOOS)" ]; then echo $(GOOS); else go env GOHOSTOS || uname | awk '{print tolower($$0)}' || true; fi) \ |
264 | 266 |
--build-arg GOARCH=$$(if [ -n "$(GOARCH)" ]; then echo $(GOARCH); else go env GOHOSTARCH || true; fi) \ |
265 |
- . && \ |
|
266 |
- id=$$(docker create moby-buildx:$(BUILDX_COMMIT)); \ |
|
267 |
- if [ -n "$${id}" ]; then docker cp $${id}:/usr/bin/buildx $@ && touch $@; docker rm -f $${id}; fi |
|
267 |
+ . |
|
268 |
+ |
|
269 |
+ id=$$(docker create moby-buildx:$${BUILDX_COMMIT:-latest}); \ |
|
270 |
+ if [ -n "$${id}" ]; then \ |
|
271 |
+ docker cp $${id}:/usr/bin/buildx $@ \ |
|
272 |
+ && touch $@; \ |
|
273 |
+ docker rm -f $${id}; \ |
|
274 |
+ fi |
|
275 |
+ |
|
276 |
+ $@ version |