From fece7c5df354b4b82ea165fc84a49940ec32c0b5 Mon Sep 17 00:00:00 2001 From: Laurent Goderre Date: Tue, 7 Nov 2023 11:06:37 -0500 Subject: [PATCH] Added ability to use image as an init container --- 11/alpine3.17/docker-entrypoint.sh | 15 +++++++++++++-- 11/alpine3.18/docker-entrypoint.sh | 15 +++++++++++++-- 11/bookworm/docker-entrypoint.sh | 17 ++++++++++++++--- 11/bullseye/docker-entrypoint.sh | 17 ++++++++++++++--- 12/alpine3.17/docker-entrypoint.sh | 15 +++++++++++++-- 12/alpine3.18/docker-entrypoint.sh | 15 +++++++++++++-- 12/bookworm/docker-entrypoint.sh | 17 ++++++++++++++--- 12/bullseye/docker-entrypoint.sh | 17 ++++++++++++++--- 13/alpine3.17/docker-entrypoint.sh | 15 +++++++++++++-- 13/alpine3.18/docker-entrypoint.sh | 15 +++++++++++++-- 13/bookworm/docker-entrypoint.sh | 17 ++++++++++++++--- 13/bullseye/docker-entrypoint.sh | 17 ++++++++++++++--- 14/alpine3.17/docker-entrypoint.sh | 15 +++++++++++++-- 14/alpine3.18/docker-entrypoint.sh | 15 +++++++++++++-- 14/bookworm/docker-entrypoint.sh | 17 ++++++++++++++--- 14/bullseye/docker-entrypoint.sh | 17 ++++++++++++++--- 15/alpine3.17/docker-entrypoint.sh | 15 +++++++++++++-- 15/alpine3.18/docker-entrypoint.sh | 15 +++++++++++++-- 15/bookworm/docker-entrypoint.sh | 17 ++++++++++++++--- 15/bullseye/docker-entrypoint.sh | 17 ++++++++++++++--- 16/alpine3.17/docker-entrypoint.sh | 15 +++++++++++++-- 16/alpine3.18/docker-entrypoint.sh | 15 +++++++++++++-- 16/bookworm/docker-entrypoint.sh | 17 ++++++++++++++--- 16/bullseye/docker-entrypoint.sh | 17 ++++++++++++++--- docker-entrypoint.sh | 17 ++++++++++++++--- 25 files changed, 338 insertions(+), 63 deletions(-) diff --git a/11/alpine3.17/docker-entrypoint.sh b/11/alpine3.17/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/11/alpine3.17/docker-entrypoint.sh +++ b/11/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/11/alpine3.18/docker-entrypoint.sh b/11/alpine3.18/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/11/alpine3.18/docker-entrypoint.sh +++ b/11/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/11/bookworm/docker-entrypoint.sh b/11/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/11/bookworm/docker-entrypoint.sh +++ b/11/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/11/bullseye/docker-entrypoint.sh b/11/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/11/bullseye/docker-entrypoint.sh +++ b/11/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/12/alpine3.17/docker-entrypoint.sh b/12/alpine3.17/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/12/alpine3.17/docker-entrypoint.sh +++ b/12/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/12/alpine3.18/docker-entrypoint.sh b/12/alpine3.18/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/12/alpine3.18/docker-entrypoint.sh +++ b/12/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/12/bookworm/docker-entrypoint.sh b/12/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/12/bookworm/docker-entrypoint.sh +++ b/12/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/12/bullseye/docker-entrypoint.sh b/12/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/12/bullseye/docker-entrypoint.sh +++ b/12/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/13/alpine3.17/docker-entrypoint.sh b/13/alpine3.17/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/13/alpine3.17/docker-entrypoint.sh +++ b/13/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/13/alpine3.18/docker-entrypoint.sh b/13/alpine3.18/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/13/alpine3.18/docker-entrypoint.sh +++ b/13/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/13/bookworm/docker-entrypoint.sh b/13/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/13/bookworm/docker-entrypoint.sh +++ b/13/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/13/bullseye/docker-entrypoint.sh b/13/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/13/bullseye/docker-entrypoint.sh +++ b/13/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/14/alpine3.17/docker-entrypoint.sh b/14/alpine3.17/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/14/alpine3.17/docker-entrypoint.sh +++ b/14/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/14/alpine3.18/docker-entrypoint.sh b/14/alpine3.18/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/14/alpine3.18/docker-entrypoint.sh +++ b/14/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/14/bookworm/docker-entrypoint.sh b/14/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/14/bookworm/docker-entrypoint.sh +++ b/14/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/14/bullseye/docker-entrypoint.sh b/14/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/14/bullseye/docker-entrypoint.sh +++ b/14/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/15/alpine3.17/docker-entrypoint.sh b/15/alpine3.17/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/15/alpine3.17/docker-entrypoint.sh +++ b/15/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/15/alpine3.18/docker-entrypoint.sh b/15/alpine3.18/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/15/alpine3.18/docker-entrypoint.sh +++ b/15/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/15/bookworm/docker-entrypoint.sh b/15/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/15/bookworm/docker-entrypoint.sh +++ b/15/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/15/bullseye/docker-entrypoint.sh b/15/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/15/bullseye/docker-entrypoint.sh +++ b/15/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/16/alpine3.17/docker-entrypoint.sh b/16/alpine3.17/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/16/alpine3.17/docker-entrypoint.sh +++ b/16/alpine3.17/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/16/alpine3.18/docker-entrypoint.sh b/16/alpine3.18/docker-entrypoint.sh index a383a36487..2639dc155d 100755 --- a/16/alpine3.18/docker-entrypoint.sh +++ b/16/alpine3.18/docker-entrypoint.sh @@ -299,7 +299,12 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories @@ -308,6 +313,10 @@ _main() { exec su-exec postgres "$BASH_SOURCE" "$@" fi + if [ "$1" = 'init' ]; then + shift + fi + # only run initialization on an empty data directory if [ -z "$DATABASE_ALREADY_EXISTS" ]; then docker_verify_minimum_env @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/16/bookworm/docker-entrypoint.sh b/16/bookworm/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/16/bookworm/docker-entrypoint.sh +++ b/16/bookworm/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/16/bullseye/docker-entrypoint.sh b/16/bullseye/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/16/bullseye/docker-entrypoint.sh +++ b/16/bullseye/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 0ae0ecf8c2..2639dc155d 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -299,13 +299,22 @@ _main() { set -- postgres "$@" fi - if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then + init= + if [ "$1" = 'init' ]; then + init=true + fi + + if $init || ( [ "$1" = 'postgres' ] && ! _pg_want_help "$@" ); then docker_setup_env # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then # then restart script as postgres user - exec gosu postgres "$BASH_SOURCE" "$@" + exec su-exec postgres "$BASH_SOURCE" "$@" + fi + + if [ "$1" = 'init' ]; then + shift fi # only run initialization on an empty data directory @@ -343,7 +352,9 @@ _main() { fi fi - exec "$@" + if ! $init; then + exec "$@" + fi } if ! _is_sourced; then