name: messenger-lab4 services: api: build: . scale: 2 environment: SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} GOMEMLIMIT: 1024MiB DATABASE_PASSWORD_FILE: /run/secrets/postgres_password REDIS_ADDR: redis:6379 S3_ENDPOINT: http://s3:9000 S3_REGION: ${S3_REGION:-us-east-1} S3_BUCKET: ${S3_BUCKET:-messenger-attachments} S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key secrets: [postgres_password, s3_access_key_id, s3_secret_access_key] # Bounded ephemeral staging; one upload at a time per API. tmpfs: - /tmp:size=16m,mode=1777 cpus: 1.0 # 16-bit PNG decoding includes the image and scanline buffers, not just bytes. mem_limit: 1536m memswap_limit: 1536m stop_grace_period: 15s depends_on: postgres: condition: service_healthy migrate: condition: service_completed_successfully redis: condition: service_started s3-bootstrap: condition: service_completed_successfully s3: build: context: ./infra/s3 target: server command: [server, /data, --console-address, "127.0.0.1:9001"] environment: MINIO_ROOT_USER_FILE: /run/secrets/s3_root_user MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_root_password MINIO_BROWSER: "off" MINIO_REGION_NAME: ${S3_REGION:-us-east-1} secrets: [s3_root_user, s3_root_password] volumes: - s3_lab4_data_v1:/data cpus: 1.0 mem_limit: 512m stop_grace_period: 30s # No published ports: S3 is reachable only inside the Compose network. s3-bootstrap: build: context: ./infra/s3 target: client entrypoint: [/bin/sh, /bootstrap/bootstrap.sh] environment: S3_BUCKET: ${S3_BUCKET:-messenger-attachments} MC_CONFIG_DIR: /tmp/mc secrets: [s3_root_user, s3_root_password, s3_access_key_id, s3_secret_access_key] volumes: - ./infra/s3:/bootstrap:ro tmpfs: [/tmp] cpus: 0.25 mem_limit: 128m depends_on: s3: condition: service_started lb: image: haproxy:3.2.4-alpine ports: - "127.0.0.1:${LB_PORT:-8084}:8080" volumes: - ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro cpus: 0.5 mem_limit: 64m depends_on: api: condition: service_healthy postgres: image: postgres:17.9-bookworm environment: POSTGRES_DB: messenger POSTGRES_USER: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password POSTGRES_INITDB_ARGS: --encoding=UTF8 secrets: [postgres_password] volumes: - postgres_lab4_data_v1:/var/lib/postgresql/data cpus: 1.0 mem_limit: 512m healthcheck: test: [CMD-SHELL, "pg_isready -U messenger -d messenger"] interval: 3s timeout: 3s retries: 20 start_period: 10s stop_grace_period: 30s redis: image: redis:7.4.11-alpine command: [redis-server, --save, "", --appendonly, "no", --maxmemory, 64mb, --maxmemory-policy, allkeys-lru] tmpfs: [/data] cpus: 0.25 mem_limit: 128m healthcheck: test: [CMD, redis-cli, ping] interval: 3s timeout: 2s retries: 10 migrate: image: postgres:17.9-bookworm environment: PGHOST: postgres PGUSER: messenger PGDATABASE: messenger PGCONNECT_TIMEOUT: "5" secrets: [postgres_password] volumes: - ./migrations:/migrations:ro entrypoint: [/bin/sh, -ec] command: - 'export PGPASSWORD="$$(cat /run/secrets/postgres_password)"; exec psql -X -f /migrations/apply.psql' cpus: 0.5 mem_limit: 128m depends_on: postgres: condition: service_healthy secrets: postgres_password: file: ./secrets/postgres_password.txt s3_root_user: file: ./secrets/s3_root_user.txt s3_root_password: file: ./secrets/s3_root_password.txt s3_access_key_id: file: ./secrets/s3_access_key_id.txt s3_secret_access_key: file: ./secrets/s3_secret_access_key.txt volumes: postgres_lab4_data_v1: s3_lab4_data_v1: