From 365b3aee2dbd5175e9c4e612ae4b2d875d15377b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 14 Oct 2019 14:32:10 +0200 Subject: [PATCH] make buildx: fix Makefile version being ignored 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 --- Makefile | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a075f64aaa..a7633a1694 100644 --- a/Makefile +++ b/Makefile @@ -252,16 +252,25 @@ else buildx: endif +BUILDX_COMMIT ?= v0.3.0 +export BUILDX_COMMIT + bundles/buildx: BUILDX_DOCKERFILE ?= Dockerfile.buildx -bundles/buildx: BUILDX_COMMIT ?= v0.3.0 bundles/buildx: bundles ## build buildx CLI tool # This intetionally is not using the `--output` flag from the docker CLI which is a buildkit option # The idea here being that if buildx is being used, it's because buildkit is not supported natively - docker build -f $(BUILDX_DOCKERFILE) -t "moby-buildx:$(BUILDX_COMMIT)" \ + docker build -f $(BUILDX_DOCKERFILE) -t "moby-buildx:$${BUILDX_COMMIT:-latest}" \ --build-arg BUILDX_COMMIT \ --build-arg BUILDX_REPO \ --build-arg GOOS=$$(if [ -n "$(GOOS)" ]; then echo $(GOOS); else go env GOHOSTOS || uname | awk '{print tolower($$0)}' || true; fi) \ --build-arg GOARCH=$$(if [ -n "$(GOARCH)" ]; then echo $(GOARCH); else go env GOHOSTARCH || true; fi) \ - . && \ - id=$$(docker create moby-buildx:$(BUILDX_COMMIT)); \ - if [ -n "$${id}" ]; then docker cp $${id}:/usr/bin/buildx $@ && touch $@; docker rm -f $${id}; fi + . + + id=$$(docker create moby-buildx:$${BUILDX_COMMIT:-latest}); \ + if [ -n "$${id}" ]; then \ + docker cp $${id}:/usr/bin/buildx $@ \ + && touch $@; \ + docker rm -f $${id}; \ + fi + + $@ version