Files
mtusi2026lab4/compose.yaml
T

137 lines
4.3 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.
# Локальный стенд lab4: LB (nginx) → API × 2 → PostgreSQL + Redis + MinIO.
# Секреты читаются из ./secrets/*.txt (не коммитятся).
services:
postgres:
image: postgres:16.4-alpine
environment:
POSTGRES_USER: messenger
POSTGRES_PASSWORD: messenger
POSTGRES_DB: messenger
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 3s
timeout: 3s
retries: 20
redis:
image: redis:7.4-alpine
command: ["redis-server", "--save", "", "--appendonly", "no"]
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 3s
timeout: 3s
retries: 20
s3:
image: chrislusf/seaweedfs:3.71
# Один контейнер: master + volume + filer + S3-шлюз на :8333.
# -ip.bind=0.0.0.0 — чтобы S3-шлюз слушал все интерфейсы внутри сети compose.
command: ["server", "-dir=/data", "-s3", "-s3.port=8333", "-ip.bind=0.0.0.0"]
environment:
# Учётные данные S3-шлюза SeaweedFS (см. документацию weed s3).
AWS_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-seaweedfs}
AWS_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-seaweedfs-local-only}
volumes:
- s3data:/data
healthcheck:
test: ["CMD-SHELL", "wget -q -O- http://127.0.0.1:8333/ >/dev/null 2>&1 || exit 1"]
interval: 3s
timeout: 3s
retries: 30
s3-init:
image: python:3.12-slim
depends_on:
s3:
condition: service_healthy
environment:
S3_ENDPOINT: http://s3:8333
S3_REGION: us-east-1
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-seaweedfs}
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-seaweedfs-local-only}
volumes:
- ./scripts/bootstrap_s3.py:/bootstrap_s3.py:ro
command: ["sh", "-c", "pip install --quiet boto3==1.35.76 && python /bootstrap_s3.py"]
restart: "no"
migrate:
build: .
environment:
DATABASE_URL: postgresql+psycopg://messenger:messenger@postgres:5432/messenger
depends_on:
postgres:
condition: service_healthy
command: ["alembic", "upgrade", "head"]
restart: "no"
api-1:
build: .
environment:
DATABASE_URL: postgresql+psycopg://messenger:messenger@postgres:5432/messenger
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
INSTANCE_ID: api-1
S3_ENDPOINT: http://s3:8333
S3_REGION: us-east-1
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-seaweedfs}
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-seaweedfs-local-only}
MAX_UPLOAD_BYTES: "10485760"
MAX_IMAGE_PIXELS: "40000000"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
s3:
condition: service_healthy
s3-init:
condition: service_completed_successfully
migrate:
condition: service_completed_successfully
command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]
api-2:
build: .
environment:
DATABASE_URL: postgresql+psycopg://messenger:messenger@postgres:5432/messenger
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
INSTANCE_ID: api-2
S3_ENDPOINT: http://s3:8333
S3_REGION: us-east-1
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-seaweedfs}
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-seaweedfs-local-only}
MAX_UPLOAD_BYTES: "10485760"
MAX_IMAGE_PIXELS: "40000000"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
s3:
condition: service_healthy
s3-init:
condition: service_completed_successfully
migrate:
condition: service_completed_successfully
command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]
lb:
image: nginx:1.27-alpine
ports:
- "8080:8080"
volumes:
- ./infra/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- api-1
- api-2
volumes:
pgdata:
s3data: