Files
mtusi2026lab5/compose.yaml
T

210 lines
6.2 KiB
YAML

name: mtusi2026lab5
services:
postgres:
image: postgres:16.8-bookworm
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
secrets: [postgres_password]
volumes: [postgres_data:/var/lib/postgresql/data]
healthcheck:
test: [CMD-SHELL, 'pg_isready -h 127.0.0.1 -U messenger -d messenger']
interval: 2s
timeout: 2s
retries: 20
cpus: 1.0
mem_limit: 512m
restart: unless-stopped
redis:
image: redis:7.4.2-alpine
command: [redis-server, --appendonly, 'yes', --appendfsync, always]
volumes: [redis_data:/data]
healthcheck:
test: [CMD, redis-cli, ping]
interval: 2s
timeout: 2s
retries: 20
cpus: 0.25
mem_limit: 128m
restart: unless-stopped
migrate:
build: .
image: mtusi2026lab5-api:local
command: [python, -m, src.migrate]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
secrets: [database_url]
depends_on:
postgres:
condition: service_healthy
cpus: 0.5
mem_limit: 256m
restart: 'no'
api:
build: .
image: mtusi2026lab5-api:local
environment:
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL: redis://redis:6379/0
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
S3_ENDPOINT: http://s3:9000
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
secrets: [database_url, s3_access_key_id, s3_secret_access_key]
depends_on:
s3-bootstrap:
condition: service_completed_successfully
migrate:
condition: service_completed_successfully
redis:
condition: service_healthy
deploy:
replicas: 2
healthcheck:
test: [CMD, python, -c, 'import urllib.request; urllib.request.urlopen("http://127.0.0.1:8080/health/ready", timeout=2).read()']
interval: 2s
timeout: 3s
retries: 3
start_period: 5s
tmpfs:
- /tmp:size=16m,mode=1777
stop_grace_period: 6s
cpus: 0.75
mem_limit: 768m
restart: unless-stopped
broker:
image: rabbitmq:4.1.4-management
entrypoint: [/bin/sh, /broker-start.sh]
environment:
RABBITMQ_DEFAULT_USER: messenger
secrets: [broker_password]
volumes:
- broker_data:/var/lib/rabbitmq
- ./infra/broker-start.sh:/broker-start.sh:ro
hostname: broker
ports: ['127.0.0.1:${BROKER_CONSOLE_PORT:-15685}:15672']
healthcheck:
test: [CMD, rabbitmq-diagnostics, -q, check_running]
interval: 4s
timeout: 5s
retries: 20
mem_limit: 768m
cpus: 1.0
restart: unless-stopped
publisher: &pipeline
image: mtusi2026lab5-api:local
command: [python, -m, src.publisher]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
S3_ENDPOINT: http://s3:9000
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
BROKER_URL_FILE: /run/secrets/broker_url
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
PIPELINE_FAULTS: ${PIPELINE_FAULTS:-0}
secrets: [database_url, s3_access_key_id, s3_secret_access_key, broker_url]
depends_on:
broker:
condition: service_healthy
migrate:
condition: service_completed_successfully
s3-bootstrap:
condition: service_completed_successfully
healthcheck:
test: [CMD, python, -m, src.pipeline_health]
interval: 3s
timeout: 2s
retries: 3
start_period: 20s
tmpfs:
- /tmp:size=16m,mode=1777
cpus: 0.25
mem_limit: 256m
restart: unless-stopped
worker:
<<: *pipeline
command: [python, -m, src.worker]
deploy:
replicas: ${WORKER_CONCURRENCY:-2}
init: true
tmpfs:
- /tmp:size=64m,mode=1777
cpus: 1.0
mem_limit: 768m
stop_grace_period: 30s
recovery:
<<: *pipeline
command: [python, -m, src.recovery]
lb:
image: haproxy:3.0.9-alpine
ports: ['127.0.0.1:${PUBLIC_PORT:-8080}:8080']
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
depends_on:
api:
condition: service_healthy
healthcheck:
test: [CMD, wget, -q, -O, /dev/null, 'http://127.0.0.1:8080/health/ready']
interval: 5s
timeout: 3s
retries: 3
cpus: 0.5
mem_limit: 128m
restart: unless-stopped
s3:
image: bitnamilegacy/minio:2025.7.23-debian-12-r5@sha256:6dabb4a2088c9a79908de3bc05f4586c23ad2182c8908e7e3acbf61c1467fb20
entrypoint: [/opt/bitnami/minio/bin/minio]
user: '0:0'
command: [server, /data, --console-address, ':9001']
environment:
MINIO_ROOT_USER_FILE: /run/secrets/s3_root_user
MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_root_password
secrets: [s3_root_user, s3_root_password]
volumes: [s3_data:/data]
ports: ['127.0.0.1:${S3_CONSOLE_PORT:-9005}:9001']
healthcheck:
test: [CMD, curl, -f, http://localhost:9000/minio/health/live]
interval: 2s
timeout: 2s
retries: 30
restart: unless-stopped
mem_limit: 768m
cpus: 1.0
s3-bootstrap:
image: bitnamilegacy/minio:2025.7.23-debian-12-r5@sha256:6dabb4a2088c9a79908de3bc05f4586c23ad2182c8908e7e3acbf61c1467fb20
entrypoint: [/bin/sh, /bootstrap.sh]
volumes:
- ./infra/s3-bootstrap.sh:/bootstrap.sh:ro
- ./infra/s3-policy.json:/policy.json:ro
secrets: [s3_root_user, s3_root_password, s3_access_key_id, s3_secret_access_key]
depends_on:
s3:
condition: service_healthy
restart: 'no'
volumes:
s3_data:
postgres_data:
redis_data:
broker_data:
secrets:
postgres_password:
file: ./secrets/postgres_password
database_url:
file: ./secrets/database_url
s3_root_user:
file: ./secrets/s3_root_user
s3_root_password:
file: ./secrets/s3_root_password
s3_access_key_id:
file: ./secrets/s3_access_key_id
s3_secret_access_key:
file: ./secrets/s3_secret_access_key
broker_url:
file: ./secrets/broker_url
broker_password:
file: ./secrets/broker_password