forked from mtusi2026/mtusi2026lab5
301 lines
8.7 KiB
YAML
301 lines
8.7 KiB
YAML
name: mtusi-messenger-lab5
|
|
|
|
services:
|
|
|
|
postgres:
|
|
image: postgres:17.6-alpine3.22
|
|
command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all"]
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
|
|
secrets:
|
|
- db_password
|
|
volumes:
|
|
- postgres-data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 10s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 1g
|
|
restart: unless-stopped
|
|
|
|
redis:
|
|
image: redis:8.4.0-alpine
|
|
# Session cache only, PostgreSQL is the source of truth: no RDB/AOF, a restart simply empties the cache.
|
|
# Every key carries a TTL, so under memory pressure volatile-lru evicts the least used sessions.
|
|
command:
|
|
- sh
|
|
- -c
|
|
- >-
|
|
exec docker-entrypoint.sh redis-server
|
|
--requirepass "$$(cat /run/secrets/redis_password)"
|
|
--save ""
|
|
--appendonly no
|
|
--maxmemory 64mb
|
|
--maxmemory-policy volatile-lru
|
|
secrets:
|
|
- redis_password
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "REDISCLI_AUTH=\"$$(cat /run/secrets/redis_password)\" redis-cli ping | grep -q PONG"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 5s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 128m
|
|
restart: unless-stopped
|
|
|
|
broker:
|
|
# RabbitMQ 4.1.8-alpine, pinned multi-platform image.
|
|
image: rabbitmq@sha256:cd4009416f83d7e5895020cd71b0963f3b8a4dfc3de74bbb6fb3bfe5f81f01e0
|
|
hostname: broker
|
|
entrypoint: ["/bin/sh", "/bootstrap.sh"]
|
|
secrets:
|
|
- broker_password
|
|
volumes:
|
|
- broker-data:/var/lib/rabbitmq
|
|
- ./infra/rabbitmq/bootstrap.sh:/bootstrap.sh:ro
|
|
- ./infra/rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
|
|
healthcheck:
|
|
test: ["CMD", "rabbitmq-diagnostics", "-q", "check_running"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 20
|
|
start_period: 20s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 512m
|
|
restart: unless-stopped
|
|
|
|
s3:
|
|
# MinIO RELEASE.2025-09-07T16-13-09Z, pinned multi-platform image.
|
|
image: quay.io/minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
|
|
command: ["server", "/data", "--console-address", "127.0.0.1:9001"]
|
|
environment:
|
|
MINIO_ROOT_USER_FILE: /run/secrets/s3_access_key_id
|
|
MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_secret_access_key
|
|
secrets:
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
volumes:
|
|
- s3-data:/data
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 512m
|
|
restart: unless-stopped
|
|
|
|
s3-init:
|
|
# mc RELEASE.2025-08-13T08-35-41Z
|
|
image: quay.io/minio/mc@sha256:a7fe349ef4bd8521fb8497f55c6042871b2ae640607cf99d9bede5e9bdf11727
|
|
depends_on:
|
|
s3:
|
|
condition: service_healthy
|
|
entrypoint: ["/bin/sh", "/bootstrap.sh"]
|
|
environment:
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
secrets:
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
- s3_api_access_key_id
|
|
- s3_api_secret_access_key
|
|
volumes:
|
|
- ./infra/s3/bootstrap.sh:/bootstrap.sh:ro
|
|
restart: "no"
|
|
|
|
# One-shot: applies Flyway migrations once and exits. Replicas start only after it succeeded,
|
|
# so they never race each other on the schema.
|
|
migrate:
|
|
image: mtusi-messenger:lab5
|
|
command: ["migrate"]
|
|
healthcheck:
|
|
test: ["NONE"]
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
environment:
|
|
DB_HOST: postgres
|
|
DB_PORT: "5432"
|
|
DB_NAME: messenger
|
|
DB_USER: messenger
|
|
DB_PASSWORD_FILE: /run/secrets/db_password
|
|
secrets:
|
|
- db_password
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 384m
|
|
restart: "no"
|
|
|
|
api:
|
|
build: .
|
|
image: mtusi-messenger:lab5
|
|
# Interchangeable replicas: no container_name and no published port, traffic only through `lb`.
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 1g
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
s3-init:
|
|
condition: service_completed_successfully
|
|
environment:
|
|
APP_HOST: "0.0.0.0"
|
|
APP_PORT: "8080"
|
|
DB_HOST: postgres
|
|
DB_PORT: "5432"
|
|
DB_NAME: messenger
|
|
DB_USER: messenger
|
|
DB_PASSWORD_FILE: /run/secrets/db_password
|
|
DB_MIGRATE_ON_START: "false"
|
|
REDIS_HOST: redis
|
|
REDIS_PORT: "6379"
|
|
REDIS_PASSWORD_FILE: /run/secrets/redis_password
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
SESSION_CACHE_SINGLE_FLIGHT: ${SESSION_CACHE_SINGLE_FLIGHT:-true}
|
|
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
|
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
|
SHUTDOWN_DRAIN_DELAY_MS: "3000"
|
|
S3_ENDPOINT: http://s3:9000
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_api_access_key_id
|
|
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_api_secret_access_key
|
|
BROKER_HOST: broker
|
|
BROKER_PORT: "5672"
|
|
BROKER_USER: messenger
|
|
BROKER_PASSWORD_FILE: /run/secrets/broker_password
|
|
BROKER_QUEUE: ${BROKER_QUEUE:-attachment.process.v1}
|
|
secrets:
|
|
- db_password
|
|
- redis_password
|
|
- s3_api_access_key_id
|
|
- s3_api_secret_access_key
|
|
- broker_password
|
|
# SIGTERM: readiness 503 and 3 s drain (HAProxy needs <= 2 s to notice), then Ktor closes the socket and
|
|
# finishes requests in flight within 5 s. 3 + 5 = 8 s < 10 s before Docker sends SIGKILL.
|
|
tmpfs:
|
|
- /tmp:size=32m,mode=1777
|
|
stop_grace_period: 10s
|
|
restart: unless-stopped
|
|
|
|
worker:
|
|
image: mtusi-messenger:lab5
|
|
command: ["worker"]
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
postgres:
|
|
condition: service_healthy
|
|
s3-init:
|
|
condition: service_completed_successfully
|
|
broker:
|
|
condition: service_healthy
|
|
environment:
|
|
APP_HOST: "0.0.0.0"
|
|
APP_PORT: "8080"
|
|
DB_HOST: postgres
|
|
DB_PORT: "5432"
|
|
DB_NAME: messenger
|
|
DB_USER: messenger
|
|
DB_PASSWORD_FILE: /run/secrets/db_password
|
|
DB_MIGRATE_ON_START: "false"
|
|
S3_ENDPOINT: http://s3:9000
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_api_access_key_id
|
|
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_api_secret_access_key
|
|
BROKER_HOST: broker
|
|
BROKER_PORT: "5672"
|
|
BROKER_USER: messenger
|
|
BROKER_PASSWORD_FILE: /run/secrets/broker_password
|
|
BROKER_QUEUE: ${BROKER_QUEUE:-attachment.process.v1}
|
|
JAVA_TOOL_OPTIONS: "-Xmx320m -XX:+ExitOnOutOfMemoryError"
|
|
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-1}
|
|
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
|
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
|
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
|
secrets:
|
|
- db_password
|
|
- s3_api_access_key_id
|
|
- s3_api_secret_access_key
|
|
- broker_password
|
|
tmpfs:
|
|
- /tmp:size=32m,mode=1777
|
|
stop_grace_period: 10s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 1g
|
|
restart: unless-stopped
|
|
|
|
lb:
|
|
image: haproxy:3.2.4-alpine
|
|
volumes:
|
|
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
ports:
|
|
- "127.0.0.1:${LAB_HTTP_PORT:-8080}:8080"
|
|
# Port 8404 (health and stats) stays inside the compose network.
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8404/healthz"]
|
|
interval: 5s
|
|
timeout: 2s
|
|
retries: 3
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 128m
|
|
restart: unless-stopped
|
|
|
|
secrets:
|
|
db_password:
|
|
file: ./secrets/db_password
|
|
redis_password:
|
|
file: ./secrets/redis_password
|
|
broker_password:
|
|
file: ./secrets/broker_password
|
|
|
|
s3_access_key_id:
|
|
file: ./secrets/s3_access_key_id
|
|
s3_secret_access_key:
|
|
file: ./secrets/s3_secret_access_key
|
|
|
|
s3_api_access_key_id:
|
|
file: ./secrets/s3_api_access_key_id
|
|
s3_api_secret_access_key:
|
|
file: ./secrets/s3_api_secret_access_key
|
|
|
|
volumes:
|
|
postgres-data:
|
|
s3-data:
|
|
broker-data:
|