Files
mtusi2026lab6/compose.yaml

377 lines
9.6 KiB
YAML

name: highload-lab6
services:
api:
build:
context: .
dockerfile: Dockerfile
scale: 2
cpus: "2.0"
mem_limit: 512m
expose:
- "8080"
env_file:
- .env
environment:
SESSION_STORE: redis
REDIS_ADDR: redis:6379
OTEL_SERVICE_NAME: messenger-api
secrets:
- database_url
- s3_access_key_id
- s3_secret_access_key
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
s3-init:
condition: service_completed_successfully
restart: unless-stopped
stop_grace_period: 20s
read_only: true
tmpfs:
- /tmp:size=32m,mode=1777
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
attachment-cleanup:
build:
context: .
dockerfile: Dockerfile
target: cleanup
command: ["cleanup", "-dry-run=${LAB6_CLEANUP_DRY_RUN:-false}"]
cpus: "0.5"
mem_limit: 128m
env_file:
- .env
environment:
BROKER_URL_FILE: ""
secrets:
- database_url
- s3_access_key_id
- s3_secret_access_key
depends_on:
postgres:
condition: service_healthy
migrate:
condition: service_completed_successfully
s3-init:
condition: service_completed_successfully
restart: unless-stopped
stop_grace_period: 20s
read_only: true
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
relay:
build:
context: .
dockerfile: Dockerfile
target: relay
env_file: [.env]
environment:
BROKER_URL_FILE: /run/secrets/broker_url
OTEL_SERVICE_NAME: messenger-relay
secrets: [database_url, broker_url]
depends_on:
migrate:
condition: service_completed_successfully
rabbitmq:
condition: service_healthy
cpus: "0.5"
mem_limit: 128m
read_only: true
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
restart: unless-stopped
worker:
build:
context: .
dockerfile: Dockerfile.worker
env_file: [.env]
environment:
BROKER_URL_FILE: /run/secrets/broker_url
OTEL_SERVICE_NAME: messenger-worker
secrets: [database_url, broker_url, s3_access_key_id, s3_secret_access_key]
depends_on:
migrate:
condition: service_completed_successfully
s3-init:
condition: service_completed_successfully
rabbitmq:
condition: service_healthy
cpus: "2.0"
mem_limit: 1536m
read_only: true
tmpfs:
- /tmp:size=768m,mode=1777
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
restart: unless-stopped
stop_grace_period: 15s
rabbitmq:
image: rabbitmq:4.2.5-alpine@sha256:d4a3806070111cc69130a6542aa4049b612789852ef11fc3862abc94631b2572
hostname: rabbitmq
entrypoint: ["/bin/sh", "-ec"]
command:
- |
export RABBITMQ_DEFAULT_PASS="$$(cat /run/secrets/rabbitmq_password)"
exec docker-entrypoint.sh rabbitmq-server
environment:
RABBITMQ_DEFAULT_USER: messenger
RABBITMQ_DEFAULT_VHOST: messenger
secrets: [rabbitmq_password]
volumes:
- rabbitmq_data:/var/lib/rabbitmq
healthcheck:
test: ["CMD", "rabbitmq-diagnostics", "-q", "check_running"]
interval: 5s
timeout: 10s
retries: 12
start_period: 60s
mem_limit: 768m
cpus: "1.0"
restart: unless-stopped
stop_grace_period: 30s
lb:
image: haproxy:3.2.24-alpine@sha256:1aca32ee932b96d2a75f1882909325839dd23c138ba9c6fd26e4d88179f30f13
cpus: "1.0"
mem_limit: 256m
ports:
- "127.0.0.1:${LAB6_HTTP_PORT:-8086}:8080"
volumes:
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on:
api:
condition: service_healthy
restart: unless-stopped
read_only: true
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
migrate:
build:
context: .
dockerfile: Dockerfile.migrate
cpus: "1.0"
mem_limit: 256m
environment:
DATABASE_URL_FILE: /run/secrets/database_url
secrets:
- database_url
depends_on:
postgres:
condition: service_healthy
restart: "no"
stop_grace_period: 20s
read_only: true
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
postgres:
image: postgres:18@sha256:5a5a84b19854a9ffaa54082c166ff4ec27473a361e496e5ea167f298f2da9722
cpus: "2.0"
mem_limit: 512m
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
secrets:
- postgres_password
ports:
- "127.0.0.1:${LAB6_POSTGRES_PORT:-15486}:5432"
volumes:
- postgres_data:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U messenger -d messenger"]
interval: 5s
timeout: 5s
retries: 5
restart: unless-stopped
stop_grace_period: 60s
redis:
image: redis:7.4-alpine@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499
cpus: "0.5"
mem_limit: 128m
restart: unless-stopped
command:
- redis-server
- --appendonly
- "yes"
- --appendfsync
- everysec
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
s3:
image: rustfs/rustfs:1.0.4@sha256:ed9210d6411d77ffceb70d94b964a3cb7d225983368bc25bebe01e995293dcc2
cpus: "1.0"
mem_limit: 512m
environment:
RUSTFS_VOLUMES: /data
RUSTFS_ACCESS_KEY_FILE: /run/secrets/rustfs_root_access_key
RUSTFS_SECRET_KEY_FILE: /run/secrets/rustfs_root_secret_key
RUSTFS_CONSOLE_ENABLE: "false"
secrets:
- rustfs_root_access_key
- rustfs_root_secret_key
volumes:
- rustfs_data:/data
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:9000/health/ready >/dev/null"]
interval: 5s
timeout: 3s
retries: 12
start_period: 30s
restart: unless-stopped
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
s3-init:
image: rustfs/rc:v0.1.30@sha256:1296510ec27800668d26a8bdca6251e587086187a9368c7b80134a169e8a3bb8
cpus: "0.5"
mem_limit: 128m
entrypoint: ["/bin/sh", "/bootstrap.sh"]
environment:
HOME: /tmp
S3_BUCKET: messenger-attachments
S3_REGION: us-east-1
secrets:
- rustfs_root_access_key
- rustfs_root_secret_key
- s3_access_key_id
- s3_secret_access_key
volumes:
- ./infra/s3/bootstrap.sh:/bootstrap.sh:ro
depends_on:
s3:
condition: service_healthy
restart: "no"
read_only: true
tmpfs:
- /tmp:uid=100,gid=101,mode=0700
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
otel-collector:
image: otel/opentelemetry-collector-contrib:0.131.0
command: ["--config=/etc/otelcol-contrib/config.yaml"]
environment:
GOMEMLIMIT: 120MiB
volumes:
- ./infra/otel/collector.yaml:/etc/otelcol-contrib/config.yaml:ro
mem_limit: 256m
cpus: "0.75"
restart: unless-stopped
prometheus:
image: prom/prometheus:v3.5.0
command:
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.path=/prometheus
- --storage.tsdb.retention.time=24h
- --storage.tsdb.retention.size=512MB
ports: ["127.0.0.1:${LAB6_PROMETHEUS_PORT:-9096}:9090"]
volumes:
- ./infra/otel/prometheus.yaml:/etc/prometheus/prometheus.yml:ro
- ./infra/otel/alerts.yaml:/etc/prometheus/alerts.yaml:ro
- prometheus_data:/prometheus
mem_limit: 256m
cpus: "0.75"
restart: unless-stopped
loki:
image: grafana/loki:3.5.0
command: ["-config.file=/etc/loki/lab.yaml"]
ports: ["127.0.0.1:${LAB6_LOKI_PORT:-3106}:3100"]
volumes:
- ./infra/otel/loki.yaml:/etc/loki/lab.yaml:ro
- loki_data:/loki
mem_limit: 384m
cpus: "0.75"
restart: unless-stopped
tempo:
image: grafana/tempo:2.8.1
command: ["-config.file=/etc/tempo/lab.yaml"]
ports: ["127.0.0.1:${LAB6_TEMPO_PORT:-3206}:3200"]
volumes:
- ./infra/otel/tempo.yaml:/etc/tempo/lab.yaml:ro
- tempo_data:/var/tempo
mem_limit: 384m
cpus: "0.75"
restart: unless-stopped
grafana:
image: grafana/grafana:12.3.1
environment:
GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer
GF_AUTH_BASIC_ENABLED: "false"
GF_AUTH_DISABLE_LOGIN_FORM: "true"
GF_SECURITY_DISABLE_INITIAL_ADMIN_CREATION: "true"
GF_ANALYTICS_REPORTING_ENABLED: "false"
GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
GF_ANALYTICS_CHECK_FOR_PLUGIN_UPDATES: "false"
GF_PLUGINS_PREINSTALL_DISABLED: "true"
ports: ["127.0.0.1:${LAB6_GRAFANA_PORT:-3006}:3000"]
volumes:
- ./infra/otel/grafana/provisioning:/etc/grafana/provisioning:ro
- ./infra/otel/grafana/dashboards:/var/lib/grafana/dashboards:ro
- grafana_data:/var/lib/grafana
mem_limit: 256m
cpus: "0.75"
restart: unless-stopped
secrets:
broker_url:
file: ./secrets/broker_url
rabbitmq_password:
file: ./secrets/rabbitmq_password
database_url:
file: ./secrets/database_url
postgres_password:
file: ./secrets/postgres_password
rustfs_root_access_key:
file: ./secrets/rustfs_root_access_key
rustfs_root_secret_key:
file: ./secrets/rustfs_root_secret_key
s3_access_key_id:
file: ./secrets/s3_access_key_id
s3_secret_access_key:
file: ./secrets/s3_secret_access_key
volumes:
rabbitmq_data:
postgres_data:
redis_data:
rustfs_data:
prometheus_data:
loki_data:
tempo_data:
grafana_data: