Done Track 4
This commit is contained in:
+103
-9
@@ -1,8 +1,9 @@
|
||||
#file: noinspection ComposeUnknownValues
|
||||
# Lab3: client -> HAProxy -> API x N -> PostgreSQL (source of truth: data,
|
||||
# sessions, idempotency keys) + Valkey (shared session cache from lab2).
|
||||
# Lab4: client -> HAProxy -> API x N -> PostgreSQL (source of truth: data,
|
||||
# sessions, idempotency keys, attachment metadata) + Valkey (session cache)
|
||||
# + SeaweedFS S3 (private bucket with attachment bytes).
|
||||
# Start: see REPORT.md, "Запуск из чистого clone".
|
||||
name: messenger-lab3
|
||||
name: messenger-lab4
|
||||
|
||||
x-api-env: &api-env
|
||||
APP_HOST: 0.0.0.0
|
||||
@@ -23,6 +24,27 @@ x-api-env: &api-env
|
||||
IDEMPOTENCY_TTL_SECONDS: "${IDEMPOTENCY_TTL_SECONDS:-86400}"
|
||||
SHUTDOWN_DRAIN_SECONDS: "3"
|
||||
SHUTDOWN_TIMEOUT_SECONDS: "8"
|
||||
# Lab4: S3 with the API's own restricted credentials (not admin).
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
S3_REGION: us-east-1
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_OBJECT_PREFIX: originals/
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
S3_CONNECT_TIMEOUT_SECONDS: "2"
|
||||
S3_READ_TIMEOUT_SECONDS: "5"
|
||||
S3_OPERATION_TIMEOUT_SECONDS: "6"
|
||||
S3_PUT_MIN_BYTES_PER_SECOND: "1048576"
|
||||
MAX_UPLOAD_BYTES: "10485760"
|
||||
MAX_IMAGE_PIXELS: "40000000"
|
||||
UPLOAD_SPOOL_MEMORY_BYTES: "1048576"
|
||||
UPLOAD_TIMEOUT_SECONDS: "60"
|
||||
MAX_CONCURRENT_UPLOADS: "8"
|
||||
UPLOAD_SLOT_WAIT_SECONDS: "10"
|
||||
UPLOAD_GRACE_SECONDS: "${UPLOAD_GRACE_SECONDS:-900}"
|
||||
JANITOR_INTERVAL_SECONDS: "${JANITOR_INTERVAL_SECONDS:-60}"
|
||||
# Experiments only: crash_after_s3_put | db_error_after_s3_put (REPORT.md).
|
||||
FAULT_INJECTION: "${FAULT_INJECTION:-}"
|
||||
|
||||
services:
|
||||
db:
|
||||
@@ -76,11 +98,71 @@ services:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M }
|
||||
|
||||
# S3: SeaweedFS all-in-one. No "ports": reachable only from the internal
|
||||
# backend network; its admin web UIs are bound to 127.0.0.1 inside the
|
||||
# container (infra/seaweedfs/start.sh). Bytes persist in the s3_data volume.
|
||||
s3:
|
||||
image: chrislusf/seaweedfs:3.97
|
||||
entrypoint: ["/bin/sh", "/opt/lab/start.sh"]
|
||||
environment:
|
||||
# Soft limit of the Go heap: without it the GC lets SeaweedFS grow to
|
||||
# the container limit under parallel 10 MiB PUTs (measured, REPORT.md).
|
||||
GOMEMLIMIT: 600MiB
|
||||
volumes:
|
||||
- s3_data:/data
|
||||
- ./infra/seaweedfs:/opt/lab:ro
|
||||
secrets:
|
||||
- s3_admin_access_key_id
|
||||
- s3_admin_secret_access_key
|
||||
- s3_access_key_id
|
||||
- s3_secret_access_key
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:9000/healthz"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
start_period: 60s
|
||||
networks: [backend]
|
||||
stop_grace_period: 30s
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
# 512M was measured to be too little: 12 parallel 10 MiB PUTs pushed
|
||||
# SeaweedFS to the limit and the kernel killed it (REPORT.md).
|
||||
limits: { cpus: "1.0", memory: 1G }
|
||||
|
||||
# Idempotent bucket bootstrap + self-checks (private bucket, least
|
||||
# privilege of the API key). The only container with the S3 admin key.
|
||||
s3-init:
|
||||
build: .
|
||||
image: messenger-lab4-api:${APP_VERSION:-dev}
|
||||
command: ["python", "scripts/s3_bootstrap.py"]
|
||||
environment:
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_OBJECT_PREFIX: originals/
|
||||
S3_ADMIN_ACCESS_KEY_ID_FILE: /run/secrets/s3_admin_access_key_id
|
||||
S3_ADMIN_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_admin_secret_access_key
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
secrets:
|
||||
- s3_admin_access_key_id
|
||||
- s3_admin_secret_access_key
|
||||
- s3_access_key_id
|
||||
- s3_secret_access_key
|
||||
depends_on:
|
||||
s3: { condition: service_healthy }
|
||||
networks: [backend]
|
||||
restart: "no"
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.5", memory: 128M }
|
||||
|
||||
# Runs the migrations once, before any API replica starts (no race of
|
||||
# replicas). A repeated run only prints SKIP.
|
||||
migrate:
|
||||
build: .
|
||||
image: messenger-lab3-api:${APP_VERSION:-dev}
|
||||
image: messenger-lab4-api:${APP_VERSION:-dev}
|
||||
command: ["python", "scripts/migrate.py"]
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
@@ -95,9 +177,9 @@ services:
|
||||
|
||||
api:
|
||||
build: .
|
||||
image: messenger-lab3-api:${APP_VERSION:-dev}
|
||||
image: messenger-lab4-api:${APP_VERSION:-dev}
|
||||
environment: *api-env
|
||||
secrets: [database_url, cache_url]
|
||||
secrets: [database_url, cache_url, s3_access_key_id, s3_secret_access_key]
|
||||
# No "ports": replicas are reachable only through the LB.
|
||||
# No "container_name": the service is scaled by deploy.replicas / --scale.
|
||||
networks: [edge, backend]
|
||||
@@ -105,6 +187,7 @@ services:
|
||||
db: { condition: service_healthy }
|
||||
valkey: { condition: service_healthy }
|
||||
migrate: { condition: service_completed_successfully }
|
||||
s3-init: { condition: service_completed_successfully }
|
||||
healthcheck:
|
||||
test:
|
||||
- CMD
|
||||
@@ -157,20 +240,23 @@ services:
|
||||
working_dir: /work
|
||||
environment:
|
||||
BASE_URL: http://lb:8080
|
||||
COMPOSE_PROJECT: messenger-lab3
|
||||
COMPOSE_PROJECT: messenger-lab4
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
volumes:
|
||||
- ./:/work
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
networks: [edge]
|
||||
# backend: only for the "private bucket from outside the API" check.
|
||||
networks: [edge, backend]
|
||||
|
||||
networks:
|
||||
edge: {}
|
||||
# PostgreSQL and Valkey: no route outside, the LB is not attached.
|
||||
# PostgreSQL, Valkey and S3: no route outside, the LB is not attached.
|
||||
backend:
|
||||
internal: true
|
||||
|
||||
volumes:
|
||||
postgres_data: {}
|
||||
s3_data: {}
|
||||
|
||||
secrets:
|
||||
postgres_password:
|
||||
@@ -181,3 +267,11 @@ secrets:
|
||||
file: ./infra/secrets/valkey_password.txt
|
||||
cache_url:
|
||||
file: ./infra/secrets/cache_url.txt
|
||||
s3_admin_access_key_id:
|
||||
file: ./infra/secrets/s3_admin_access_key_id.txt
|
||||
s3_admin_secret_access_key:
|
||||
file: ./infra/secrets/s3_admin_secret_access_key.txt
|
||||
s3_access_key_id:
|
||||
file: ./infra/secrets/s3_access_key_id.txt
|
||||
s3_secret_access_key:
|
||||
file: ./infra/secrets/s3_secret_access_key.txt
|
||||
|
||||
Reference in New Issue
Block a user