name: mtusi-lab4 x-application: &application image: mtusi-messenger:lab4 env_file: .env 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 api: <<: *application build: . deploy: replicas: ${API_REPLICAS:-2} 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 postgres-restore: <<: *postgres profiles: [research] volumes: [restore_data:/var/lib/postgresql/data] volumes: postgres_data: valkey_data: restore_data: s3_data: networks: s3-internal: internal: true secrets: 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