Files
mtusi2026lab3/compose.yaml
T

77 lines
2.0 KiB
YAML

services:
postgres:
image: postgres:16.4-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 5s
timeout: 5s
retries: 5
redis:
image: valkey/valkey:8.0-alpine
command: valkey-server --appendonly yes --save 60 1
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "valkey-cli", "ping"]
interval: 5s
timeout: 5s
retries: 5
api:
build:
context: .
dockerfile: Dockerfile
environment:
- DATABASE_URL=${DATABASE_URL}
- REDIS_URL=${REDIS_URL}
- SECRET_SESSION_KEY=${SECRET_SESSION_KEY}
- SESSION_TTL_SECONDS=${SESSION_TTL_SECONDS}
# ВАЖНО: Не публикуем порты наружу! Только Nginx имеет доступ к API
expose:
- "8080"
volumes:
- ./alembic/versions:/app/alembic/versions
- ./app:/app/app
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
# Graceful shutdown: даём 30 секунд на завершение текущих запросов
stop_grace_period: 30s
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health/live"]
interval: 10s
timeout: 5s
retries: 3
start_period: 10s
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.25'
memory: 128M
nginx:
image: nginx:1.25-alpine
ports:
- "8080:8080"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
api:
condition: service_healthy # <--- КРИТИЧНО: ждём, пока api станет healthy
restart: unless-stopped
volumes:
postgres_data:
redis_data: