#!/usr/bin/env bash set -Eeo pipefail # This script extends the original entrypoint with support for adding # a non-superuser owner to the $POSTGRES_DB database # source vendor entrypoint . /usr/local/bin/docker-entrypoint.sh # create initial database # uses environment variables for input: POSTGRES_DB docker_setup_db() { if [ "$POSTGRES_DB_USER" != 'postgres' ]; then if [ -n "$POSTGRES_DB_PASSWORD" ]; then POSTGRES_DB= docker_process_sql --dbname postgres --set user="$POSTGRES_DB_USER" --set password="$POSTGRES_DB_PASSWORD" < /dev/null docker_init_database_dir pg_setup_hba_conf # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" docker_temp_server_start "$@" docker_setup_db docker_process_init_files /docker-entrypoint-initdb.d/* docker_temp_server_stop unset PGPASSWORD echo echo 'PostgreSQL init process complete; ready for start up.' echo else echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo fi fi exec "$@" } if ! _is_sourced; then _main "$@" fi