Files
mtusi2026lab2/compose.yaml
T
2026-10-30 19:37:21 +03:00

105 lines
3.2 KiB
YAML

# Local laboratory stand for lab 2.
# Roles: api (application), postgres (source of truth), valkey (session cache).
# Secrets are generated into ./secrets by scripts/bootstrap-secrets.sh and are
# mounted as files, so no credential ever appears in this file or in `docker inspect`.
services:
api:
build:
context: .
image: mtusi-messenger:lab2
environment:
APP_HOST: 0.0.0.0
APP_PORT: "8080"
APP_ENV: ${APP_ENV:-lab}
SESSION_STORE: ${SESSION_STORE:-postgres}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
CACHE_TTL_SECONDS: ${CACHE_TTL_SECONDS:-300}
DB_POOL_MIN: ${DB_POOL_MIN:-1}
DB_POOL_MAX: ${DB_POOL_MAX:-10}
DB_POOL_TIMEOUT_SECONDS: ${DB_POOL_TIMEOUT_SECONDS:-2}
DB_CONNECT_TIMEOUT_SECONDS: ${DB_CONNECT_TIMEOUT_SECONDS:-2}
DB_STATEMENT_TIMEOUT_MS: ${DB_STATEMENT_TIMEOUT_MS:-5000}
CACHE_TIMEOUT_SECONDS: ${CACHE_TIMEOUT_SECONDS:-0.5}
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
secrets:
- database_url
- cache_url
ports:
- "127.0.0.1:${API_PUBLISH_PORT:-8080}:8080"
depends_on:
postgres:
condition: service_healthy
valkey:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2).read()"]
interval: 5s
timeout: 5s
start_period: 20s
retries: 3
restart: unless-stopped
networks:
- backend
postgres:
image: postgres:17.6-bookworm@sha256:f3bd19c606e442c3d7bdfa8002e03fe260a1023351e0ea4598032022b68dd6e3
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=C"
secrets:
- postgres_password
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger --timeout=3"]
interval: 5s
timeout: 5s
start_period: 10s
retries: 12
restart: unless-stopped
networks:
- backend
valkey:
image: valkey/valkey:8.1.3@sha256:fea8b3e67b15729d4bb70589eb03367bab9ad1ee89c876f54327fc7c6e618571
# Valkey is a cache here; AOF is enabled so a restart is still fast and warm,
# but PostgreSQL remains the durable source of truth for sessions.
command:
- sh
- -c
- 'exec valkey-server --requirepass "$$(cat /run/secrets/valkey_password)" --appendonly yes --appendfsync everysec --save "" --dir /data'
secrets:
- valkey_password
volumes:
- valkeydata:/data
healthcheck:
test: ["CMD-SHELL", 'valkey-cli --no-auth-warning -a "$$(cat /run/secrets/valkey_password)" ping | grep -q PONG']
interval: 5s
timeout: 5s
start_period: 5s
retries: 12
restart: unless-stopped
networks:
- backend
secrets:
database_url:
file: ./secrets/database_url
cache_url:
file: ./secrets/cache_url
postgres_password:
file: ./secrets/postgres_password
valkey_password:
file: ./secrets/valkey_password
volumes:
pgdata:
valkeydata:
networks:
backend:
driver: bridge