Files
mtusi2026lab4/compose.yaml

118 lines
3.4 KiB
YAML

x-app: &app
build: .
image: shemruk-messenger-lab4:local
cpus: 1.0
mem_limit: 320m
init: true
environment:
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
CURSOR_KEY_FILE: /run/secrets/cursor_key
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
S3_ACCESS_KEY_FILE: /run/secrets/s3_access
S3_SECRET_KEY_FILE: /run/secrets/s3_secret
secrets: [database_url, cache_url, cursor_key, s3_access, s3_secret]
services:
db:
image: postgres:17.6-bookworm
cpus: 1.0
mem_limit: 512m
environment:
POSTGRES_USER: messenger
POSTGRES_DB: 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 -h 127.0.0.1]
interval: 2s
timeout: 2s
retries: 20
cache:
image: redis:7.4.6-bookworm
cpus: 0.5
mem_limit: 128m
command: [redis-server, /run/secrets/redis_config]
secrets: [redis_config, cache_password]
volumes: [redis_data:/data]
healthcheck:
test: [CMD-SHELL, 'REDISCLI_AUTH=$$(cat /run/secrets/cache_password) redis-cli ping | grep -qx PONG']
interval: 2s
timeout: 2s
retries: 20
migrate:
<<: *app
command: [python, -m, db]
depends_on:
db: {condition: service_healthy}
s3-perms:
image: busybox:1.37.0
command: ["chown", "10001:10001", "/data"]
volumes: [object_data:/data]
s3:
image: rustfs/rustfs:1.0.7
cpus: 0.75
mem_limit: 512m
env_file: ./secrets/s3_root.env
environment:
RUSTFS_VOLUMES: /data
RUSTFS_ADDRESS: :9000
RUSTFS_CONSOLE_ENABLE: "false"
volumes: [object_data:/data]
depends_on:
s3-perms: {condition: service_completed_successfully}
healthcheck:
test: [CMD, curl, -fsS, "http://127.0.0.1:9000/health/ready"]
interval: 2s
timeout: 2s
retries: 30
s3-init:
image: rustfs/rc:v0.1.38
cpus: 0.25
mem_limit: 96m
env_file: ./secrets/s3_root.env
entrypoint: ["/bin/sh", "/bootstrap/s3-init.sh"]
volumes: ["./infra/s3:/bootstrap:ro"]
secrets: [s3_access, s3_secret]
depends_on:
s3: {condition: service_healthy}
api:
<<: *app
scale: ${API_REPLICAS:-2}
cpus: ${API_CPUS:-0.75}
mem_limit: ${API_MEMORY:-448m}
stop_grace_period: 12s
depends_on:
migrate: {condition: service_completed_successfully}
cache: {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=3)"]
interval: 2s
timeout: 4s
retries: 20
lb:
image: haproxy:3.2.28-trixie
cpus: 0.5
mem_limit: 96m
ports: ["127.0.0.1:${HTTP_PORT:-8080}:8080"]
volumes:
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on: [api]
volumes:
postgres_data:
redis_data:
object_data:
secrets:
database_url: {file: ./secrets/database_url}
db_password: {file: ./secrets/db_password}
cache_url: {file: ./secrets/cache_url}
cache_password: {file: ./secrets/cache_password}
cursor_key: {file: ./secrets/cursor_key}
redis_config: {file: ./secrets/redis.conf}
s3_access: {file: ./secrets/s3_access}
s3_secret: {file: ./secrets/s3_secret}