version: '3.8' services: postgres: image: postgres:17.6-alpine3.22 environment: POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] volumes: [postgres_data:/var/lib/postgresql/data] networks: [data] healthcheck: test: [CMD-SHELL, 'pg_isready -U messenger -d messenger'] interval: 2s timeout: 2s retries: 15 stop_grace_period: 20s deploy: replicas: 1 placement: constraints: [node.labels.mtusi_lab4_storage == true] resources: limits: {cpus: '1.0', memory: 512M} update_config: {parallelism: 1, order: stop-first} redis: image: redis:7.4.5-alpine3.21 command: [redis-server, /usr/local/etc/redis/redis.conf] configs: - source: redis target: /usr/local/etc/redis/redis.conf volumes: [redis_data:/data] networks: [data] healthcheck: test: [CMD, redis-cli, ping] interval: 2s timeout: 1s retries: 15 stop_grace_period: 20s deploy: replicas: 1 placement: constraints: [node.labels.mtusi_lab4_storage == true] resources: limits: {cpus: '0.5', memory: 128M} update_config: {parallelism: 1, order: stop-first} minio: image: ${S3_IMAGE:-mtusi-minio:RELEASE.2025-09-07T16-13-09Z} secrets: [s3_root_access_key, s3_root_secret_key] volumes: [s3_data:/data] networks: [data] healthcheck: test: [CMD, wget, -q, -T, '2', -O, /dev/null, 'http://127.0.0.1:9000/minio/health/live'] interval: 2s timeout: 3s start_period: 15s retries: 15 stop_grace_period: 20s deploy: replicas: 1 placement: constraints: [node.labels.mtusi_lab4_storage == true] resources: limits: {cpus: '1.0', memory: 512M} update_config: {parallelism: 1, order: stop-first} api: image: ${API_IMAGE:-mtusi-messenger:lab4} environment: INSTANCE_ID: '{{.Task.ID}}' POSTGRES_HOST: postgres POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password CURSOR_KEY_FILE: /run/secrets/cursor_key POSTGRES_MAX_CONNS: '10' REDIS_ADDR: redis:6379 SESSION_TTL_SECONDS: '3600' QUERY_TIMEOUT_MS: '1000' S3_ENDPOINT: minio:9000 S3_BUCKET: attachments S3_ACCESS_KEY_FILE: /run/secrets/s3_access_key S3_SECRET_KEY_FILE: /run/secrets/s3_secret_key S3_USE_SSL: 'false' GOMEMLIMIT: 1152MiB GOGC: '50' secrets: [postgres_password, cursor_key, s3_access_key, s3_secret_key] networks: [backend, data] stop_grace_period: 15s healthcheck: test: [CMD, wget, -q, -T, '2', -O, /dev/null, 'http://127.0.0.1:8080/health/ready'] interval: 2s timeout: 3s start_period: 10s retries: 3 deploy: replicas: ${API_REPLICAS:-2} endpoint_mode: dnsrr resources: limits: {cpus: '1.0', memory: 1536M} restart_policy: {condition: any, delay: 1s} update_config: parallelism: 1 order: start-first delay: 5s monitor: 15s failure_action: rollback rollback_config: {parallelism: 1, order: start-first} lb: image: haproxy:3.2.6-alpine configs: - source: haproxy target: /usr/local/etc/haproxy/haproxy.cfg networks: [backend] ports: - target: 8080 published: ${PORT:-8080} protocol: tcp mode: host healthcheck: test: [CMD, haproxy, -c, -f, /usr/local/etc/haproxy/haproxy.cfg] interval: 5s timeout: 2s retries: 3 deploy: replicas: 1 resources: limits: {cpus: '0.5', memory: 128M} update_config: {parallelism: 1, order: stop-first} networks: backend: driver: overlay data: driver: overlay volumes: postgres_data: redis_data: s3_data: configs: haproxy: file: ./infra/haproxy.cfg redis: file: ./infra/redis.conf s3_bootstrap: file: ./infra/s3-bootstrap.sh s3_policy: file: ./infra/s3-policy.json secrets: postgres_password: external: true name: ${STACK_NAME:-mtusi-lab4}_postgres_password cursor_key: external: true name: ${STACK_NAME:-mtusi-lab4}_cursor_key s3_root_access_key: external: true name: ${STACK_NAME:-mtusi-lab4}_s3_root_access_key s3_root_secret_key: external: true name: ${STACK_NAME:-mtusi-lab4}_s3_root_secret_key s3_access_key: external: true name: ${STACK_NAME:-mtusi-lab4}_s3_access_key s3_secret_key: external: true name: ${STACK_NAME:-mtusi-lab4}_s3_secret_key