|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] CI: use --platform on `docker build` and `push`
commit 61f957d48c78df6c5254b6f54d6170d3bd3d717e
Author: Anthony PERARD <anthony.perard@xxxxxxxxxx>
AuthorDate: Wed Apr 29 14:48:01 2026 +0200
Commit: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Fri May 1 10:51:19 2026 +0100
CI: use --platform on `docker build` and `push`
Without --platform, it seems recent versions of docker ignores the
platform of the image when pushing, and it's pushed as the platform of
the runner.
If we happen to build an arm64 image on x86, with recent version of
docker, the image will be push as if it was an x86 image, then
`docker run --platform=linux/arm64 ...` fails. Even if it would
work without --platform, gitlab-runner will not be able to use the
image.
To go back to the previous behavior, we will extract --platform from
the dockerfiles, and use it on the command line.
--platform= is needed on both docker-build and docker-push. The first
one so that the image is tagged with the right platform, and the
second one so that we can push a "generic" image without been tagged
to a particular platform. --platform on docker-push allow to easly use
the container on any arch, without having to use --platform on
docker-pull or docker-run.
`docker push --platform` seem to have been added to 1.46, according to
the [doc], and doesn't exist on Podman. So we need to check that we
are using `docker` and that the API version is new enough.
[doc] https://docs.docker.com/reference/cli/docker/image/push/
Also, introduce the $img variable, to make the lines a bit shorter.
Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
automation/build/Makefile | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/automation/build/Makefile b/automation/build/Makefile
index fedf7524da..d578cd3476 100644
--- a/automation/build/Makefile
+++ b/automation/build/Makefile
@@ -15,10 +15,28 @@ help:
include yocto/yocto.inc
+# Find out if we are running Podman, if not is likely docker.
+is-docker = $(if $(filter Podman,$(shell $(DOCKER_CMD) version)),,1)
+
+# Find out the docker API version is at least 1.46. We exploit `sort -V` to
+# compare the versions at it can sort by version.
+docker-api-version = $(shell $(DOCKER_CMD) version -f '{{.Client.APIVersion}}')
+docker-min-version = $(firstword $(shell printf "1.46\n$(docker-api-version)"
| sort -V))
+docker-have-push-platform = $(if $(filter 1.46,$(docker-min-version)),1)
+
+# check if we can use `X push --platform`.
+# `podman push` doesn't support --platform.
+# `docker` only have it on recent version.
+builder-have-push-platform = $(and $(is-docker),$(docker-have-push-platform))
+
%: %.dockerfile ## Builds containers
- $(DOCKER_CMD) build --pull -t $(REGISTRY)/$(@D):$(@F) -f $< $(<D)
- @if [ ! -z $${PUSH+x} ]; then \
- $(DOCKER_CMD) push $(REGISTRY)/$(@D):$(@F); \
+ set -xe; \
+ $(if $(builder-have-push-platform), \
+ platform=$$(sed -n '/^FROM/{s/.*\(--platform=[^ ]*\) .*/\1/p;q}'
$<); ) \
+ img="$(REGISTRY)/$(@D):$(@F)"; \
+ $(DOCKER_CMD) build --pull $$platform -t $$img -f $< $(<D); \
+ if [ ! -z $${PUSH+x} ]; then \
+ $(DOCKER_CMD) push $$platform $$img; \
fi
.PHONY: all clean
--
generated by git-patchbot for /home/xen/git/xen.git#master
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |