From 941dbcd01855354a9568edfcda353dfd00730fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Fei?= Date: Thu, 12 Nov 2026 17:24:15 +0100 Subject: [PATCH 1/6] fix: build PostGIS from master with address_standardizer and tiger geocoder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PostGIS 3.7.0 removed address_standardizer and postgis_tiger_geocoder from the main repository. With the base images on the CNPG side now shipping 3.7.0, the upgrade tests were trying to upgrade from 3.6 to 3.7.0, which cannot work. Go back to building PostGIS from master (reverting the stable-3.6 pin from #128) and build the two extensions from their new standalone repositories. Also add git-clone-retry.sh and use it for the clones from non-GitHub remotes (git.postgresql.org, git.osgeo.org), as they can sometimes time out from GitHub runners. The script and build-deps.txt are now bind-mounted into the RUN steps instead of copied, so they don't end up in the image. Signed-off-by: Niccolò Fei --- Dockerfile | 33 ++++++++++++++++++++++++--------- build-deps.txt | 1 + git-clone-retry.sh | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 9 deletions(-) create mode 100755 git-clone-retry.sh diff --git a/Dockerfile b/Dockerfile index b1475ff..c71a0a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,12 +25,12 @@ ARG PG_REPO=https://git.postgresql.org/git/postgresql.git ARG PG_BRANCH=master ARG PG_MAJOR=20 -COPY build-deps.txt / - ENV PATH=/usr/lib/postgresql/$PG_MAJOR/bin:$PATH # Install runtime and build dependencies -RUN apt-get update && \ +RUN --mount=type=bind,source=build-deps.txt,target=/build-deps.txt \ + --mount=type=bind,source=git-clone-retry.sh,target=/git-clone-retry.sh \ + apt-get update && \ apt-get install -y --no-install-recommends -o Dpkg::::="--force-confdef" -o Dpkg::::="--force-confold" \ gnupg \ dirmngr \ @@ -53,7 +53,7 @@ RUN apt-get update && \ usermod -u 26 postgres && \ # Build PostgreSQL mkdir -p /usr/src/postgresql && \ - git clone -b "$PG_BRANCH" --single-branch "$PG_REPO" /usr/src/postgresql && \ + /git-clone-retry.sh -b "$PG_BRANCH" --single-branch "$PG_REPO" /usr/src/postgresql && \ cd /usr/src/postgresql && \ export LLVM_CONFIG="/usr/lib/llvm-19/bin/llvm-config" && \ export CLANG=clang-19 && \ @@ -125,9 +125,16 @@ USER 26 FROM standard AS postgis USER root ARG POSTGIS_REPO=https://github.com/postgis/postgis.git -ARG POSTGIS_BRANCH=stable-3.6 +ARG POSTGIS_BRANCH=master +# PostGIS 3.7 moved these extensions out of the main repository +ARG ADDRESS_STANDARDIZER_REPO=https://github.com/postgis/address_standardizer.git +ARG ADDRESS_STANDARDIZER_BRANCH=main +ARG POSTGIS_TIGER_GEOCODER_REPO=https://git.osgeo.org/postgis/postgis_tiger_geocoder.git +ARG POSTGIS_TIGER_GEOCODER_BRANCH=main -RUN apt-get update && \ +RUN --mount=type=bind,source=build-deps.txt,target=/build-deps.txt \ + --mount=type=bind,source=git-clone-retry.sh,target=/git-clone-retry.sh \ + apt-get update && \ apt-get install -y --no-install-recommends \ $(cat /build-deps.txt) \ # runtime deps @@ -136,16 +143,24 @@ RUN apt-get update && \ libgdal36 \ libgeos-c1t64 \ libsfcgal2 \ + libpcre2-8-0 \ && \ + export PG_CONFIG=/usr/lib/postgresql/$PG_MAJOR/bin/pg_config && \ mkdir -p /usr/src/postgis && \ - git clone -b "$POSTGIS_BRANCH" --single-branch "$POSTGIS_REPO" /usr/src/postgis && \ + git clone -b "$POSTGIS_BRANCH" --single-branch --depth 1 "$POSTGIS_REPO" /usr/src/postgis && \ cd /usr/src/postgis && \ ./autogen.sh && \ - ./configure --with-pgconfig=/usr/lib/postgresql/$PG_MAJOR/bin/pg_config --with-sfcgal && \ + ./configure --with-sfcgal && \ make -j$(nproc) && \ make install && \ + git clone -b "$ADDRESS_STANDARDIZER_BRANCH" --single-branch --depth 1 "$ADDRESS_STANDARDIZER_REPO" /usr/src/address_standardizer && \ + make -C /usr/src/address_standardizer -j$(nproc) PG_CONFIG="$PG_CONFIG" && \ + make -C /usr/src/address_standardizer PG_CONFIG="$PG_CONFIG" install && \ + /git-clone-retry.sh -b "$POSTGIS_TIGER_GEOCODER_BRANCH" --single-branch --depth 1 "$POSTGIS_TIGER_GEOCODER_REPO" /usr/src/postgis_tiger_geocoder && \ + make -C /usr/src/postgis_tiger_geocoder -j$(nproc) PG_CONFIG="$PG_CONFIG" && \ + make -C /usr/src/postgis_tiger_geocoder PG_CONFIG="$PG_CONFIG" install && \ apt-get purge -y --auto-remove $(cat /build-deps.txt) && \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ - rm -rf /var/lib/apt/lists/* /var/cache/* /var/log/* /usr/src/postgis + rm -rf /var/lib/apt/lists/* /var/cache/* /var/log/* /usr/src/postgis /usr/src/address_standardizer /usr/src/postgis_tiger_geocoder USER 26 diff --git a/build-deps.txt b/build-deps.txt index e16527d..542c404 100644 --- a/build-deps.txt +++ b/build-deps.txt @@ -23,6 +23,7 @@ libldap-dev liblz4-dev libnuma-dev libpam0g-dev +libpcre2-dev libperl-dev libproj-dev libprotobuf-c-dev diff --git a/git-clone-retry.sh b/git-clone-retry.sh new file mode 100755 index 0000000..694a912 --- /dev/null +++ b/git-clone-retry.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Usage: git-clone-retry.sh [git clone options...] +# +# Wrapper around `git clone` that retries on failure. +# Meant for remotes that are known to time out often from CI runners. +# The destination directory is wiped between attempts. +# +# Tunables: GIT_CLONE_RETRIES (default 5), GIT_CLONE_RETRY_DELAY (default 5s). +set -u + +retries="${GIT_CLONE_RETRIES:-5}" +delay="${GIT_CLONE_RETRY_DELAY:-5}" + +if [ "$#" -lt 2 ]; then + echo "usage: $0 [git clone options...] " >&2 + exit 2 +fi + +# The destination is the last argument +for dest; do :; done + +i=1 +while [ "$i" -le "$retries" ]; do + if git clone "$@"; then + exit 0 + fi + rm -rf "$dest" + if [ "$i" -lt "$retries" ]; then + echo "git clone failed, retrying ($i/$retries)..." >&2 + sleep "$delay" + fi + i=$((i + 1)) +done + +echo "git clone failed after $retries attempts" >&2 +exit 1 From 53777dcef327082a4986fa02df2135b78e7ce18b Mon Sep 17 00:00:00 2001 From: Tao Li Date: Fri, 13 Nov 2026 16:26:29 +0800 Subject: [PATCH 2/6] chore: make build independent of PATH variable Signed-off-by: Tao Li --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c71a0a8..2097d8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -150,7 +150,7 @@ RUN --mount=type=bind,source=build-deps.txt,target=/build-deps.txt \ git clone -b "$POSTGIS_BRANCH" --single-branch --depth 1 "$POSTGIS_REPO" /usr/src/postgis && \ cd /usr/src/postgis && \ ./autogen.sh && \ - ./configure --with-sfcgal && \ + ./configure --with-pgconfig="$PG_CONFIG" --with-sfcgal && \ make -j$(nproc) && \ make install && \ git clone -b "$ADDRESS_STANDARDIZER_BRANCH" --single-branch --depth 1 "$ADDRESS_STANDARDIZER_REPO" /usr/src/address_standardizer && \ From d10fa9de8e6b586c3e62e672165d37eeca9772d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Fei?= Date: Mon, 16 Nov 2026 17:26:24 +0100 Subject: [PATCH 3/6] fix: install newer GDAL libs from pgdg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Niccolò Fei --- Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2097d8b..e9a74ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -128,19 +128,23 @@ ARG POSTGIS_REPO=https://github.com/postgis/postgis.git ARG POSTGIS_BRANCH=master # PostGIS 3.7 moved these extensions out of the main repository ARG ADDRESS_STANDARDIZER_REPO=https://github.com/postgis/address_standardizer.git -ARG ADDRESS_STANDARDIZER_BRANCH=main +# TODO: move back to main once there's an upgrade path from v3 to v4 +ARG ADDRESS_STANDARDIZER_BRANCH=v3.7.0 ARG POSTGIS_TIGER_GEOCODER_REPO=https://git.osgeo.org/postgis/postgis_tiger_geocoder.git ARG POSTGIS_TIGER_GEOCODER_BRANCH=main RUN --mount=type=bind,source=build-deps.txt,target=/build-deps.txt \ --mount=type=bind,source=git-clone-retry.sh,target=/git-clone-retry.sh \ apt-get update && \ + # Install PGDG repo to have updated libs for postgis + apt-get install -y --no-install-recommends postgresql-common ca-certificates && \ + /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && \ apt-get install -y --no-install-recommends \ $(cat /build-deps.txt) \ # runtime deps libproj25 \ libpq5 \ - libgdal36 \ + libgdal39 \ libgeos-c1t64 \ libsfcgal2 \ libpcre2-8-0 \ @@ -159,8 +163,8 @@ RUN --mount=type=bind,source=build-deps.txt,target=/build-deps.txt \ /git-clone-retry.sh -b "$POSTGIS_TIGER_GEOCODER_BRANCH" --single-branch --depth 1 "$POSTGIS_TIGER_GEOCODER_REPO" /usr/src/postgis_tiger_geocoder && \ make -C /usr/src/postgis_tiger_geocoder -j$(nproc) PG_CONFIG="$PG_CONFIG" && \ make -C /usr/src/postgis_tiger_geocoder PG_CONFIG="$PG_CONFIG" install && \ - apt-get purge -y --auto-remove $(cat /build-deps.txt) && \ + apt-get purge -y --auto-remove $(cat /build-deps.txt) postgresql-common && \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ - rm -rf /var/lib/apt/lists/* /var/cache/* /var/log/* /usr/src/postgis /usr/src/address_standardizer /usr/src/postgis_tiger_geocoder + rm -rf /etc/apt/sources.list.d/pgdg.sources /var/lib/apt/lists/* /var/cache/* /var/log/* /usr/src/postgis /usr/src/address_standardizer /usr/src/postgis_tiger_geocoder USER 26 From 435bf1dd7627edcc53ec6ac928d25300e465a0de Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Mon, 16 Nov 2026 21:45:22 +0100 Subject: [PATCH 4/6] fix(postgis): check linked libraries after purging build deps The runtime libraries are pinned by soname. If PGDG bumps one, the extensions link against the new version, the purge removes it, and the image breaks at runtime while the build stays green. Run ldd on the installed extension libraries after the purge and fail the build if a dependency is missing. Signed-off-by: Marco Nenciarini --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index e9a74ba..707a155 100644 --- a/Dockerfile +++ b/Dockerfile @@ -165,6 +165,9 @@ RUN --mount=type=bind,source=build-deps.txt,target=/build-deps.txt \ make -C /usr/src/postgis_tiger_geocoder PG_CONFIG="$PG_CONFIG" install && \ apt-get purge -y --auto-remove $(cat /build-deps.txt) postgresql-common && \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ + # Fail if the purge removed a library the extensions link against + libs=$(ls "$($PG_CONFIG --pkglibdir)"/*postgis*.so* "$($PG_CONFIG --pkglibdir)"/*address_standardizer*.so*) && \ + ! ldd $libs | grep 'not found' && \ rm -rf /etc/apt/sources.list.d/pgdg.sources /var/lib/apt/lists/* /var/cache/* /var/log/* /usr/src/postgis /usr/src/address_standardizer /usr/src/postgis_tiger_geocoder USER 26 From 57919ad102424cd7bc3e9eb1cf58d25af55ab915 Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Tue, 17 Nov 2026 09:31:29 +0100 Subject: [PATCH 5/6] fix: back off longer between git clone retries Five retries with a fixed 5 second delay all failed within 45 seconds when git.postgresql.org dropped connections. Use 15 seconds multiplied by the attempt number, so the script waits about 150 seconds in total before giving up. Signed-off-by: Marco Nenciarini --- git-clone-retry.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-clone-retry.sh b/git-clone-retry.sh index 694a912..7b4c4a4 100755 --- a/git-clone-retry.sh +++ b/git-clone-retry.sh @@ -5,11 +5,11 @@ # Meant for remotes that are known to time out often from CI runners. # The destination directory is wiped between attempts. # -# Tunables: GIT_CLONE_RETRIES (default 5), GIT_CLONE_RETRY_DELAY (default 5s). +# Tunables: GIT_CLONE_RETRIES (default 5), GIT_CLONE_RETRY_DELAY (default 15s, multiplied by the attempt number). set -u retries="${GIT_CLONE_RETRIES:-5}" -delay="${GIT_CLONE_RETRY_DELAY:-5}" +delay="${GIT_CLONE_RETRY_DELAY:-15}" if [ "$#" -lt 2 ]; then echo "usage: $0 [git clone options...] " >&2 @@ -27,7 +27,7 @@ while [ "$i" -le "$retries" ]; do rm -rf "$dest" if [ "$i" -lt "$retries" ]; then echo "git clone failed, retrying ($i/$retries)..." >&2 - sleep "$delay" + sleep "$((delay * i))" fi i=$((i + 1)) done From e7d213bb5fe48da97aac4c0eb60a982a1ee9b69c Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Tue, 17 Nov 2026 10:01:22 +0100 Subject: [PATCH 6/6] fix: use a shallow clone for the PostgreSQL source The build only needs the tip of the branch and its short commit hash. A shallow clone transfers far less data, which makes it faster and less exposed to connection drops from git.postgresql.org. Signed-off-by: Marco Nenciarini --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 707a155..d867f67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,7 +53,7 @@ RUN --mount=type=bind,source=build-deps.txt,target=/build-deps.txt \ usermod -u 26 postgres && \ # Build PostgreSQL mkdir -p /usr/src/postgresql && \ - /git-clone-retry.sh -b "$PG_BRANCH" --single-branch "$PG_REPO" /usr/src/postgresql && \ + /git-clone-retry.sh -b "$PG_BRANCH" --single-branch --depth 1 "$PG_REPO" /usr/src/postgresql && \ cd /usr/src/postgresql && \ export LLVM_CONFIG="/usr/lib/llvm-19/bin/llvm-config" && \ export CLANG=clang-19 && \