From 20f8a0ed698487be64eccc50f00bcdfd1d6b0a9e Mon Sep 17 00:00:00 2001 From: Maurus Frey Date: Thu, 13 Feb 2020 17:32:43 +0100 Subject: [PATCH] Add image for PostGIS v3.0.0 (excluding alpine) --- 12-3.0/Dockerfile | 20 ++++++++++++++++ 12-3.0/README.md | 51 ++++++++++++++++++++++++++++++++++++++++ 12-3.0/initdb-postgis.sh | 23 ++++++++++++++++++ 12-3.0/update-postgis.sh | 28 ++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 12-3.0/Dockerfile create mode 100644 12-3.0/README.md create mode 100644 12-3.0/initdb-postgis.sh create mode 100755 12-3.0/update-postgis.sh diff --git a/12-3.0/Dockerfile b/12-3.0/Dockerfile new file mode 100644 index 00000000..c31a31bb --- /dev/null +++ b/12-3.0/Dockerfile @@ -0,0 +1,20 @@ +FROM postgres:12 +MAINTAINER Mike Dillon + +ENV POSTGIS_MAJOR 3 +#ENV POSTGIS_VERSION 3.0.0+dfsg-6 +ENV POSTGIS_VERSION 3.0.0+dfsg-2~exp1.pgdg100+1 + + +RUN apt-get update \ + && apt-cache showpkg postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR \ + && apt-get install -y --no-install-recommends \ + postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \ + postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \ +# postgis=$POSTGIS_VERSION \ + && rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /docker-entrypoint-initdb.d +COPY ./initdb-postgis.sh /docker-entrypoint-initdb.d/postgis.sh +COPY ./update-postgis.sh /usr/local/bin + diff --git a/12-3.0/README.md b/12-3.0/README.md new file mode 100644 index 00000000..a7fd753b --- /dev/null +++ b/12-3.0/README.md @@ -0,0 +1,51 @@ +# postgis/postgis + +[![Build Status](https://travis-ci.org/postgis/docker-postgis.svg)](https://travis-ci.org/postgis/docker-postgis) [![Join the chat at https://gitter.im/appropriate/docker-postgis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/appropriate/docker-postgis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +The `postgis/postgis` image provides a Docker container running Postgres with [PostGIS 3.0](http://postgis.net/) installed. This image is based on the official [`postgres`](https://registry.hub.docker.com/_/postgres/) image and provides debian and alpine variants for each version of Postgres 9 supported by the base image (9.4-9.6), Postgres 10, Postgres 11, and Postgres 12. + +This image ensures that the default database created by the parent `postgres` image will have the following extensions installed: + +* `postgis` +* `postgis_topology` +* `fuzzystrmatch` +* `postgis_tiger_geocoder` + +Unless `-e POSTGRES_DB` is passed to the container at startup time, this database will be named after the admin user (either `postgres` or the user specified with `-e POSTGRES_USER`). If you would prefer to use the older template database mechanism for enabling PostGIS, the image also provides a PostGIS-enabled template database called `template_postgis`. + +## Usage + +In order to run a basic container capable of serving a PostGIS-enabled database, start a container as follows: + + docker run --name some-postgis -e POSTGRES_PASSWORD=mysecretpassword -d postgis/postgis + +For more detailed instructions about how to start and control your Postgres container, see the documentation for the `postgres` image [here](https://registry.hub.docker.com/_/postgres/). + +Once you have started a database container, you can then connect to the database as follows: + + docker run -it --link some-postgis:postgres --rm postgres \ + sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres' + +See [the PostGIS documentation](http://postgis.net/docs/postgis_installation.html#create_new_db_extensions) for more details on your options for creating and using a spatially-enabled database. + +## Known Issues / Errors + +When You encouter errors due to PostGIS update `OperationalError: could not access file "$libdir/postgis-X.X`, run: + +`docker exec some-postgis update-postgis.sh` + +It will update to Your newest PostGIS. Update is idempotent, so it won't hurt when You run it more than once, You will get notification like: + +``` +Updating PostGIS extensions template_postgis to X.X.X +NOTICE: version "X.X.X" of extension "postgis" is already installed +NOTICE: version "X.X.X" of extension "postgis_topology" is already installed +NOTICE: version "X.X.X" of extension "postgis_tiger_geocoder" is already installed +ALTER EXTENSION +Updating PostGIS extensions docker to X.X.X +NOTICE: version "X.X.X" of extension "postgis" is already installed +NOTICE: version "X.X.X" of extension "postgis_topology" is already installed +NOTICE: version "X.X.X" of extension "postgis_tiger_geocoder" is already installed +ALTER EXTENSION +``` + diff --git a/12-3.0/initdb-postgis.sh b/12-3.0/initdb-postgis.sh new file mode 100644 index 00000000..43012885 --- /dev/null +++ b/12-3.0/initdb-postgis.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +# Create the 'template_postgis' template db +"${psql[@]}" <<- 'EOSQL' +CREATE DATABASE template_postgis; +UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis'; +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; + CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; + CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder; +EOSQL +done diff --git a/12-3.0/update-postgis.sh b/12-3.0/update-postgis.sh new file mode 100755 index 00000000..f98abd26 --- /dev/null +++ b/12-3.0/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