feat(db): switch to discourse/postgres image (auto-upgrade, minimal wrapper)
Replace the bitnami-era pgvector:pg17 db + hand-rolled pg_upgrade entrypoint with discourse/postgres:pg18 (pgvector + discourse's auto-upgrade layer, as suggested on coop-cloud/discourse#16). The image does the in-place major-version pg_upgrade itself on boot, so the recipe just configures it via env: - cc-db-entrypoint.sh is now a 5-line wrapper that only injects the password secret (the image reads DB_PASSWORD/POSTGRES_PASSWORD from env, no *_FILE); - POSTGRES_USER (the install user pg_upgrade must match) defaults to the image's 'postgres' -- correct for fresh installs and bitnami-origin clusters -- and is overridable from the app .env for a cluster bootstrapped with another superuser; - POSTGRES_INITDB_ARGS=--no-data-checksums so the new pg18 cluster matches the pre-18 clusters (pg18 initdb enables checksums by default, pg_upgrade requires a match). No need to install the old postgres in our wrapper anymore. - mount postgresql_data at /var/lib/postgresql (versioned PGDATA .../18/docker) - pg_backup.sh: detect the superuser at runtime; fix paths for the new layout - document POSTGRES_USER override in .env.sample and README - bump DB_ENTRYPOINT_VERSION v7, PG_BACKUP_VERSION v3 (immutable swarm configs) - drop entrypoint.postgres.sh.tmpl Verified on cctest: pg17->pg18 upgrade (install user 'postgres', checksums off) preserves data and serves over HTTPS; fresh install also works.
This commit is contained in:
38
compose.yml
38
compose.yml
@ -63,35 +63,50 @@ services:
|
||||
start_period: 25m
|
||||
|
||||
db:
|
||||
image: pgvector/pgvector:pg17
|
||||
# discourse/postgres = pgvector + discourse's postgres management layer, which
|
||||
# auto-upgrades an older cluster in place on boot (pg_upgrade into the versioned
|
||||
# PGDATA /var/lib/postgresql/${MAJOR}/docker). The cc-db-entrypoint wrapper only
|
||||
# injects the password secret; everything else is driven by the env below.
|
||||
image: discourse/postgres:pg18
|
||||
networks:
|
||||
- internal
|
||||
secrets:
|
||||
- db_password
|
||||
volumes:
|
||||
- 'postgresql_data:/var/lib/postgresql/data'
|
||||
# the image expects the whole cluster tree mounted here (not the data subdir);
|
||||
# an existing pg17 cluster at the volume root is found and upgraded into /18/docker
|
||||
- 'postgresql_data:/var/lib/postgresql'
|
||||
configs:
|
||||
- source: db_entrypoint
|
||||
target: /docker-entrypoint.sh
|
||||
target: /usr/local/bin/cc-db-entrypoint.sh
|
||||
mode: 0555
|
||||
- source: pg_backup
|
||||
target: /pg_backup.sh
|
||||
mode: 0555
|
||||
entrypoint: /docker-entrypoint.sh
|
||||
entrypoint: /usr/local/bin/cc-db-entrypoint.sh
|
||||
environment:
|
||||
# internal-only overlay network; keep all-trust so the app and the
|
||||
# backup/restore hooks connect without juggling the superuser password
|
||||
- POSTGRES_HOST_AUTH_METHOD=trust
|
||||
- POSTGRES_USER=discourse
|
||||
- POSTGRES_DB=discourse
|
||||
- POSTGRES_PASSWORD_FILE=/run/secrets/db_password
|
||||
- DB_USER=discourse
|
||||
# pg_upgrade runs as this role and initdb's the new cluster with it; it must
|
||||
# match the OLD cluster's bootstrap superuser (oid 10). The image default
|
||||
# `postgres` matches fresh installs and bitnami-origin clusters. Override in
|
||||
# the app .env (POSTGRES_USER=...) only for a cluster bootstrapped differently.
|
||||
- POSTGRES_USER=${POSTGRES_USER:-postgres}
|
||||
# pg18's initdb enables data checksums by default, but pg13-17 clusters here
|
||||
# have them off and pg_upgrade requires a match -> initialise without them.
|
||||
- POSTGRES_INITDB_ARGS=--no-data-checksums
|
||||
healthcheck:
|
||||
test: "pg_isready -U discourse -d discourse"
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
# generous: a postgres major-version upgrade (apt install + pg_upgrade) runs
|
||||
# in the entrypoint before the server accepts connections — don't let the
|
||||
# healthcheck kill an in-progress migration
|
||||
start_period: 10m
|
||||
# generous: on a major-version bump the image installs the old binaries and
|
||||
# runs pg_upgrade on first boot before the server accepts connections —
|
||||
# don't let the healthcheck kill an in-progress migration
|
||||
start_period: 15m
|
||||
deploy:
|
||||
labels:
|
||||
backupbot.backup: "true"
|
||||
@ -140,8 +155,7 @@ configs:
|
||||
file: migrate-uploads.sh
|
||||
db_entrypoint:
|
||||
name: ${STACK_NAME}_db_entrypoint_${DB_ENTRYPOINT_VERSION}
|
||||
file: entrypoint.postgres.sh.tmpl
|
||||
template_driver: golang
|
||||
file: cc-db-entrypoint.sh
|
||||
pg_backup:
|
||||
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
|
||||
file: pg_backup.sh
|
||||
|
||||
Reference in New Issue
Block a user