x-lab-number: 3 x-required-roles: - api - postgres - load_balancer # Лабораторная 3. LB + 2 API-реплики + PostgreSQL + Redis. services: postgres: image: postgres:18.6-alpine container_name: mtuci-postgres environment: POSTGRES_USER: ${POSTGRES_USER:-messenger} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} POSTGRES_DB: ${POSTGRES_DB:-high_load_messenger} volumes: - postgres-data:/var/lib/postgresql healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-messenger} -d ${POSTGRES_DB:-high_load_messenger}"] interval: 5s timeout: 5s retries: 20 start_period: 30s restart: unless-stopped redis: image: redis:7.4.1-alpine container_name: mtuci-redis command: ["redis-server", "--appendonly", "yes", "--appendfsync", "everysec", "--save", "60", "1"] volumes: - redis-data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 10 start_period: 3s restart: unless-stopped api: build: . image: mtuci-messenger:lab3 # НЕТ container_name: нужно масштабирование (--scale api=2). # НЕТ ports: реплики не публикуют порт наружу — только через LB. env_file: - .env depends_on: postgres: condition: service_healthy redis: condition: service_healthy healthcheck: test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready').read()"] interval: 5s timeout: 3s retries: 5 start_period: 10s restart: unless-stopped deploy: replicas: 2 resources: limits: cpus: "1.0" memory: 512M lb: image: nginx:1.27.3-alpine container_name: mtuci-lb ports: - "127.0.0.1:8080:80" volumes: - ./infra/nginx.conf:/etc/nginx/nginx.conf:ro depends_on: api: condition: service_healthy restart: unless-stopped volumes: postgres-data: name: mtuci2026lab3_postgres-data redis-data: name: mtuci2026lab3_redis-data networks: default: name: mtuci2026lab3_default