name: mtusi-lab6 x-application: &application image: mtusi-messenger:lab6 env_file: .env environment: &pipeline-environment OTEL_PYTHON_SDK_INTERNAL_METRICS_ENABLED: "true" JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5} JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60} JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-90} JOB_BACKOFF_SECONDS: ${JOB_BACKOFF_SECONDS:-2} WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2} WORKER_TASK_MEMORY_MB: ${WORKER_TASK_MEMORY_MB:-640} ENABLE_FAULT_INJECTION: ${ENABLE_FAULT_INJECTION:-0} cpus: 1 mem_limit: 384m x-postgres: &postgres image: postgres:17.6-bookworm environment: POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] cpus: 1 mem_limit: 512m healthcheck: test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"] interval: 2s timeout: 3s retries: 30 services: postgres: <<: *postgres volumes: [postgres_data:/var/lib/postgresql/data] valkey: image: valkey/valkey:8.1.3 command: ["valkey-server", "--appendonly", "yes", "--appendfsync", "always", "--save", "", "--maxmemory", "64mb", "--maxmemory-policy", "noeviction"] volumes: [valkey_data:/data] cpus: 0.5 mem_limit: 128m healthcheck: test: ["CMD", "valkey-cli", "ping"] interval: 2s timeout: 3s retries: 30 broker: image: valkey/valkey:8.1.3 command: ["sh", "-c", 'exec valkey-server --appendonly yes --appendfsync always --save "" --maxmemory 128mb --maxmemory-policy noeviction --requirepass "$$(cat /run/secrets/broker_password)"'] secrets: [broker_password] volumes: [broker_data:/data] cpus: 0.5 mem_limit: 256m healthcheck: test: ["CMD-SHELL", 'REDISCLI_AUTH="$$(cat /run/secrets/broker_password)" valkey-cli ping | grep -q PONG'] interval: 2s timeout: 3s retries: 30 publisher: <<: *application command: ["python", "-m", "src.publisher"] secrets: [database_url, broker_url] restart: unless-stopped healthcheck: disable: true depends_on: migrate: {condition: service_completed_successfully} broker: {condition: service_healthy} worker: <<: *application command: ["python", "-m", "src.worker"] secrets: [database_url, broker_url, s3_access_key_id, s3_secret_access_key] restart: unless-stopped mem_limit: 1536m cpus: 2 pids_limit: 96 healthcheck: disable: true depends_on: migrate: {condition: service_completed_successfully} broker: {condition: service_healthy} s3-bootstrap: {condition: service_completed_successfully} stop_grace_period: 8s api: <<: *application build: . deploy: replicas: ${API_REPLICAS:-2} environment: <<: *pipeline-environment SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} secrets: [database_url, cache_url, s3_access_key_id, s3_secret_access_key] depends_on: postgres: {condition: service_healthy} valkey: {condition: service_healthy} migrate: {condition: service_completed_successfully} s3: {condition: service_healthy} s3-bootstrap: {condition: service_completed_successfully} stop_grace_period: 8s migrate: <<: *application command: ["python", "-m", "src.migrate"] secrets: [database_url] healthcheck: disable: true depends_on: postgres: {condition: service_healthy} s3: image: chrislusf/seaweedfs:3.85@sha256:49312939c00c01e5ee6afbd7d728b18027821d3764c35a797a72acd4fdf3296a command: ["s3", "-filer=s3-storage:8888", "-ip.bind=0.0.0.0", "-port=9000", "-config=/run/secrets/s3_config"] secrets: [s3_config] networks: [default, s3-internal] depends_on: s3-storage: {condition: service_healthy} cpus: 0.5 mem_limit: 256m healthcheck: test: ["CMD", "nc", "-z", "127.0.0.1", "9000"] interval: 2s timeout: 2s retries: 30 s3-storage: image: chrislusf/seaweedfs:3.85@sha256:49312939c00c01e5ee6afbd7d728b18027821d3764c35a797a72acd4fdf3296a command: ["server", "-dir=/data", "-ip=s3-storage", "-ip.bind=0.0.0.0", "-filer", "-master.volumeSizeLimitMB=64", "-volume.max=64", "-volume.preStopSeconds=0"] volumes: [s3_data:/data] networks: [s3-internal] cpus: 1 mem_limit: 512m healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8888/"] interval: 2s timeout: 2s retries: 30 s3-bootstrap: <<: *application command: ["python", "-m", "src.bootstrap_s3"] environment: S3_ROOT_USER_FILE: /run/secrets/s3_root_user S3_ROOT_PASSWORD_FILE: /run/secrets/s3_root_password secrets: [s3_root_user, s3_root_password] cpus: 0.5 mem_limit: 128m healthcheck: disable: true depends_on: s3: {condition: service_healthy} cleanup: <<: *application command: ["python", "-m", "src.cleanup"] secrets: [database_url, s3_access_key_id, s3_secret_access_key] restart: unless-stopped healthcheck: disable: true depends_on: migrate: {condition: service_completed_successfully} s3-bootstrap: {condition: service_completed_successfully} lb: image: haproxy:3.2.6-alpine ports: ["127.0.0.1:${HOST_PORT:-8080}:8080"] volumes: [./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro] cpus: 0.5 mem_limit: 64m depends_on: api: {condition: service_healthy} stop_grace_period: 10s healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/ready"] interval: 2s timeout: 2s retries: 3 otel-collector: image: otel/opentelemetry-collector-contrib:0.123.0 command: ["--config=/etc/otelcol/config.yaml"] volumes: [./infra/otel/collector.yaml:/etc/otelcol/config.yaml:ro] depends_on: [loki, tempo] cpus: 1 mem_limit: 256m restart: unless-stopped prometheus: image: prom/prometheus:v3.4.1 command: ["--config.file=/etc/prometheus/prometheus.yaml", "--storage.tsdb.path=/prometheus", "--storage.tsdb.retention.time=7d"] volumes: - ./infra/otel/prometheus.yaml:/etc/prometheus/prometheus.yaml:ro - ./infra/otel/alerts.yaml:/etc/prometheus/alerts.yaml:ro - prometheus_data:/prometheus depends_on: [otel-collector] cpus: 1 mem_limit: 384m restart: unless-stopped loki: image: grafana/loki:3.5.1 command: ["-config.file=/etc/loki/config.yaml"] volumes: - ./infra/otel/loki.yaml:/etc/loki/config.yaml:ro - loki_data:/loki cpus: 1 mem_limit: 384m restart: unless-stopped tempo: image: grafana/tempo:2.8.1 environment: GOMEMLIMIT: 384MiB command: ["-config.file=/etc/tempo/config.yaml"] volumes: - ./infra/otel/tempo.yaml:/etc/tempo/config.yaml:ro - tempo_data:/var/tempo cpus: 1 mem_limit: 512m restart: unless-stopped grafana: image: grafana/grafana:12.0.2 environment: GF_AUTH_ANONYMOUS_ENABLED: "true" GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer GF_AUTH_BASIC_ENABLED: "false" GF_AUTH_DISABLE_LOGIN_FORM: "true" GF_ANALYTICS_REPORTING_ENABLED: "false" GF_ANALYTICS_CHECK_FOR_UPDATES: "false" GF_PLUGINS_PREINSTALL_DISABLED: "true" GF_PLUGINS_CHECK_FOR_UPDATES: "false" GF_NEWS_NEWS_FEED_ENABLED: "false" ports: ["127.0.0.1:${GRAFANA_PORT:-3000}:3000"] volumes: - ./infra/grafana/provisioning:/etc/grafana/provisioning:ro - ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro - grafana_data:/var/lib/grafana depends_on: [prometheus, loki, tempo] cpus: 1 mem_limit: 384m restart: unless-stopped postgres-restore: <<: *postgres profiles: [research] volumes: [restore_data:/var/lib/postgresql/data] volumes: prometheus_data: loki_data: tempo_data: grafana_data: postgres_data: valkey_data: restore_data: s3_data: broker_data: networks: s3-internal: internal: true secrets: broker_password: file: ./secrets/broker_password broker_url: file: ./secrets/broker_url postgres_password: file: ./secrets/postgres_password database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url s3_root_user: file: ./secrets/s3_root_user s3_root_password: file: ./secrets/s3_root_password s3_access_key_id: file: ./secrets/s3_access_key_id s3_secret_access_key: file: ./secrets/s3_secret_access_key s3_config: file: ./secrets/s3_config