Skip to content

Commit 02da713

Browse files
authored
bugfix initdb args (#19)
* bugfix for ivorysql & bugfix for #20 initdb error
1 parent 3047b08 commit 02da713

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

3/bookworm/docker-entrypoint.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ docker_create_db_directories() {
6161
}
6262

6363
# initialize empty PGDATA directory with new database via 'initdb'
64-
# arguments to `initdb` can be passed via IVORYSQL_INITDB_ARGS or as arguments to this function
64+
# arguments to `initdb` can be passed via POSTGRES_INITDB_ARGS or as arguments to this function
6565
# `initdb` automatically creates the "postgres", "template0", and "template1" dbnames
6666
# this is also where the database user is created, specified by `IVORYSQL_USER` env
6767
docker_init_database_dir() {
@@ -89,9 +89,11 @@ docker_init_database_dir() {
8989
fi
9090

9191
# --pwfile refuses to handle a properly-empty file (hence the "\n"): https://github.com/docker-library/postgres/issues/1025
92-
eval 'initdb --username="$IVORYSQL_USER" --pwfile=<(printf "%s\n" "$IVORYSQL_PASSWORD") '"$IVORYSQL_INITDB_ARGS"' "$@"'
92+
eval 'initdb --username="$IVORYSQL_USER" --pwfile=<(printf "%s\n" "$IVORYSQL_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
9393
sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" $PGDATA/postgresql.conf
94-
sed -ri "s!^#?(ivorysql.listen_addresses)\s*=\s*\S+.*!\1 = '*'!" $PGDATA/ivorysql.conf
94+
if [ -e "$PGDATA/ivorysql.conf" ]; then
95+
sed -ri "s!^#?(ivorysql.listen_addresses)\s*=\s*\S+.*!\1 = '*'!" $PGDATA/ivorysql.conf
96+
fi
9597
# unset/cleanup "nss_wrapper" bits
9698
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
9799
rm -f "$NSS_WRAPPER_PASSWD" "$NSS_WRAPPER_GROUP"
@@ -325,7 +327,7 @@ _main() {
325327
pg_setup_hba_conf "$@"
326328

327329
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
328-
# e.g. when '--auth=md5' or '--auth-local=md5' is used in IVORYSQL_INITDB_ARGS
330+
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
329331
export PGPASSWORD="${PGPASSWORD:-$IVORYSQL_PASSWORD}"
330332
docker_temp_server_start "$@"
331333

3/ubi8/docker-entrypoint.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ docker_create_db_directories() {
6161
}
6262

6363
# initialize empty PGDATA directory with new database via 'initdb'
64-
# arguments to `initdb` can be passed via IVORYSQL_INITDB_ARGS or as arguments to this function
64+
# arguments to `initdb` can be passed via POSTGRES_INITDB_ARGS or as arguments to this function
6565
# `initdb` automatically creates the "postgres", "template0", and "template1" dbnames
6666
# this is also where the database user is created, specified by `IVORYSQL_USER` env
6767
docker_init_database_dir() {
@@ -89,9 +89,11 @@ docker_init_database_dir() {
8989
fi
9090

9191
# --pwfile refuses to handle a properly-empty file (hence the "\n"): https://github.com/docker-library/postgres/issues/1025
92-
eval 'initdb --username="$IVORYSQL_USER" --pwfile=<(printf "%s\n" "$IVORYSQL_PASSWORD") '"$IVORYSQL_INITDB_ARGS"' "$@"'
92+
eval 'initdb --username="$IVORYSQL_USER" --pwfile=<(printf "%s\n" "$IVORYSQL_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
9393
sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" $PGDATA/postgresql.conf
94-
sed -ri "s!^#?(ivorysql.listen_addresses)\s*=\s*\S+.*!\1 = '*'!" $PGDATA/ivorysql.conf
94+
if [ -e "$PGDATA/ivorysql.conf" ]; then
95+
sed -ri "s!^#?(ivorysql.listen_addresses)\s*=\s*\S+.*!\1 = '*'!" $PGDATA/ivorysql.conf
96+
fi
9597
# unset/cleanup "nss_wrapper" bits
9698
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
9799
rm -f "$NSS_WRAPPER_PASSWD" "$NSS_WRAPPER_GROUP"
@@ -325,7 +327,7 @@ _main() {
325327
pg_setup_hba_conf "$@"
326328

327329
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
328-
# e.g. when '--auth=md5' or '--auth-local=md5' is used in IVORYSQL_INITDB_ARGS
330+
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
329331
export PGPASSWORD="${PGPASSWORD:-$IVORYSQL_PASSWORD}"
330332
docker_temp_server_start "$@"
331333

docker-entrypoint.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ docker_create_db_directories() {
6161
}
6262

6363
# initialize empty PGDATA directory with new database via 'initdb'
64-
# arguments to `initdb` can be passed via IVORYSQL_INITDB_ARGS or as arguments to this function
64+
# arguments to `initdb` can be passed via POSTGRES_INITDB_ARGS or as arguments to this function
6565
# `initdb` automatically creates the "postgres", "template0", and "template1" dbnames
6666
# this is also where the database user is created, specified by `IVORYSQL_USER` env
6767
docker_init_database_dir() {
@@ -89,9 +89,11 @@ docker_init_database_dir() {
8989
fi
9090

9191
# --pwfile refuses to handle a properly-empty file (hence the "\n"): https://github.com/docker-library/postgres/issues/1025
92-
eval 'initdb --username="$IVORYSQL_USER" --pwfile=<(printf "%s\n" "$IVORYSQL_PASSWORD") '"$IVORYSQL_INITDB_ARGS"' "$@"'
92+
eval 'initdb --username="$IVORYSQL_USER" --pwfile=<(printf "%s\n" "$IVORYSQL_PASSWORD") '"$POSTGRES_INITDB_ARGS"' "$@"'
9393
sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" $PGDATA/postgresql.conf
94-
sed -ri "s!^#?(ivorysql.listen_addresses)\s*=\s*\S+.*!\1 = '*'!" $PGDATA/ivorysql.conf
94+
if [ -e "$PGDATA/ivorysql.conf" ]; then
95+
sed -ri "s!^#?(ivorysql.listen_addresses)\s*=\s*\S+.*!\1 = '*'!" $PGDATA/ivorysql.conf
96+
fi
9597
# unset/cleanup "nss_wrapper" bits
9698
if [[ "${LD_PRELOAD:-}" == */libnss_wrapper.so ]]; then
9799
rm -f "$NSS_WRAPPER_PASSWD" "$NSS_WRAPPER_GROUP"
@@ -325,7 +327,7 @@ _main() {
325327
pg_setup_hba_conf "$@"
326328

327329
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
328-
# e.g. when '--auth=md5' or '--auth-local=md5' is used in IVORYSQL_INITDB_ARGS
330+
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
329331
export PGPASSWORD="${PGPASSWORD:-$IVORYSQL_PASSWORD}"
330332
docker_temp_server_start "$@"
331333

0 commit comments

Comments
 (0)