forked from mtusi2026/mtusi2026lab3
139 lines
3.0 KiB
YAML
139 lines
3.0 KiB
YAML
services:
|
|
postgres:
|
|
image: postgres:16.6-alpine
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/database_password
|
|
secrets:
|
|
- database_password
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
|
interval: 3s
|
|
timeout: 2s
|
|
retries: 20
|
|
cpus: 0.50
|
|
mem_limit: 384m
|
|
restart: unless-stopped
|
|
networks:
|
|
- backend
|
|
|
|
redis:
|
|
image: redis:7.4.2-alpine
|
|
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "everysec"]
|
|
volumes:
|
|
- redis_data:/data
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 3s
|
|
timeout: 2s
|
|
retries: 20
|
|
cpus: 0.25
|
|
mem_limit: 128m
|
|
restart: unless-stopped
|
|
networks:
|
|
- backend
|
|
|
|
migrate:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
command: ["python", "-m", "app.migrate"]
|
|
environment:
|
|
DB_HOST: postgres
|
|
DB_PORT: 5432
|
|
DB_NAME: messenger
|
|
DB_USER: messenger
|
|
DB_PASSWORD_FILE: /run/secrets/database_password
|
|
secrets:
|
|
- database_password
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
cpus: 0.50
|
|
mem_limit: 256m
|
|
networks:
|
|
- backend
|
|
profiles:
|
|
- tools
|
|
|
|
api:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
environment:
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
DB_HOST: postgres
|
|
DB_PORT: 5432
|
|
DB_NAME: messenger
|
|
DB_USER: messenger
|
|
DB_PASSWORD_FILE: /run/secrets/database_password
|
|
DB_POOL_MAX_SIZE: ${DB_POOL_MAX_SIZE:-8}
|
|
REDIS_URL: redis://redis:6379/0
|
|
secrets:
|
|
- database_password
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test:
|
|
- CMD
|
|
- python
|
|
- -c
|
|
- "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 3
|
|
start_period: 8s
|
|
stop_grace_period: 12s
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
endpoint_mode: dnsrr
|
|
resources:
|
|
limits:
|
|
cpus: "${API_CPUS:-0.50}"
|
|
memory: ${API_MEMORY:-256M}
|
|
restart: unless-stopped
|
|
networks:
|
|
- backend
|
|
|
|
load_balancer:
|
|
image: haproxy:3.1-alpine
|
|
ports:
|
|
- "${LB_PORT:-8080}:8080"
|
|
volumes:
|
|
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD", "haproxy", "-c", "-f", "/usr/local/etc/haproxy/haproxy.cfg"]
|
|
interval: 5s
|
|
timeout: 2s
|
|
retries: 3
|
|
cpus: 0.25
|
|
mem_limit: 128m
|
|
restart: unless-stopped
|
|
networks:
|
|
- frontend
|
|
- backend
|
|
|
|
secrets:
|
|
database_password:
|
|
file: ./secrets/database_password
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
|
|
networks:
|
|
frontend:
|
|
backend:
|
|
internal: true
|