Files
mtusi2026lab3-fork/compose.yaml
T

86 lines
1.9 KiB
YAML

x-app: &app
image: mtusi-messenger:lab3
cpus: 1.0
mem_limit: 320m
env_file: .env
environment:
CURSOR_KEY_FILE: /run/secrets/cursor_key
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
secrets: [database_url, cache_url, cursor_key]
services:
db:
cpus: 1.0
mem_limit: 384m
image: postgres:17.5-alpine
environment:
POSTGRES_USER: messenger
POSTGRES_DB: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
secrets: [db_password]
volumes: [pgdata:/var/lib/postgresql/data]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 2s
timeout: 2s
retries: 20
cache:
cpus: 0.25
mem_limit: 96m
image: redis:7.4.3-alpine
command: ["redis-server", "--save", "", "--appendonly", "no", "--maxmemory", "32mb", "--maxmemory-policy", "allkeys-lru"]
migrate:
<<: *app
build: .
command: ["python", "src/migrate.py"]
healthcheck:
disable: true
depends_on:
db:
condition: service_healthy
api-a: &api
<<: *app
environment:
CURSOR_KEY_FILE: /run/secrets/cursor_key
INSTANCE_ID: api-a
depends_on:
migrate:
condition: service_completed_successfully
cache:
condition: service_started
stop_grace_period: 8s
api-b:
<<: *api
environment:
CURSOR_KEY_FILE: /run/secrets/cursor_key
INSTANCE_ID: api-b
lb:
image: haproxy:3.0.11-alpine
cpus: 0.5
mem_limit: 96m
ports: ["127.0.0.1:${PUBLIC_PORT:-8080}:8080"]
volumes: ["./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro"]
depends_on:
api-a:
condition: service_healthy
api-b:
condition: service_healthy
secrets:
db_password:
file: ./secrets/db_password
database_url:
file: ./secrets/database_url
cache_url:
file: ./secrets/cache_url
cursor_key:
file: ./secrets/cursor_key
volumes:
pgdata: