forked from mtusi2026/mtusi2026lab6
365 lines
9.8 KiB
YAML
365 lines
9.8 KiB
YAML
services:
|
|
load_balancer:
|
|
image: nginx:1.27-alpine
|
|
ports:
|
|
- "8080:8080"
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
depends_on:
|
|
api-1:
|
|
condition: service_healthy
|
|
api-2:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/live"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.25'
|
|
memory: 128M
|
|
|
|
migration:
|
|
image: postgres:16-alpine
|
|
restart: "no"
|
|
environment:
|
|
PGPASSWORD: postgres
|
|
command: >
|
|
sh -c "until pg_isready -h postgres -U postgres -d messenger; do sleep 1; done;
|
|
psql -h postgres -U postgres -d messenger -f /docker-entrypoint-initdb.d/init.sql"
|
|
volumes:
|
|
- ./infra/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.25'
|
|
memory: 128M
|
|
|
|
api-1:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
image: highload-messenger:lab6
|
|
stop_grace_period: 15s
|
|
environment:
|
|
APP_HOST: "0.0.0.0"
|
|
APP_PORT: "8080"
|
|
APP_ENV: "lab"
|
|
INSTANCE_ID: "api-1"
|
|
SESSION_TTL_SECONDS: "3600"
|
|
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/messenger"
|
|
SESSION_STORE: "redis"
|
|
CACHE_URL: "redis://redis:6379/0"
|
|
IDEMPOTENCY_TTL_SECONDS: "86400"
|
|
BROKER_URL: "amqp://messenger:messenger_broker_pass@broker:5672/"
|
|
S3_ENDPOINT: "http://minio:9000"
|
|
S3_REGION: "us-east-1"
|
|
S3_BUCKET: "messenger-attachments"
|
|
S3_ACCESS_KEY_ID: "minioadmin"
|
|
S3_SECRET_ACCESS_KEY: "minioadmin"
|
|
MAX_UPLOAD_BYTES: "10485760"
|
|
MAX_IMAGE_PIXELS: "40000000"
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: "${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}"
|
|
OTEL_TRACES_SAMPLER: "${OTEL_TRACES_SAMPLER:-always_on}"
|
|
OTEL_TRACES_SAMPLER_ARG: "${OTEL_TRACES_SAMPLER_ARG:-1.0}"
|
|
OTEL_SDK_DISABLED: "${OTEL_SDK_DISABLED:-false}"
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
minio:
|
|
condition: service_healthy
|
|
broker:
|
|
condition: service_healthy
|
|
migration:
|
|
condition: service_completed_successfully
|
|
healthcheck:
|
|
test: ["CMD", "python3", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8080/health/ready')"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.50'
|
|
memory: 512M
|
|
|
|
api-2:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
image: highload-messenger:lab6
|
|
stop_grace_period: 15s
|
|
environment:
|
|
APP_HOST: "0.0.0.0"
|
|
APP_PORT: "8080"
|
|
APP_ENV: "lab"
|
|
INSTANCE_ID: "api-2"
|
|
SESSION_TTL_SECONDS: "3600"
|
|
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/messenger"
|
|
SESSION_STORE: "redis"
|
|
CACHE_URL: "redis://redis:6379/0"
|
|
IDEMPOTENCY_TTL_SECONDS: "86400"
|
|
BROKER_URL: "amqp://messenger:messenger_broker_pass@broker:5672/"
|
|
S3_ENDPOINT: "http://minio:9000"
|
|
S3_REGION: "us-east-1"
|
|
S3_BUCKET: "messenger-attachments"
|
|
S3_ACCESS_KEY_ID: "minioadmin"
|
|
S3_SECRET_ACCESS_KEY: "minioadmin"
|
|
MAX_UPLOAD_BYTES: "10485760"
|
|
MAX_IMAGE_PIXELS: "40000000"
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: "${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}"
|
|
OTEL_TRACES_SAMPLER: "${OTEL_TRACES_SAMPLER:-always_on}"
|
|
OTEL_TRACES_SAMPLER_ARG: "${OTEL_TRACES_SAMPLER_ARG:-1.0}"
|
|
OTEL_SDK_DISABLED: "${OTEL_SDK_DISABLED:-false}"
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
minio:
|
|
condition: service_healthy
|
|
broker:
|
|
condition: service_healthy
|
|
migration:
|
|
condition: service_completed_successfully
|
|
healthcheck:
|
|
test: ["CMD", "python3", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8080/health/ready')"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.50'
|
|
memory: 512M
|
|
|
|
worker:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
image: highload-messenger:lab6
|
|
command: python -m app.worker
|
|
stop_grace_period: 15s
|
|
environment:
|
|
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/messenger"
|
|
BROKER_URL: "amqp://messenger:messenger_broker_pass@broker:5672/"
|
|
S3_ENDPOINT: "http://minio:9000"
|
|
S3_REGION: "us-east-1"
|
|
S3_BUCKET: "messenger-attachments"
|
|
S3_ACCESS_KEY_ID: "minioadmin"
|
|
S3_SECRET_ACCESS_KEY: "minioadmin"
|
|
WORKER_CONCURRENCY: "4"
|
|
WORKER_LEASE_SECONDS: "60"
|
|
MAX_JOB_RETRIES: "5"
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: "${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}"
|
|
OTEL_TRACES_SAMPLER: "${OTEL_TRACES_SAMPLER:-always_on}"
|
|
OTEL_TRACES_SAMPLER_ARG: "${OTEL_TRACES_SAMPLER_ARG:-1.0}"
|
|
OTEL_SDK_DISABLED: "${OTEL_SDK_DISABLED:-false}"
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "python -c 'import pika, os; conn = pika.BlockingConnection(pika.URLParameters(os.environ[\"BROKER_URL\"])); conn.close()' || exit 1"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 3
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
broker:
|
|
condition: service_healthy
|
|
minio:
|
|
condition: service_healthy
|
|
migration:
|
|
condition: service_completed_successfully
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.50'
|
|
memory: 512M
|
|
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
environment:
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: postgres
|
|
POSTGRES_DB: messenger
|
|
volumes:
|
|
- pg_data:/var/lib/postgresql/data
|
|
- ./infra/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U postgres -d messenger"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.50'
|
|
memory: 512M
|
|
|
|
broker:
|
|
image: rabbitmq:3.13-alpine
|
|
environment:
|
|
RABBITMQ_DEFAULT_USER: messenger
|
|
RABBITMQ_DEFAULT_PASS: messenger_broker_pass
|
|
volumes:
|
|
- rabbitmq_data:/var/lib/rabbitmq
|
|
healthcheck:
|
|
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
|
|
interval: 3s
|
|
timeout: 5s
|
|
retries: 10
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.50'
|
|
memory: 512M
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
command: ["redis-server", "--appendonly", "yes"]
|
|
volumes:
|
|
- redis_data:/data
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.25'
|
|
memory: 256M
|
|
|
|
minio:
|
|
image: cleanstart/minio:0.20260330.001845
|
|
user: "0:0"
|
|
command: server /data --address ":9000" --console-address ":9001"
|
|
environment:
|
|
MINIO_ROOT_USER: minioadmin
|
|
MINIO_ROOT_PASSWORD: minioadmin
|
|
volumes:
|
|
- minio_data:/data
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:9000/minio/health/live"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.50'
|
|
memory: 512M
|
|
|
|
otel-collector:
|
|
image: otel/opentelemetry-collector-contrib:0.96.0
|
|
restart: unless-stopped
|
|
command: ["--config=/etc/otelcol-contrib/config.yaml"]
|
|
volumes:
|
|
- ./infra/otel/collector.yaml:/etc/otelcol-contrib/config.yaml:ro
|
|
ports:
|
|
- "4318:4318"
|
|
depends_on:
|
|
- prometheus
|
|
- tempo
|
|
- loki
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.25'
|
|
memory: 256M
|
|
|
|
prometheus:
|
|
image: prom/prometheus:v2.51.0
|
|
restart: unless-stopped
|
|
command:
|
|
- "--config.file=/etc/prometheus/prometheus.yml"
|
|
- "--storage.tsdb.path=/prometheus"
|
|
- "--web.enable-lifecycle"
|
|
volumes:
|
|
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
|
- prometheus_data:/prometheus
|
|
ports:
|
|
- "9090:9090"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.25'
|
|
memory: 256M
|
|
|
|
tempo:
|
|
image: grafana/tempo:2.4.1
|
|
restart: unless-stopped
|
|
command: ["-config.file=/etc/tempo.yaml"]
|
|
volumes:
|
|
- ./infra/tempo/tempo.yaml:/etc/tempo.yaml:ro
|
|
- tempo_data:/var/tempo
|
|
ports:
|
|
- "3200:3200"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.25'
|
|
memory: 256M
|
|
|
|
loki:
|
|
image: grafana/loki:3.0.0
|
|
restart: unless-stopped
|
|
command: ["-config.file=/etc/loki/local-config.yaml"]
|
|
volumes:
|
|
- ./infra/loki/loki.yaml:/etc/loki/local-config.yaml:ro
|
|
- loki_data:/loki
|
|
ports:
|
|
- "3100:3100"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.25'
|
|
memory: 256M
|
|
|
|
grafana:
|
|
image: grafana/grafana:10.4.1
|
|
restart: unless-stopped
|
|
environment:
|
|
- GF_SECURITY_ADMIN_USER=admin
|
|
- GF_SECURITY_ADMIN_PASSWORD=admin
|
|
- GF_USERS_ALLOW_SIGN_UP=false
|
|
volumes:
|
|
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
|
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
|
- grafana_data:/var/lib/grafana
|
|
ports:
|
|
- "3000:3000"
|
|
depends_on:
|
|
- prometheus
|
|
- tempo
|
|
- loki
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.25'
|
|
memory: 256M
|
|
|
|
volumes:
|
|
pg_data:
|
|
redis_data:
|
|
minio_data:
|
|
rabbitmq_data:
|
|
prometheus_data:
|
|
tempo_data:
|
|
loki_data:
|
|
grafana_data:
|