Files
mtusi2026lab3/compose.yaml

73 lines
1.8 KiB
YAML

name: gavrilenko-lab3
services:
db:
image: postgres:17.6-bookworm
environment:
POSTGRES_USER: messenger
POSTGRES_DB: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
secrets: [db_password]
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 2s
timeout: 3s
retries: 30
cpus: 1
mem_limit: 512m
restart: unless-stopped
migrate:
build: .
command: ["python", "src/db.py"]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
secrets: [database_url]
depends_on:
db:
condition: service_healthy
cpus: 0.5
mem_limit: 128m
api:
build: .
environment:
APP_HOST: 0.0.0.0
APP_PORT: 8080
DATABASE_URL_FILE: /run/secrets/database_url
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
secrets: [database_url]
depends_on:
migrate:
condition: service_completed_successfully
deploy:
replicas: ${API_REPLICAS:-2}
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8080/health/ready', timeout=3)"]
interval: 2s
timeout: 4s
retries: 15
cpus: 0.5
mem_limit: 256m
stop_grace_period: 15s
restart: unless-stopped
lb:
image: haproxy:3.2.6-alpine
volumes:
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
ports:
- "127.0.0.1:${HOST_PORT:-8083}:8080"
depends_on:
api:
condition: service_healthy
cpus: 0.5
mem_limit: 128m
restart: unless-stopped
secrets:
db_password:
file: ./secrets/db_password
database_url:
file: ./secrets/database_url
volumes:
postgres_data: