Compare commits
2 Commits
discourse-
...
c8ba2e4e2b
| Author | SHA1 | Date | |
|---|---|---|---|
| c8ba2e4e2b | |||
| 7b7ddd70bc |
24
.env.sample
24
.env.sample
@ -5,19 +5,19 @@ DOMAIN=discourse.example.com
|
|||||||
#EXTRA_DOMAINS=', `www.discourse.example.com`'
|
#EXTRA_DOMAINS=', `www.discourse.example.com`'
|
||||||
LETS_ENCRYPT_ENV=production
|
LETS_ENCRYPT_ENV=production
|
||||||
|
|
||||||
# Admin / developer accounts (comma-separated); these become admins on signup
|
# Outgoing email
|
||||||
DISCOURSE_DEVELOPER_EMAILS=admin@example.com
|
#DISCOURSE_SMTP_HOST=
|
||||||
|
#DISCOURSE_SMTP_PORT=
|
||||||
|
#DISCOURSE_SMTP_USER=
|
||||||
|
#DISCOURSE_SMTP_PROTOCOL=
|
||||||
|
#DISCOURSE_SMTP_AUTH=
|
||||||
|
# Set this if you send e-mails from a different domain than noreply@$DOMAIN
|
||||||
|
#DISCOURSE_NOTIFICATION_EMAIL=$SMTP_USER
|
||||||
|
|
||||||
# Outgoing email (official discourse/discourse env names)
|
# SMTP authentication
|
||||||
#DISCOURSE_SMTP_ADDRESS=
|
#COMPOSE_FILE="compose.yml:compose.smtpauth.yml"
|
||||||
#DISCOURSE_SMTP_PORT=587
|
|
||||||
#DISCOURSE_SMTP_USER_NAME=
|
|
||||||
#DISCOURSE_SMTP_AUTHENTICATION=login
|
|
||||||
#DISCOURSE_SMTP_ENABLE_START_TLS=true
|
|
||||||
# Set this if you send e-mail from a different address than noreply@$DOMAIN
|
|
||||||
#DISCOURSE_NOTIFICATION_EMAIL=
|
|
||||||
|
|
||||||
# SMTP password as a secret
|
|
||||||
#SECRET_SMTP_PASSWORD_VERSION=v1
|
#SECRET_SMTP_PASSWORD_VERSION=v1
|
||||||
|
|
||||||
SECRET_DB_PASSWORD_VERSION=v1
|
SECRET_DB_PASSWORD_VERSION=v1
|
||||||
|
|
||||||
|
# APP_START_PERIOD=5m # healthcheck start_period; raise on slow hosts (cc-ci sets larger for Rails cold boot)
|
||||||
|
|||||||
90
README.md
90
README.md
@ -6,65 +6,67 @@ A platform for community discussion
|
|||||||
|
|
||||||
<!-- metadata -->
|
<!-- metadata -->
|
||||||
* **Category**: Apps
|
* **Category**: Apps
|
||||||
* **Status**: 3, experimental
|
* **Status**:
|
||||||
* **Image**: [`discourse/discourse`](https://hub.docker.com/r/discourse/discourse), 4, upstream
|
* **Image**: [`bitnami/discourse`](https://hub.docker.com/r/bitnami/discourse)
|
||||||
* **Healthcheck**: yes
|
* **Healthcheck**: yes
|
||||||
* **Backups**: yes
|
* **Backups**: no
|
||||||
* **Email**: yes
|
* **Email**: yes
|
||||||
* **Tests**: yes
|
* **Tests**: no
|
||||||
* **SSO**: no
|
* **SSO**: no
|
||||||
<!-- endmetadata -->
|
<!-- endmetadata -->
|
||||||
|
|
||||||
> **Note**: this recipe runs the official, **experimental** `discourse/discourse`
|
|
||||||
> image. Upstream does not yet recommend it for production — see
|
|
||||||
> <https://meta.discourse.org/t/380646>. Use with care.
|
|
||||||
|
|
||||||
## Basic usage
|
## Basic usage
|
||||||
|
|
||||||
1. Set up Docker Swarm and [`abra`]
|
1. Set up Docker Swarm and [`abra`]
|
||||||
2. Deploy [`coop-cloud/traefik`]
|
2. Deploy [`coop-cloud/traefik`]
|
||||||
3. `abra app new discourse --secrets`
|
3. `abra app new discourse --secrets` (optionally with `--pass` if you'd like
|
||||||
4. `abra app config YOURAPPDOMAIN` — set `DOMAIN` and `DISCOURSE_DEVELOPER_EMAILS`
|
to save secrets in `pass`)
|
||||||
|
4. `abra app config YOURAPPDOMAIN` - be sure to change `$DOMAIN` to something that resolves to
|
||||||
|
your Docker swarm box
|
||||||
5. `abra app deploy YOURAPPDOMAIN`
|
5. `abra app deploy YOURAPPDOMAIN`
|
||||||
6. Open the configured domain in your browser to finish set-up. The first account
|
6. Open the configured domain in your browser to finish set-up
|
||||||
that registers with an address listed in `DISCOURSE_DEVELOPER_EMAILS` becomes
|
|
||||||
an admin.
|
|
||||||
|
|
||||||
[`abra`]: https://docs.coopcloud.tech/abra/
|
[`abra`]: https://git.autonomic.zone/autonomic-cooperative/abra
|
||||||
[`coop-cloud/traefik`]: https://git.coopcloud.tech/coop-cloud/traefik
|
[`coop-cloud/traefik`]: https://git.autonomic.zone/coop-cloud/traefik
|
||||||
|
|
||||||
The app serves plain HTTP on port 80; Traefik terminates TLS in front of it. The
|
## To add a new admin user
|
||||||
image's built-in nginx/Let's Encrypt is disabled by the recipe (`install-ssl`
|
|
||||||
override) so it works behind the reverse proxy.
|
|
||||||
|
|
||||||
## Add an admin user
|
1. Login to the instance `abra app run APPNAME app sh`
|
||||||
|
2. `cd /opt/bitnami/discourse`
|
||||||
|
3. `RAILS_ENV=production bundle exec rake admin:create` and follow prompts.
|
||||||
|
|
||||||
```
|
## Install plugins
|
||||||
abra app run YOURAPPDOMAIN app discourse admin create
|
|
||||||
```
|
1. Login to instance `abra app run APPNAME app sh`
|
||||||
|
2. `cd /bitnami/discourse/plugins/`
|
||||||
|
3. `git clone plugin.git` for example `https://github.com/discourse/discourse-openid-connect.git`
|
||||||
|
4. `abra app restart YOURAPPDOMAIN app`
|
||||||
|
|
||||||
|
### Events / calendar plugin
|
||||||
|
|
||||||
|
We've had some luck running [discourse-events](https://github.com/paviliondev/discourse-events).
|
||||||
|
|
||||||
|
## Setup Notes
|
||||||
|
|
||||||
|
Until issue #1 is fixed, the default user is `user` and the default password is `bitnami123`
|
||||||
|
|
||||||
## Postgres major version upgrades
|
## Postgres major version upgrades
|
||||||
|
|
||||||
Handled automatically by the [`discourse/postgres`] image (pgvector + an
|
Welcome to hell.
|
||||||
auto-upgrade layer). On deploy it finds an older cluster, installs the old
|
|
||||||
binaries and runs `pg_upgrade` into the new versioned data directory. The recipe
|
|
||||||
adds a small entrypoint wrapper that injects the password secret and detects the
|
|
||||||
old cluster's real install superuser (oid 10), so the upgrade works whether that
|
|
||||||
user is `postgres` or `discourse`. No manual dump/restore needed.
|
|
||||||
|
|
||||||
[`discourse/postgres`]: https://github.com/discourse/discourse-postgres
|
1. `abra app run YOURAPPDOMAIN db pg_dumpall -U discourse | gzip > YOURAPPDOMAIN_db_DATE.sql.gz`
|
||||||
|
2. `abra app volume ls YOURAPPDOMAIN`, find the name of the Postgres data volume
|
||||||
## Migrating from the previous (bitnami) recipe
|
3. `scp` the backup to your VPS
|
||||||
|
4. `abra app undeploy YOURAPPDOMAIN`
|
||||||
The official image stores uploads under `/shared` rather than bitnami's
|
5. `abra app volume rm YOURAPPDOMAIN`, choose the Postgres data volume
|
||||||
`/bitnami/discourse`. On first boot the recipe copies uploads + backups from the
|
6. `abra app deploy YOURAPPDOMAIN`, then `abra app undeploy YOURAPPDOMAIN`
|
||||||
old bitnami volume (mounted read-only at `/legacy`) into `/shared`, once,
|
7. `ssh` to the VPS, run (replacing `13-alpine` with the new Postgres version)
|
||||||
idempotently. The Postgres database is reused as-is. After a successful migration
|
`docker run -v YOURDATAVOLUME:/var/lib/postgresql/data -e POSTGRES_HOST_AUTH_METHOD=trust -it postgres:13-alpine`
|
||||||
a later recipe version will drop the transitional `/legacy` mount.
|
8. In another SSH session on the server, run `docker ps` to find the ID of the
|
||||||
|
new Postgres container, then `docker exec -it CONTAINERID bash`
|
||||||
If you are upgrading from the bitnami recipe, also remove the now-unused sidekiq
|
9. In the shell you just launched, run `dropdb -U discourse discourse`, then
|
||||||
service that swarm leaves behind (sidekiq runs inside the app container now):
|
`createdb -U discourse discourse`, then Ctrl+D or run `exit`
|
||||||
|
10. In the second SSH session, run `zcat YOURAPPDOMAIN_db_DATE.sql.gz | docker exec -it CONTAINERID psql -U discourse`
|
||||||
```
|
11. Exit the second SSH session
|
||||||
docker service rm YOURSTACK_sidekiq
|
12. Back in the first SSH session, Ctrl+C to shut down the database
|
||||||
```
|
13. `abra app deploy YOURAPPDOMAIN`
|
||||||
|
|||||||
7
abra.sh
7
abra.sh
@ -1,5 +1,2 @@
|
|||||||
export DB_ENTRYPOINT_VERSION=v6
|
export DB_ENTRYPOINT_VERSION=v1
|
||||||
export PG_BACKUP_VERSION=v3
|
export PG_BACKUP_VERSION=v1
|
||||||
export APP_ENTRYPOINT_VERSION=v2
|
|
||||||
export APP_INSTALL_SSL_VERSION=v1
|
|
||||||
export APP_MIGRATE_UPLOADS_VERSION=v1
|
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Overrides the official image's /etc/runit/1.d/install-ssl.
|
|
||||||
#
|
|
||||||
# The stock install-ssl always runs configure-ssl (and configure-letsencrypt),
|
|
||||||
# which empties the default `listen 80` nginx outlet and switches to `listen 443
|
|
||||||
# ssl` against a cert that does not exist here — nginx then crash-loops, or the
|
|
||||||
# image tries to obtain its own Let's Encrypt cert. Under Co-op Cloud, Traefik
|
|
||||||
# terminates TLS and proxies plain HTTP to port 80, so we skip the image's SSL
|
|
||||||
# setup entirely and let nginx keep its default HTTP-on-80 config.
|
|
||||||
echo "install-ssl overridden by recipe: serving plain HTTP on :80 behind Traefik"
|
|
||||||
exit 0
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Co-op Cloud wrapper around the official image's /sbin/boot.
|
|
||||||
# discourse/discourse reads passwords from the process env (pups/Ruby; it has no
|
|
||||||
# *_FILE support), so inject them from the docker secrets before booting.
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ -f /run/secrets/db_password ]; then
|
|
||||||
export DISCOURSE_DB_PASSWORD="$(cat /run/secrets/db_password)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f /run/secrets/smtp_password ]; then
|
|
||||||
export DISCOURSE_SMTP_PASSWORD="$(cat /run/secrets/smtp_password)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec /sbin/boot
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Co-op Cloud entrypoint wrapper for the discourse/postgres image.
|
|
||||||
#
|
|
||||||
# discourse/postgres (https://github.com/discourse/discourse-postgres) is pgvector
|
|
||||||
# plus a management layer that auto-upgrades an older cluster on boot. It does the
|
|
||||||
# heavy lifting (apt-installs the old binaries, runs pg_upgrade, writes the new
|
|
||||||
# cluster to the versioned PGDATA). This wrapper only fills the two gaps it leaves:
|
|
||||||
#
|
|
||||||
# 1. Secrets: the image reads DB_PASSWORD / POSTGRES_PASSWORD from the process
|
|
||||||
# env (no *_FILE support), so inject them from the docker secret.
|
|
||||||
# 2. Install user: the image runs `pg_upgrade --username="$POSTGRES_USER"` and
|
|
||||||
# initdb's the new cluster with $POSTGRES_USER, but never detects the OLD
|
|
||||||
# cluster's real bootstrap superuser (the install user, oid 10). pg_upgrade
|
|
||||||
# aborts unless the new cluster's install-user name matches the old one. Real
|
|
||||||
# deployments differ: some were bootstrapped with `postgres` as the install
|
|
||||||
# user (+ a separate `discourse` app role), others with `discourse` itself.
|
|
||||||
# So detect oid 10 from the old cluster and export POSTGRES_USER to match
|
|
||||||
# before handing off to the image's run-postgres.sh.
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# --- 1. secret injection -----------------------------------------------------
|
|
||||||
if [ -f /run/secrets/db_password ]; then
|
|
||||||
pw="$(cat /run/secrets/db_password)"
|
|
||||||
export DB_PASSWORD="$pw"
|
|
||||||
export POSTGRES_PASSWORD="$pw"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# --- 2. install-user detection (only matters on the upgrade path) ------------
|
|
||||||
NEW_MAJOR="$(postgres --version | sed -rn 's/^[^0-9]*([0-9]+).*/\1/p')"
|
|
||||||
|
|
||||||
# Newest existing cluster under the data mount (same search the image uses).
|
|
||||||
PGVER_FILE="$(find /var/lib/postgresql -maxdepth 3 -type f -name PG_VERSION 2>/dev/null \
|
|
||||||
| xargs -I{} sh -c 'printf "%s " "{}"; cat "{}"' \
|
|
||||||
| sort -nk2,2 | tail -n1 | awk '{print $1}')"
|
|
||||||
|
|
||||||
if [ -n "$PGVER_FILE" ]; then
|
|
||||||
OLD_DIR="$(dirname "$PGVER_FILE")"
|
|
||||||
OLD_MAJOR="$(cat "$PGVER_FILE")"
|
|
||||||
if [ "$OLD_MAJOR" != "$NEW_MAJOR" ]; then
|
|
||||||
echo "cc-db-entrypoint: existing pg${OLD_MAJOR} cluster at ${OLD_DIR}, image is pg${NEW_MAJOR} -> detecting install user"
|
|
||||||
OLD_BIN="/usr/lib/postgresql/${OLD_MAJOR}/bin"
|
|
||||||
if [ ! -x "$OLD_BIN/pg_ctl" ]; then
|
|
||||||
echo "cc-db-entrypoint: installing postgresql-${OLD_MAJOR} to read the old cluster"
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y --no-install-recommends "postgresql-${OLD_MAJOR}" >/dev/null
|
|
||||||
fi
|
|
||||||
chown -R postgres "$OLD_DIR" 2>/dev/null || true
|
|
||||||
|
|
||||||
# Briefly start the old cluster on a local socket only, ask it for oid 10.
|
|
||||||
gosu postgres "$OLD_BIN/pg_ctl" -D "$OLD_DIR" -w \
|
|
||||||
-o "-c listen_addresses= -c unix_socket_directories=/tmp" start >/dev/null 2>&1 || true
|
|
||||||
detected=""
|
|
||||||
for login_role in discourse postgres; do
|
|
||||||
detected="$(gosu postgres psql -h /tmp -U "$login_role" -d postgres -tAc \
|
|
||||||
'select rolname from pg_roles where oid = 10' 2>/dev/null | tr -d '[:space:]')"
|
|
||||||
[ -n "$detected" ] && break
|
|
||||||
done
|
|
||||||
gosu postgres "$OLD_BIN/pg_ctl" -D "$OLD_DIR" -w stop >/dev/null 2>&1 || true
|
|
||||||
|
|
||||||
if [ -n "$detected" ]; then
|
|
||||||
echo "cc-db-entrypoint: old cluster install user is '$detected' -> POSTGRES_USER=$detected"
|
|
||||||
export POSTGRES_USER="$detected"
|
|
||||||
else
|
|
||||||
echo "cc-db-entrypoint: WARNING could not detect old install user; leaving POSTGRES_USER=${POSTGRES_USER:-<image default>}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# pg_upgrade refuses to run if the old and new clusters disagree on data
|
|
||||||
# checksums. PostgreSQL 18's initdb enables checksums by default, but the
|
|
||||||
# older clusters in this recipe's lineage (pg13-17) were created without
|
|
||||||
# them, so initdb the new cluster to match. Default to OFF (the lineage
|
|
||||||
# reality) and only enable when the old cluster positively reports them on.
|
|
||||||
csum=""
|
|
||||||
if [ -x "$OLD_BIN/pg_controldata" ]; then
|
|
||||||
csum="$("$OLD_BIN/pg_controldata" "$OLD_DIR" 2>/dev/null \
|
|
||||||
| awk -F: '/checksum version/{gsub(/[^0-9]/,"",$2); print $2}')"
|
|
||||||
fi
|
|
||||||
if [ "$csum" = "1" ]; then
|
|
||||||
echo "cc-db-entrypoint: old cluster data checksums ON -> initdb new cluster --data-checksums"
|
|
||||||
export POSTGRES_INITDB_ARGS="${POSTGRES_INITDB_ARGS:+$POSTGRES_INITDB_ARGS }--data-checksums"
|
|
||||||
else
|
|
||||||
echo "cc-db-entrypoint: old cluster data checksums OFF (version='${csum:-unknown}') -> initdb new cluster --no-data-checksums"
|
|
||||||
export POSTGRES_INITDB_ARGS="${POSTGRES_INITDB_ARGS:+$POSTGRES_INITDB_ARGS }--no-data-checksums"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec run-postgres.sh postgres
|
|
||||||
@ -3,8 +3,14 @@ version: "3.8"
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
# the wrapper entrypoint reads /run/secrets/smtp_password and exports
|
environment:
|
||||||
# DISCOURSE_SMTP_PASSWORD (the official image has no *_FILE support)
|
- DISCOURSE_SMTP_PASSWORD_FILE=/var/run/secrets/smtp_password
|
||||||
|
secrets:
|
||||||
|
- smtp_password
|
||||||
|
|
||||||
|
sidekiq:
|
||||||
|
environment:
|
||||||
|
- DISCOURSE_SMTP_PASSWORD_FILE=/var/run/secrets/smtp_password
|
||||||
secrets:
|
secrets:
|
||||||
- smtp_password
|
- smtp_password
|
||||||
|
|
||||||
|
|||||||
135
compose.yml
135
compose.yml
@ -3,102 +3,75 @@ version: "3.8"
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: discourse/discourse:3.5.3
|
image: bitnamilegacy/discourse:3.3.1
|
||||||
networks:
|
networks:
|
||||||
- proxy
|
- proxy
|
||||||
- internal
|
- internal
|
||||||
# official image CMD is /sbin/boot; wrapper injects the DB password secret first
|
# entrypoint: ['tail', '-f', '/dev/null']
|
||||||
entrypoint: /usr/local/bin/cc-app-entrypoint.sh
|
|
||||||
environment:
|
environment:
|
||||||
- DISCOURSE_HOSTNAME=${DOMAIN}
|
- ALLOW_EMPTY_PASSWORD=yes
|
||||||
- DISCOURSE_DEVELOPER_EMAILS=${DISCOURSE_DEVELOPER_EMAILS}
|
- DISCOURSE_DATABASE_HOST=${STACK_NAME}_db
|
||||||
- DISCOURSE_DB_HOST=${STACK_NAME}_db
|
- DISCOURSE_DATABASE_NAME=discourse
|
||||||
- DISCOURSE_DB_PORT=5432
|
- DISCOURSE_DATABASE_PASSWORD_FILE=/run/secrets/db_password
|
||||||
- DISCOURSE_DB_NAME=discourse
|
- DISCOURSE_DATABASE_USER=discourse
|
||||||
- DISCOURSE_DB_USERNAME=discourse
|
- DISCOURSE_HOST=${DOMAIN}
|
||||||
- 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
|
- DISCOURSE_NOTIFICATION_EMAIL
|
||||||
|
- DISCOURSE_SMTP_AUTH
|
||||||
|
- DISCOURSE_SMTP_HOST
|
||||||
|
- DISCOURSE_SMTP_PORT
|
||||||
|
- DISCOURSE_SMTP_PROTOCOL
|
||||||
|
- DISCOURSE_SMTP_USER
|
||||||
|
- PASSENGER_COMPILE_NATIVE_SUPPORT_BINARY=0
|
||||||
volumes:
|
volumes:
|
||||||
- 'discourse_shared:/shared'
|
- 'discourse_data:/bitnami/discourse'
|
||||||
# transition only: legacy bitnami volume, read-only, for one-time upload migration
|
|
||||||
- 'discourse_data:/legacy:ro'
|
|
||||||
secrets:
|
secrets:
|
||||||
- db_password
|
- 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:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
- redis
|
- redis
|
||||||
deploy:
|
deploy:
|
||||||
update_config:
|
update_config:
|
||||||
failure_action: rollback
|
failure_action: rollback
|
||||||
order: stop-first
|
order: start-first
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
- "traefik.http.services.${STACK_NAME}.loadbalancer.server.port=80"
|
- "traefik.http.services.${STACK_NAME}.loadbalancer.server.port=3000"
|
||||||
- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`${EXTRA_DOMAINS})"
|
- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`${EXTRA_DOMAINS})"
|
||||||
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
|
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
|
||||||
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
|
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
|
||||||
- "coop-cloud.${STACK_NAME}.version=1.0.0+3.5.3"
|
## Redirect from EXTRA_DOMAINS to DOMAIN
|
||||||
|
#- "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"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: "curl -fsS http://localhost/srv/status || exit 1"
|
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
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 6
|
retries: 6
|
||||||
start_period: 25m
|
start_period: ${APP_START_PERIOD:-5m}
|
||||||
|
|
||||||
db:
|
db:
|
||||||
# discourse/postgres = pgvector + discourse's postgres management layer, which
|
image: postgres:13
|
||||||
# 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
|
|
||||||
# injects the password secret and detects the old cluster's install user.
|
|
||||||
image: discourse/postgres:pg18
|
|
||||||
networks:
|
networks:
|
||||||
- internal
|
- internal
|
||||||
secrets:
|
secrets:
|
||||||
- db_password
|
- db_password
|
||||||
volumes:
|
volumes:
|
||||||
# the image expects the whole cluster tree mounted here (not the data subdir);
|
- 'postgresql_data:/var/lib/postgresql/data'
|
||||||
# an existing pg17 cluster at the volume root is found and upgraded into /18/docker
|
|
||||||
- 'postgresql_data:/var/lib/postgresql'
|
|
||||||
configs:
|
configs:
|
||||||
- source: db_entrypoint
|
- source: db_entrypoint
|
||||||
target: /usr/local/bin/cc-db-entrypoint.sh
|
target: /docker-entrypoint.sh
|
||||||
mode: 0555
|
mode: 0555
|
||||||
- source: pg_backup
|
- source: pg_backup
|
||||||
target: /pg_backup.sh
|
target: /pg_backup.sh
|
||||||
mode: 0555
|
mode: 0555
|
||||||
entrypoint: /usr/local/bin/cc-db-entrypoint.sh
|
entrypoint: /docker-entrypoint.sh
|
||||||
environment:
|
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_HOST_AUTH_METHOD=trust
|
||||||
|
- POSTGRES_USER=discourse
|
||||||
- POSTGRES_DB=discourse
|
- POSTGRES_DB=discourse
|
||||||
- DB_USER=discourse
|
- POSTGRES_PASSWORD_FILE=/run/secrets/db_password
|
||||||
healthcheck:
|
|
||||||
test: "pg_isready -U discourse -d discourse"
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 5
|
|
||||||
# generous: a postgres major-version upgrade (apt install old binaries +
|
|
||||||
# pg_upgrade) runs in the entrypoint before the server accepts connections —
|
|
||||||
# don't let the healthcheck kill an in-progress migration
|
|
||||||
start_period: 15m
|
|
||||||
deploy:
|
deploy:
|
||||||
labels:
|
labels:
|
||||||
backupbot.backup: "true"
|
backupbot.backup: "true"
|
||||||
@ -112,12 +85,35 @@ services:
|
|||||||
- internal
|
- internal
|
||||||
volumes:
|
volumes:
|
||||||
- 'redis_data:/data'
|
- 'redis_data:/data'
|
||||||
healthcheck:
|
|
||||||
test: "redis-cli ping | grep -q PONG"
|
sidekiq:
|
||||||
interval: 30s
|
image: bitnamilegacy/discourse:3.3.1
|
||||||
timeout: 5s
|
networks:
|
||||||
retries: 5
|
- proxy
|
||||||
start_period: 30s
|
- internal
|
||||||
|
depends_on:
|
||||||
|
- discourse
|
||||||
|
volumes:
|
||||||
|
- 'discourse_data:/bitnami/discourse'
|
||||||
|
command: /opt/bitnami/scripts/discourse-sidekiq/run.sh
|
||||||
|
secrets:
|
||||||
|
- db_password
|
||||||
|
environment:
|
||||||
|
- ALLOW_EMPTY_PASSWORD=yes
|
||||||
|
- DISCOURSE_DATABASE_HOST=db
|
||||||
|
- DISCOURSE_DATABASE_NAME=discourse
|
||||||
|
- DISCOURSE_DATABASE_PASSWORD_FILE=/run/secrets/db_password
|
||||||
|
- DISCOURSE_DATABASE_PORT_NUMBER=5432
|
||||||
|
- DISCOURSE_DATABASE_USER=discourse
|
||||||
|
- DISCOURSE_HOST=${DOMAIN}
|
||||||
|
- DISCOURSE_REDIS_HOST=redis
|
||||||
|
- DISCOURSE_REDIS_PORT_NUMBER=6379
|
||||||
|
- DISCOURSE_SMTP_HOST
|
||||||
|
- DISCOURSE_SMTP_PORT
|
||||||
|
- DISCOURSE_SMTP_PROTOCOL
|
||||||
|
- DISCOURSE_SMTP_USER
|
||||||
|
- PASSENGER_COMPILE_NATIVE_SUPPORT_BINARY=0
|
||||||
|
- DISCOURSE_SMTP_AUTH
|
||||||
|
|
||||||
secrets:
|
secrets:
|
||||||
db_password:
|
db_password:
|
||||||
@ -127,7 +123,6 @@ secrets:
|
|||||||
volumes:
|
volumes:
|
||||||
postgresql_data:
|
postgresql_data:
|
||||||
redis_data:
|
redis_data:
|
||||||
discourse_shared:
|
|
||||||
discourse_data:
|
discourse_data:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
@ -136,18 +131,10 @@ networks:
|
|||||||
internal:
|
internal:
|
||||||
|
|
||||||
configs:
|
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
|
|
||||||
db_entrypoint:
|
db_entrypoint:
|
||||||
name: ${STACK_NAME}_db_entrypoint_${DB_ENTRYPOINT_VERSION}
|
name: ${STACK_NAME}_db_entrypoint_${DB_ENTRYPOINT_VERSION}
|
||||||
file: cc-db-entrypoint.sh
|
file: entrypoint.postgres.sh.tmpl
|
||||||
|
template_driver: golang
|
||||||
pg_backup:
|
pg_backup:
|
||||||
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
|
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
|
||||||
file: pg_backup.sh
|
file: pg_backup.sh
|
||||||
|
|||||||
46
entrypoint.postgres.sh.tmpl
Normal file
46
entrypoint.postgres.sh.tmpl
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
MIGRATION_MARKER=$PGDATA/migration_in_progress
|
||||||
|
OLDDATA=$PGDATA/old_data
|
||||||
|
NEWDATA=$PGDATA/new_data
|
||||||
|
|
||||||
|
echo "Running as $(id)"
|
||||||
|
|
||||||
|
if [ -e $MIGRATION_MARKER ]; then
|
||||||
|
echo "FATAL: migration was started but did not complete in a previous run. manual recovery necessary"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f $PGDATA/PG_VERSION ]; then
|
||||||
|
DATA_VERSION=$(cat $PGDATA/PG_VERSION)
|
||||||
|
|
||||||
|
if [ -n "$DATA_VERSION" -a "$PG_MAJOR" != "$DATA_VERSION" ]; then
|
||||||
|
echo "postgres data version $DATA_VERSION found, but need $PG_MAJOR. Starting migration"
|
||||||
|
echo "Installing postgres $DATA_VERSION"
|
||||||
|
sed -i "s/$/ $DATA_VERSION/" /etc/apt/sources.list.d/pgdg.list
|
||||||
|
apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
postgresql-$DATA_VERSION \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
echo "shuffling around"
|
||||||
|
gosu postgres mkdir $OLDDATA $NEWDATA
|
||||||
|
chmod 700 $OLDDATA $NEWDATA
|
||||||
|
mv $PGDATA/* $OLDDATA/ || true
|
||||||
|
touch $MIGRATION_MARKER
|
||||||
|
echo "running initdb"
|
||||||
|
# abuse entrypoint script for initdb by making server error out
|
||||||
|
gosu postgres bash -c "export PGDATA=$NEWDATA ; /usr/local/bin/docker-entrypoint.sh --invalid-arg || true"
|
||||||
|
echo "running pg_upgrade"
|
||||||
|
cd /tmp
|
||||||
|
gosu postgres pg_upgrade --link -b /usr/lib/postgresql/$DATA_VERSION/bin -d $OLDDATA -D $NEWDATA -U $POSTGRES_USER
|
||||||
|
cp $OLDDATA/pg_hba.conf $NEWDATA/
|
||||||
|
mv $NEWDATA/* $PGDATA
|
||||||
|
rm -rf $OLDDATA
|
||||||
|
rmdir $NEWDATA
|
||||||
|
rm $MIGRATION_MARKER
|
||||||
|
echo "migration complete"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
/usr/local/bin/docker-entrypoint.sh postgres
|
||||||
@ -1,24 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# One-time, idempotent, NON-destructive migration of uploads + backups from a
|
|
||||||
# legacy bitnami discourse volume into the official image's /shared.
|
|
||||||
#
|
|
||||||
# Runs on every boot as a runit 1.d hook but no-ops after the first success
|
|
||||||
# (sentinel) and when there is no legacy volume mounted (fresh installs). It only
|
|
||||||
# ever COPIES from the read-only /legacy mount, so an interruption just re-copies
|
|
||||||
# on the next boot — there is no move/delete to leave the data half-migrated.
|
|
||||||
set -e
|
|
||||||
|
|
||||||
SENTINEL=/shared/.bitnami-uploads-migrated
|
|
||||||
[ -e "$SENTINEL" ] && exit 0
|
|
||||||
|
|
||||||
if [ -d /legacy/public/uploads ]; then
|
|
||||||
echo "[migrate-uploads] copying bitnami uploads/backups -> /shared"
|
|
||||||
mkdir -p /shared/uploads /shared/backups
|
|
||||||
cp -a /legacy/public/uploads/. /shared/uploads/ 2>/dev/null || true
|
|
||||||
cp -a /legacy/public/backups/. /shared/backups/ 2>/dev/null || true
|
|
||||||
# discourse runs as uid 1000; the official boot also chowns /shared, but be explicit
|
|
||||||
chown -R discourse:discourse /shared/uploads /shared/backups 2>/dev/null || true
|
|
||||||
echo "[migrate-uploads] done"
|
|
||||||
fi
|
|
||||||
|
|
||||||
touch "$SENTINEL"
|
|
||||||
63
pg_backup.sh
63
pg_backup.sh
@ -1,59 +1,34 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Postgres backup/restore hook for the discourse `db` service (discourse/postgres image).
|
# 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 TCP connections open to the DB, so
|
||||||
|
# restore must terminate them and FORCE-drop before recreating, then reimport the dump deterministically.
|
||||||
|
# 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.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# discourse/postgres keeps the live cluster at a versioned PGDATA under the
|
BACKUP_FILE='/var/lib/postgresql/data/backup.sql'
|
||||||
# /var/lib/postgresql mount. Write the dump at the volume root so backupbot's
|
export PGPASSWORD=$(cat "${POSTGRES_PASSWORD_FILE:-/run/secrets/db_password}")
|
||||||
# `postgresql_data.path: backup.sql` label captures it.
|
DB_USER="${POSTGRES_USER:-discourse}"
|
||||||
BACKUP_FILE='/var/lib/postgresql/backup.sql'
|
|
||||||
DATADIR="${PGDATA:-/var/lib/postgresql/18/docker}"
|
|
||||||
DB_NAME="${POSTGRES_DB:-discourse}"
|
DB_NAME="${POSTGRES_DB:-discourse}"
|
||||||
|
|
||||||
# The bootstrap superuser (install user, oid 10) differs between deployments
|
|
||||||
# (`postgres` on bitnami-origin clusters, `discourse` on others). Detect it at
|
|
||||||
# runtime over the local trust socket rather than hard-coding a name.
|
|
||||||
detect_superuser() {
|
|
||||||
local u name
|
|
||||||
for u in discourse postgres; do
|
|
||||||
name="$(psql -U "$u" -d "$DB_NAME" -tAc 'select rolname from pg_roles where oid = 10' 2>/dev/null | tr -d '[:space:]')"
|
|
||||||
if [ -n "$name" ]; then echo "$name"; return 0; fi
|
|
||||||
done
|
|
||||||
echo postgres
|
|
||||||
}
|
|
||||||
SU="$(detect_superuser)"
|
|
||||||
|
|
||||||
function backup {
|
function backup {
|
||||||
pg_dump -U "$SU" "$DB_NAME" | gzip > "$BACKUP_FILE"
|
pg_dump -U "$DB_USER" "$DB_NAME" | gzip > "$BACKUP_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore {
|
function restore {
|
||||||
cd "$DATADIR"
|
psql -U "$DB_USER" -d postgres -c \
|
||||||
|
|
||||||
# Block all non-local connections so the running discourse app + sidekiq cannot reconnect and
|
|
||||||
# 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
|
|
||||||
su postgres -c "pg_ctl -D '$DATADIR' reload"
|
|
||||||
}
|
|
||||||
cp pg_hba.conf pg_hba.conf.bak
|
|
||||||
echo 'local all all trust' > pg_hba.conf
|
|
||||||
su postgres -c "pg_ctl -D '$DATADIR' reload"
|
|
||||||
trap restore_hba EXIT INT TERM
|
|
||||||
|
|
||||||
# terminate any lingering local sessions before recreate
|
|
||||||
# see https://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection
|
|
||||||
psql -U "$SU" -d postgres -c \
|
|
||||||
"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='${DB_NAME}' AND pid<>pg_backend_pid();"
|
"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='${DB_NAME}' AND pid<>pg_backend_pid();"
|
||||||
|
psql -U "$DB_USER" -d postgres -c "DROP DATABASE ${DB_NAME} WITH (FORCE);"
|
||||||
# drop database and then recreate it
|
createdb -U "$DB_USER" "$DB_NAME"
|
||||||
psql -U "$SU" -d postgres -c "DROP DATABASE ${DB_NAME} WITH (FORCE);"
|
gunzip -c "$BACKUP_FILE" | psql -U "$DB_USER" -d "$DB_NAME" -1 -v ON_ERROR_STOP=1 -f -
|
||||||
createdb -U "$SU" "$DB_NAME"
|
|
||||||
|
|
||||||
# reimport data
|
|
||||||
gunzip -c "$BACKUP_FILE" | psql -U "$SU" -d "$DB_NAME" -1 -v ON_ERROR_STOP=1 -f -
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$@
|
$@
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
This release switches from the bitnami image to the official discourse/discourse
|
|
||||||
image. Some env vars need to be renamed for this migration; everything else
|
|
||||||
should happen automatically.
|
|
||||||
|
|
||||||
Rename these in your app's .env (the values carry over):
|
|
||||||
|
|
||||||
DISCOURSE_SMTP_HOST --> DISCOURSE_SMTP_ADDRESS
|
|
||||||
DISCOURSE_SMTP_USER --> DISCOURSE_SMTP_USER_NAME
|
|
||||||
DISCOURSE_SMTP_AUTH --> DISCOURSE_SMTP_AUTHENTICATION
|
|
||||||
DISCOURSE_SMTP_PROTOCOL --> DISCOURSE_SMTP_ENABLE_START_TLS (takes a boolean true/false, not the old tls/ssl value, so translate it rather than copying it straight across)
|
|
||||||
Reference in New Issue
Block a user