Files
phishingclub/docker-compose.postgres.yml
2026-12-01 19:40:55 +01:00

109 lines
4.3 KiB
YAML

# Runs Phishing Club on PostgreSQL in its own container. It is added to the
# compose file that runs phishingclub, the production file or your own.
#
# PostgreSQL support is experimental. SQLite is the default and the
# recommended engine.
#
# Before the first start, next to the compose files:
#
# 1. Make every docker compose command (up, pull, logs, exec) use both files:
# printf 'COMPOSE_FILE=docker-compose.production.yml:docker-compose.postgres.yml\n' >> .env
# Name your own file in place of docker-compose.production.yml if you use one.
#
# 2. Create the two passwords. The folder is open to you only, the files in it
# must be readable inside the containers, which run as other users:
# install -d -m 700 secrets
# openssl rand -hex 32 > secrets/postgres_password
# openssl rand -hex 32 > secrets/phishingclub_db_password
# chmod 644 secrets/postgres_password secrets/phishingclub_db_password
# postgres_password is for the postgres superuser, which phishingclub never
# uses. phishingclub_db_password is for the phishingclub role, which owns
# the phishingclub database and is not a superuser. Keep the folder out of
# version control. The passwords are read from the files, not from the
# environment, so they are not shown by docker inspect.
#
# 3. docker compose up -d
#
# The roles and the database are made on the first start of an empty volume,
# changing a password file later does not change the password in the
# database.
#
# The database is only on the phishingclub-db network, which has no access
# to the internet and is shared with phishingclub only. Its port is not
# published. sslmode=disable is fine on that network; the server logs a
# warning about it on every start. Use sslmode=verify-full for a database on
# another host.
#
# The backup in the settings page holds files only on postgres. Back up the
# database with pg_dump, in a file only you can read:
# (umask 077 && docker compose exec -T postgres \
# pg_dump -U phishingclub -Fc phishingclub > phishingclub.dump)
services:
phishingclub:
environment:
# checked on every start, used only when config.json is created. An
# existing config.json keeps its engine.
PHISHINGCLUB_DATABASE_ENGINE: postgres
# read on every start, never written to config.json
PHISHINGCLUB_DATABASE_DSN: postgres://phishingclub@postgres:5432/phishingclub?sslmode=disable
PHISHINGCLUB_DATABASE_PASSWORD_FILE: /run/secrets/phishingclub_db_password
secrets:
- phishingclub_db_password
networks:
# default is for a compose file without networks, the production file
# puts phishingclub on its own network as well
- default
- phishingclub-db
depends_on:
postgres:
condition: service_healthy
postgres:
image: postgres:17.12@sha256:97fb53376be3e4fb1a8a61421daa69dcc3bf2fa39bda3259f5245f9a455af1a9
container_name: phishingclub-postgres
restart: unless-stopped
environment:
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
secrets:
- postgres_password
- phishingclub_db_password
configs:
- source: phishingclub_db_init
target: /docker-entrypoint-initdb.d/10-phishingclub.sql
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- phishingclub-db
healthcheck:
# over TCP, the server the image runs while it sets up the database
# listens on the unix socket only
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U phishingclub -d phishingclub"]
interval: 5s
timeout: 5s
retries: 10
configs:
# runs once as the postgres superuser on an empty volume. The password is
# read from the secret by psql and passed as a quoted literal.
phishingclub_db_init:
content: |
\set ON_ERROR_STOP on
\set app_password `cat /run/secrets/phishingclub_db_password`
CREATE ROLE phishingclub LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE PASSWORD :'app_password';
\unset app_password
CREATE DATABASE phishingclub OWNER phishingclub;
REVOKE ALL ON DATABASE phishingclub FROM PUBLIC;
secrets:
postgres_password:
file: ./secrets/postgres_password
phishingclub_db_password:
file: ./secrets/phishingclub_db_password
networks:
phishingclub-db:
internal: true
volumes:
postgres_data: