Files
mtusi2026lab4/compose.yaml
T
Artu-RitoandClaude Sonnet 5 38268f63f8 Лаба 4: SeaweedFS S3-хранилище и вложения (оценка 4)
Переиспользован стек lab3 (LB/2 реплики/Postgres/Redis/идемпотентность).
Добавлены: S3-хранилище байтов вложений (SeaweedFS вместо MinIO — публичные
MinIO-образы недоступны без авторизации), метаданные attachments в Postgres,
проверка изображений по содержимому с защитой от decompression bomb,
ограниченные S3-credentials, скрипт сверки orphan-объектов. make test/
test-persistence/test-failover/validate зелёные для обеих реплик; собраны
доказательства по превышению размера, MIME-спуфингу, чужим attachment_id,
приватности bucket, конкурентным загрузкам и orphan-очистке — см. REPORT.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-30 00:59:13 +03:00

150 lines
3.7 KiB
YAML

name: mtusi2026lab4
services:
lb:
image: nginx:1.27.2
ports:
- "8080:8080"
volumes:
- ./infra/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
api1:
condition: service_healthy
api2:
condition: service_healthy
deploy:
resources:
limits:
cpus: "0.5"
memory: 128M
api1: &api
build: .
image: mtusi2026lab4-api:local
environment: &api-env
APP_HOST: 0.0.0.0
APP_PORT: 8080
APP_ENV: lab
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
S3_ENDPOINT: http://seaweedfs:8333
S3_REGION: us-east-1
S3_BUCKET: messenger-attachments
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
INSTANCE_ID: api1
secrets: &api-secrets
- database_url
- cache_url
- s3_access_key_id
- s3_secret_access_key
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
seaweedfs:
condition: service_healthy
healthcheck: &api-healthcheck
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"]
interval: 5s
timeout: 3s
retries: 5
start_period: 10s
deploy:
resources:
limits:
cpus: "1.0"
memory: 256M
api2:
<<: *api
environment:
<<: *api-env
INSTANCE_ID: api2
postgres:
image: postgres:16.4
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
secrets:
- postgres_password
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 5s
timeout: 3s
retries: 10
deploy:
resources:
limits:
cpus: "1.0"
memory: 512M
redis:
image: redis:7.4.1
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "everysec"]
volumes:
- redisdata:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
deploy:
resources:
limits:
cpus: "0.5"
memory: 256M
seaweedfs:
image: chrislusf/seaweedfs:3.73
# All-in-one (master+volume+filer+S3 gateway) is enough for a single-bucket
# lab stand; s3.json scopes the API's own identity to this one bucket only
# (no admin console is exposed to the network).
command:
- server
- -dir=/data
- -s3
- -s3.port=8333
- -s3.config=/etc/seaweedfs/s3.json
volumes:
- seaweed_data:/data
- ./secrets/s3.json:/etc/seaweedfs/s3.json:ro
healthcheck:
# S3 requires auth (403 on anonymous GET) -- a TCP connect is enough to
# prove the S3 gateway is accepting connections.
test: ["CMD", "nc", "-z", "127.0.0.1", "8333"]
interval: 5s
timeout: 3s
retries: 10
start_period: 10s
deploy:
resources:
limits:
cpus: "1.0"
memory: 512M
volumes:
pgdata:
redisdata:
seaweed_data:
secrets:
database_url:
file: ./secrets/database_url.txt
cache_url:
file: ./secrets/cache_url.txt
postgres_password:
file: ./secrets/postgres_password.txt
s3_access_key_id:
file: ./secrets/s3_access_key_id.txt
s3_secret_access_key:
file: ./secrets/s3_secret_access_key.txt