From 4b9e2fd6c1e11c6171b4a907e89807c16b9c5737 Mon Sep 17 00:00:00 2001
From: Nicco Kunzmann <niccokunzmann@rambler.ru>
Date: Wed, 5 Feb 2025 15:37:58 +0000
Subject: [PATCH 1/3] Create first draft of multiplatform build

---
 .github/workflows/main.yml |  1 +
 Makefile                   | 11 +++++++++--
 README.md                  | 15 +++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 2617f734..9c49bddc 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -32,6 +32,7 @@ jobs:
     env:
       VERSION: ${{ matrix.postgres }}-${{ matrix.postgis }}
       VARIANT: ${{ matrix.variant }}
+      PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7,linux/386
 
     steps:
     - name: Checkout source
diff --git a/Makefile b/Makefile
index cb6f6abb..a8137164 100644
--- a/Makefile
+++ b/Makefile
@@ -58,6 +58,13 @@ IMAGE_NAME ?= postgis
 DOCKER=docker
 DOCKERHUB_DESC_IMG=peterevans/dockerhub-description:latest
 
+# choice between buildx and build depending on the PLATFORMS variable
+ifdef PLATFORMS
+  BUILD := buildx build --platform $(PLATFORMS)
+else
+  BUILD := build
+endif
+
 GIT=git
 OFFIMG_LOCAL_CLONE=$(HOME)/official-images
 OFFIMG_REPO_URL=https://github.com/docker-library/official-images.git
@@ -76,12 +83,12 @@ update:
 define build-version
 build-$1:
 ifeq ($(do_default),true)
-	$(DOCKER) build --pull -t $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1) $1
+	$(DOCKER) $(BUILD) --pull -t $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1) $1
 	$(DOCKER) images          $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1)
 endif
 ifeq ($(do_alpine),true)
 ifneq ("$(wildcard $1/alpine)","")
-	$(DOCKER) build --pull -t $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1)-alpine $1/alpine
+	$(DOCKER) $(BUILD) --pull -t $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1)-alpine $1/alpine
 	$(DOCKER) images          $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1)-alpine
 endif
 endif
diff --git a/README.md b/README.md
index 5211685b..a06ff3f2 100644
--- a/README.md
+++ b/README.md
@@ -193,6 +193,21 @@ This Docker-PostGIS project [is part of the PostGIS group](https://postgis.net/d
 * If you have a major change in mind, we kindly ask you to start a discussion about it first.
 * After making changes to the templates, please run the `./update.sh` script.
 
+## Building Docker Images
+
+To build the all Docker images on your local machine, run:
+
+```sh
+make build
+```
+
+To build for a different platform, install `docker buildx` and run:
+
+```sh
+export PLATFORMS="linux/arm64,linux/amd64"
+make build
+```
+
 ## Code of Conduct
 
 see: https://postgis.net/community/conduct/

From 5bb1ff1f7aa1741fed65534a32eccdf8f14c12d0 Mon Sep 17 00:00:00 2001
From: Nicco Kunzmann <niccokunzmann@rambler.ru>
Date: Wed, 5 Feb 2025 15:42:30 +0000
Subject: [PATCH 2/3] Add buildx install to github actions

---
 .github/workflows/main.yml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 9c49bddc..a931870f 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -38,6 +38,12 @@ jobs:
     - name: Checkout source
       uses: actions/checkout@v4
 
+    - name: Set up QEMU
+      uses: docker/setup-qemu-action@v3
+
+    - name: Set up Docker Buildx
+      uses: docker/setup-buildx-action@v3
+
     - name: Build docker image for ${{ env.VERSION }} ${{ env.VARIANT }}
       run: make test
 

From c91da6dd013a86db4da1e77d6ae175dd7c437fff Mon Sep 17 00:00:00 2001
From: Nicco Kunzmann <niccokunzmann@rambler.ru>
Date: Thu, 6 Feb 2025 14:23:10 +0000
Subject: [PATCH 3/3] Remove modification to docker build action

---
 .github/workflows/main.yml | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index a931870f..2617f734 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -32,18 +32,11 @@ jobs:
     env:
       VERSION: ${{ matrix.postgres }}-${{ matrix.postgis }}
       VARIANT: ${{ matrix.variant }}
-      PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7,linux/386
 
     steps:
     - name: Checkout source
       uses: actions/checkout@v4
 
-    - name: Set up QEMU
-      uses: docker/setup-qemu-action@v3
-
-    - name: Set up Docker Buildx
-      uses: docker/setup-buildx-action@v3
-
     - name: Build docker image for ${{ env.VERSION }} ${{ env.VARIANT }}
       run: make test