Files
mtusi2026lab3/compose.yaml

104 lines
2.6 KiB
YAML

services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD: messenger_password
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger"]
interval: 5s
timeout: 5s
retries: 5
deploy:
resources:
limits:
cpus: '1.00'
memory: 512M
redis:
image: redis:7-alpine
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
deploy:
resources:
limits:
cpus: '0.50'
memory: 128M
# Однократный сервис миграций: применяется ОДИН РАЗ перед стартом реплик.
# Реплики API зависят от него через condition: service_completed_successfully.
migrate:
build:
context: .
dockerfile: Dockerfile
entrypoint: ["/app/server", "-migrate-only"]
depends_on:
postgres:
condition: service_healthy
environment:
DATABASE_URL: postgres://messenger:messenger_password@postgres:5432/messenger?sslmode=disable
deploy:
resources:
limits:
cpus: '0.50'
memory: 128M
api:
build:
context: .
dockerfile: Dockerfile
deploy:
replicas: 2
resources:
limits:
cpus: '0.50'
memory: 256M
depends_on:
# Реплики стартуют ТОЛЬКО после успешного завершения миграций
migrate:
condition: service_completed_successfully
postgres:
condition: service_healthy
redis:
condition: service_healthy
environment:
APP_HOST: 0.0.0.0
APP_PORT: 8080
DATABASE_URL: postgres://messenger:messenger_password@postgres:5432/messenger?sslmode=disable
REDIS_URL: redis://redis:6379/0
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
CACHE_MODE: ${CACHE_MODE:-versioned}
SESSION_STORE: ${SESSION_STORE:-redis}
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8080/health/ready"]
interval: 2s
timeout: 2s
retries: 3
start_period: 5s
nginx:
image: nginx:1.25-alpine
ports:
- "8080:8080"
depends_on:
api:
condition: service_healthy
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
deploy:
resources:
limits:
cpus: '0.25'
memory: 64M
volumes:
postgres_data:
redis_data: