forked from mtusi2026/mtusi2026lab4
Перенести рабочий стенд lab3 в репозиторий lab4.
API, Postgres, Redis и HAProxy остаются базой для вложений: сессии и история уже общие для нескольких реплик.
This commit is contained in:
+131
@@ -0,0 +1,131 @@
|
||||
# Port of the lab3 stand. Client -> lb:8080 -> api (scale) -> shared Postgres and Redis.
|
||||
# API replicas do not publish host ports. Migrations run once in `migrate`.
|
||||
# Check period: HAProxy inter 1s, fall 2, rise 1. Worst detection of a dead
|
||||
# or not-ready replica is about 2s, plus the 1s DNS hold. API on SIGTERM
|
||||
# fails /health/ready immediately and exits after LB_DRAIN_SECONDS (default 2).
|
||||
|
||||
services:
|
||||
migrate:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: mtusi-messenger:lab4
|
||||
command: ["python", "-m", "app.migrate"]
|
||||
environment:
|
||||
APP_ENV: lab
|
||||
LOG_LEVEL: info
|
||||
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD}@postgres:5432/messenger
|
||||
DB_POOL_MIN: "1"
|
||||
DB_POOL_MAX: "2"
|
||||
MIGRATIONS_ON_START: "1"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
mem_limit: 256m
|
||||
cpus: "0.50"
|
||||
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: mtusi-messenger:lab4
|
||||
environment:
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: "8080"
|
||||
APP_ENV: lab
|
||||
LOG_LEVEL: info
|
||||
SHUTDOWN_GRACE_SECONDS: "3"
|
||||
LB_DRAIN_SECONDS: ${LB_DRAIN_SECONDS:-2}
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
CACHE_TTL_SECONDS: ${CACHE_TTL_SECONDS:-60}
|
||||
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
||||
SESSION_STORE: redis
|
||||
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD}@postgres:5432/messenger
|
||||
REDIS_URL: redis://redis:6379/0
|
||||
DB_POOL_MIN: "1"
|
||||
DB_POOL_MAX: ${DB_POOL_MAX:-4}
|
||||
DB_COMMAND_TIMEOUT: "5"
|
||||
DB_CONNECT_TIMEOUT: "5"
|
||||
MIGRATIONS_ON_START: "0"
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
expose:
|
||||
- "8080"
|
||||
restart: unless-stopped
|
||||
mem_limit: ${API_MEM:-256m}
|
||||
cpus: ${API_CPUS:-0.50}
|
||||
stop_grace_period: 8s
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
"CMD",
|
||||
"python",
|
||||
"-c",
|
||||
"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)",
|
||||
]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 6
|
||||
start_period: 5s
|
||||
|
||||
lb:
|
||||
image: haproxy:2.8.14-alpine
|
||||
volumes:
|
||||
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
ports:
|
||||
- "127.0.0.1:8080:8080"
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_started
|
||||
restart: unless-stopped
|
||||
mem_limit: 128m
|
||||
cpus: "0.25"
|
||||
|
||||
postgres:
|
||||
image: postgres:16.6-alpine
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: messenger
|
||||
volumes:
|
||||
- pg_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
restart: unless-stopped
|
||||
mem_limit: ${POSTGRES_MEM:-512m}
|
||||
cpus: ${POSTGRES_CPUS:-1.0}
|
||||
|
||||
redis:
|
||||
image: redis:7.4.2-alpine
|
||||
command:
|
||||
- redis-server
|
||||
- --appendonly
|
||||
- "yes"
|
||||
- --appendfsync
|
||||
- everysec
|
||||
- --save
|
||||
- "60"
|
||||
- "1"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
restart: unless-stopped
|
||||
mem_limit: 128m
|
||||
cpus: "0.50"
|
||||
|
||||
volumes:
|
||||
pg_data:
|
||||
redis_data:
|
||||
Reference in New Issue
Block a user