diff --git a/data.sql b/data.sql index d735716..1e849c3 100644 --- a/data.sql +++ b/data.sql @@ -1,4 +1,6 @@ \connect insylva +CREATE EXTENSION postgis; + CREATE TABLE IF NOT EXISTS users ( id serial UNIQUE PRIMARY KEY, kc_id varchar(100) UNIQUE NOT NULL, @@ -397,7 +399,7 @@ CREATE TABLE IF NOT EXISTS profile_specifications( createdAt timestamp NOT NULL DEFAULT NOW(), updatedAt timestamp -); +); CREATE TABLE unblurred_sites ( diff --git a/postgresql/Dockerfile b/postgresql/Dockerfile index 4d17fba..049332d 100644 --- a/postgresql/Dockerfile +++ b/postgresql/Dockerfile @@ -1,6 +1,79 @@ -FROM postgres:12.3-alpine +FROM postgres:12-alpine + +LABEL maintainer="PostGIS Project - https://postgis.net" + +ENV POSTGIS_VERSION 3.0.2 +ENV POSTGIS_SHA256 2d4eb79ea9af1257320922a8a7d2663d37189c805746e975a5951ee6dc5ac4ef + +RUN set -ex \ + \ + && apk add --no-cache --virtual .fetch-deps \ + ca-certificates \ + openssl \ + tar \ + \ + && wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/$POSTGIS_VERSION.tar.gz" \ + && echo "$POSTGIS_SHA256 *postgis.tar.gz" | sha256sum -c - \ + && mkdir -p /usr/src/postgis \ + && tar \ + --extract \ + --file postgis.tar.gz \ + --directory /usr/src/postgis \ + --strip-components 1 \ + && rm postgis.tar.gz \ + \ + && apk add --no-cache --virtual .build-deps \ + autoconf \ + automake \ + file \ + json-c-dev \ + libtool \ + libxml2-dev \ + make \ + perl \ + clang-dev \ + g++ \ + gcc \ + gdal-dev \ + geos-dev \ + llvm10-dev \ + proj-dev \ + protobuf-c-dev \ + && cd /usr/src/postgis \ + && ./autogen.sh \ +# configure options taken from: +# https://anonscm.debian.org/cgit/pkg-grass/postgis.git/tree/debian/rules?h=jessie + && ./configure \ +# --with-gui \ + && make -j$(nproc) \ + && make install \ +# regress check + && mkdir /tempdb \ + && chown -R postgres:postgres /tempdb \ + && su postgres -c 'pg_ctl -D /tempdb init' \ + && su postgres -c 'pg_ctl -D /tempdb start' \ + && cd regress \ + && make -j$(nproc) check RUNTESTFLAGS=--extension PGUSER=postgres \ + && su postgres -c 'pg_ctl -D /tempdb --mode=immediate stop' \ + && rm -rf /tempdb \ + && rm -rf /tmp/pgis_reg \ +# add .postgis-rundeps + && apk add --no-cache --virtual .postgis-rundeps \ + json-c \ + geos \ + gdal \ + proj \ + libstdc++ \ + protobuf-c \ +# clean + && cd / \ + && rm -rf /usr/src/postgis \ + && apk del .fetch-deps .build-deps + +COPY ./initdb-postgis.sh /docker-entrypoint-initdb.d/10_postgis.sh +COPY ./update-postgis.sh /usr/local/bin COPY create-multiple-postgresql-databases.sh /docker-entrypoint-initdb.d/ -# RUN chown postgres:postgres /docker-entrypoint-initdb.d/ +RUN chown postgres:postgres /docker-entrypoint-initdb.d/ -EXPOSE 5432 \ No newline at end of file +EXPOSE 5432 diff --git a/postgresql/initdb-postgis.sh b/postgresql/initdb-postgis.sh new file mode 100644 index 0000000..cdde274 --- /dev/null +++ b/postgresql/initdb-postgis.sh @@ -0,0 +1,22 @@ +#!/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 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; + CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; + CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder; +EOSQL +done diff --git a/postgresql/update-postgis.sh b/postgresql/update-postgis.sh new file mode 100755 index 0000000..f98abd2 --- /dev/null +++ b/postgresql/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