From f78ebe46a49a726cb8ff32ccb5139654e5b01524 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 22 Sep 2026 02:03:52 +0200 Subject: [PATCH] fix(svc-db-postgres): build on the official multi-arch postgres 18 image postgis/postgis publishes amd64 only, so every postgres consumer failed on arm64. The official postgres image serves both architectures and already ships the contrib extensions bloom, pg_trgm and unaccent. PostGIS moves into the postgres_libraries registry and is installed from PGDG (postgresql-18-postgis-3) only for a consumer that declares it as an extension, which is mobilizon alone. apt update reads every source list again, because the PostGIS package depends on GDAL from Debian main, which a PGDG-only update left without an install candidate. Postgres 18 keeps its cluster in /var/lib/postgresql/18/docker and its entrypoint treats a volume at the former /var/lib/postgresql/data as an old database, so the central and the dedicated data volume both mount at /var/lib/postgresql. Existing 17 clusters are not migrated: their data directory trips the entrypoint's old-data check and the container refuses to start. Co-Authored-By: Claude Opus 5 (1M context) --- plugins/lookup/postgres_libraries.py | 10 +++++++--- roles/svc-db-postgres/meta/services.yml | 4 ++-- roles/svc-db-postgres/meta/volumes.yml | 2 +- roles/svc-db-postgres/templates/Dockerfile.j2 | 5 +---- .../templates/services/postgres.yml.j2 | 2 +- .../plugins/lookup/test_postgres_libraries.py | 15 ++++++++++++--- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/plugins/lookup/postgres_libraries.py b/plugins/lookup/postgres_libraries.py index 45b9f74bbf..8e031854d6 100644 --- a/plugins/lookup/postgres_libraries.py +++ b/plugins/lookup/postgres_libraries.py @@ -4,9 +4,9 @@ Usage: {{ lookup('postgres_libraries', ['vector', 'bloom']) }} Takes a list of extension names and returns the subset that needs a -custom library install on top of the postgis/postgis base image -(bloom, postgis, pg_trgm, unaccent are already in the base — those are -filtered out). Each returned entry is a dict with: +custom library install on top of the official postgres base image +(the contrib extensions bloom, pg_trgm and unaccent are already in the +base — those are filtered out). Each returned entry is a dict with: - extension: the extension name (matches the SQL identifier) - name: the library/source name (used in the Dockerfile context) - apt_package: the PGDG package suffix, installed as @@ -25,6 +25,10 @@ if TYPE_CHECKING: _REGISTRY: dict[str, dict[str, str]] = { + "postgis": { + "name": "postgis", + "apt_package": "postgis-3", + }, "vector": { "name": "pgvector", "apt_package": "pgvector", diff --git a/roles/svc-db-postgres/meta/services.yml b/roles/svc-db-postgres/meta/services.yml index a950600b68..c3b6d8d1e7 100644 --- a/roles/svc-db-postgres/meta/services.yml +++ b/roles/svc-db-postgres/meta/services.yml @@ -12,9 +12,9 @@ postgres: shared: true healthcheck: test: ["CMD-SHELL", "pg_isready -h 127.0.0.1"] - image: postgis/postgis + image: postgres name: postgres - version: 17-3.5 + version: "18" custom: true min_storage: 419MB backup: diff --git a/roles/svc-db-postgres/meta/volumes.yml b/roles/svc-db-postgres/meta/volumes.yml index f0b4811828..aa123a4104 100644 --- a/roles/svc-db-postgres/meta/volumes.yml +++ b/roles/svc-db-postgres/meta/volumes.yml @@ -4,4 +4,4 @@ data: name: postgres_data mounts: - service: postgres - target: /var/lib/postgresql/data + target: /var/lib/postgresql diff --git a/roles/svc-db-postgres/templates/Dockerfile.j2 b/roles/svc-db-postgres/templates/Dockerfile.j2 index eaf1be0e52..f35c4d4089 100644 --- a/roles/svc-db-postgres/templates/Dockerfile.j2 +++ b/roles/svc-db-postgres/templates/Dockerfile.j2 @@ -2,10 +2,7 @@ FROM {{ POSTGRES_IMAGE }}:{{ POSTGRES_VERSION }} {% if POSTGRES_LIBRARIES | length > 0 %} RUN rm -rf /var/lib/apt/lists/* \ - && apt-get -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/pgdg.list \ - -o Dir::Etc::sourceparts=- \ - -o APT::Get::List-Cleanup=0 \ - -o Acquire::Retries=3 update \ + && apt-get -o Acquire::Retries=3 update \ && apt-get -o Acquire::Retries=3 install -y --no-install-recommends \ {% for lib in POSTGRES_LIBRARIES %} postgresql-{{ POSTGRES_VERSION_MAJOR }}-{{ lib.apt_package }} \ diff --git a/roles/sys-svc-rdbms/templates/services/postgres.yml.j2 b/roles/sys-svc-rdbms/templates/services/postgres.yml.j2 index caf5b6c390..8336da1ace 100644 --- a/roles/sys-svc-rdbms/templates/services/postgres.yml.j2 +++ b/roles/sys-svc-rdbms/templates/services/postgres.yml.j2 @@ -28,7 +28,7 @@ volumes: - type: volume source: database - target: /var/lib/postgresql/data + target: /var/lib/postgresql {% if _extensions | length > 0 %} - type: bind source: {{ lookup('database', application_id, 'initdb_dir') }} diff --git a/tests/unit/python/plugins/lookup/test_postgres_libraries.py b/tests/unit/python/plugins/lookup/test_postgres_libraries.py index 5100931c71..f1549a6094 100644 --- a/tests/unit/python/plugins/lookup/test_postgres_libraries.py +++ b/tests/unit/python/plugins/lookup/test_postgres_libraries.py @@ -53,13 +53,22 @@ class PostgresLibrariesLookupTests(unittest.TestCase): self.assertEqual(result[0]["apt_package"], "pgvector") def test_base_extensions_are_filtered_out(self): - result = self._run([["bloom", "postgis", "pg_trgm", "unaccent"]])[0] + result = self._run([["bloom", "pg_trgm", "unaccent"]])[0] self.assertEqual(result, []) + def test_postgis_is_built_only_for_a_role_that_declares_it(self): + result = self._run([["bloom", "postgis"]])[0] + self.assertEqual( + [(r["extension"], r["apt_package"]) for r in result], + [("postgis", "postgis-3")], + ) + def test_mixed_extensions_returns_only_non_base(self): result = self._run([["bloom", "vector", "postgis"]])[0] - self.assertEqual(len(result), 1) - self.assertEqual(result[0]["extension"], "vector") + self.assertEqual( + [r["extension"] for r in result], + ["vector", "postgis"], + ) def test_duplicates_are_deduplicated(self): result = self._run([["vector", "vector"]])[0]