forked from mtusi2026/mtusi2026lab3
72 lines
2.2 KiB
YAML
72 lines
2.2 KiB
YAML
name: mtusi-lab3
|
|
x-api: &api
|
|
build: .
|
|
image: ${API_IMAGE:-mtusi-lab3-api:local}
|
|
environment: &environment
|
|
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD:?Run scripts/bootstrap.sh}@db:5432/messenger
|
|
CACHE_URL: redis://valkey:6379/0
|
|
SESSION_STORE: valkey
|
|
SESSION_TTL_SECONDS: 3600
|
|
DB_POOL_MAX_SIZE: ${DB_POOL_MAX_SIZE:-5}
|
|
CACHE_CLIENT_MODE: ${CACHE_CLIENT_MODE:-shared}
|
|
cpus: ${API_CPUS:-2}
|
|
mem_limit: ${API_MEMORY:-256m}
|
|
stop_grace_period: 12s
|
|
services:
|
|
db:
|
|
image: postgres:16.6-alpine
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Run scripts/bootstrap.sh}
|
|
volumes: [postgres_data:/var/lib/postgresql/data]
|
|
cpus: ${DB_CPUS:-1}
|
|
mem_limit: 512m
|
|
healthcheck:
|
|
test: [CMD-SHELL, pg_isready -U messenger -d messenger]
|
|
interval: 2s
|
|
timeout: 1s
|
|
retries: 30
|
|
valkey:
|
|
image: valkey/valkey:8.0.2-alpine
|
|
command: [valkey-server, --appendonly, 'yes']
|
|
volumes: [valkey_data:/data]
|
|
cpus: 0.25
|
|
mem_limit: 128m
|
|
migrate:
|
|
<<: *api
|
|
command: [python, migrate.py]
|
|
depends_on:
|
|
db: {condition: service_healthy}
|
|
api:
|
|
<<: *api
|
|
command: [uvicorn, 'app:app', --host, 0.0.0.0, --port, '8080', --timeout-graceful-shutdown, '8']
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
valkey: {condition: service_started}
|
|
healthcheck:
|
|
test: [CMD, python, -c, "import socket; s=socket.create_connection(('127.0.0.1',8080),1); s.sendall(b'GET /health/ready HTTP/1.0\\r\\nHost: localhost\\r\\n\\r\\n'); assert s.makefile('rb').readline().split()[1]==b'200'"]
|
|
interval: 2s
|
|
timeout: 4s
|
|
retries: 2
|
|
lb:
|
|
image: haproxy:3.0.5-alpine
|
|
ports: ['${APP_PORT:-8080}:8080']
|
|
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
|
|
depends_on: [api]
|
|
cpus: ${LB_CPUS:-0.25}
|
|
mem_limit: 64m
|
|
load:
|
|
image: ${API_IMAGE:-mtusi-lab3-api:local}
|
|
profiles: [research]
|
|
entrypoint: [python, scripts/benchmark.py]
|
|
environment:
|
|
BASE_URL: http://lb:8080
|
|
cpus: 1
|
|
mem_limit: 256m
|
|
volumes:
|
|
postgres_data:
|
|
valkey_data:
|