--- version: "3.8" x-postgres-env: &postgres-env POSTGRES_DB: ${POSTGRES_DB:-tymeslot} POSTGRES_USER: ${POSTGRES_USER:-tymeslot} services: app: environment: <<: *postgres-env # Any DATABASE_HOST other than localhost puts start-docker.sh into external-database mode, which is what the slim image requires. DATABASE_HOST: ${STACK_NAME}_db DATABASE_PORT: 5432 secrets: - postgres_password db: # Matches the version upstream's docker-compose.with-postgres.yml pins, and the version the bundled-database image variant creates its cluster with, so a data directory moved over from that image opens as-is. image: ${DB_DOCKER_IMAGE:-postgres}:${DB_DOCKER_VERSION:-17-alpine} # give Postgres time to shut down cleanly: the Swarm default (10s) force-kills it mid-shutdown on every redeploy, which wipes the cumulative stats (pg_stat_*) that autovacuum's triggers depend on stop_grace_period: 2m volumes: - db-data:/var/lib/postgresql/data networks: - internal environment: <<: *postgres-env POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: - postgres_password healthcheck: test: ["CMD-SHELL", "pg_isready -h localhost -U $$POSTGRES_USER -d $$POSTGRES_DB"] interval: 10s timeout: 5s retries: 5 deploy: labels: backupbot.backup: ${ENABLE_BACKUPS:-true} backupbot.backup.pre-hook: "/pg_backup.sh backup" backupbot.backup.volumes.db-data.path: "backup.sql" backupbot.restore.post-hook: '/pg_backup.sh restore' configs: - source: pg_backup target: /pg_backup.sh mode: 0555 volumes: db-data: configs: pg_backup: name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION:-v1} file: pg_backup.sh secrets: postgres_password: external: true name: ${STACK_NAME}_postgres_password_${SECRET_POSTGRES_PASSWORD_VERSION:-v1}