name: mtusi-messenger-lab3 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: "1.0" memory: 1G reservations: cpus: "0.25" memory: 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: "0.5" 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 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: "3600" IDEMPOTENCY_TTL_SECONDS: "86400" 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: 2 resources: limits: cpus: "0.5" memory: 256M reservations: cpus: "0.1" memory: 64M networks: - internal lb: image: nginx:1.27.4-alpine restart: unless-stopped ports: - "8080:8080" volumes: - ./infra/nginx.conf:/etc/nginx/nginx.conf:ro depends_on: api: condition: service_started 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