forked from mtusi2026/mtusi2026lab5
Complete Lab 5: implementation, fault scenarios, and Track 1 report
This commit is contained in:
+131
@@ -0,0 +1,131 @@
|
||||
name: mtusi_lab5_solution
|
||||
x-api: &api
|
||||
build: .
|
||||
image: mtusi-lab5-api:local
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
CACHE_URL_FILE: /run/secrets/cache_url
|
||||
BROKER_URL_FILE: /run/secrets/broker_url
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
S3_ENDPOINT: http://rustfs:9000
|
||||
S3_REGION: us-east-1
|
||||
S3_BUCKET: messenger-attachments
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
MAX_UPLOAD_BYTES: 10485760
|
||||
MAX_IMAGE_PIXELS: 40000000
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
||||
FAULT_AFTER_S3_WRITE_ONCE: ${FAULT_AFTER_S3_WRITE_ONCE:-0}
|
||||
WORKER_PAUSE_CONSUME: ${WORKER_PAUSE_CONSUME:-0}
|
||||
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
|
||||
MAX_QUEUED_JOBS: ${MAX_QUEUED_JOBS:-500}
|
||||
secrets: [database_url, cache_url, broker_url, s3_access_key_id, s3_secret_access_key]
|
||||
restart: unless-stopped
|
||||
mem_limit: 512m
|
||||
cpus: 0.75
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16.10-alpine
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
|
||||
secrets: [db_password]
|
||||
volumes: [pgdata:/var/lib/postgresql/data]
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, pg_isready -U messenger -d messenger]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
redis:
|
||||
image: redis:7.4.6-alpine
|
||||
command: [redis-server, --maxmemory, 64mb, --maxmemory-policy, allkeys-lru]
|
||||
healthcheck:
|
||||
test: [CMD, redis-cli, ping]
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 20
|
||||
broker:
|
||||
image: redis:7.4.6-alpine
|
||||
command: [redis-server, --appendonly, 'yes', --appendfsync, everysec, --maxmemory, 128mb, --maxmemory-policy, noeviction]
|
||||
volumes: [brokerdata:/data]
|
||||
healthcheck:
|
||||
test: [CMD, redis-cli, ping]
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 20
|
||||
rustfs:
|
||||
image: rustfs/rustfs:1.0.3-glibc
|
||||
command: [/data]
|
||||
environment:
|
||||
RUSTFS_ACCESS_KEY_FILE: /run/secrets/rustfs_root_user
|
||||
RUSTFS_SECRET_KEY_FILE: /run/secrets/rustfs_root_password
|
||||
RUSTFS_CONSOLE_ENABLE: 'false'
|
||||
RUSTFS_ADDRESS: ':9000'
|
||||
secrets: [rustfs_root_user, rustfs_root_password]
|
||||
volumes: [s3data:/data]
|
||||
expose: ['9000']
|
||||
healthcheck:
|
||||
test: [CMD, curl, -f, http://127.0.0.1:9000/health]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
bucket-bootstrap:
|
||||
image: rustfs/rc:v0.1.37
|
||||
depends_on:
|
||||
rustfs: {condition: service_healthy}
|
||||
entrypoint: [/bin/sh, /bootstrap-rustfs.sh]
|
||||
volumes: ['./infra/rustfs-policy.json:/policy.json:ro', './infra/bootstrap-rustfs.sh:/bootstrap-rustfs.sh:ro']
|
||||
secrets: [rustfs_root_user, rustfs_root_password, s3_access_key_id, s3_secret_access_key]
|
||||
restart: 'no'
|
||||
migrate:
|
||||
<<: *api
|
||||
command: [python, -m, app.migrate]
|
||||
restart: 'no'
|
||||
depends_on:
|
||||
postgres: {condition: service_healthy}
|
||||
api:
|
||||
<<: *api
|
||||
command: [gunicorn, --bind, 0.0.0.0:8080, --workers, '1', --threads, '2', --timeout, '35', --graceful-timeout, '5', app.main:app]
|
||||
scale: ${API_REPLICAS:-2}
|
||||
depends_on:
|
||||
migrate: {condition: service_completed_successfully}
|
||||
redis: {condition: service_healthy}
|
||||
broker: {condition: service_healthy}
|
||||
bucket-bootstrap: {condition: service_completed_successfully}
|
||||
healthcheck:
|
||||
test: [CMD, python, -c, "import urllib.request; urllib.request.urlopen('http://localhost:8080/health/ready', timeout=3)"]
|
||||
interval: 2s
|
||||
timeout: 4s
|
||||
retries: 3
|
||||
worker:
|
||||
<<: *api
|
||||
command: [python, -m, app.worker]
|
||||
depends_on:
|
||||
migrate: {condition: service_completed_successfully}
|
||||
broker: {condition: service_healthy}
|
||||
bucket-bootstrap: {condition: service_completed_successfully}
|
||||
healthcheck:
|
||||
disable: true
|
||||
deploy:
|
||||
replicas: 1
|
||||
lb:
|
||||
image: haproxy:3.0.11-alpine
|
||||
ports: ['127.0.0.1:${APP_PORT:-8081}:8080']
|
||||
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
|
||||
depends_on:
|
||||
api: {condition: service_healthy}
|
||||
volumes:
|
||||
pgdata:
|
||||
s3data:
|
||||
brokerdata:
|
||||
secrets:
|
||||
db_password: {file: ./secrets/db_password}
|
||||
database_url: {file: ./secrets/database_url}
|
||||
cache_url: {file: ./secrets/cache_url}
|
||||
broker_url: {file: ./secrets/broker_url}
|
||||
rustfs_root_user: {file: ./secrets/rustfs_root_user}
|
||||
rustfs_root_password: {file: ./secrets/rustfs_root_password}
|
||||
s3_access_key_id: {file: ./secrets/s3_access_key_id}
|
||||
s3_secret_access_key: {file: ./secrets/s3_secret_access_key}
|
||||
Reference in New Issue
Block a user