From 8a93f144b27fc404cd9958128cdf2c3174c37b15 Mon Sep 17 00:00:00 2001 From: Bobbie Soedirgo Date: Tue, 5 May 2026 23:46:59 +0800 Subject: [PATCH] feat(multigres): wire up init scripts & pg conf Signed-off-by: Bobbie Soedirgo --- Dockerfile-multigres | 41 ++++++++++++++++++++++++++++++++++++++++- ansible/vars.yml | 6 +++--- flake.lock | 6 +++--- nix/packages/pgctld.nix | 2 +- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Dockerfile-multigres b/Dockerfile-multigres index b8af86c40d..350887d1ce 100644 --- a/Dockerfile-multigres +++ b/Dockerfile-multigres @@ -145,10 +145,13 @@ RUN sed -i \ -e "s|#unix_socket_directories = '/tmp'|unix_socket_directories = '/var/run/postgresql'|g" \ -e "s|#session_preload_libraries = ''|session_preload_libraries = 'supautils'|g" \ -e "s|#include = '/etc/postgresql-custom/supautils.conf'|include = '/etc/postgresql-custom/supautils.conf'|g" \ - -e "s|#include = '/etc/postgresql-custom/wal-g.conf'|include = '/etc/postgresql-custom/wal-g.conf'|g" \ + # skip wal-g - unused by multigres + # -e "s|#include = '/etc/postgresql-custom/wal-g.conf'|include = '/etc/postgresql-custom/wal-g.conf'|g" \ -e "s/ timescaledb,//g" \ -e "s/ pgsodium,//g" \ -e "s/db_user_namespace = off/#db_user_namespace = off/g" \ + # skip - managed by pgctld + -e "s|^data_directory |#data_directory |g" \ /etc/postgresql/postgresql.conf && \ echo "pgsodium.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \ echo "vault.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \ @@ -203,6 +206,25 @@ RUN printf '#!/bin/sh\nexec /nix/var/nix/profiles/default/bin/pgctld --postgres- # Strip extensions absent from pg17 vanilla build RUN sed -i 's/ timescaledb,//g; s/ plv8,//g' /etc/postgresql-custom/supautils.conf +# Generate a single SQL manifest that pgctld runs via --init-db-sql-file after initdb. +# Creates the postgres role, runs init-scripts as postgres (matching migrate.sh), +# then runs migrations as supabase_admin. +RUN set -e && \ + manifest=/docker-entrypoint-initdb.d/multigres-init.sql && \ + printf -- "-- Auto-generated: run init-scripts and migrations after initdb\n" > "$manifest" && \ + printf "DO \$\$ BEGIN\n IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'postgres') THEN\n CREATE ROLE postgres SUPERUSER LOGIN;\n END IF;\nEND \$\$;\n" >> "$manifest" && \ + printf "ALTER DATABASE postgres OWNER TO postgres;\n\n" >> "$manifest" && \ + printf "SET SESSION AUTHORIZATION postgres;\n" >> "$manifest" && \ + for f in $(ls /docker-entrypoint-initdb.d/init-scripts/*.sql 2>/dev/null | sort); do \ + printf '\\ir init-scripts/%s\n' "$(basename "$f")" >> "$manifest"; \ + done && \ + printf "\nRESET SESSION AUTHORIZATION;\n\n" >> "$manifest" && \ + for f in $(ls /docker-entrypoint-initdb.d/migrations/*.sql 2>/dev/null | sort); do \ + printf '\\ir migrations/%s\n' "$(basename "$f")" >> "$manifest"; \ + done && \ + chown postgres:postgres "$manifest" + +ENV POSTGRES_INITDB_SQL_FILES=/docker-entrypoint-initdb.d/multigres-init.sql ENV PATH="/nix/var/nix/profiles/default/bin:/usr/lib/postgresql/bin:${PATH}" ENV LOCALE_ARCHIVE=/nix/var/nix/profiles/default/lib/locale/locale-archive @@ -267,6 +289,23 @@ RUN printf '#!/bin/sh\nexec /nix/var/nix/profiles/default/bin/pgctld --postgres- > /usr/local/bin/pgctld && \ chmod +x /usr/local/bin/pgctld +# Regenerate manifest after orioledb added 00-pre-init.sql to init-scripts/ +RUN set -e && \ + manifest=/docker-entrypoint-initdb.d/multigres-init.sql && \ + printf -- "-- Auto-generated: run init-scripts and migrations after initdb\n" > "$manifest" && \ + printf "DO \$\$ BEGIN\n IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'postgres') THEN\n CREATE ROLE postgres SUPERUSER LOGIN;\n END IF;\nEND \$\$;\n" >> "$manifest" && \ + printf "ALTER DATABASE postgres OWNER TO postgres;\n\n" >> "$manifest" && \ + printf "SET SESSION AUTHORIZATION postgres;\n" >> "$manifest" && \ + for f in $(ls /docker-entrypoint-initdb.d/init-scripts/*.sql 2>/dev/null | sort); do \ + printf '\\ir init-scripts/%s\n' "$(basename "$f")" >> "$manifest"; \ + done && \ + printf "\nRESET SESSION AUTHORIZATION;\n\n" >> "$manifest" && \ + for f in $(ls /docker-entrypoint-initdb.d/migrations/*.sql 2>/dev/null | sort); do \ + printf '\\ir migrations/%s\n' "$(basename "$f")" >> "$manifest"; \ + done && \ + chown postgres:postgres "$manifest" + +ENV POSTGRES_INITDB_SQL_FILES=/docker-entrypoint-initdb.d/multigres-init.sql ENV PATH="/nix/var/nix/profiles/default/bin:/usr/lib/postgresql/bin:${PATH}" ENV LOCALE_ARCHIVE=/nix/var/nix/profiles/default/lib/locale/locale-archive diff --git a/ansible/vars.yml b/ansible/vars.yml index 252862dd50..d4b922e5ae 100644 --- a/ansible/vars.yml +++ b/ansible/vars.yml @@ -10,9 +10,9 @@ postgres_major: # Full version strings for each major version postgres_release: - postgresorioledb-17: "17.6.0.072-orioledb" - postgres17: "17.6.1.115" - postgres15: "15.14.1.115" + postgresorioledb-17: "17.6.0.073-orioledb" + postgres17: "17.6.1.116" + postgres15: "15.14.1.116" # Non Postgres Extensions pgbouncer_release: 1.25.1 diff --git a/flake.lock b/flake.lock index 1eeaee0710..e5497f68d6 100644 --- a/flake.lock +++ b/flake.lock @@ -118,11 +118,11 @@ "multigres": { "flake": false, "locked": { - "lastModified": 1773763606, - "narHash": "sha256-ceShYR1Ocgt+glEzipF/l6Bje+sxuxDbDttaUfUAe44=", + "lastModified": 1777958128, + "narHash": "sha256-bW7Giftisi2pObfCSKoxr+yi4pINjoXdfSk3fwN3er0=", "owner": "multigres", "repo": "multigres", - "rev": "2a0b08680a95e5108bd7d33fe55c832bef3b90bb", + "rev": "7c14506b93d62b86e7ba922a90dcbf7b5574aa09", "type": "github" }, "original": { diff --git a/nix/packages/pgctld.nix b/nix/packages/pgctld.nix index 4dd04670fa..2e66d97c0e 100644 --- a/nix/packages/pgctld.nix +++ b/nix/packages/pgctld.nix @@ -17,7 +17,7 @@ buildGoModule { ''; # Tests require a running PostgreSQL instance (integration tests); skip in sandbox. doCheck = false; - vendorHash = "sha256-cqSd6Dv0WYOVwg7AE1tZPh9uzsjDG32gF6eJzARsHo8="; + vendorHash = "sha256-P+B5fDlCdL0gxUa96BXz+1D0+6RSlul8eMv7iEI3Lpo="; meta = { description = "PostgreSQL control daemon for Multigres cluster lifecycle management";