forked from mtusi2026/mtusi2026lab3
113 lines
2.9 KiB
YAML
113 lines
2.9 KiB
YAML
name: mtusi-lab3
|
|
services:
|
|
postgres:
|
|
image: postgres:17.6-alpine
|
|
environment:
|
|
POSTGRES_DB: ${POSTGRES_DB:-messenger}
|
|
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
networks: [backend]
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
cpus: 1.0
|
|
mem_limit: 768m
|
|
restart: unless-stopped
|
|
|
|
redis:
|
|
image: redis:7.4.2-alpine
|
|
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "everysec"]
|
|
volumes:
|
|
- redis_data:/data
|
|
networks: [backend]
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
cpus: 0.25
|
|
mem_limit: 256m
|
|
restart: unless-stopped
|
|
|
|
migrate:
|
|
build: .
|
|
image: mtusi-lab3-api:1.0.0
|
|
command: ["python", "scripts/migrate.py"]
|
|
environment:
|
|
PGHOST: postgres
|
|
PGPORT: "5432"
|
|
PGDATABASE: ${POSTGRES_DB:-messenger}
|
|
PGUSER: ${POSTGRES_USER:-messenger}
|
|
PGPASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
|
|
networks: [backend]
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
cpus: 0.5
|
|
mem_limit: 384m
|
|
|
|
api:
|
|
build: .
|
|
image: mtusi-lab3-api:1.0.0
|
|
environment:
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: "8080"
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
DB_POOL_MIN_SIZE: ${DB_POOL_MIN_SIZE:-1}
|
|
DB_POOL_MAX_SIZE: ${DB_POOL_MAX_SIZE:-10}
|
|
DB_POOL_TIMEOUT_SECONDS: ${DB_POOL_TIMEOUT_SECONDS:-5}
|
|
PGHOST: postgres
|
|
PGPORT: "5432"
|
|
PGDATABASE: ${POSTGRES_DB:-messenger}
|
|
PGUSER: ${POSTGRES_USER:-messenger}
|
|
PGPASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
|
|
REDIS_URL: redis://redis:6379/0
|
|
expose: ["8080"]
|
|
networks: [backend]
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
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: 3s
|
|
timeout: 3s
|
|
retries: 3
|
|
start_period: 5s
|
|
stop_grace_period: 15s
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
restart: unless-stopped
|
|
|
|
load_balancer:
|
|
image: haproxy:3.2.5-alpine
|
|
ports:
|
|
- "127.0.0.1:${APP_PORT:-8080}:8080"
|
|
volumes:
|
|
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
networks: [backend]
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD", "haproxy", "-c", "-f", "/usr/local/etc/haproxy/haproxy.cfg"]
|
|
interval: 10s
|
|
timeout: 3s
|
|
retries: 3
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
restart: unless-stopped
|
|
|
|
networks:
|
|
backend:
|
|
driver: bridge
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|