n8n/compose.postgres.yml

61 lines
1.6 KiB
YAML

---
version: '3.8'
# Compose for PostGres mode instead of the default sqlite mode.
services:
app:
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=${STACK_NAME}_db
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=root
- DB_POSTGRESDB_PASSWORD_FILE=/run/secrets/db_password
depends_on:
- db
secrets:
- db_password
db:
image: postgres:16
networks:
- internal_network
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD_FILE=/run/secrets/db_password
- POSTGRES_DB=n8n
configs:
- source: db_entrypoint
target: /docker-entrypoint.sh
mode: 0555
secrets:
- db_password
healthcheck:
test: ["CMD", "pg_isready", "-U", "root", "-d", "n8n"]
volumes:
- 'postgresql_data:/var/lib/postgresql/data'
entrypoint: /docker-entrypoint.sh
deploy:
labels:
backupbot.backup: "true"
backupbot.backup.pre-hook: "bash -c 'PGPASSWORD=$$(cat $${POSTGRES_PASSWORD_FILE}) pg_dump -U $${POSTGRES_USER} $${POSTGRES_DB} > /tmp/backup.sql'"
backupbot.backup.post-hook: "rm -rf /tmp/backup.sql"
backupbot.backup.path: "/tmp/backup.sql"
secrets:
# db_non_root_password:
# external: true
# name: ${STACK_NAME}_db_non_root_password_${SECRET_DB_NON_ROOT_PASSWORD_VERSION}
db_password:
external: true
name: ${STACK_NAME}_db_password_${SECRET_DB_PASSWORD_VERSION}
volumes:
postgresql_data:
configs:
db_entrypoint:
name: ${STACK_NAME}_db_entrypoint_${DB_ENTRYPOINT_VERSION}
file: entrypoint.postgres.sh.tmpl
template_driver: golang