# Локальный стенд лабораторной 3. Секреты только из .env, volumes не удаляются restart-скриптом. # Клиент ходит в haproxy:8080. Реплики api порт наружу не публикуют. name: messenger-lab3 services: postgres: image: postgres:16.10-bookworm environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} command: - postgres - -c - synchronous_commit=on - -c - max_connections=50 volumes: - pgdata:/var/lib/postgresql/data ports: - "127.0.0.1:5432:5432" healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] interval: 5s timeout: 3s retries: 12 start_period: 5s deploy: resources: limits: cpus: "1.00" memory: 512M restart: unless-stopped redis: image: redis:7.4.6-alpine environment: REDIS_PASSWORD: ${REDIS_PASSWORD} # exec нужен, чтобы SIGTERM пришёл самому Redis и он дописал AOF перед выходом. command: - sh - -c - exec redis-server --appendonly yes --appendfsync everysec --aof-use-rdb-preamble yes --dir /data --requirepass "$$REDIS_PASSWORD" --bind 0.0.0.0 --protected-mode yes volumes: - redisdata:/data ports: - "127.0.0.1:6379:6379" healthcheck: test: ["CMD-SHELL", "redis-cli --no-auth-warning -a \"$$REDIS_PASSWORD\" ping | grep -q PONG"] interval: 5s timeout: 3s retries: 12 start_period: 3s deploy: resources: limits: cpus: "0.25" memory: 128M restart: unless-stopped migrate: build: . image: messenger-api:lab3 command: ["migrate"] depends_on: postgres: condition: service_healthy environment: DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable healthcheck: disable: true deploy: resources: limits: cpus: "0.50" memory: 128M restart: "no" api: build: . image: messenger-api:lab3 depends_on: migrate: condition: service_completed_successfully postgres: condition: service_healthy redis: condition: service_healthy environment: APP_HOST: 0.0.0.0 APP_PORT: "8080" APP_ENV: lab SHUTDOWN_TIMEOUT_SECONDS: ${SHUTDOWN_TIMEOUT_SECONDS:-8} DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0 SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400} DB_MAX_CONNS: ${DB_MAX_CONNS:-8} ARGON2_TIME: ${ARGON2_TIME:-2} ARGON2_MEMORY_KIB: ${ARGON2_MEMORY_KIB:-19456} ARGON2_THREADS: ${ARGON2_THREADS:-1} expose: - "8080" healthcheck: test: ["CMD", "/messenger", "healthcheck"] interval: 5s timeout: 3s retries: 12 start_period: 10s deploy: replicas: ${API_REPLICAS:-2} resources: limits: cpus: "${API_CPU_LIMIT:-0.50}" memory: ${API_MEM_LIMIT:-256M} restart: unless-stopped haproxy: image: haproxy:2.8.14 depends_on: api: condition: service_healthy volumes: - ./deploy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro ports: - "127.0.0.1:8080:8080" healthcheck: test: ["CMD", "haproxy", "-c", "-f", "/usr/local/etc/haproxy/haproxy.cfg"] interval: 5s timeout: 3s retries: 6 start_period: 3s deploy: resources: limits: cpus: "0.25" memory: 128M restart: unless-stopped volumes: pgdata: redisdata: