Files
mtusi2026lab4/compose.yaml
T
qrtx dc46ac213d feat(storage): add RustFS attachments and presigned uploads
Add two API replicas, safe object reconciliation, upload validation, regression tests and documented load experiments.
2026-11-12 10:16:39 +03:00

190 lines
6.0 KiB
YAML

services:
api:
build:
context: .
target: runtime
restart: unless-stopped
init: true
deploy:
replicas: 2
command: ['sh', '-c', 'INSTANCE_ID=$$(hostname) exec node dist/main.js']
environment:
NODE_ENV: production
UPLOAD_MEMORY_PROFILE: ${UPLOAD_MEMORY_PROFILE:-0}
APP_ENV: ${APP_ENV:-lab}
APP_HOST: 0.0.0.0
APP_PORT: 8080
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-local_dev_password}@postgres:5432/${POSTGRES_DB:-chat}
DB_POOL_MAX: ${DB_POOL_MAX:-15}
CACHE_URL: redis://redis:6379/0
CACHE_PREFIX: ${CACHE_PREFIX:-messenger:cache:v1}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
S3_ENDPOINT: http://s3:9000
S3_REGION: us-east-1
S3_BUCKET: messenger-attachments
S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT:-http://127.0.0.1:${S3_PUBLIC_PORT:-9000}}
DIRECT_UPLOAD_TTL_SECONDS: ${DIRECT_UPLOAD_TTL_SECONDS:-60}
S3_ACCESS_KEY_ID: ${S3_API_ACCESS_KEY_ID:-LABAPI}
S3_SECRET_ACCESS_KEY: ${S3_API_SECRET_ACCESS_KEY:-local_api_storage_password}
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
UPLOAD_BODY_TIMEOUT_MS: ${UPLOAD_BODY_TIMEOUT_MS:-15000}
depends_on:
migrate:
condition: service_completed_successfully
postgres:
condition: service_healthy
redis:
condition: service_healthy
s3-init:
condition: service_completed_successfully
healthcheck:
test:
- CMD
- curl
- --fail
- --silent
- --show-error
- --max-time
- '2'
- --output
- /dev/null
- http://127.0.0.1:8080/health/ready
interval: 10s
timeout: 3s
start_period: 20s
retries: 5
stop_grace_period: 30s
reconciler:
build:
context: .
target: runtime
command: ['node', 'dist/Attachment/reconcile.cli.js', '--watch', '--apply']
restart: unless-stopped
init: true
environment:
NODE_ENV: production
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-local_dev_password}@postgres:5432/${POSTGRES_DB:-chat}
DB_POOL_MAX: 2
S3_ENDPOINT: http://s3:9000
S3_REGION: us-east-1
S3_BUCKET: messenger-attachments
S3_ACCESS_KEY_ID: ${S3_RECONCILER_ACCESS_KEY_ID:-LABRECONCILER}
S3_SECRET_ACCESS_KEY: ${S3_RECONCILER_SECRET_ACCESS_KEY:-local_reconciler_storage_password}
ORPHAN_GRACE_SECONDS: ${ORPHAN_GRACE_SECONDS:-600}
RECONCILE_INTERVAL_SECONDS: ${RECONCILE_INTERVAL_SECONDS:-60}
depends_on:
api:
condition: service_healthy
healthcheck:
test: ['CMD', 'node', 'dist/Attachment/reconcile-health.js']
interval: 10s
timeout: 5s
start_period: 30s
retries: 5
stop_grace_period: 30s
nginx:
image: nginx:1.30.6-alpine
restart: unless-stopped
ports:
- '127.0.0.1:${APP_PORT:-8080}:80'
- '127.0.0.1:${S3_PUBLIC_PORT:-9000}:9000'
volumes:
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
- ./infra/start-nginx.sh:/etc/nginx/start-nginx.sh:ro
entrypoint: ['/bin/sh', '/etc/nginx/start-nginx.sh']
depends_on:
api:
condition: service_healthy
healthcheck:
test: ['CMD', 'wget', '-q', '-T', '2', '-t', '1', '-O', '/dev/null', 'http://127.0.0.1/health/ready']
interval: 5s
timeout: 3s
start_period: 10s
retries: 5
migrate:
build:
context: .
target: migrate
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-local_dev_password}@postgres:5432/${POSTGRES_DB:-chat}
depends_on:
postgres:
condition: service_healthy
postgres:
image: postgres:17.6-bookworm
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-chat}
POSTGRES_USER: ${POSTGRES_USER:-app}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-local_dev_password}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB"']
interval: 5s
timeout: 3s
start_period: 10s
retries: 10
stop_grace_period: 30s
redis:
image: redis:7.4.5-alpine
restart: unless-stopped
command:
['redis-server', '--appendonly', 'yes', '--appendfsync', 'everysec']
volumes:
- redis_data:/data
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 5s
timeout: 3s
retries: 10
stop_grace_period: 30s
s3:
image: rustfs/rustfs:1.0.4
restart: unless-stopped
environment:
RUSTFS_ACCESS_KEY: ${S3_ROOT_ACCESS_KEY_ID:-${S3_ACCESS_KEY_ID:-LABSTORAGE}}
RUSTFS_SECRET_KEY: ${S3_ROOT_SECRET_ACCESS_KEY:-${S3_SECRET_ACCESS_KEY:-local_app_storage_password}}
RUSTFS_VOLUMES: /data
RUSTFS_ADDRESS: 0.0.0.0:9000
RUSTFS_CONSOLE_ENABLE: 'false'
volumes:
- s3_data:/data
healthcheck:
test: ['CMD', 'curl', '--fail', '--silent', 'http://127.0.0.1:9000/health']
interval: 5s
timeout: 3s
retries: 10
start_period: 30s
s3-init:
build:
context: .
target: storage-init
environment:
S3_ENDPOINT: http://s3:9000
S3_REGION: us-east-1
S3_BUCKET: messenger-attachments
S3_ACCESS_KEY_ID: ${S3_ROOT_ACCESS_KEY_ID:-${S3_ACCESS_KEY_ID:-LABSTORAGE}}
S3_SECRET_ACCESS_KEY: ${S3_ROOT_SECRET_ACCESS_KEY:-${S3_SECRET_ACCESS_KEY:-local_app_storage_password}}
S3_API_ACCESS_KEY_ID: ${S3_API_ACCESS_KEY_ID:-LABAPI}
S3_API_SECRET_ACCESS_KEY: ${S3_API_SECRET_ACCESS_KEY:-local_api_storage_password}
S3_RECONCILER_ACCESS_KEY_ID: ${S3_RECONCILER_ACCESS_KEY_ID:-LABRECONCILER}
S3_RECONCILER_SECRET_ACCESS_KEY: ${S3_RECONCILER_SECRET_ACCESS_KEY:-local_reconciler_storage_password}
depends_on:
s3:
condition: service_healthy
volumes:
postgres_data:
redis_data:
s3_data: