diff --git a/Dockerfile b/Dockerfile index b3c8991..bf1c30f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,16 @@ RUN wget -q -O - https://github.com/pgbackrest/pgbackrest/archive/release/2.45.t RUN cd /build/pgbackrest-release-2.45/src && ./configure && make +FROM postgres:15-bullseye as patch + +# https://github.com/docker-library/postgres/issues/159 +RUN apt-get update +RUN apt-get install -y \ + patch + +COPY safe-initdb.docker-entrypoint.sh.diff . +RUN patch /usr/local/bin/docker-entrypoint.sh < safe-initdb.docker-entrypoint.sh.diff + FROM postgres:15-bullseye as install # https://pgbackrest.org/user-guide.html#installation @@ -65,6 +75,8 @@ COPY pgbackrest-init.sh /docker-entrypoint-initdb.d/ COPY pg_cron.sql /docker-entrypoint-initdb.d/ COPY plpython3u.sql /docker-entrypoint-initdb.d/ +COPY --from=patch /usr/local/bin/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh + FROM setup as run CMD ["postgres", "--config_file=/etc/postgresql/postgresql.conf"] diff --git a/VERSION b/VERSION index afaf360..1cc5f65 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 \ No newline at end of file +1.1.0 \ No newline at end of file diff --git a/safe-initdb.docker-entrypoint.sh.diff b/safe-initdb.docker-entrypoint.sh.diff new file mode 100644 index 0000000..3fbf176 --- /dev/null +++ b/safe-initdb.docker-entrypoint.sh.diff @@ -0,0 +1,29 @@ +@@ -308,8 +308,19 @@ _main() { + exec gosu postgres "$BASH_SOURCE" "$@" + fi + ++ local initFailed="$PGDATA/INITFAILED" ++ ++ if [ -s "$initFailed" ]; then ++ cat >&2 <<-'EOE' ++ Error: Previous database initialization failed. ++ EOE ++ exit 1 ++ fi ++ + # only run initialization on an empty data directory + if [ -z "$DATABASE_ALREADY_EXISTS" ]; then ++ trap "mkdir $initFailed" EXIT ++ + docker_verify_minimum_env + + # check dir permissions to reduce likelihood of half-initialized database +@@ -329,6 +340,8 @@ _main() { + docker_temp_server_stop + unset PGPASSWORD + ++ trap - EXIT ++ + cat <<-'EOM' + + PostgreSQL init process complete; ready for start up.