-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint
executable file
·32 lines (25 loc) · 1.13 KB
/
entrypoint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
set -e
CHAR_MAP=${LANG#*.}; INPUT_FILE=${LANG%.*}; LOCALE=$LANG
localedef -f $CHAR_MAP -i $INPUT_FILE $LOCALE
echo "Container locale: $LOCALE"
# Initialize Postgres if it is the first time the container is run
if [ "$1" == "postgres" ] && [ ! -s "$PGDATA/PG_VERSION" ]; then
# Set $PGPASSWORD as /run/secrets/pgpassword contents or current value of PGPASSWORD or default value "postgres"
export PGPASSWORD=$(grep -s . /run/secrets/pgpassword || echo "${PGPASSWORD:-postgres}")
initdb --locale="$LANG" --auth=scram-sha-256 --no-instructions \
--username="${PGUSER:-postgres}" --pwfile=<(echo "$PGPASSWORD")
echo 'local all all scram-sha-256' > $PGDATA/pg_hba.conf
echo 'host all all all scram-sha-256' >> $PGDATA/pg_hba.conf
sed -i '/listen_addresses/{ s/^#//; s/localhost/*/ }' $PGDATA/postgresql.conf
# Create a database named $PGDATABASE when Postgres starts, if $PGDATABASE is not "postgres"
if [ "${PGDATABASE:-postgres}" != "postgres" ]; then
(
until grep -sq ready $PGDATA/postmaster.pid; do sleep 0.1; done
createdb -e --no-password -O "$PGUSER" "$PGDATABASE"
) &
fi
echo ""
fi
unset PGPASSWORD
exec "$@"