138 lines
3.6 KiB
YAML
138 lines
3.6 KiB
YAML
x-lab-number: 3
|
|
x-required-roles:
|
|
- api
|
|
- postgres
|
|
- load_balancer
|
|
|
|
# Лабораторная 3. LB + 2 API-реплики + PostgreSQL + Redis + one-shot migrate.
|
|
# Миграции вынесены в отдельный сервис migrate.
|
|
# Лимиты CPU/RAM заданы для ВСЕХ сервисов
|
|
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
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 1G
|
|
reservations:
|
|
cpus: "0.25"
|
|
memory: 256M
|
|
|
|
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
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 256M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 64M
|
|
|
|
migrate:
|
|
build: .
|
|
image: mtuci-messenger:lab3
|
|
# One-shot: применяет схему БД один раз и завершается с кодом 0.
|
|
# Реплики api стартуют только после успешного выхода (см. depends_on).
|
|
command: ["python", "-m", "app.storage.db"]
|
|
env_file:
|
|
- .env
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 256M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 64M
|
|
|
|
api:
|
|
build: .
|
|
image: mtuci-messenger:lab3
|
|
# НЕТ container_name: нужно масштабирование (--scale api=2).
|
|
# НЕТ ports: реплики не публикуют порт наружу — только через LB.
|
|
env_file:
|
|
- .env
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
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
|
|
reservations:
|
|
cpus: "0.25"
|
|
memory: 128M
|
|
|
|
lb:
|
|
image: nginx:1.27.3-alpine
|
|
container_name: mtuci-lb
|
|
ports:
|
|
- "127.0.0.1:8080:80"
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 128M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 32M
|
|
|
|
volumes:
|
|
postgres-data:
|
|
name: mtuci2026lab3_postgres-data
|
|
redis-data:
|
|
name: mtuci2026lab3_redis-data
|
|
|
|
networks:
|
|
default:
|
|
name: mtuci2026lab3_default |