diff --git a/Docker/postgresql/Dockerfile b/Docker/postgres/Dockerfile similarity index 55% rename from Docker/postgresql/Dockerfile rename to Docker/postgres/Dockerfile index 898a06b1f..b90cf6e14 100644 --- a/Docker/postgresql/Dockerfile +++ b/Docker/postgres/Dockerfile @@ -12,9 +12,17 @@ RUN set -x \ && rm -rf /var/lib/apt/lists/* && apt-get purge -y --auto-remove ca-certificates wget unzip make postgresql-server-dev-${POSTGRES_DEV_VERSION} gcc libc6-dev libssl-dev libkrb5-dev \ && rm -rf /tmp/pg_* -ENV POSTGRES_USERNAME="postgres" \ - POSTGRES_PASSWORD="" \ - PGDATA="/bitnami/postgresql" +ENV POSTGRES_USERNAME="postgres" +ENV POSTGRES_INITDB_ARGS="-D /var/lib/postgresql/data" +ENV PGDATA="/var/lib/postgresql/config" +ENV PGCONFIG="/var/lib/postgresql/config" +ENV AUTH="trust" -COPY initdb.d/* /docker-entrypoint-initdb.d/ -COPY after-initdb.sh /docker-entrypoint-initdb.d/0-after-initdb.sh +RUN mkdir -p $PGDATA +RUN cp /usr/share/postgresql/postgresql.conf.sample $PGDATA/postgresql.conf +RUN sed -i -e "s/#include_dir = 'conf.d'/include_dir = 'conf.d'/" $PGDATA/postgresql.conf +COPY conf.d $PGDATA/conf.d/ + +RUN mkdir -p /docker-entrypoint-initdb.d +COPY ./initdb-auth.sh /docker-entrypoint-initdb.d/00-auth.sh +COPY ./initdb-pg_pathman.sh /docker-entrypoint-initdb.d/01-pg_pathman.sh diff --git a/Docker/postgres/conf.d/00-files.conf b/Docker/postgres/conf.d/00-files.conf new file mode 100644 index 000000000..9c5ba4a24 --- /dev/null +++ b/Docker/postgres/conf.d/00-files.conf @@ -0,0 +1,2 @@ +data_directory = '/var/lib/postgresql/data' +hba_file = '/var/lib/postgresql/config/pg_hba.conf' diff --git a/Docker/postgres/conf.d/01-vacuum.conf b/Docker/postgres/conf.d/01-vacuum.conf new file mode 100644 index 000000000..12ce327bc --- /dev/null +++ b/Docker/postgres/conf.d/01-vacuum.conf @@ -0,0 +1,2 @@ +vacuum_cost_delay = 10 +vacuum_cost_limit = 10000 diff --git a/Docker/postgres/conf.d/02-client.conf b/Docker/postgres/conf.d/02-client.conf new file mode 100644 index 000000000..908d63c72 --- /dev/null +++ b/Docker/postgres/conf.d/02-client.conf @@ -0,0 +1 @@ +shared_preload_libraries = 'pg_pathman' diff --git a/Docker/postgres/initdb-auth.sh b/Docker/postgres/initdb-auth.sh new file mode 100644 index 000000000..116167356 --- /dev/null +++ b/Docker/postgres/initdb-auth.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +set -e + +{ + echo "# TYPE DATABASE USER ADDRESS METHOD" + echo "local all all trust" + echo "host all all 127.0.0.1/32 trust" + echo "host all all 0.0.0.0/0 $AUTH" +} >> "$PGCONFIG/pg_hba.conf" diff --git a/Docker/postgres/initdb-pg_pathman.sh b/Docker/postgres/initdb-pg_pathman.sh new file mode 100644 index 000000000..9e0e5f74a --- /dev/null +++ b/Docker/postgres/initdb-pg_pathman.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +# Load pg_pathman into $POSTGRES_DB +for DB in "$POSTGRES_DB"; do + echo "Loading pg_pathman extensions into $DB" + "${psql[@]}" <<-'EOSQL' + CREATE EXTENSION IF NOT EXISTS pg_pathman; +EOSQL +done diff --git a/Docker/postgresql/after-initdb.sh b/Docker/postgresql/after-initdb.sh deleted file mode 100644 index 5efc00595..000000000 --- a/Docker/postgresql/after-initdb.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -mkdir $PGDATA/conf.d -sed -i "s/#include_dir = 'conf.d'/include_dir = 'conf.d'/" $PGDATA/postgresql.conf -cp /docker-entrypoint-initdb.d/*.conf $PGDATA/conf.d/ - -echo "Stop PG" -pg_ctl -D "$PGDATA" -m fast -w stop - -echo "Start PG" -pg_ctl -D "$PGDATA" \ - -w start - -echo "Reload done" diff --git a/Docker/postgresql/initdb.d/pg_pathman_enable.sql b/Docker/postgresql/initdb.d/pg_pathman_enable.sql deleted file mode 100644 index 057bfb979..000000000 --- a/Docker/postgresql/initdb.d/pg_pathman_enable.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE EXTENSION pg_pathman; \ No newline at end of file diff --git a/Docker/postgresql/initdb.d/shared_preload_libraries.conf b/Docker/postgresql/initdb.d/shared_preload_libraries.conf deleted file mode 100644 index d7a279cd1..000000000 --- a/Docker/postgresql/initdb.d/shared_preload_libraries.conf +++ /dev/null @@ -1 +0,0 @@ -shared_preload_libraries = 'pg_pathman' \ No newline at end of file diff --git a/scripts/docker_ops.py b/scripts/docker_ops.py index 2c158277a..cf5964bc7 100755 --- a/scripts/docker_ops.py +++ b/scripts/docker_ops.py @@ -264,6 +264,7 @@ def create(ctx, net, port, host, password, data_volume): me = 'md5' click.echo('{}: Password is set only if it\'s the first time creating postgres, otherwise it will reuse old password. Please use {} command.'.format( green('NOTICE'), green('postgres updpass'))) + return else: me = 'trust'