Browse Source

fix: [postgres] proper support of ``postgis`` extension.

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
dev1
Valentin Lab 4 years ago
parent
commit
7dc24d9908
  1. 9
      postgres/build/Dockerfile
  2. 13
      postgres/hooks/init
  3. 4
      postgres/lib/common

9
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 FROM common AS builder
@ -25,12 +24,12 @@ USER root
RUN apk add curl 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 chmod +x /bin/pgm
FROM common 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 /home/packager/packages/tmp/x86_64/*.apk /tmp/
COPY --from=builder /bin/pgm /bin COPY --from=builder /bin/pgm /bin

13
postgres/hooks/init

@ -21,14 +21,25 @@ set -e
if ! [ -f "$LOCAL_DB_PASSFILE" ]; then if ! [ -f "$LOCAL_DB_PASSFILE" ]; then
POSTGRES_ROOT_PASSWORD="$(gen_password)" 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'") ddb < <(echo "ALTER USER postgres WITH ENCRYPTED password '$POSTGRES_ROOT_PASSWORD'")
cat <<EOF > "$LOCAL_DB_PASSFILE" cat <<EOF > "$LOCAL_DB_PASSFILE"
*:*:*:postgres:$POSTGRES_ROOT_PASSWORD *:*:*:postgres:$POSTGRES_ROOT_PASSWORD
EOF EOF
chmod 600 "$LOCAL_DB_PASSFILE" 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 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) 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 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' \ sed -ri 's%^host all all (0\.0\.0\.0/0|all) trust$%host all all \1 md5%g' \

4
postgres/lib/common

@ -74,7 +74,7 @@ db_install_extensions() {
case "$1" in case "$1" in
postgis) postgis)
ddb -d "$dbname" < <(echo "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;") || return 1 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'." info "Installed postgis extensions on database '$dbname'."
;; ;;
*) *)
@ -129,5 +129,5 @@ PGM() {
db_grant_rights () { db_grant_rights () {
local dbname="$1" user="$2" local dbname="$1" user="$2"
PGM chown "$user" "$dbname"
PGM chown -v "$user" "$dbname"
} }
Loading…
Cancel
Save