name: messenger-lab7 x-lockdown: &lockdown security_opt: [no-new-privileges:true] cap_drop: [ALL] x-runtime: &runtime <<: *lockdown image: mtusi-messenger-lab7-api:dev build: context: . target: runtime init: true restart: unless-stopped x-runtime-env: &runtime-env BAO_ADDR: https://openbao:8200 NODE_EXTRA_CA_CERTS: /run/tls/ca.crt x-s3-env: &s3-env S3_ENDPOINT: https://s3:9000 S3_BUCKET: ${S3_BUCKET:-messenger-attachments} S3_REGION: us-east-1 x-otel-env: &otel-env OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318 OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab x-telemetry-proxy: &telemetry-proxy <<: *lockdown image: haproxy:3.0.6-alpine restart: unless-stopped deploy: resources: limits: {cpus: "0.15", memory: 64M} services: bootstrap: build: dockerfile_inline: | FROM python:3.12.7-alpine RUN apk add --no-cache openssl ENTRYPOINT ["python", "/work/bootstrap.py"] image: mtusi-messenger-lab7-bootstrap:dev network_mode: none security_opt: [no-new-privileges:true] cap_drop: [ALL] cap_add: [CHOWN, DAC_OVERRIDE, FOWNER] volumes: - ./infra/bootstrap.py:/work/bootstrap.py:ro - secrets:/state - baodata:/bao-data deploy: resources: limits: {cpus: "1.0", memory: 96M} openbao: <<: *lockdown image: openbao/openbao:2.4.4@sha256:595c83b42614a4d2b044608e4593c05b019c5db25bc9c185d8fff3ac96c03ddd user: "100:1000" entrypoint: [bao] command: ["server", "-config=/bao/config/server.hcl"] ports: - "127.0.0.1:${BAO_PORT:-8200}:8200" volumes: - ./infra/openbao/server.hcl:/bao/config/server.hcl:ro - baodata:/bao/data - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: openbao}} environment: BAO_ADDR: https://openbao:8200 BAO_CACERT: /run/tls/ca.crt healthcheck: test: ["CMD", "bao", "status"] interval: 3s timeout: 3s retries: 15 depends_on: bootstrap: {condition: service_completed_successfully} restart: unless-stopped deploy: resources: limits: {cpus: "0.5", memory: 256M} postgres: image: postgres:17.2-alpine environment: POSTGRES_USER: stand_operator POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/tls/operator_password command: ["postgres", "-c", "ssl=on", "-c", "ssl_cert_file=/run/tls/postgres.crt", "-c", "ssl_key_file=/run/tls/postgres.key", "-c", "ssl_min_protocol_version=TLSv1.2", "-c", "hba_file=/etc/postgresql/pg_hba.conf"] security_opt: [no-new-privileges:true] volumes: - pgdata:/var/lib/postgresql/data - ./infra/postgres/init.sh:/docker-entrypoint-initdb.d/roles.sh:ro - ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: postgres}} healthcheck: test: ["CMD", "pg_isready", "-d", "host=postgres dbname=messenger user=migrate sslmode=verify-full sslrootcert=/run/tls/ca.crt"] interval: 3s timeout: 3s retries: 15 depends_on: bootstrap: {condition: service_completed_successfully} restart: unless-stopped deploy: resources: limits: {cpus: "1.0", memory: 512M} migrate: <<: *lockdown build: context: . target: migrate image: mtusi-messenger-lab7-migrate:dev volumes: - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: migrate}} depends_on: postgres: {condition: service_healthy} deploy: resources: limits: {cpus: "0.5", memory: 512M} s3: <<: *lockdown image: pgsty/minio:RELEASE.2026-08-04T00-00-00Z@sha256:b6bfe7239bfc83fb90d31612d9704d86039dd714f7904b3f1ad68f211e602372 command: ["server", "/data", "--address", ":9000", "--console-address", "127.0.0.1:9001", "--certs-dir", "/run/tls"] environment: MINIO_ROOT_USER_FILE: /run/tls/root_user MINIO_ROOT_PASSWORD_FILE: /run/tls/root_password MINIO_BROWSER: "off" volumes: - s3data:/data - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: s3}} healthcheck: test: ["CMD", "curl", "-fsS", "--cacert", "/run/tls/ca.crt", "https://s3:9000/minio/health/live"] interval: 3s timeout: 3s retries: 15 depends_on: bootstrap: {condition: service_completed_successfully} restart: unless-stopped deploy: resources: limits: {cpus: "0.5", memory: 512M} s3-init: <<: *lockdown image: pgsty/mc:RELEASE.2026-10-26T00-00-00Z@sha256:ce62c9053c69ce12a527a322345b5ad9f44b5f8a7b8189f82e516f2e3f30f1d8 entrypoint: ["sh", "/work/init.sh"] environment: S3_BUCKET: ${S3_BUCKET:-messenger-attachments} volumes: - ./infra/s3/init.sh:/work/init.sh:ro - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: s3-init}} depends_on: s3: {condition: service_healthy} deploy: resources: limits: {cpus: "0.25", memory: 192M} rabbitmq: image: rabbitmq:4.0.5-alpine@sha256:e045b5166b9188a38eee5c99411709aa1f0ffa2ac75664053e64cb69411f7c32 hostname: rabbitmq security_opt: [no-new-privileges:true] environment: RABBITMQ_NODENAME: rabbit@localhost ERL_EPMD_ADDRESS: 127.0.0.1 volumes: - rabbitmqdata:/var/lib/rabbitmq - ./infra/rabbitmq/10-messenger.conf:/etc/rabbitmq/conf.d/10-messenger.conf:ro - ./infra/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins:ro - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: rabbitmq}} healthcheck: test: ["CMD", "rabbitmq-diagnostics", "-q", "check_port_connectivity"] interval: 5s timeout: 8s start_period: 20s retries: 12 depends_on: bootstrap: {condition: service_completed_successfully} stop_grace_period: 30s restart: unless-stopped deploy: resources: limits: {cpus: "0.5", memory: 512M} api: <<: *runtime environment: <<: [*runtime-env, *s3-env, *otel-env] BAO_ROLE: api OTEL_SERVICE_NAME: messenger-api SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760} MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000} volumes: - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: api}} depends_on: openbao: {condition: service_healthy} migrate: {condition: service_completed_successfully} s3-init: {condition: service_completed_successfully} deploy: replicas: ${API_REPLICAS:-2} resources: limits: {cpus: "0.5", memory: 384M} relay: <<: *runtime environment: <<: [*runtime-env, *otel-env] BAO_ROLE: relay OTEL_SERVICE_NAME: messenger-relay AMQP_TOPOLOGY_PREPROVISIONED: "true" volumes: - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: relay}} depends_on: openbao: {condition: service_healthy} migrate: {condition: service_completed_successfully} rabbitmq: {condition: service_healthy} deploy: resources: limits: {cpus: "0.25", memory: 192M} worker: <<: *runtime environment: <<: [*runtime-env, *s3-env, *otel-env] BAO_ROLE: worker OTEL_SERVICE_NAME: messenger-worker AMQP_TOPOLOGY_PREPROVISIONED: "true" MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760} MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000} WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2} JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60} volumes: - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: worker}} depends_on: openbao: {condition: service_healthy} migrate: {condition: service_completed_successfully} rabbitmq: {condition: service_healthy} s3-init: {condition: service_completed_successfully} stop_grace_period: 30s deploy: resources: limits: {cpus: "1.0", memory: 768M} reconciler: <<: *runtime command: ["node", "dist/stand.js", "--apply", "--loop"] environment: <<: [*runtime-env, *s3-env] BAO_ROLE: reconciler volumes: - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: reconciler}} depends_on: openbao: {condition: service_healthy} migrate: {condition: service_completed_successfully} s3-init: {condition: service_completed_successfully} deploy: resources: limits: {cpus: "0.25", memory: 192M} lb: <<: *lockdown image: haproxy:3.0.6-alpine user: "1000:1000" ports: - "127.0.0.1:${HTTPS_PORT:-8443}:8443" volumes: - ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: lb}} healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8404/"] interval: 3s timeout: 2s retries: 20 depends_on: api: {condition: service_started} restart: unless-stopped deploy: resources: limits: {cpus: "0.25", memory: 96M} otel-collector: <<: *lockdown image: otel/opentelemetry-collector-contrib:0.115.1@sha256:d2da12c4336a79758826700be9e21ecf4a9f7d945b7f8a58ba55ee3fa45427c8 command: ["--config=/etc/otelcol/collector.yaml"] volumes: - ./infra/otel/collector.yaml:/etc/otelcol/collector.yaml:ro - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: otel-collector}} networks: [default, telemetry] depends_on: bootstrap: {condition: service_completed_successfully} restart: unless-stopped deploy: resources: limits: {cpus: "0.5", memory: 256M} collector-scrape: <<: *telemetry-proxy user: "10001:10001" network_mode: service:otel-collector environment: {READ_PORT: "8888", INGEST_PORT: "8888", MODE: scrape} volumes: - ./infra/haproxy/telemetry.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: otel-collector}} prometheus: <<: *lockdown image: prom/prometheus:v3.1.0 command: - --config.file=/etc/prometheus/prometheus.yml - --storage.tsdb.path=/prometheus - --storage.tsdb.retention.time=7d - --storage.tsdb.retention.size=1GB - --web.enable-otlp-receiver - --web.listen-address=127.0.0.1:9090 volumes: - ./infra/prometheus:/etc/prometheus:ro - prometheusdata:/prometheus - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: prometheus}} networks: [telemetry] depends_on: bootstrap: {condition: service_completed_successfully} restart: unless-stopped deploy: resources: limits: {cpus: "0.5", memory: 512M} prometheus-tls: <<: *telemetry-proxy user: "65534:65534" network_mode: service:prometheus environment: {READ_PORT: "9090", INGEST_PORT: "9090", MODE: backend} volumes: - ./infra/haproxy/telemetry.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: prometheus}} loki: <<: *lockdown image: grafana/loki:3.3.2 command: ["-config.file=/etc/loki/loki.yaml"] volumes: - ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro - lokidata:/loki networks: [telemetry] restart: unless-stopped deploy: resources: limits: {cpus: "0.5", memory: 512M} loki-tls: <<: *telemetry-proxy user: "10001:10001" network_mode: service:loki environment: {READ_PORT: "3100", INGEST_PORT: "3100", MODE: backend} volumes: - ./infra/haproxy/telemetry.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: loki}} depends_on: bootstrap: {condition: service_completed_successfully} tempo: <<: *lockdown image: grafana/tempo:2.6.1 command: ["-config.file=/etc/tempo/tempo.yaml"] volumes: - ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro - tempodata:/var/tempo networks: [telemetry] restart: unless-stopped deploy: resources: limits: {cpus: "0.5", memory: 512M} tempo-tls: <<: *telemetry-proxy user: "10001:10001" network_mode: service:tempo environment: {READ_PORT: "3200", INGEST_PORT: "4318", MODE: backend} volumes: - ./infra/haproxy/telemetry.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: tempo}} depends_on: bootstrap: {condition: service_completed_successfully} grafana: <<: *lockdown image: grafana/grafana:11.4.0@sha256:d8ea37798ccc41061a62ab080f2676dda6bf7815558499f901bdb0f533a456fb entrypoint: ["sh", "/work/grafana.sh"] ports: - "127.0.0.1:${GRAFANA_PORT:-3000}:3000" environment: GF_SERVER_PROTOCOL: https GF_SERVER_CERT_FILE: /run/tls/grafana.crt GF_SERVER_CERT_KEY: /run/tls/grafana.key GF_SECURITY_ADMIN_USER: admin GF_SECURITY_ADMIN_PASSWORD__FILE: /run/tls/admin_password GF_SECURITY_COOKIE_SECURE: "true" GF_AUTH_ANONYMOUS_ENABLED: "false" GF_USERS_ALLOW_SIGN_UP: "false" GF_ANALYTICS_REPORTING_ENABLED: "false" GF_ANALYTICS_CHECK_FOR_UPDATES: "false" GF_NEWS_NEWS_FEED_ENABLED: "false" volumes: - ./infra/grafana/start.sh:/work/grafana.sh:ro - ./infra/grafana/provisioning:/etc/grafana/provisioning:ro - ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro - grafanadata:/var/lib/grafana - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: grafana}} networks: [telemetry, admin] depends_on: bootstrap: {condition: service_completed_successfully} prometheus-tls: {condition: service_started} loki-tls: {condition: service_started} tempo-tls: {condition: service_started} restart: unless-stopped deploy: resources: limits: {cpus: "0.5", memory: 256M} checks: <<: *lockdown profiles: [tools] image: mtusi-messenger-lab7-bootstrap:dev entrypoint: [python] working_dir: /work volumes: - .:/work:ro - {type: volume, source: secrets, target: /run/tls, read_only: true, volume: {subpath: checks}} depends_on: bootstrap: {condition: service_completed_successfully} deploy: resources: limits: {cpus: "0.5", memory: 128M} volumes: secrets: baodata: pgdata: s3data: rabbitmqdata: prometheusdata: lokidata: tempodata: grafanadata: networks: telemetry: internal: true admin: