diff --git a/Dockerfile b/Dockerfile index b1475ff..d867f67 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 --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 && \ @@ -125,27 +125,49 @@ 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 +# 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 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 && \ + # 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 \ && \ + 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-pgconfig="$PG_CONFIG" --with-sfcgal && \ make -j$(nproc) && \ make install && \ - apt-get purge -y --auto-remove $(cat /build-deps.txt) && \ + 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) 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 + # 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 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..7b4c4a4 --- /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 15s, multiplied by the attempt number). +set -u + +retries="${GIT_CLONE_RETRIES:-5}" +delay="${GIT_CLONE_RETRY_DELAY:-15}" + +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 * i))" + fi + i=$((i + 1)) +done + +echo "git clone failed after $retries attempts" >&2 +exit 1