Files
mtusi2026lab3/compose.yaml
T

133 lines
2.8 KiB
YAML

name: mtusi2026lab3
x-db-environment: &db-environment
PGHOST: postgres
PGPORT: "5432"
PGDATABASE: messenger
PGUSER: messenger
PGPASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
services:
postgres:
image: postgres:16.4-bookworm
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test:
- CMD-SHELL
- pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB"
interval: 2s
timeout: 2s
retries: 15
start_period: 20s
cpus: "1.0"
mem_limit: 512m
restart: unless-stopped
redis:
image: redis:7.2.5-bookworm
command:
- redis-server
- --appendonly
- "yes"
- --appendfsync
- everysec
- --maxmemory
- 64mb
- --maxmemory-policy
- allkeys-lru
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 2s
timeout: 2s
retries: 10
start_period: 5s
cpus: "0.25"
mem_limit: 128m
restart: unless-stopped
migrate:
build:
context: .
image: mtusi-messenger:lab3
command: ["python", "-m", "app.migrate"]
environment: *db-environment
depends_on:
postgres:
condition: service_healthy
healthcheck:
disable: true
cpus: "0.5"
mem_limit: 256m
restart: "no"
api:
build:
context: .
image: mtusi-messenger:lab3
command:
- python
- -m
- uvicorn
- app.main:app
- --host
- 0.0.0.0
- --port
- "8080"
- --workers
- "1"
- --timeout-graceful-shutdown
- "5"
- --no-access-log
environment:
<<: *db-environment
REDIS_HOST: redis
REDIS_PORT: "6379"
USER_CACHE_TTL_SECONDS: "${USER_CACHE_TTL_SECONDS:-60}"
SESSION_TTL_SECONDS: "${SESSION_TTL_SECONDS:-3600}"
depends_on:
postgres:
condition: service_healthy
migrate:
condition: service_completed_successfully
healthcheck:
test:
- CMD
- python
- -c
- "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2).read()"
interval: 2s
timeout: 3s
retries: 3
start_period: 10s
deploy:
replicas: 2
cpus: "0.75"
mem_limit: 512m
stop_grace_period: 10s
restart: unless-stopped
lb:
image: haproxy:3.0.5-bookworm
ports:
- "127.0.0.1:18082:8080"
volumes:
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on:
api:
condition: service_started
cpus: "0.25"
mem_limit: 128m
stop_grace_period: 10s
restart: unless-stopped
volumes:
postgres_data:
redis_data: