feat: add haproxy load balancer, api replicas and graceful shutdown

This commit is contained in:
2026-11-01 14:50:16 +03:00
parent cdcff89d25
commit e9bc51288b
8 changed files with 103 additions and 8 deletions
+16 -3
View File
@@ -78,12 +78,14 @@ services:
APP_ENV: ${APP_ENV:-lab}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
SHUTDOWN_DELAY_MS: 3000
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
ports:
- "127.0.0.1:${APP_PORT:-8080}:8080"
volumes:
- secrets:/run/secrets:ro
deploy:
replicas: ${API_REPLICAS:-2}
stop_grace_period: 10s
depends_on:
migrate:
condition: service_completed_successfully
@@ -91,6 +93,17 @@ services:
condition: service_started
restart: unless-stopped
lb:
image: haproxy:3.0.6-alpine
ports:
- "127.0.0.1:${APP_PORT:-8080}:8080"
volumes:
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on:
api:
condition: service_healthy
restart: unless-stopped
tools:
profiles: [tools]
build:
@@ -100,7 +113,7 @@ services:
WORKDIR /work
image: mtusi-messenger-lab3-tools:dev
environment:
BASE_URL: http://api:8080
BASE_URL: http://lb:8080
volumes:
- .:/work
- /var/run/docker.sock:/var/run/docker.sock