Compare commits

4 Commits

Author SHA1 Message Date
b0f9ae743a fix(db): switch postgres image to pgvector/pgvector:pg17 + bump PG_BACKUP_VERSION
All checks were successful
cc-ci/testme cc-ci: success
2026-06-02 20:07:06 +00:00
5091fd999e improved comments
Some checks failed
cc-ci/testme cc-ci: failure
2026-06-02 19:10:27 +00:00
ec7bbdf786 fix(backup): add pg_backup.sh + proper backup/restore hooks, 20m start_period 2026-06-02 19:10:27 +00:00
0f873433ba chore: upgrade to 0.8.0+3.5.0 2026-06-02 19:10:27 +00:00
4 changed files with 13 additions and 22 deletions

View File

@ -19,4 +19,3 @@ LETS_ENCRYPT_ENV=production
#SECRET_SMTP_PASSWORD_VERSION=v1
SECRET_DB_PASSWORD_VERSION=v1

View File

@ -1,2 +1,2 @@
export DB_ENTRYPOINT_VERSION=v1
export PG_BACKUP_VERSION=v1
export PG_BACKUP_VERSION=v2

View File

@ -3,7 +3,7 @@ version: "3.8"
services:
app:
image: bitnamilegacy/discourse:3.3.1
image: bitnamilegacy/discourse:3.5.0
networks:
- proxy
- internal
@ -43,7 +43,7 @@ services:
#- "traefik.http.routers.${STACK_NAME}.middlewares=${STACK_NAME}-redirect"
#- "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLForceHost=true"
#- "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLHost=${DOMAIN}"
- "coop-cloud.${STACK_NAME}.version=0.8.0+3.3.1"
- "coop-cloud.${STACK_NAME}.version=0.8.0+3.5.0"
healthcheck:
test: "ruby -e \"require 'uri'; require 'net/http'; uri = URI('http://localhost:3000/srv/status'); res = Net::HTTP.get_response(uri); if res.is_a?(Net::HTTPSuccess) then exit (0) else exit (1) end\""
interval: 30s
@ -52,7 +52,7 @@ services:
start_period: 20m
db:
image: postgres:13
image: pgvector/pgvector:pg17
networks:
- internal
secrets:
@ -87,7 +87,7 @@ services:
- 'redis_data:/data'
sidekiq:
image: bitnamilegacy/discourse:3.3.1
image: bitnamilegacy/discourse:3.5.0
networks:
- proxy
- internal

View File

@ -1,18 +1,6 @@
#!/bin/bash
# Postgres backup/restore hook for the discourse `db` service. Invoked by backupbot-two via:
# backupbot.backup.pre-hook = "/pg_backup.sh backup"
# backupbot.backup.volumes.postgresql_data.path = "backup.sql"
# backupbot.restore.post-hook = "/pg_backup.sh restore"
# Backup dumps the DB to backup.sql (gzip) inside the postgresql_data volume; backupbot archives it.
# Restore reimports it. Discourse (the rails app + sidekiq) keeps many TCP connections open to the DB
# and reconnects within milliseconds, so a one-shot pg_terminate_backend is NOT enough: restore must
# first block all non-local connections at the pg_hba level (so the app cannot reconnect and interfere
# mid-reimport), then FORCE-drop, recreate, and deterministically reimport the dump, then restore
# pg_hba. (Mirrors the proven matrix-synapse restore hook.) The previous recipe shipped a pg_dump
# backup but NO restore hook — a file-level restore did not reload into the running postgres, so a
# restored backup silently kept the live (un-restored) state. cc-ci caught this: a seeded ci_marker row
# was gone after restore. Same pattern as the immich / mattermost-lts / ghost recipe-PRs.
# Postgres backup/restore hook for the discourse `db` service.
set -e
@ -29,8 +17,7 @@ function restore {
cd /var/lib/postgresql/data/
# Block all non-local connections so the running discourse app + sidekiq cannot reconnect and
# interfere with the drop/recreate/reimport (a one-shot pg_terminate_backend is not enough — the
# app reconnects within ms over TCP). Restored on exit.
# interfere with the drop/recreate/reimport. Restored on exit.
restore_hba() {
cat pg_hba.conf.bak > pg_hba.conf
rm -f pg_hba.conf.bak
@ -41,11 +28,16 @@ function restore {
su postgres -c 'pg_ctl reload'
trap restore_hba EXIT INT TERM
# Terminate lingering local sessions, then FORCE-drop + recreate + deterministic reimport.
# terminate any lingering local sessions before recreate
# see https://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection
psql -U "$DB_USER" -d postgres -c \
"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='${DB_NAME}' AND pid<>pg_backend_pid();"
# drop database and then recreate it
psql -U "$DB_USER" -d postgres -c "DROP DATABASE ${DB_NAME} WITH (FORCE);"
createdb -U "$DB_USER" "$DB_NAME"
# reimport data
gunzip -c "$BACKUP_FILE" | psql -U "$DB_USER" -d "$DB_NAME" -1 -v ON_ERROR_STOP=1 -f -
}