Files
mtusi2026lab4/compose.yaml
T
nothingredmouth e594df18f9 Поднять стенд из двух реплик за HAProxy с приватным MinIO S3
Dockerfile (python:3.11, waitress), compose: api1/api2 + postgres +
migrate + s3 (pinned minio, без опубликованных портов) + s3-bootstrap +
lb (haproxy, round-robin, healthcheck на /health/ready). Секреты DATABASE_URL
и S3 — через Docker secrets, локальная инициализация — scripts/init_local.py.
2026-11-17 03:37:34 +00:00

110 lines
2.7 KiB
YAML

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
S3_ENDPOINT: http://s3:9000
S3_BUCKET: messenger-attachments
S3_ACCESS_KEY: messengeradmin
S3_SECRET_FILE: /run/secrets/s3_password
secrets:
- database_url
- s3_password
depends_on:
db:
condition: service_healthy
migrate:
condition: service_completed_successfully
s3-bootstrap:
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
s3:
image: minio/minio:RELEASE.2025-02-07T23-21-09Z
command: server /data --address ':9000'
environment:
MINIO_ROOT_USER: messengeradmin
MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_password
secrets:
- s3_password
volumes:
- s3_data:/data
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:9000/minio/health/live >/dev/null"]
interval: 3s
timeout: 5s
retries: 25
s3-bootstrap:
build: .
command: ["python", "-m", "messenger.bootstrap_s3"]
environment: *app-environment
secrets:
- database_url
- s3_password
depends_on:
s3:
condition: service_started
restart: "no"
migrate:
build: .
command: ["python", "-m", "messenger.migrate"]
environment: *app-environment
secrets:
- database_url
- s3_password
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:
s3_data:
secrets:
postgres_password:
file: ./secrets/postgres_password
database_url:
file: ./secrets/database_url
s3_password:
file: ./secrets/s3_password