diff --git a/compose.prod.yaml b/compose.prod.yaml index 6bde629e7..59e713de4 100644 --- a/compose.prod.yaml +++ b/compose.prod.yaml @@ -53,11 +53,36 @@ services: depends_on: postgres: condition: service_healthy + postgres-init: + condition: service_completed_successfully seaweedfs: condition: service_started chrome: condition: service_started + # One-shot, idempotent DB bootstrap. Postgres only runs + # docker-entrypoint-initdb.d scripts the very first time it starts against + # an empty data volume, so if that volume was ever initialized without the + # "probod" database existing (e.g. an earlier deploy attempt), it never + # gets created on later restarts. This runs on every startup and is safe + # to repeat. + postgres-init: + image: "postgres@sha256:7ad98329d513dd497293b951c195ca354274a77f12ddbbbbf85e68a811823d72" + depends_on: + postgres: + condition: service_healthy + environment: + PGPASSWORD: "postgres" + entrypoint: + - "/bin/sh" + - "-c" + - | + set -eu + psql -h postgres -U postgres -v ON_ERROR_STOP=1 <<-'SQL' + SELECT 'CREATE DATABASE probod' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'probod')\gexec + ALTER DATABASE probod SET probo.trust_center_base_domain TO 'probopage.localhost'; + SQL + postgres: image: "postgres@sha256:7ad98329d513dd497293b951c195ca354274a77f12ddbbbbf85e68a811823d72" shm_size: "1g"