forked from mtusi2026/mtusi2026lab6
314 lines
8.8 KiB
YAML
314 lines
8.8 KiB
YAML
x-api: &api
|
|
image: mtusi2026lab6-api:local
|
|
pull_policy: never
|
|
dns_opt:
|
|
- timeout:1
|
|
- attempts:1
|
|
environment: &app-env
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
POSTGRES_HOST: postgres
|
|
POSTGRES_DB: ${POSTGRES_DB:-messenger}
|
|
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
|
|
REDIS_URL: redis://redis:6379/0
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
CACHE_TTL_SECONDS: ${CACHE_TTL_SECONDS:-30}
|
|
MAX_REQUEST_BYTES: ${MAX_REQUEST_BYTES:-65536}
|
|
MAX_INFLIGHT: ${MAX_INFLIGHT:-32}
|
|
S3_ENDPOINT: http://s3:9000
|
|
S3_REGION: us-east-1
|
|
S3_BUCKET: messenger-attachments
|
|
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:?Set S3_ACCESS_KEY_ID in .env}
|
|
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:?Set S3_SECRET_ACCESS_KEY in .env}
|
|
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
|
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
|
MAX_PENDING_ATTACHMENTS: ${MAX_PENDING_ATTACHMENTS:-64}
|
|
BROKER_URL: redis://broker:6379/0
|
|
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
|
|
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
|
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
|
JOB_MEMORY_MB: ${JOB_MEMORY_MB:-768}
|
|
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
|
OTEL_SERVICE_NAME: messenger-api
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
|
|
OTEL_SDK_DISABLED: ${OTEL_SDK_DISABLED:-false}
|
|
networks: [backend]
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
stop_grace_period: 10s
|
|
|
|
services:
|
|
broker:
|
|
image: redis:7.4.2-bookworm
|
|
command: [redis-server, --appendonly, 'yes', --appendfsync, always, --maxmemory, 128mb, --maxmemory-policy, noeviction]
|
|
volumes:
|
|
- broker_data:/data
|
|
networks: [backend]
|
|
healthcheck:
|
|
test: [CMD, redis-cli, ping]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
cpus: 0.5
|
|
mem_limit: 256m
|
|
|
|
dispatcher:
|
|
<<: *api
|
|
environment:
|
|
<<: *app-env
|
|
OTEL_SERVICE_NAME: messenger-dispatcher
|
|
command: [python, -m, src.jobs, dispatch]
|
|
healthcheck:
|
|
disable: true
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
broker:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
mem_limit: 128m
|
|
|
|
worker:
|
|
<<: *api
|
|
environment:
|
|
<<: *app-env
|
|
OTEL_SERVICE_NAME: messenger-worker
|
|
command: [python, -m, src.worker]
|
|
init: true
|
|
healthcheck:
|
|
disable: true
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
broker:
|
|
condition: service_healthy
|
|
s3-init:
|
|
condition: service_completed_successfully
|
|
restart: unless-stopped
|
|
cpus: 2.0
|
|
mem_limit: 2g
|
|
pids_limit: 64
|
|
|
|
api:
|
|
<<: *api
|
|
build: .
|
|
deploy:
|
|
replicas: 2
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
redis:
|
|
condition: service_healthy
|
|
s3-init:
|
|
condition: service_completed_successfully
|
|
healthcheck:
|
|
test: [CMD, python, -c, "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=1).read()"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
start_period: 5s
|
|
retries: 2
|
|
|
|
migrate:
|
|
<<: *api
|
|
environment:
|
|
<<: *app-env
|
|
OTEL_SDK_DISABLED: 'true'
|
|
command: [python, -m, src.database]
|
|
healthcheck:
|
|
disable: true
|
|
restart: 'no'
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
|
|
s3:
|
|
# RELEASE.2025-09-07T16-13-09Z, pinned by immutable image digest.
|
|
image: minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
|
|
command: [server, /data, --console-address, '127.0.0.1:9001']
|
|
environment:
|
|
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?Set MINIO_ROOT_USER in .env}
|
|
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?Set MINIO_ROOT_PASSWORD in .env}
|
|
MINIO_BROWSER: 'off'
|
|
volumes:
|
|
- s3_data:/data
|
|
networks: [backend]
|
|
healthcheck:
|
|
test: [CMD, curl, -f, http://127.0.0.1:9000/minio/health/live]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
|
|
s3-init:
|
|
# The pinned server image also contains mc; no second image is needed.
|
|
image: minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
|
|
entrypoint: [sh, /bootstrap.sh]
|
|
environment:
|
|
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?Set MINIO_ROOT_USER in .env}
|
|
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?Set MINIO_ROOT_PASSWORD in .env}
|
|
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:?Set S3_ACCESS_KEY_ID in .env}
|
|
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:?Set S3_SECRET_ACCESS_KEY in .env}
|
|
volumes:
|
|
- ./infra/s3-bootstrap.sh:/bootstrap.sh:ro
|
|
- ./infra/s3-policy.json:/policy.json:ro
|
|
depends_on:
|
|
s3:
|
|
condition: service_healthy
|
|
networks: [backend]
|
|
restart: 'no'
|
|
cpus: 0.25
|
|
mem_limit: 128m
|
|
|
|
cleanup:
|
|
<<: *api
|
|
environment:
|
|
<<: *app-env
|
|
OTEL_SDK_DISABLED: 'true'
|
|
command: [python, -m, src.cleanup]
|
|
healthcheck:
|
|
disable: true
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
s3-init:
|
|
condition: service_completed_successfully
|
|
restart: unless-stopped
|
|
cpus: 0.25
|
|
mem_limit: 128m
|
|
|
|
nginx:
|
|
image: nginx:1.28.0-alpine
|
|
entrypoint: [sh, /etc/nginx/readiness.sh]
|
|
dns_opt:
|
|
- timeout:1
|
|
- attempts:1
|
|
ports:
|
|
- '127.0.0.1:${APP_PORT:-8080}:8080'
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
- ./infra/readiness.sh:/etc/nginx/readiness.sh:ro
|
|
networks: [edge, backend]
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: [CMD-SHELL, 'wget -q -O /dev/null http://127.0.0.1:8080/health/ready']
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 3
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
stop_grace_period: 10s
|
|
|
|
postgres:
|
|
image: postgres:17.4-bookworm
|
|
environment:
|
|
POSTGRES_DB: ${POSTGRES_DB:-messenger}
|
|
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
networks: [backend]
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
|
|
redis:
|
|
image: redis:7.4.2-bookworm
|
|
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always", "--maxmemory", "128mb", "--maxmemory-policy", "noeviction"]
|
|
volumes:
|
|
- redis_data:/data
|
|
networks: [backend]
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
cpus: 0.5
|
|
mem_limit: 256m
|
|
|
|
otel-collector:
|
|
image: otel/opentelemetry-collector-contrib:0.136.0
|
|
command: [--config=/etc/otel/collector.yaml]
|
|
volumes:
|
|
- ./infra/otel/collector.yaml:/etc/otel/collector.yaml:ro
|
|
networks: [backend]
|
|
mem_limit: 256m
|
|
cpus: 0.5
|
|
restart: unless-stopped
|
|
|
|
prometheus:
|
|
image: prom/prometheus:v3.6.0
|
|
command: [--config.file=/etc/prometheus/prometheus.yaml, --storage.tsdb.retention.time=3d]
|
|
volumes:
|
|
- ./infra/otel/prometheus.yaml:/etc/prometheus/prometheus.yaml:ro
|
|
- ./infra/otel/alerts.yaml:/etc/prometheus/alerts.yaml:ro
|
|
- prometheus_data:/prometheus
|
|
ports: ['127.0.0.1:9090:9090']
|
|
networks: [edge, backend]
|
|
mem_limit: 512m
|
|
cpus: 0.5
|
|
restart: unless-stopped
|
|
|
|
loki:
|
|
image: grafana/loki:3.5.7
|
|
command: [-config.file=/etc/loki/local.yaml]
|
|
volumes:
|
|
- ./infra/otel/loki.yaml:/etc/loki/local.yaml:ro
|
|
- loki_data:/loki
|
|
ports: ['127.0.0.1:3100:3100']
|
|
networks: [edge, backend]
|
|
mem_limit: 384m
|
|
cpus: 0.5
|
|
restart: unless-stopped
|
|
|
|
tempo:
|
|
image: grafana/tempo:2.9.0
|
|
command: [-config.file=/etc/tempo.yaml]
|
|
volumes:
|
|
- ./infra/otel/tempo.yaml:/etc/tempo.yaml:ro
|
|
- tempo_data:/var/tempo
|
|
ports: ['127.0.0.1:3200:3200']
|
|
networks: [edge, backend]
|
|
mem_limit: 384m
|
|
cpus: 0.5
|
|
restart: unless-stopped
|
|
|
|
grafana:
|
|
image: grafana/grafana:12.2.0
|
|
environment:
|
|
GF_SECURITY_ADMIN_USER: admin
|
|
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:?Set GRAFANA_ADMIN_PASSWORD in .env}
|
|
GF_USERS_ALLOW_SIGN_UP: 'false'
|
|
GF_ANALYTICS_REPORTING_ENABLED: 'false'
|
|
GF_ANALYTICS_CHECK_FOR_UPDATES: 'false'
|
|
volumes:
|
|
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
|
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
|
- grafana_data:/var/lib/grafana
|
|
ports: ['127.0.0.1:3000:3000']
|
|
networks: [edge, backend]
|
|
mem_limit: 384m
|
|
cpus: 0.5
|
|
restart: unless-stopped
|
|
|
|
networks:
|
|
edge:
|
|
backend:
|
|
internal: true
|
|
volumes:
|
|
broker_data:
|
|
postgres_data:
|
|
redis_data:
|
|
s3_data:
|
|
prometheus_data:
|
|
loki_data:
|
|
tempo_data:
|
|
grafana_data:
|