474 lines
14 KiB
YAML
474 lines
14 KiB
YAML
x-lab-number: 6
|
|
x-required-roles:
|
|
- api
|
|
- postgres
|
|
- load_balancer
|
|
- s3
|
|
- broker
|
|
- worker
|
|
- otel_collector
|
|
- telemetry_storage
|
|
- grafana
|
|
|
|
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
|
|
|
|
minio:
|
|
image: netvark/minio:20260213
|
|
container_name: mtuci-minio
|
|
command: ["server", "/data", "--console-address", ":9001"]
|
|
environment:
|
|
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
|
|
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin}
|
|
MINIO_BROWSER_REDIRECT_URL: http://localhost:9001
|
|
volumes:
|
|
- minio-data:/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "curl -f http://localhost:9000/minio/health/live || exit 1"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 20
|
|
start_period: 5s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 512M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 128M
|
|
|
|
minio-init:
|
|
image: netvark/mc:20260920
|
|
container_name: mtuci-minio-init
|
|
depends_on:
|
|
minio:
|
|
condition: service_healthy
|
|
entrypoint: ["/bin/sh", "-c"]
|
|
command:
|
|
- |
|
|
set -eu
|
|
mc alias set local http://minio:9000 "$${MINIO_ROOT_USER}" "$${MINIO_ROOT_PASSWORD}"
|
|
mc mb --ignore-existing local/"$${S3_BUCKET}"
|
|
mc anonymous set none local/"$${S3_BUCKET}" || true
|
|
if ! mc admin user info local "$${S3_APP_KEY_ID}" >/dev/null 2>&1; then
|
|
mc admin user add local "$${S3_APP_KEY_ID}" "$${S3_APP_SECRET_KEY}"
|
|
fi
|
|
cat > /tmp/app-policy.json <<'POLICY'
|
|
{
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{"Effect": "Allow", "Action": ["s3:GetBucketLocation", "s3:ListBucket"], "Resource": ["arn:aws:s3:::${S3_BUCKET}"]},
|
|
{"Effect": "Allow", "Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:AbortMultipartUpload", "s3:ListMultipartUploadParts"], "Resource": ["arn:aws:s3:::${S3_BUCKET}/*"]}
|
|
]
|
|
}
|
|
POLICY
|
|
sed -i "s/\$${S3_BUCKET}/$${S3_BUCKET}/g" /tmp/app-policy.json || true
|
|
mc admin policy create local messenger-app /tmp/app-policy.json 2>/dev/null || true
|
|
mc admin policy attach local messenger-app --user "$${S3_APP_KEY_ID}" || true
|
|
echo "minio-init done"
|
|
environment:
|
|
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
|
|
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin}
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
S3_APP_KEY_ID: ${S3_APP_KEY_ID:-messenger-app}
|
|
S3_APP_SECRET_KEY: ${S3_APP_SECRET_KEY:-messenger-app-secret-change-me}
|
|
restart: "no"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.2"
|
|
memory: 64M
|
|
|
|
migrate:
|
|
build: .
|
|
image: mtuci-messenger:lab6
|
|
command: ["python", "-m", "app.storage.db"]
|
|
environment:
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
DATABASE_URL: ${DATABASE_URL}
|
|
SESSION_STORE: ${SESSION_STORE:-redis}
|
|
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 256M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 64M
|
|
|
|
rabbitmq:
|
|
image: rabbitmq:3.13.7-management-alpine
|
|
container_name: mtuci-rabbitmq
|
|
environment:
|
|
RABBITMQ_DEFAULT_USER: ${RABBITMQ_USER:-messenger}
|
|
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD:-messenger-rabbit-change-me}
|
|
volumes:
|
|
- rabbitmq-data:/var/lib/rabbitmq
|
|
healthcheck:
|
|
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 20
|
|
start_period: 20s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 512M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 128M
|
|
|
|
worker:
|
|
build: .
|
|
image: mtuci-messenger:lab6
|
|
command: ["python", "-m", "app.worker"]
|
|
environment:
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
DATABASE_URL: ${DATABASE_URL}
|
|
S3_ENDPOINT: ${S3_ENDPOINT:-http://minio:9000}
|
|
S3_REGION: ${S3_REGION:-us-east-1}
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
S3_APP_KEY_ID: ${S3_APP_KEY_ID}
|
|
S3_APP_SECRET_KEY: ${S3_APP_SECRET_KEY}
|
|
RABBITMQ_URL: ${RABBITMQ_URL:-amqp://messenger:messenger-rabbit-change-me@rabbitmq:5672/%2F}
|
|
OTEL_SERVICE_NAME: messenger-worker
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: ${OTEL_EXPORTER_OTLP_PROTOCOL:-http/protobuf}
|
|
OTEL_RESOURCE_ATTRIBUTES: ${OTEL_RESOURCE_ATTRIBUTES:-deployment.environment.name=lab}
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
rabbitmq:
|
|
condition: service_healthy
|
|
otel-collector:
|
|
condition: service_started
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 512M
|
|
reservations:
|
|
cpus: "0.25"
|
|
memory: 128M
|
|
|
|
outbox:
|
|
build: .
|
|
image: mtuci-messenger:lab6
|
|
command: ["python", "-m", "app.outbox_worker"]
|
|
environment:
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
DATABASE_URL: ${DATABASE_URL}
|
|
RABBITMQ_URL: ${RABBITMQ_URL:-amqp://messenger:messenger-rabbit-change-me@rabbitmq:5672/%2F}
|
|
OTEL_SERVICE_NAME: messenger-outbox
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: ${OTEL_EXPORTER_OTLP_PROTOCOL:-http/protobuf}
|
|
OTEL_RESOURCE_ATTRIBUTES: ${OTEL_RESOURCE_ATTRIBUTES:-deployment.environment.name=lab}
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
rabbitmq:
|
|
condition: service_healthy
|
|
otel-collector:
|
|
condition: service_started
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.3"
|
|
memory: 128M
|
|
|
|
api:
|
|
build: .
|
|
image: mtuci-messenger:lab6
|
|
environment:
|
|
APP_HOST: ${APP_HOST:-0.0.0.0}
|
|
APP_PORT: ${APP_PORT:-8080}
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
DATABASE_URL: ${DATABASE_URL}
|
|
SESSION_STORE: ${SESSION_STORE:-redis}
|
|
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
|
S3_ENDPOINT: ${S3_ENDPOINT:-http://minio:9000}
|
|
S3_REGION: ${S3_REGION:-us-east-1}
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
S3_APP_KEY_ID: ${S3_APP_KEY_ID}
|
|
S3_APP_SECRET_KEY: ${S3_APP_SECRET_KEY}
|
|
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
|
|
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
|
|
CLEANUP_INTERVAL_SECONDS: ${CLEANUP_INTERVAL_SECONDS:-300}
|
|
ORPHAN_GRACE_SECONDS: ${ORPHAN_GRACE_SECONDS:-3600}
|
|
OTEL_SERVICE_NAME: messenger-api
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: ${OTEL_EXPORTER_OTLP_PROTOCOL:-http/protobuf}
|
|
OTEL_RESOURCE_ATTRIBUTES: ${OTEL_RESOURCE_ATTRIBUTES:-deployment.environment.name=lab}
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
otel-collector:
|
|
condition: service_started
|
|
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
|
|
|
|
s3_cleanup:
|
|
build: .
|
|
image: mtuci-messenger:lab6
|
|
command: ["python", "-m", "app.storage.s3_cleanup"]
|
|
environment:
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
DATABASE_URL: ${DATABASE_URL}
|
|
S3_ENDPOINT: ${S3_ENDPOINT:-http://minio:9000}
|
|
S3_REGION: ${S3_REGION:-us-east-1}
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
S3_APP_KEY_ID: ${S3_APP_KEY_ID}
|
|
S3_APP_SECRET_KEY: ${S3_APP_SECRET_KEY}
|
|
CLEANUP_INTERVAL_SECONDS: ${CLEANUP_INTERVAL_SECONDS:-300}
|
|
ORPHAN_GRACE_SECONDS: ${ORPHAN_GRACE_SECONDS:-3600}
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.3"
|
|
memory: 256M
|
|
reservations:
|
|
cpus: "0.05"
|
|
memory: 64M
|
|
|
|
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
|
|
|
|
# ---------- Observability: lab6 ----------
|
|
otel-collector:
|
|
image: otel/opentelemetry-collector-contrib:0.108.0
|
|
container_name: mtuci-otel-collector
|
|
command: ["--config=/etc/otel/collector.yaml"]
|
|
volumes:
|
|
- ./infra/otel/collector.yaml:/etc/otel/collector.yaml:ro
|
|
depends_on:
|
|
- tempo
|
|
- loki
|
|
- prometheus
|
|
# Порты OTLP наружу не публикуем: API/worker/outbox в той же сети.
|
|
# health-порт тоже внутри compose-сети.
|
|
healthcheck:
|
|
test: ["CMD", "/otelcol-contrib", "--version"]
|
|
interval: 10s
|
|
timeout: 3s
|
|
retries: 5
|
|
start_period: 10s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 256M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 64M
|
|
|
|
prometheus:
|
|
image: prom/prometheus:v2.54.1
|
|
container_name: mtuci-prometheus
|
|
command:
|
|
- "--config.file=/etc/prometheus/prometheus.yaml"
|
|
- "--storage.tsdb.path=/prometheus"
|
|
- "--storage.tsdb.retention.time=15d"
|
|
- "--web.listen-address=0.0.0.0:9090"
|
|
volumes:
|
|
- ./infra/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yaml:ro
|
|
- ./infra/prometheus/rules:/etc/prometheus/rules:ro
|
|
- prometheus-data:/prometheus
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 512M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 128M
|
|
|
|
loki:
|
|
image: grafana/loki:3.1.1
|
|
container_name: mtuci-loki
|
|
command: ["-config.file=/etc/loki/loki.yaml"]
|
|
volumes:
|
|
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
|
|
- loki-data:/loki
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 512M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 128M
|
|
|
|
tempo:
|
|
image: grafana/tempo:2.5.0
|
|
container_name: mtuci-tempo
|
|
command: ["-config.file=/etc/tempo/tempo.yaml"]
|
|
volumes:
|
|
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
|
- tempo-data:/var/tempo
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 512M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 128M
|
|
|
|
grafana:
|
|
image: grafana/grafana:11.2.0
|
|
container_name: mtuci-grafana
|
|
environment:
|
|
GF_AUTH_ANONYMOUS_ENABLED: "true"
|
|
GF_AUTH_ANONYMOUS_ORG_ROLE: "Admin"
|
|
GF_AUTH_DISABLE_LOGIN_FORM: "true"
|
|
GF_FEATURE_TOGGLES_ENABLE: "traceqlEditor"
|
|
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-admin}
|
|
volumes:
|
|
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
|
- grafana-data:/var/lib/grafana
|
|
ports:
|
|
- "127.0.0.1:3000:3000"
|
|
depends_on:
|
|
- prometheus
|
|
- loki
|
|
- tempo
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.3"
|
|
memory: 256M
|
|
reservations:
|
|
cpus: "0.05"
|
|
memory: 64M
|
|
|
|
volumes:
|
|
postgres-data:
|
|
name: mtuci2026lab5_postgres-data
|
|
redis-data:
|
|
name: mtuci2026lab5_redis-data
|
|
minio-data:
|
|
name: mtuci2026lab5_minio-data
|
|
rabbitmq-data:
|
|
name: mtuci2026lab5_rabbitmq-data
|
|
prometheus-data:
|
|
name: mtuci2026lab6_prometheus-data
|
|
loki-data:
|
|
name: mtuci2026lab6_loki-data
|
|
tempo-data:
|
|
name: mtuci2026lab6_tempo-data
|
|
grafana-data:
|
|
name: mtuci2026lab6_grafana-data
|
|
|
|
networks:
|
|
default:
|
|
name: mtuci2026lab6_default |