Files

111 lines
3.6 KiB
YAML

name: mtusi-lab4
x-api: &api
build: .
image: ${API_IMAGE:-mtusi-lab4-api:local}
environment: &environment
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD:?Run scripts/bootstrap.sh}@db:5432/messenger
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: ['${APP_PORT:-8084}:8080']
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
depends_on: [api]
cpus: 0.25
mem_limit: 64m
reconciler:
<<: *api
command: [python, scripts/reconcile_loop.py]
cpus: 0.25
mem_limit: 256m
depends_on:
migrate: {condition: service_completed_successfully}
s3-init: {condition: service_completed_successfully}
restart: unless-stopped
ops:
<<: *api
profiles: [tools]
volumes: ['./tests:/app/tests:ro', './scripts:/app/scripts:ro']
command: [python, reconcile.py]
cpus: 1
mem_limit: 512m
volumes:
postgres_data:
valkey_data:
s3_data: