File tree Expand file tree Collapse file tree
root/etc/services.d/postgresql Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ FROM ghcr.io/daemonless/base:${BASE_VERSION}
44ARG PG_VERSION
55
66ARG FREEBSD_ARCH=amd64
7- ARG PACKAGES="postgresql${PG_VERSION}-server postgresql${PG_VERSION}-client"
7+ ARG PACKAGES="postgresql${PG_VERSION}-server postgresql${PG_VERSION}-client postgresql${PG_VERSION}-contrib "
88ARG UPSTREAM_URL="https://www.postgresql.org/docs/release/"
99ARG HEALTHCHECK_ENDPOINT="pg_isready -q"
1010
Original file line number Diff line number Diff line change @@ -27,13 +27,23 @@ if [ ! -f "$PGDATA/PG_VERSION" ]; then
2727 # Start temporarily to create user/database and run init scripts
2828 /usr/local/bin/s6-setuidgid bsd /usr/local/bin/pg_ctl -D " $PGDATA " -w start
2929
30- # Create user and database if specified
30+ # Create user if not default 'bsd' user
31+ PGUSER=" ${POSTGRES_USER:- postgres} "
32+ if [ " $PGUSER " != " bsd" ]; then
33+ echo " Creating user '$PGUSER '..."
34+ /usr/local/bin/s6-setuidgid bsd /usr/local/bin/psql -d postgres -c " CREATE ROLE $PGUSER WITH LOGIN SUPERUSER" 2> /dev/null || true
35+ fi
36+
37+ # Set password if specified
3138 if [ -n " $POSTGRES_PASSWORD " ]; then
32- /usr/local/bin/s6-setuidgid bsd /usr/local/bin/psql -c " ALTER USER $POSTGRES_USER PASSWORD '$POSTGRES_PASSWORD '" 2> /dev/null
39+ echo " Setting password for '$PGUSER '..."
40+ /usr/local/bin/s6-setuidgid bsd /usr/local/bin/psql -d postgres -c " ALTER ROLE $PGUSER PASSWORD '$POSTGRES_PASSWORD '" 2> /dev/null
3341 fi
3442
43+ # Create database if specified and not 'postgres'
3544 if [ -n " $POSTGRES_DB " ] && [ " $POSTGRES_DB " != " postgres" ]; then
36- /usr/local/bin/s6-setuidgid bsd /usr/local/bin/createdb " $POSTGRES_DB " 2> /dev/null
45+ echo " Creating database '$POSTGRES_DB '..."
46+ /usr/local/bin/s6-setuidgid bsd /usr/local/bin/createdb -O " $PGUSER " " $POSTGRES_DB " 2> /dev/null || true
3747 fi
3848
3949 # Run init scripts from /docker-entrypoint-initdb.d/
You can’t perform that action at this time.
0 commit comments