diff --git a/Dockerfile b/Dockerfile index 730641b..d0b91b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,11 @@ FROM thallian/confd-env:latest -ENV PGDATA /var/lib/postgresql/data +ENV PGDATA=/var/lib/postgresql/data +ENV S6_KEEP_ENV=1 -RUN apk add --no-cache postgresql14 postgresql14-contrib +RUN apk add --no-cache \ + postgresql14 \ + postgresql14-contrib RUN mkdir -p /run/postgresql && mkdir -p $PGDATA RUN chown -R postgres /run/postgresql && chown -R postgres $PGDATA diff --git a/rootfs/bin/db-password b/rootfs/bin/db-password new file mode 100755 index 0000000..838dd45 --- /dev/null +++ b/rootfs/bin/db-password @@ -0,0 +1,9 @@ +#!/command/with-contenv sh + +echo "local all all trust" > "$PGDATA/pg_hba.conf" + +pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost'" -w start + +psql --command "ALTER USER postgres WITH PASSWORD '${POSTGRES_PASSWORD}';" + +pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost'" -w stop diff --git a/rootfs/bin/initdb b/rootfs/bin/initdb new file mode 100755 index 0000000..c4412d3 --- /dev/null +++ b/rootfs/bin/initdb @@ -0,0 +1,5 @@ +#!/command/with-contenv sh + +if [ ! -f "/var/lib/postgresql/data/PG_VERSION" ]; then + s6-setuidgid postgres initdb --username=postgres +fi diff --git a/rootfs/etc/cont-init.d/00-initdb b/rootfs/etc/cont-init.d/00-initdb deleted file mode 100644 index b03b3d0..0000000 --- a/rootfs/etc/cont-init.d/00-initdb +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/with-contenv sh - -if [ ! -f ${PGDATA}/PG_VERSION ]; then - s6-setuidgid postgres initdb --username=postgres -fi diff --git a/rootfs/etc/cont-init.d/00-password b/rootfs/etc/cont-init.d/00-password deleted file mode 100644 index a7278ab..0000000 --- a/rootfs/etc/cont-init.d/00-password +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/with-contenv sh - -cat < /var/lib/postgresql/data/pg_hba.conf -local all all trust -EOF - -s6-setuidgid postgres pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost'" -w start - -s6-setuidgid postgres psql --command "ALTER USER postgres WITH PASSWORD '${POSTGRES_PASSWORD}';" - -s6-setuidgid postgres pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost'" -w stop diff --git a/rootfs/etc/fix-attrs.d/01-pgdata b/rootfs/etc/fix-attrs.d/01-pgdata deleted file mode 100644 index 217b138..0000000 --- a/rootfs/etc/fix-attrs.d/01-pgdata +++ /dev/null @@ -1 +0,0 @@ -/var/lib/postgresql true postgres 0600 0700 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/confd/dependencies b/rootfs/etc/s6-overlay/s6-rc.d/confd/dependencies new file mode 100644 index 0000000..0111504 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/confd/dependencies @@ -0,0 +1,2 @@ +initdb +db-password diff --git a/rootfs/etc/s6-overlay/s6-rc.d/db-password/dependencies b/rootfs/etc/s6-overlay/s6-rc.d/db-password/dependencies new file mode 100644 index 0000000..2e27436 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/db-password/dependencies @@ -0,0 +1 @@ +initdb diff --git a/rootfs/etc/s6-overlay/s6-rc.d/db-password/type b/rootfs/etc/s6-overlay/s6-rc.d/db-password/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/db-password/type @@ -0,0 +1 @@ +oneshot diff --git a/rootfs/etc/s6-overlay/s6-rc.d/db-password/up b/rootfs/etc/s6-overlay/s6-rc.d/db-password/up new file mode 100644 index 0000000..1727f5e --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/db-password/up @@ -0,0 +1 @@ +s6-setuidgid postgres db-password diff --git a/rootfs/etc/s6-overlay/s6-rc.d/initdb/type b/rootfs/etc/s6-overlay/s6-rc.d/initdb/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/initdb/type @@ -0,0 +1 @@ +oneshot diff --git a/rootfs/etc/s6-overlay/s6-rc.d/initdb/up b/rootfs/etc/s6-overlay/s6-rc.d/initdb/up new file mode 100644 index 0000000..a017310 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/initdb/up @@ -0,0 +1 @@ + s6-setuidgid postgres initdb diff --git a/rootfs/etc/s6-overlay/s6-rc.d/postgres/dependencies b/rootfs/etc/s6-overlay/s6-rc.d/postgres/dependencies new file mode 100644 index 0000000..d64b510 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/postgres/dependencies @@ -0,0 +1,3 @@ +initdb +db-password +confd diff --git a/rootfs/etc/services.d/postgres/run b/rootfs/etc/s6-overlay/s6-rc.d/postgres/run old mode 100755 new mode 100644 similarity index 75% rename from rootfs/etc/services.d/postgres/run rename to rootfs/etc/s6-overlay/s6-rc.d/postgres/run index a5bcdf7..ccd2baa --- a/rootfs/etc/services.d/postgres/run +++ b/rootfs/etc/s6-overlay/s6-rc.d/postgres/run @@ -1,4 +1,4 @@ -#!/usr/bin/with-contenv sh +#!/command/with-contenv sh exec s6-setuidgid postgres postgres \ -D $PGDATA \ diff --git a/rootfs/etc/s6-overlay/s6-rc.d/postgres/type b/rootfs/etc/s6-overlay/s6-rc.d/postgres/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/postgres/type @@ -0,0 +1 @@ +longrun diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/postgres b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/postgres new file mode 100644 index 0000000..e69de29