ЛР3: балансировка, отказоустойчивость и идемпотентность

This commit is contained in:
2026-10-23 18:54:18 +03:00
parent 3f7c306f4f
commit 57b4e8b5ec
20 changed files with 659 additions and 39 deletions
+34 -5
View File
@@ -1,6 +1,8 @@
services:
postgres:
image: postgres:17.4-alpine
cpus: "1.0"
mem_limit: 512m
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
@@ -15,6 +17,8 @@ services:
redis:
image: redis:7.4.2-alpine
cpus: "0.25"
mem_limit: 128m
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always"]
volumes:
- redis_data:/data
@@ -26,6 +30,8 @@ services:
migrate:
build: .
cpus: "0.5"
mem_limit: 256m
command: ["alembic", "upgrade", "head"]
environment:
DATABASE_URL: ${DATABASE_URL}
@@ -38,13 +44,17 @@ services:
api:
build: .
cpus: "0.5"
mem_limit: 256m
environment:
DATABASE_URL: ${DATABASE_URL}
REDIS_URL: ${REDIS_URL}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS}
LOG_LEVEL: ${LOG_LEVEL:-info}
ports:
- "${APP_PORT:-8080}:8080"
expose:
- "8080"
deploy:
replicas: 2
depends_on:
migrate:
condition: service_completed_successfully
@@ -52,9 +62,28 @@ services:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=3).read()"]
interval: 10s
timeout: 3s
retries: 10
interval: 2s
timeout: 2s
retries: 5
stop_grace_period: 10s
lb:
image: haproxy:3.2.26-alpine
cpus: "0.25"
mem_limit: 128m
ports:
- "${APP_PORT:-8080}:8080"
volumes:
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on:
api:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/live"]
interval: 2s
timeout: 2s
retries: 5
stop_grace_period: 5s
volumes:
postgres_data: