mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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 <github@gone.nl>
This commit is contained in:
parent
ce28a91cca
commit
365b3aee2d
1 changed files with 14 additions and 5 deletions
19
Makefile
19
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
|
||||
|
|
Loading…
Reference in a new issue