From 7dc24d9908a34282dee4dae7959da2053128f36a Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Sat, 26 Sep 2020 08:30:25 +0200 Subject: [PATCH] fix: [postgres] proper support of ``postgis`` extension. Signed-off-by: Valentin Lab --- postgres/build/Dockerfile | 9 ++++----- postgres/hooks/init | 13 ++++++++++++- postgres/lib/common | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/postgres/build/Dockerfile b/postgres/build/Dockerfile index c416738..6bfae6e 100644 --- a/postgres/build/Dockerfile +++ b/postgres/build/Dockerfile @@ -1,6 +1,5 @@ -## is a simple copy of postgres:10-alpine -FROM docker.0k.io/postgres:10-alpine as common - +## is a simple copy of postgis/postgis:10-3.0-alpine +FROM docker.0k.io/postgis:10-3.0-alpine as common FROM common AS builder @@ -25,12 +24,12 @@ USER root RUN apk add curl -RUN curl -L https://raw.githubusercontent.com/0k/pgm/0.0.2/bin/pgm > /bin/pgm && \ +RUN curl -L https://raw.githubusercontent.com/0k/pgm/0.0.3/bin/pgm > /bin/pgm && \ chmod +x /bin/pgm FROM common -RUN apk -U add pv python file +RUN apk -U add pv python2 file sed COPY --from=builder /home/packager/packages/tmp/x86_64/*.apk /tmp/ COPY --from=builder /bin/pgm /bin diff --git a/postgres/hooks/init b/postgres/hooks/init index 87c5419..f90da72 100755 --- a/postgres/hooks/init +++ b/postgres/hooks/init @@ -21,14 +21,25 @@ set -e if ! [ -f "$LOCAL_DB_PASSFILE" ]; then POSTGRES_ROOT_PASSWORD="$(gen_password)" + + ## required by image of postgres for first run + server_docker_opts=("${server_docker_opts[@]}" -e POSTGRES_HOST_AUTH_METHOD=trust) ddb < <(echo "ALTER USER postgres WITH ENCRYPTED password '$POSTGRES_ROOT_PASSWORD'") cat < "$LOCAL_DB_PASSFILE" *:*:*:postgres:$POSTGRES_ROOT_PASSWORD EOF chmod 600 "$LOCAL_DB_PASSFILE" - info "New root password for postgres. " + info "New root password for postgres." + + ## resetting ``server_docker_opts``, and forcing stop to remove the + ## POSTGRES_HOST_AUTH_METHOD arg. + docker stop "$container_id" + docker rm "$container_id" + server_docker_opts=() + _set_server_db_params fi + if ! egrep "^host all all (0.0.0.0/0|all) md5\$" "$PG_HBA" >/dev/null 2>&1; then if egrep "^host all all (0.0.0.0/0|all) trust\$" "$PG_HBA" >/dev/null 2>&1; then sed -ri 's%^host all all (0\.0\.0\.0/0|all) trust$%host all all \1 md5%g' \ diff --git a/postgres/lib/common b/postgres/lib/common index f08be7a..75716f7 100644 --- a/postgres/lib/common +++ b/postgres/lib/common @@ -74,7 +74,7 @@ db_install_extensions() { case "$1" in postgis) ddb -d "$dbname" < <(echo "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;") || return 1 - dcmd /bin/bash -c "psql -d '$dbname' -f /usr/share/postgresql/*/contrib/postgis-2.1/legacy.sql" || return 1 + dcmd /bin/bash -c "psql -d '$dbname' -v ON_ERROR_STOP=1 -f /usr/local/share/postgresql/contrib/postgis-*/legacy.sql" || return 1 info "Installed postgis extensions on database '$dbname'." ;; *) @@ -129,5 +129,5 @@ PGM() { db_grant_rights () { local dbname="$1" user="$2" - PGM chown "$user" "$dbname" + PGM chown -v "$user" "$dbname" }