144 lines
4.6 KiB
YAML
144 lines
4.6 KiB
YAML
name: mtusi-lab5
|
|
x-api: &api
|
|
build: .
|
|
image: ${API_IMAGE:-mtusi-lab5-api:local}
|
|
environment: &environment
|
|
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD:?Run scripts/bootstrap.sh}@db:5432/messenger
|
|
BROKER_URL: redis://broker:6379/0
|
|
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
|
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-20}
|
|
JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-30}
|
|
MAX_PENDING_JOBS: ${MAX_PENDING_JOBS:-100}
|
|
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
|
CACHE_URL: redis://valkey:6379/0
|
|
SESSION_STORE: valkey
|
|
SESSION_TTL_SECONDS: 3600
|
|
DB_POOL_MAX_SIZE: 5
|
|
CACHE_CLIENT_MODE: shared
|
|
S3_ENDPOINT: http://s3:9000
|
|
S3_REGION: us-east-1
|
|
S3_BUCKET: messenger-attachments
|
|
S3_ACCESS_KEY_ID: lab4api
|
|
S3_SECRET_ACCESS_KEY: ${S3_API_PASSWORD:?Run scripts/bootstrap.sh}
|
|
cpus: ${API_CPUS:-2}
|
|
mem_limit: 512m
|
|
stop_grace_period: 40s
|
|
services:
|
|
db:
|
|
image: postgres:16.6-alpine
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Run scripts/bootstrap.sh}
|
|
volumes: [postgres_data:/var/lib/postgresql/data]
|
|
cpus: 1
|
|
mem_limit: 512m
|
|
healthcheck:
|
|
test: [CMD-SHELL, pg_isready -U messenger -d messenger]
|
|
interval: 2s
|
|
timeout: 1s
|
|
retries: 30
|
|
valkey:
|
|
image: valkey/valkey:8.0.2-alpine
|
|
command: [valkey-server, --appendonly, 'yes']
|
|
volumes: [valkey_data:/data]
|
|
cpus: 0.25
|
|
mem_limit: 128m
|
|
s3:
|
|
# RELEASE.2025-09-07T16-13-09Z, verified locally, linux/arm64.
|
|
image: minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
|
|
command: [server, /data, --address, ':9000', --console-address, '127.0.0.1:9001']
|
|
environment:
|
|
MINIO_ROOT_USER: lab4root
|
|
MINIO_ROOT_PASSWORD: ${S3_ROOT_PASSWORD:?Run scripts/bootstrap.sh}
|
|
MINIO_BROWSER: 'off'
|
|
volumes: [s3_data:/data]
|
|
cpus: 0.5
|
|
mem_limit: 768m
|
|
s3-init:
|
|
# mc RELEASE.2025-08-13T08-35-41Z.
|
|
image: minio/mc@sha256:a7fe349ef4bd8521fb8497f55c6042871b2ae640607cf99d9bede5e9bdf11727
|
|
entrypoint: [/bin/sh, /bootstrap/init-s3.sh]
|
|
environment:
|
|
S3_ROOT_USER: lab4root
|
|
S3_ROOT_PASSWORD: ${S3_ROOT_PASSWORD:?Run scripts/bootstrap.sh}
|
|
S3_API_USER: lab4api
|
|
S3_API_PASSWORD: ${S3_API_PASSWORD:?Run scripts/bootstrap.sh}
|
|
volumes: ['./infra:/bootstrap:ro']
|
|
depends_on: [s3]
|
|
cpus: 1
|
|
mem_limit: 512m
|
|
migrate:
|
|
<<: *api
|
|
command: [python, migrate.py]
|
|
depends_on:
|
|
db: {condition: service_healthy}
|
|
api:
|
|
<<: *api
|
|
command: [uvicorn, 'app:app', --host, 0.0.0.0, --port, '8080', --timeout-graceful-shutdown, '35', --limit-concurrency, '64']
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
s3-init: {condition: service_completed_successfully}
|
|
valkey: {condition: service_started}
|
|
healthcheck:
|
|
test: [CMD, python, -c, "import socket; s=socket.create_connection(('127.0.0.1',8080),1); s.sendall(b'GET /health/ready HTTP/1.0\\r\\nHost: localhost\\r\\n\\r\\n'); assert s.makefile('rb').readline().split()[1]==b'200'"]
|
|
interval: 2s
|
|
timeout: 4s
|
|
retries: 2
|
|
lb:
|
|
image: haproxy:3.0.5-alpine
|
|
ports: ['127.0.0.1:${APP_PORT:-8085}:8080']
|
|
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
|
|
depends_on: [api]
|
|
cpus: 0.25
|
|
mem_limit: 64m
|
|
broker:
|
|
image: valkey/valkey:8.0.2-alpine
|
|
command: [valkey-server, --appendonly, 'yes', --appendfsync, always, --maxmemory-policy, noeviction]
|
|
volumes: [broker_data:/data]
|
|
cpus: 0.25
|
|
mem_limit: 192m
|
|
restart: unless-stopped
|
|
publisher:
|
|
<<: *api
|
|
command: [python, publisher.py]
|
|
restart: unless-stopped
|
|
cpus: 0.25
|
|
mem_limit: 192m
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
broker: {condition: service_started}
|
|
worker:
|
|
<<: *api
|
|
command: [python, worker.py]
|
|
restart: unless-stopped
|
|
cpus: 1
|
|
mem_limit: 768m
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
s3-init: {condition: service_completed_successfully}
|
|
broker: {condition: service_started}
|
|
janitor:
|
|
<<: *api
|
|
command: [python, janitor.py]
|
|
restart: unless-stopped
|
|
cpus: 0.25
|
|
mem_limit: 192m
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
s3-init: {condition: service_completed_successfully}
|
|
ops:
|
|
<<: *api
|
|
profiles: [tools]
|
|
volumes: ['./tests:/app/tests:ro', './scripts:/app/scripts:ro']
|
|
command: [python, manage.py, failed]
|
|
cpus: 1
|
|
mem_limit: 512m
|
|
volumes:
|
|
postgres_data:
|
|
valkey_data:
|
|
s3_data:
|
|
broker_data:
|