From 7620a2c32a6d33264aee1f3b2e5d452292515c80 Mon Sep 17 00:00:00 2001
From: Robin Goodall <rjg21@cam.ac.uk>
Date: Fri, 21 Mar 2025 16:20:01 +0000
Subject: [PATCH] feat: no parallelism for multiarch builds

---
 build-and-push.gitlab-ci.yml |  5 +----
 prep-buildx.sh               | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100755 prep-buildx.sh

diff --git a/build-and-push.gitlab-ci.yml b/build-and-push.gitlab-ci.yml
index 5bf6a1f..28cdb68 100644
--- a/build-and-push.gitlab-ci.yml
+++ b/build-and-push.gitlab-ci.yml
@@ -9,10 +9,7 @@
     - apk update
     - apk add bash gettext  # for envsubst command
     - apk add jq # for querying manifests
-    # The official docs state that `docker buildx create --use` should be enough on its own. However, there appears to be
-    # a bug which, even though this issue is closed https://github.com/docker/buildx/issues/584#issuecomment-830041059,
-    # still requires this `docker run --rm` workaround.
-    - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes || true; docker buildx create --use
+    - ./prep-buildx.sh
   script:
     - ./build.sh
   variables:
diff --git a/prep-buildx.sh b/prep-buildx.sh
new file mode 100755
index 0000000..4d7aaec
--- /dev/null
+++ b/prep-buildx.sh
@@ -0,0 +1,19 @@
+#! /bin/bash
+
+set -ex
+
+# Change max-parallelism to 1 if building multiple archs
+
+echo "[worker.oci]" > /etc/buildkitd.toml
+
+if [[ $IMAGE_ARCHS == *","* ]]; then
+    echo "Setting max-parallelism to 1 as building multiple archs"
+    echo "  max-parallelism = 1" >> /etc/buildkitd.toml
+fi
+
+# The official docs state that `docker buildx create --use` should be enough on its own. However, there appears to be
+# a bug which, even though this issue is closed https://github.com/docker/buildx/issues/584#issuecomment-830041059,
+# still requires this `docker run --rm` workaround.
+docker run --rm --privileged multiarch/qemu-user-static --reset -p yes || true; docker buildx create --config /etc/buildkitd.toml --use
+
+docker buildx inspect --bootstrap
-- 
GitLab