diff --git a/16-3.4/Dockerfile b/16-3.4/Dockerfile new file mode 100644 index 00000000..d12194b9 --- /dev/null +++ b/16-3.4/Dockerfile @@ -0,0 +1,58 @@ +# Base image: PostgreSQL 16 on Bullseye (amd64/arm64) +FROM postgres:16-bullseye + +LABEL maintainer="PostGIS Project - https://postgis.net" \ + org.opencontainers.image.description="PostGIS 3.4.3 spatial extension with PostgreSQL 16, built from source" \ + org.opencontainers.image.source="https://github.com/postgis/docker-postgis" + +ENV POSTGIS_MAJOR=3 +ENV POSTGIS_VERSION=3.4.3 +ENV PG_MAJOR=16 + +# Install build dependencies for PostGIS +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + wget \ + curl \ + gnupg \ + software-properties-common \ + autoconf \ + automake \ + libtool \ + pkg-config \ + libxml2-dev \ + libgeos-dev \ + libproj-dev \ + libgdal-dev \ + libjson-c-dev \ + libprotobuf-c-dev \ + libsqlite3-dev \ + libcurl4-openssl-dev \ + libreadline-dev \ + liblzma-dev \ + libpcre2-dev \ + bison \ + flex \ + postgresql-server-dev-$PG_MAJOR \ + && rm -rf /var/lib/apt/lists/* + +# Download and build PostGIS 3.4.3 from source +WORKDIR /usr/src +RUN wget -qO postgis.tar.gz "https://download.osgeo.org/postgis/source/postgis-$POSTGIS_VERSION.tar.gz" \ + && tar xzf postgis.tar.gz \ + && rm postgis.tar.gz \ + && cd postgis-$POSTGIS_VERSION \ + && ./configure --with-pgconfig=/usr/lib/postgresql/$PG_MAJOR/bin/pg_config --without-protobuf \ + && make \ + && make install + +# Clean up source directory +RUN rm -rf /usr/src/postgis-$POSTGIS_VERSION + +# Init scripts directory +RUN mkdir -p /docker-entrypoint-initdb.d +COPY ./initdb-postgis.sh /docker-entrypoint-initdb.d/10_postgis.sh +COPY ./update-postgis.sh /usr/local/bin + diff --git a/16-3.4/initdb-postgis.sh b/16-3.4/initdb-postgis.sh new file mode 100644 index 00000000..e38ad7d6 --- /dev/null +++ b/16-3.4/initdb-postgis.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -e + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +# Create the 'template_postgis' template db +"${psql[@]}" <<- 'EOSQL' +CREATE DATABASE template_postgis IS_TEMPLATE true; +EOSQL + +# Load PostGIS into both template_database and $POSTGRES_DB +for DB in template_postgis "$POSTGRES_DB"; do + echo "Loading PostGIS extensions into $DB" + "${psql[@]}" --dbname="$DB" <<-'EOSQL' + CREATE EXTENSION IF NOT EXISTS postgis; + CREATE EXTENSION IF NOT EXISTS postgis_topology; + -- Reconnect to update pg_setting.resetval + -- See https://github.com/postgis/docker-postgis/issues/288 + \c + CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; + CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder; +EOSQL +done diff --git a/16-3.4/update-postgis.sh b/16-3.4/update-postgis.sh new file mode 100755 index 00000000..3e60e398 --- /dev/null +++ b/16-3.4/update-postgis.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +set -e + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +POSTGIS_VERSION="${POSTGIS_VERSION%%+*}" + +# Load PostGIS into both template_database and $POSTGRES_DB +for DB in template_postgis "$POSTGRES_DB" "${@}"; do + echo "Updating PostGIS extensions '$DB' to $POSTGIS_VERSION" + psql --dbname="$DB" -c " + -- Upgrade PostGIS (includes raster) + CREATE EXTENSION IF NOT EXISTS postgis VERSION '$POSTGIS_VERSION'; + ALTER EXTENSION postgis UPDATE TO '$POSTGIS_VERSION'; + + -- Upgrade Topology + CREATE EXTENSION IF NOT EXISTS postgis_topology VERSION '$POSTGIS_VERSION'; + ALTER EXTENSION postgis_topology UPDATE TO '$POSTGIS_VERSION'; + + -- Install Tiger dependencies in case not already installed + CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; + -- Upgrade US Tiger Geocoder + CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder VERSION '$POSTGIS_VERSION'; + ALTER EXTENSION postgis_tiger_geocoder UPDATE TO '$POSTGIS_VERSION'; + " +done