name: mtusi-messenger-lab3 x-api-resources: &api-resources limits: cpus: "${API_CPUS:-0.5}" memory: "${API_MEMORY:-256M}" reservations: cpus: "${API_CPU_RESERVATION:-0.1}" memory: "${API_MEMORY_RESERVATION:-64M}" services: postgres: image: postgres:16.4-alpine restart: unless-stopped environment: POSTGRES_USER: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password POSTGRES_DB: messenger secrets: - postgres_password volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"] interval: 5s timeout: 3s retries: 10 start_period: 5s deploy: resources: limits: cpus: "${POSTGRES_CPUS:-1.0}" memory: ${POSTGRES_MEMORY:-1G} reservations: cpus: "${POSTGRES_CPU_RESERVATION:-0.25}" memory: ${POSTGRES_MEMORY_RESERVATION:-256M} networks: - internal redis: image: redis:7.4-alpine restart: unless-stopped command: - redis-server - --appendonly - "yes" - --appendfsync - everysec - --save - "60 1000" volumes: - redis_data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 10 start_period: 5s deploy: resources: limits: cpus: "${REDIS_CPUS:-0.5}" memory: ${REDIS_MEMORY:-256M} networks: - internal migrate: build: context: . dockerfile: Dockerfile image: mtusi-messenger-api:lab3 restart: "no" command: ["migrate"] environment: DATABASE_URL_FILE: /run/secrets/database_url secrets: - database_url depends_on: postgres: condition: service_healthy healthcheck: disable: true deploy: resources: limits: cpus: "0.5" memory: 128M networks: - internal api: build: context: . dockerfile: Dockerfile image: mtusi-messenger-api:lab3 restart: unless-stopped environment: APP_HOST: "0.0.0.0" APP_PORT: "8080" DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url SESSION_STORE: "redis" SESSION_TTL_SECONDS: "${SESSION_TTL_SECONDS:-3600}" IDEMPOTENCY_TTL_SECONDS: "${IDEMPOTENCY_TTL_SECONDS:-86400}" SHUTDOWN_DRAIN_SECONDS: "${SHUTDOWN_DRAIN_SECONDS:-3}" GIN_MODE: "release" secrets: - database_url - cache_url depends_on: postgres: condition: service_healthy redis: condition: service_healthy migrate: condition: service_completed_successfully expose: - "8080" stop_grace_period: 15s healthcheck: test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:8080/health/ready >/dev/null || exit 1"] interval: 5s timeout: 3s retries: 5 start_period: 10s deploy: replicas: ${API_REPLICAS:-2} resources: *api-resources networks: - internal lb: image: nginx:1.27.4-alpine restart: unless-stopped ports: - "${LB_PORT:-8080}:8080" volumes: - ./infra/nginx.conf:/etc/nginx/nginx.conf:ro depends_on: api: condition: service_started deploy: resources: limits: cpus: "0.5" memory: 128M networks: - internal secrets: postgres_password: file: ./secrets/postgres_password database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url volumes: postgres_data: redis_data: networks: internal: driver: bridge