Files
mtusi2026lab3/compose.yaml
T
sxdees 41af01ecad ЛР3 на 4: HAProxy, реплики API, Idempotency-Key и failover.
Общие Redis-сессии и Postgres, X-Instance-Id, REPORT и DEFENSE.
2026-12-01 21:54:37 +03:00

125 lines
3.1 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Локальный стенд lab3: Клиент → HAProxy → API×N → общие PostgreSQL и Redis.
# Публикуется только LB (:8080). Порты API наружу не публикуются.
# Запуск: bash scripts/up.sh (миграции однократно через compose run, затем --scale api=N)
name: gavrilenko-lab3
x-api-env: &api-env
APP_HOST: 0.0.0.0
APP_PORT: 8080
APP_ENV: ${APP_ENV:-lab}
APP_ACCESS_LOG: ${APP_ACCESS_LOG:-1}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
DB_MAX_CONNS: ${DB_MAX_CONNS:-5}
DATABASE_URL: postgres://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:-messenger}@postgres:5432/${POSTGRES_DB:-messenger}?sslmode=disable
REDIS_URL: redis://redis:6379/0
services:
postgres:
image: postgres:16.6
environment:
POSTGRES_USER: ${POSTGRES_USER:-messenger}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger}
POSTGRES_DB: ${POSTGRES_DB:-messenger}
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "127.0.0.1:5433:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-messenger} -d ${POSTGRES_DB:-messenger}"]
interval: 5s
timeout: 3s
retries: 20
stop_grace_period: 10s
deploy:
resources:
limits:
cpus: "1.0"
memory: 512M
redis:
image: redis:7.4.1
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "everysec"]
volumes:
- redisdata:/data
ports:
- "127.0.0.1:6380:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 20
stop_grace_period: 10s
deploy:
resources:
limits:
cpus: "0.50"
memory: 256M
migrate:
build: .
command: ["-migrate"]
environment:
<<: *api-env
depends_on:
postgres:
condition: service_healthy
restart: "no"
healthcheck:
disable: true
deploy:
resources:
limits:
cpus: "0.50"
memory: 256M
api:
build: .
environment:
<<: *api-env
expose:
- "8080"
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
healthcheck:
test: ["CMD", "/server", "-healthcheck"]
interval: 2s
timeout: 2s
retries: 10
start_period: 15s
stop_grace_period: 10s
restart: "no"
deploy:
resources:
limits:
cpus: ${API_CPUS:-0.50}
memory: ${API_MEMORY:-256M}
lb:
image: haproxy:2.9.14-alpine
volumes:
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
ports:
- "127.0.0.1:8080:8080"
depends_on:
api:
condition: service_healthy
healthcheck:
test: ["CMD", "haproxy", "-c", "-f", "/usr/local/etc/haproxy/haproxy.cfg"]
interval: 10s
timeout: 3s
retries: 5
start_period: 5s
stop_grace_period: 10s
deploy:
resources:
limits:
cpus: "0.50"
memory: 128M
volumes:
pgdata:
redisdata: