Files
discourse/compose.yml
notplants f783d9988b feat(db): switch to discourse/postgres image (auto-upgrade, no custom entrypoint file)
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 runs the in-place major-version
pg_upgrade itself on boot, so the recipe just configures it via env:

- the db password secret is read into $DB_PASSWORD by a small inline entrypoint
  (the image expects it in the env, no *_FILE support; the base image's
  POSTGRES_PASSWORD_FILE can't be used because run-postgres.sh pre-generates
  POSTGRES_PASSWORD). No separate entrypoint file/config any more.
- 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 needs a
  match).

- 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 PG_BACKUP_VERSION v3; drop DB_ENTRYPOINT_VERSION + 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.
2026-06-22 18:23:22 +00:00

163 lines
5.3 KiB
YAML

---
version: "3.8"
services:
app:
image: discourse/discourse:3.5.3
networks:
- proxy
- internal
# official image CMD is /sbin/boot; wrapper injects the DB password secret first
entrypoint: /usr/local/bin/cc-app-entrypoint.sh
environment:
- DISCOURSE_HOSTNAME=${DOMAIN}
- DISCOURSE_DEVELOPER_EMAILS=${DISCOURSE_DEVELOPER_EMAILS}
- DISCOURSE_DB_HOST=${STACK_NAME}_db
- DISCOURSE_DB_PORT=5432
- DISCOURSE_DB_NAME=discourse
- DISCOURSE_DB_USERNAME=discourse
- DISCOURSE_REDIS_HOST=${STACK_NAME}_redis
- DISCOURSE_REDIS_PORT=6379
- DISCOURSE_SMTP_ADDRESS
- DISCOURSE_SMTP_PORT
- DISCOURSE_SMTP_USER_NAME
- DISCOURSE_SMTP_PASSWORD
- DISCOURSE_SMTP_AUTHENTICATION
- DISCOURSE_SMTP_ENABLE_START_TLS
- DISCOURSE_NOTIFICATION_EMAIL
volumes:
- 'discourse_shared:/shared'
# transition only: legacy bitnami volume, read-only, for one-time upload migration
- 'discourse_data:/legacy:ro'
secrets:
- db_password
configs:
- source: app_entrypoint
target: /usr/local/bin/cc-app-entrypoint.sh
mode: 0555
- source: app_install_ssl
target: /etc/runit/1.d/install-ssl
mode: 0555
- source: app_migrate_uploads
target: /etc/runit/1.d/02-migrate-bitnami-uploads
mode: 0555
depends_on:
- db
- redis
deploy:
update_config:
failure_action: rollback
order: stop-first
labels:
- "traefik.enable=true"
- "traefik.http.services.${STACK_NAME}.loadbalancer.server.port=80"
- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`${EXTRA_DOMAINS})"
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
- "coop-cloud.${STACK_NAME}.version=1.0.0+3.5.3"
healthcheck:
test: "curl -fsS http://localhost/srv/status || exit 1"
interval: 30s
timeout: 10s
retries: 6
start_period: 25m
db:
# 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); everything is driven by the env below.
image: discourse/postgres:pg18
networks:
- internal
secrets:
- db_password
volumes:
# 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: pg_backup
target: /pg_backup.sh
mode: 0555
entrypoint:
- /bin/bash
- -c
- |
if [ -f /run/secrets/db_password ]; then
DB_PASSWORD="$$(cat /run/secrets/db_password)"
export DB_PASSWORD POSTGRES_PASSWORD="$$DB_PASSWORD"
fi
exec run-postgres.sh postgres
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_DB=discourse
- 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: 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"
backupbot.backup.pre-hook: "/pg_backup.sh backup"
backupbot.backup.volumes.postgresql_data.path: "backup.sql"
backupbot.restore.post-hook: "/pg_backup.sh restore"
redis:
image: redis:7.4-alpine
networks:
- internal
volumes:
- 'redis_data:/data'
healthcheck:
test: "redis-cli ping | grep -q PONG"
interval: 30s
timeout: 5s
retries: 5
start_period: 30s
secrets:
db_password:
external: true
name: ${STACK_NAME}_db_password_${SECRET_DB_PASSWORD_VERSION}
volumes:
postgresql_data:
redis_data:
discourse_shared:
discourse_data:
networks:
proxy:
external: true
internal:
configs:
app_entrypoint:
name: ${STACK_NAME}_app_entrypoint_${APP_ENTRYPOINT_VERSION}
file: cc-app-entrypoint.sh
app_install_ssl:
name: ${STACK_NAME}_app_install_ssl_${APP_INSTALL_SSL_VERSION}
file: app-install-ssl.sh
app_migrate_uploads:
name: ${STACK_NAME}_app_migrate_uploads_${APP_MIGRATE_UPLOADS_VERSION}
file: migrate-uploads.sh
pg_backup:
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
file: pg_backup.sh