Browse Source

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

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
dhcp
Valentin Lab 4 years ago
parent
commit
785cf5e4dd
  1. 9
      postgres/build/Dockerfile
  2. 11
      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
@ -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

11
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 <<EOF > "$LOCAL_DB_PASSFILE"
*:*:*:postgres:$POSTGRES_ROOT_PASSWORD
EOF
chmod 600 "$LOCAL_DB_PASSFILE"
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' \

4
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"
}
Loading…
Cancel
Save