Поднять балансировочный стенд из двух реплик за HAProxy
Dockerfile, compose (api1, api2, postgres, migrate, lb), haproxy.cfg с round-robin и healthcheck на /health/ready, secrets с DATABASE_URL и инициализация локальной БД (scripts/init_local.py).
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
x-api: &api
|
||||
build: .
|
||||
environment: &app-environment
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: 8080
|
||||
APP_ENV: ${APP_ENV:-lab}
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
||||
SESSION_STORE: postgres
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
secrets:
|
||||
- database_url
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
stop_grace_period: 8s
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=3)"]
|
||||
interval: 2s
|
||||
timeout: 4s
|
||||
retries: 20
|
||||
|
||||
services:
|
||||
db:
|
||||
image: postgres:16.6-bookworm
|
||||
environment:
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
secrets:
|
||||
- postgres_password
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
migrate:
|
||||
build: .
|
||||
command: ["python", "-m", "messenger.migrate"]
|
||||
environment: *app-environment
|
||||
secrets:
|
||||
- database_url
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
api1:
|
||||
<<: *api
|
||||
api2:
|
||||
<<: *api
|
||||
lb:
|
||||
image: haproxy:3.0.8-bookworm
|
||||
ports:
|
||||
- "127.0.0.1:8080:8080"
|
||||
volumes:
|
||||
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
depends_on:
|
||||
api1:
|
||||
condition: service_healthy
|
||||
api2:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
postgres_data:
|
||||
secrets:
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password
|
||||
database_url:
|
||||
file: ./secrets/database_url
|
||||
Reference in New Issue
Block a user