forked from mtusi2026/mtusi2026lab2
69 lines
1.9 KiB
YAML
69 lines
1.9 KiB
YAML
x-app-env: &app-env
|
|
DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-messenger_db}
|
|
REDIS_URL: redis://valkey:6379/0
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
SESSION_CACHE_TTL_SECONDS: ${SESSION_CACHE_TTL_SECONDS:-30}
|
|
|
|
services:
|
|
db:
|
|
image: postgres:16-alpine
|
|
container_name: lab2_postgres
|
|
environment:
|
|
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
|
POSTGRES_DB: ${POSTGRES_DB:-messenger_db}
|
|
ports:
|
|
- "5433:5432"
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U postgres -d messenger_db"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 5
|
|
|
|
valkey:
|
|
image: valkey/valkey:8.0-alpine
|
|
container_name: lab2_valkey
|
|
# Кэш сессий: источник истины - PostgreSQL, persistence не нужен.
|
|
command: ["valkey-server", "--save", "", "--appendonly", "no",
|
|
"--maxmemory", "64mb", "--maxmemory-policy", "allkeys-lru"]
|
|
healthcheck:
|
|
test: ["CMD", "valkey-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 5
|
|
|
|
migrate:
|
|
build: .
|
|
image: lab2-app
|
|
container_name: lab2_migrate
|
|
command: ["alembic", "upgrade", "head"]
|
|
environment: *app-env
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
|
|
app:
|
|
build: .
|
|
image: lab2-app
|
|
container_name: lab2_app
|
|
environment: *app-env
|
|
ports:
|
|
- "8080:8080"
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
valkey:
|
|
condition: service_started # мягкая зависимость: API работает и без кэша
|
|
restart: unless-stopped
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "http://localhost:8080/health/ready"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
volumes:
|
|
postgres_data:
|