Use buildx to support multi-arch images#86
Use buildx to support multi-arch images#86lexbritvin wants to merge 1 commit intoskilld-labs:masterfrom
Conversation
| @echo "Building images for tags: $(TAGS)" | ||
| set -e; for i in $(TAGS); do printf "\nBuilding $(NAME):$$i \n\n"; cd php$$i; \ | ||
| DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build -t $(NAME):$$i \ | ||
| --platform $(PLATFORM) \ |
There was a problem hiding this comment.
this option is available because DOCKER_BUILDKIT=1 means that build is using buildx
There was a problem hiding this comment.
Otherwise it needs just to replace s/build/buildx and remove there DOCKER_BUILDKIT
There was a problem hiding this comment.
From my experience, simple build is like buildx build --load which doesn't provide multiarch.
BTW, since Docker 23 it's always buildkit, but it still doesn't support multiarch for build
There was a problem hiding this comment.
I mean we just need to remove usage of DOCKER_BUILDKIT
|
Used following patch to try build diff --git a/Makefile b/Makefile
index 306cf99..dd658d0 100644
--- a/Makefile
+++ b/Makefile
@@ -3,18 +3,18 @@ TAGS ?= 81 81-fpm 81-unit 82 82-fpm 82-unit
COMPOSER_HASH ?= 55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae
DRUSH_VERSION ?= 8.4.12
-DOCKER_BUILDKIT ?= 1
-PLATFORM ?= linux/amd64
+PLATFORM ?= linux/amd64,linux/arm64
-.PHONY: all build push
+.PHONY: all build push prepare
all: build push
build:
@echo "Building images for tags: $(TAGS)"
set -e; for i in $(TAGS); do printf "\nBuilding $(NAME):$$i \n\n"; cd php$$i; \
- DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build -t $(NAME):$$i \
+ docker buildx build -t $(NAME):$$i \
--platform $(PLATFORM) \
+ --push \
--no-cache --progress=plain \
--build-arg COMPOSER_HASH=$(COMPOSER_HASH) \
--build-arg DRUSH_VERSION=$(DRUSH_VERSION) \
@@ -28,3 +28,7 @@ push:
unit:
make -C unit-php-builder/dev build
+
+prepare:
+ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
+ docker buildx create --useIt means the builder needs setup (qemu) Moreover the problem is that you can only push image (it's not stored locally) |
|
@ lexbritvin I pushed this way the |
|
I think we need 2 makefile targets :
|
I don't know/see how you tag specific versions except upstream tags. Please, correct me if I'm wrong or describe the build flow more precisely. |
|
Yes, you're right, so one target to push tagged release and another for latest ones |
|
btw as I got |
|
For the FYI You can actually attach different contexts to a builder to support native builds on remote machines (rpi4 or vps) without QEMU, if you are an enthusiast 😉 For me, a preparing step is strange to have in Makefile because it must be done once in the environment, like installing Docker. |
|
Hello @andypost ! |
|
Oh, I see you already push to 81 and 82. |
|
I can rebuild |
|
@lexbritvin please try pull fresh |
To provide multi-arch images, we have to use
buildxin the builds.Due to standard
buildcommand doesn't support multi-arch builds, andbuildx --loaddoesn't allow making multi-arch images locally also,make buildmust only be used for building images locally for the current arch.New target
make buildx-pushis introduced to create multi-arch images and is intended to build and push images to Docker Hub as a default way.We have to agree on the best build flow here and maybe introduce github actions to simplify the build procedure.
We must also rebuild the images for php74 to support older projects.