Files
mtusi2026lab2/compose.yaml
T

74 lines
1.9 KiB
YAML

# Lab2 topology: API + PostgreSQL (source of truth) + Valkey (session cache).
# Versions are pinned; PostgreSQL and Valkey are not published outside the
# compose network. Secrets are file-based and live in ./secrets (gitignored).
x-api-env: &api-env
APP_HOST: "0.0.0.0"
APP_PORT: "8080"
APP_ENV: ${APP_ENV:-lab}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
SESSION_STORE: ${SESSION_STORE:-valkey}
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
DB_POOL_MIN: ${DB_POOL_MIN:-1}
DB_POOL_MAX: ${DB_POOL_MAX:-10}
DB_POOL_TIMEOUT: ${DB_POOL_TIMEOUT:-5}
DB_STATEMENT_TIMEOUT_MS: ${DB_STATEMENT_TIMEOUT_MS:-5000}
services:
api:
build:
context: .
environment: *api-env
secrets:
- database_url
- cache_url
ports:
- "127.0.0.1:${PUBLISH_PORT:-8080}:8080"
depends_on:
postgres:
condition: service_healthy
valkey:
condition: service_healthy
restart: unless-stopped
postgres:
image: postgres:16.6-bookworm
environment:
POSTGRES_USER: messenger
POSTGRES_DB: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/database_password
secrets:
- database_password
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 5s
timeout: 3s
retries: 12
restart: unless-stopped
valkey:
image: valkey/valkey:8.0.2-alpine
command: ["valkey-server", "--appendonly", "yes"]
volumes:
- valkeydata:/data
healthcheck:
test: ["CMD", "valkey-cli", "ping"]
interval: 5s
timeout: 3s
retries: 12
restart: unless-stopped
volumes:
pgdata:
valkeydata:
secrets:
database_url:
file: ./secrets/database_url
database_password:
file: ./secrets/database_password
cache_url:
file: ./secrets/cache_url