Files
mtusi2026lab3/compose.yaml
T

124 lines
3.2 KiB
YAML

name: mtusi-lab3
services:
loadgen:
profiles: [research]
image: mtusi-messenger:lab3
entrypoint: [loadgen]
networks: [front]
cpus: 2.0
mem_limit: 256m
read_only: true
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
postgres:
image: postgres:17.6-alpine3.22
environment:
POSTGRES_USER: messenger
POSTGRES_DB: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
secrets: [postgres_password]
volumes: [postgres_data:/var/lib/postgresql/data]
networks: [storage]
healthcheck:
test: [CMD-SHELL, 'pg_isready -U messenger -d messenger']
interval: 2s
timeout: 2s
retries: 30
cpus: ${DB_CPUS:-1.0}
mem_limit: ${DB_MEMORY:-512m}
restart: unless-stopped
redis:
image: redis:7.4.5-alpine3.21
command: [redis-server, /etc/redis/redis.conf]
volumes:
- redis_data:/data
- ./infra/redis.conf:/etc/redis/redis.conf:ro
networks: [storage]
healthcheck:
test: [CMD, redis-cli, ping]
interval: 2s
timeout: 2s
retries: 30
cpus: 0.25
mem_limit: 128m
restart: unless-stopped
migrate:
image: mtusi-messenger:lab3
build: .
command: [migrate]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
secrets: [database_url]
networks: [storage]
depends_on:
postgres: {condition: service_healthy}
cpus: 0.5
mem_limit: 128m
read_only: true
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
restart: 'no'
api:
image: mtusi-messenger:lab3
build: .
environment:
APP_HOST: 0.0.0.0
APP_PORT: 8080
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
SESSION_STORE: postgres
CHAT_CACHE_ENABLED: ${CHAT_CACHE_ENABLED:-true}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DB_MAX_CONNECTIONS: ${DB_MAX_CONNECTIONS:-8}
DB_TIMEOUT_MS: 2000
DRAIN_DELAY_MS: 2500
MAX_IN_FLIGHT: 128
MAX_BODY_BYTES: 1048576
KDF_CONCURRENCY: 4
secrets: [database_url, cache_url]
networks: [front, storage]
depends_on:
migrate: {condition: service_completed_successfully}
redis: {condition: service_healthy}
deploy:
replicas: ${API_REPLICAS:-2}
healthcheck:
test: [CMD, wget, -q, -O, /dev/null, 'http://127.0.0.1:8080/health/ready']
interval: 1s
timeout: 3s
retries: 30
cpus: ${API_CPUS:-0.5}
mem_limit: ${API_MEMORY:-256m}
stop_grace_period: 15s
read_only: true
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
restart: unless-stopped
lb:
image: haproxy:3.0.11-alpine
ports: ['127.0.0.1:${HOST_PORT:-8083}:8080']
volumes: [./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro]
networks: [front]
depends_on:
api: {condition: service_healthy}
cpus: ${LB_CPUS:-0.5}
mem_limit: 128m
read_only: true
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
restart: unless-stopped
volumes:
postgres_data:
redis_data:
networks:
front:
storage:
internal: true
secrets:
postgres_password:
file: ./secrets/postgres_password
database_url:
file: ./secrets/database_url
cache_url:
file: ./secrets/cache_url