Files
Lexicon/docker-compose.managed-db.yml
adminandClaude Opus 5.5 57d82488ae
CI / backend (16) (push) Successful in 2m9s
CI / backend (17) (push) Successful in 2m10s
CI / managed-db (push) Successful in 1m31s
CI / compose-smoke (push) Successful in 2m2s
Fetch private dredd-core from the Haski Gitea, not GitHub
The Dockerfiles still rewrote credentials for github.com only, so the build
token never reached Gitea and installs worked only while dredd-core was
public. Rewrite http://77.216.148.202:3000/ instead, give every workflow
that pip-installs the same rewrite (org secret DREDD_CORE_TOKEN, the
read-only haski-reader token), and drop the GitHub PAT leftovers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 22:18:29 +01:00

71 lines
4.2 KiB
YAML

# Lexicon on a managed PostgreSQL database (the family's shared one, or any Postgres 16/17 reached
# over a network): an override for docker-compose.yml.
#
# DREDD_CORE_TOKEN=<read-only Gitea token> \
# docker compose -f docker-compose.yml -f docker-compose.managed-db.yml up -d --build
#
# The database lives elsewhere — the family shares ONE managed database, and Lexicon has schema
# `lexicon` in it — so the local postgres service is switched off and nothing waits for it;
# migrate (+seed) and backend are otherwise unchanged. Provision Lexicon first
# (db/managed/README.md), and give .env the database's URLs — the provider's host and port (through a
# pooler, its session mode, never transaction mode), user names lexicon_migrator /
# lexicon_app (with the `.<tenant>` suffix where the pooler wants one),
# ?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt — plus DB_APP_ROLE=lexicon_app.
# `python backend/scripts/deploy_check.py` checks the .env side before you start.
#
# Uses the !reset merge tag (docs.docker.com/reference/compose-file/merge/, "Reset value"), so it needs a
# Compose v2 release that supports it; `docker compose -f ... -f ... config` shows the merged result.
# Pass -f with BOTH files on every command (ps, logs, run, down), or Compose falls back to the
# local-postgres stack.
#
# Migrations are not retried on failure: some providers ban a client IP for a while after a few failed
# password logins in a row, and a retry loop around a wrong password would trigger exactly that.
services:
postgres:
# Off: a profile nobody activates keeps the service defined but never starts it.
profiles: ["local-postgres"]
# No data volume and no db/init mount — the schema and roles come from dredd-core's provisioning.
volumes: !reset []
migrate:
# docker-compose.yml makes migrate wait for the local postgres healthcheck; there is none here.
# (backend depends only on migrate, so it stays as it is.)
depends_on: !reset null
environment:
# The one-shot migrate service keeps the whole .env: alembic runs as MIGRATION_DATABASE_URL's
# lexicon_migrator, the seed as DATABASE_URL's lexicon_app. 0002_runtime_grants grants
# the role DB_APP_ROLE names, so an unset DB_APP_ROLE stops here rather than inside the migration.
DB_APP_ROLE: ${DB_APP_ROLE:?set DB_APP_ROLE in .env to the runtime role, lexicon_app in the shared database}
volumes: &managed_db_ca
# The provider's root CA (downloaded from its dashboard; when the server's certificate chains to
# a public CA, drop this mount and the URLs' sslrootcert — verify-full then uses the system trust
# store), read-only, at the path the URLs' sslrootcert names. One file serves the whole shared
# database. create_host_path: false makes a missing file an error at start-up instead of an
# empty directory in its place.
- type: bind
source: ${MANAGED_DB_CA_FILE:-./certs/db-ca.crt}
target: /run/certs/db-ca.crt
read_only: true
bind:
create_host_path: false
backend:
environment:
# Least privilege: the long-running backend connects ONLY as lexicon_app (DATABASE_URL).
# Blank the migrator's URL and the local-postgres passwords that `env_file: .env` would otherwise
# inject (`environment:` wins over `env_file:`), so a compromised backend cannot log in as
# lexicon_migrator and rewrite audit_log. This skeleton never needs the migrator at runtime.
# An app that adds an in-app restore (Galena and Sygna have one) needs it there: keeping it is a
# documented opt-in, and a one-shot restore container (`docker compose run --rm` with the
# migrator's URL) is the recommended path.
MIGRATION_DATABASE_URL: ""
DB_MIGRATOR_PASSWORD: ""
DB_APP_PASSWORD: ""
POSTGRES_PASSWORD: ""
# Passed through explicitly so the running configuration is visible here. The pool bounds the
# connections this backend takes from the shared database's limit (db/managed/README.md).
DB_APP_ROLE: ${DB_APP_ROLE:?set DB_APP_ROLE in .env to the runtime role, lexicon_app in the shared database}
DB_POOL_SIZE: ${DB_POOL_SIZE:-5}
DB_MAX_OVERFLOW: ${DB_MAX_OVERFLOW:-10}
volumes: *managed_db_ca