services: postgres: image: postgres:16.2-alpine environment: POSTGRES_USER: appuser POSTGRES_PASSWORD: apppassword POSTGRES_DB: messenger_db volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U appuser -d messenger_db"] interval: 3s timeout: 2s retries: 5 deploy: resources: limits: cpus: "1.00" memory: 512M restart: unless-stopped redis: image: redis:7.2.4-alpine command: redis-server --appendonly yes volumes: - redis_data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 3s timeout: 2s retries: 5 deploy: resources: limits: cpus: "0.50" memory: 256M restart: unless-stopped migrator: build: context: . dockerfile: Dockerfile command: ["python", "src/migrate.py"] environment: DATABASE_URL: postgresql://appuser:apppassword@postgres:5432/messenger_db volumes: - ./migrations:/app/migrations:ro - ./src:/app/src:ro depends_on: postgres: condition: service_healthy restart: "no" api: build: context: . dockerfile: Dockerfile image: mtusi-messenger:lab3 command: ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"] env_file: - .env volumes: - ./secrets:/run/secrets:ro - ./src:/app/src:ro - ./scripts:/app/scripts:ro depends_on: postgres: condition: service_healthy redis: condition: service_healthy migrator: condition: service_completed_successfully healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8000/health/live"] interval: 3s timeout: 2s retries: 3 deploy: replicas: 2 resources: limits: cpus: "0.50" memory: 256M restart: unless-stopped load_balancer: image: nginx:1.25.4-alpine volumes: - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro ports: - "8080:8080" depends_on: - api healthcheck: test: ["CMD-SHELL", "curl -f http://localhost:8080/health/live || exit 1"] interval: 3s timeout: 2s retries: 3 deploy: resources: limits: cpus: "0.50" memory: 128M restart: unless-stopped volumes: postgres_data: name: mtusi2026lab3_postgres_data redis_data: name: mtusi2026lab3_redis_data