From 05459d357701d255708b6bf55eadf884fce666ee Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Sun, 13 Feb 2022 08:23:50 +0100 Subject: [PATCH] switch to s6-rc --- Dockerfile | 7 +++++-- rootfs/bin/db-password | 9 +++++++++ rootfs/bin/initdb | 5 +++++ rootfs/etc/cont-init.d/00-initdb | 5 ----- rootfs/etc/cont-init.d/00-password | 11 ----------- rootfs/etc/fix-attrs.d/01-pgdata | 1 - rootfs/etc/s6-overlay/s6-rc.d/confd/dependencies | 2 ++ .../etc/s6-overlay/s6-rc.d/db-password/dependencies | 1 + rootfs/etc/s6-overlay/s6-rc.d/db-password/type | 1 + rootfs/etc/s6-overlay/s6-rc.d/db-password/up | 1 + rootfs/etc/s6-overlay/s6-rc.d/initdb/type | 1 + rootfs/etc/s6-overlay/s6-rc.d/initdb/up | 1 + rootfs/etc/s6-overlay/s6-rc.d/postgres/dependencies | 3 +++ .../{services.d => s6-overlay/s6-rc.d}/postgres/run | 2 +- rootfs/etc/s6-overlay/s6-rc.d/postgres/type | 1 + .../etc/s6-overlay/s6-rc.d/user/contents.d/postgres | 0 16 files changed, 31 insertions(+), 20 deletions(-) create mode 100755 rootfs/bin/db-password create mode 100755 rootfs/bin/initdb delete mode 100644 rootfs/etc/cont-init.d/00-initdb delete mode 100644 rootfs/etc/cont-init.d/00-password delete mode 100644 rootfs/etc/fix-attrs.d/01-pgdata create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/confd/dependencies create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/db-password/dependencies create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/db-password/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/db-password/up create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/initdb/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/initdb/up create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/postgres/dependencies rename rootfs/etc/{services.d => s6-overlay/s6-rc.d}/postgres/run (75%) mode change 100755 => 100644 create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/postgres/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/postgres 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