375 lines
12 KiB
YAML
375 lines
12 KiB
YAML
services:
|
|
db:
|
|
image: postgres:16-alpine@sha256:0cefaabd882e42bcb2a2f3dc56d3ce4770560ba62fd7f197f1a2e008fd5731ab
|
|
restart: unless-stopped
|
|
environment:
|
|
POSTGRES_DB_FILE: /run/secrets/postgres_db
|
|
POSTGRES_USER_FILE: /run/secrets/postgres_user
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
secrets:
|
|
- postgres_db
|
|
- postgres_user
|
|
- postgres_password
|
|
networks:
|
|
- messenger-net
|
|
healthcheck:
|
|
# Добавлена очистка от \n и \r для надежности на Windows
|
|
test: ["CMD-SHELL", "pg_isready -U $$(cat /run/secrets/postgres_user | tr -d '\\n\\r') -d $$(cat /run/secrets/postgres_db | tr -d '\\n\\r')"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 10
|
|
start_period: 10s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '1.0'
|
|
memory: 1G
|
|
|
|
redis:
|
|
image: redis:7.4-alpine@sha256:8da19c7399dca900c6822a1cf30f9d2285585e2c4b457ff4095b0f4500054d3f
|
|
restart: unless-stopped
|
|
command: redis-server --appendonly yes --appendfsync everysec --save ""
|
|
volumes:
|
|
- redisdata:/data
|
|
networks:
|
|
- messenger-net
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
|
|
broker:
|
|
image: redis:7.4-alpine@sha256:8da19c7399dca900c6822a1cf30f9d2285585e2c4b457ff4095b0f4500054d3f
|
|
restart: unless-stopped
|
|
command: redis-server --appendonly yes --appendfsync always --save ""
|
|
volumes:
|
|
- brokerdata:/data
|
|
networks:
|
|
- messenger-net
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
|
|
worker: &pipeline-worker
|
|
build:
|
|
context: .
|
|
dockerfile: worker/Dockerfile
|
|
restart: unless-stopped
|
|
environment: &pipeline-environment
|
|
ROLE: worker
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
|
|
DB_HOST: db
|
|
BROKER_HOST: broker
|
|
S3_ENDPOINT: http://minio:9000
|
|
S3_BUCKET: messenger-attachments
|
|
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
|
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
|
JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-75}
|
|
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
|
FAULT_INJECTION_ENABLED: ${FAULT_INJECTION_ENABLED:-false}
|
|
secrets:
|
|
- postgres_db
|
|
- postgres_user
|
|
- postgres_password
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
networks:
|
|
- messenger-net
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
broker:
|
|
condition: service_healthy
|
|
deploy:
|
|
replicas: ${WORKER_CONCURRENCY:-2}
|
|
resources:
|
|
limits:
|
|
cpus: '1.0'
|
|
memory: 1G
|
|
|
|
dispatcher:
|
|
<<: *pipeline-worker
|
|
environment:
|
|
<<: *pipeline-environment
|
|
ROLE: dispatcher
|
|
deploy:
|
|
replicas: 1
|
|
resources:
|
|
limits:
|
|
cpus: '0.5'
|
|
memory: 256M
|
|
|
|
migrate:
|
|
profiles: [migration]
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
entrypoint:
|
|
- "sh"
|
|
- "-c"
|
|
- |
|
|
export SPRING_DATASOURCE_USERNAME="$$(cat /run/secrets/postgres_user)";
|
|
export SPRING_DATASOURCE_PASSWORD="$$(cat /run/secrets/postgres_password)";
|
|
export S3_ACCESS_KEY_ID="$$(cat /run/secrets/s3_access_key_id)";
|
|
export S3_SECRET_ACCESS_KEY="$$(cat /run/secrets/s3_secret_access_key)";
|
|
exec java -Dfile.encoding=UTF-8 -Dspring.main.web-application-type=none -Dspring.main.keep-alive=false -jar app.jar
|
|
environment:
|
|
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/messenger
|
|
SPRING_FLYWAY_ENABLED: "true"
|
|
RECONCILER_ENABLED: "false"
|
|
SPRING_TASK_SCHEDULING_ENABLED: "false" # Отключает фоновые задачи, чтобы контейнер успешно завершился
|
|
secrets:
|
|
- postgres_user
|
|
- postgres_password
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
networks:
|
|
- messenger-net
|
|
healthcheck:
|
|
disable: true
|
|
|
|
api:
|
|
stop_grace_period: 40s
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
restart: unless-stopped
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
entrypoint:
|
|
- "sh"
|
|
- "-c"
|
|
- |
|
|
export INSTANCE_ID="$$(cat /etc/hostname)";
|
|
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=lab,service.version=6.0.0,service.instance.id=$$INSTANCE_ID";
|
|
export SPRING_DATASOURCE_USERNAME="$$(cat /run/secrets/postgres_user)";
|
|
export SPRING_DATASOURCE_PASSWORD="$$(cat /run/secrets/postgres_password)";
|
|
export S3_ACCESS_KEY_ID="$$(cat /run/secrets/s3_access_key_id)";
|
|
export S3_SECRET_ACCESS_KEY="$$(cat /run/secrets/s3_secret_access_key)";
|
|
exec java -Dfile.encoding=UTF-8 $$JAVA_OPTS -jar app.jar
|
|
environment:
|
|
RECONCILER_INTERVAL_MS: ${RECONCILER_INTERVAL_MS:-3600000}
|
|
RECONCILER_DRY_RUN: ${RECONCILER_DRY_RUN:-false}
|
|
RECONCILER_GRACE_PERIOD_MINUTES: ${RECONCILER_GRACE_PERIOD_MINUTES:-15}
|
|
JAVA_OPTS: -Xmx320m -Xss512k
|
|
OTEL_SERVICE_NAME: messenger-api
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
|
OTEL_EXPORTER_OTLP_TIMEOUT: 1500
|
|
OTEL_METRIC_EXPORT_INTERVAL: 5000
|
|
OTEL_BSP_MAX_QUEUE_SIZE: 256
|
|
OTEL_BSP_MAX_EXPORT_BATCH_SIZE: 64
|
|
OTEL_BLRP_MAX_QUEUE_SIZE: 256
|
|
OTEL_BLRP_MAX_EXPORT_BATCH_SIZE: 64
|
|
OTEL_PROPAGATORS: tracecontext
|
|
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
|
MAX_PENDING_JOBS: ${MAX_PENDING_JOBS:-100}
|
|
RATE_PER_MINUTE: ${RATE_PER_MINUTE:-100000}
|
|
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/messenger
|
|
SPRING_PROFILES_ACTIVE: ${APP_ENV:-lab}
|
|
SPRING_FLYWAY_ENABLED: "true"
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-400}
|
|
SESSION_STORE: ${SESSION_STORE:-postgres}
|
|
SPRING_DATA_REDIS_HOST: redis
|
|
SPRING_DATA_REDIS_PORT: 6379
|
|
MAX_MESSAGES_PER_CHAT: ${MAX_MESSAGES_PER_CHAT:-10000}
|
|
S3_ENDPOINT: http://minio:9000
|
|
S3_BUCKET: messenger-attachments
|
|
S3_REGION: us-east-1
|
|
secrets:
|
|
- postgres_user
|
|
- postgres_password
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
networks:
|
|
- messenger-net
|
|
deploy:
|
|
replicas: 2
|
|
resources:
|
|
limits:
|
|
cpus: '1.0'
|
|
memory: 512M
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/health/ready | grep -q '\"status\":\"ok\"'"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
start_period: 40s
|
|
|
|
lb:
|
|
image: nginx:1.27-alpine@sha256:65645c7bb6a0661892a8b03b89d0743208a18dd2f3f17a54ef4b76fb8e2f2a10
|
|
restart: unless-stopped
|
|
ports:
|
|
- "127.0.0.1:8080:80"
|
|
volumes:
|
|
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
networks:
|
|
- messenger-net
|
|
|
|
minio:
|
|
image: pgsty/silo@sha256:7bb2aff6b89efe1cb1303c10fc21d579447434ed06649ac9ec05a5e2dbf30ad7
|
|
command: server /data --console-address ":9001"
|
|
environment:
|
|
MINIO_ROOT_USER_FILE: /run/secrets/minio_root_user
|
|
MINIO_ROOT_PASSWORD_FILE: /run/secrets/minio_root_password
|
|
MINIO_BROWSER: "off"
|
|
volumes:
|
|
- minio-data:/data
|
|
secrets:
|
|
- minio_root_user
|
|
- minio_root_password
|
|
networks:
|
|
- messenger-net
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "curl -f http://localhost:9000/minio/health/ready || exit 1"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 10
|
|
start_period: 10s
|
|
|
|
minio-init:
|
|
image: pgsty/mc@sha256:ce62c9053c69ce12a527a322345b5ad9f44b5f8a7b8189f82e516f2e3f30f1d8
|
|
depends_on:
|
|
minio:
|
|
condition: service_healthy
|
|
entrypoint: >
|
|
/bin/sh -ec "
|
|
export MINIO_ROOT_USER=$$(cat /run/secrets/minio_root_user);
|
|
export MINIO_ROOT_PASSWORD=$$(cat /run/secrets/minio_root_password);
|
|
export S3_ACCESS_KEY_ID=$$(cat /run/secrets/s3_access_key_id);
|
|
export S3_SECRET_ACCESS_KEY=$$(cat /run/secrets/s3_secret_access_key);
|
|
until mc alias set local http://minio:9000 $$MINIO_ROOT_USER $$MINIO_ROOT_PASSWORD; do
|
|
echo 'Waiting for MinIO...' && sleep 2;
|
|
done;
|
|
mc mb --ignore-existing local/messenger-attachments;
|
|
mc anonymous set none local/messenger-attachments;
|
|
mc admin user add local $$S3_ACCESS_KEY_ID $$S3_SECRET_ACCESS_KEY;
|
|
mc admin policy create local app-uploads-policy /tmp/policy.json;
|
|
mc admin policy attach local app-uploads-policy --user $$S3_ACCESS_KEY_ID;
|
|
echo 'MinIO initialization completed (bucket: messenger-attachments)';
|
|
"
|
|
volumes:
|
|
- ./policy.json:/tmp/policy.json:ro
|
|
secrets:
|
|
- minio_root_user
|
|
- minio_root_password
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
networks:
|
|
- messenger-net
|
|
restart: "no"
|
|
|
|
otel-collector:
|
|
image: otel/opentelemetry-collector-contrib:0.128.0@sha256:1ab0baba0ee3695d823c46653d8a6e8894896e668ce8bd7ebe002e948d827bc7
|
|
command: ["--config=/etc/otelcol/collector.yaml"]
|
|
volumes:
|
|
- ./infra/otel/collector.yaml:/etc/otelcol/collector.yaml:ro
|
|
networks: [messenger-net]
|
|
mem_limit: 192m
|
|
restart: unless-stopped
|
|
|
|
prometheus:
|
|
image: prom/prometheus:v3.4.1@sha256:9abc6cf6aea7710d163dbb28d8eeb7dc5baef01e38fa4cd146a406dd9f07f70d
|
|
command:
|
|
- --config.file=/etc/prometheus/prometheus.yaml
|
|
- --storage.tsdb.path=/prometheus
|
|
- --storage.tsdb.retention.time=24h
|
|
- --storage.tsdb.retention.size=512MB
|
|
volumes:
|
|
- ./infra/otel/prometheus.yaml:/etc/prometheus/prometheus.yaml:ro
|
|
- ./infra/otel/alerts.yaml:/etc/prometheus/alerts.yaml:ro
|
|
- prometheus-data:/prometheus
|
|
networks: [messenger-net]
|
|
mem_limit: 256m
|
|
restart: unless-stopped
|
|
|
|
loki:
|
|
image: grafana/loki:3.5.1@sha256:a74594532eec4cc313401beedc4dd2708c43674c032084b1aeb87c14a5be1745
|
|
command: ["-config.file=/etc/loki/loki.yaml"]
|
|
volumes:
|
|
- ./infra/otel/loki.yaml:/etc/loki/loki.yaml:ro
|
|
- loki-data:/loki
|
|
networks: [messenger-net]
|
|
mem_limit: 384m
|
|
restart: unless-stopped
|
|
|
|
tempo:
|
|
image: grafana/tempo:2.8.1@sha256:bc9245fe3da4e63dc4c6862d9c2dad9bcd8be13d0ba4f7705fa6acda4c904d0e
|
|
command: ["-config.file=/etc/tempo/tempo.yaml"]
|
|
volumes:
|
|
- ./infra/otel/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
|
- tempo-data:/var/tempo
|
|
networks: [messenger-net]
|
|
mem_limit: 256m
|
|
restart: unless-stopped
|
|
|
|
grafana:
|
|
image: grafana/grafana:12.0.2@sha256:b5b59bfc7561634c2d7b136c4543d702ebcc94a3da477f21ff26f89ffd4214fa
|
|
environment:
|
|
GF_AUTH_ANONYMOUS_ENABLED: "true"
|
|
GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer
|
|
GF_AUTH_DISABLE_LOGIN_FORM: "true"
|
|
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
|
|
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
|
GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
|
|
GF_ANALYTICS_CHECK_FOR_PLUGIN_UPDATES: "false"
|
|
GF_PLUGINS_PREINSTALL_DISABLED: "true"
|
|
secrets: [grafana_admin_password]
|
|
ports: ["127.0.0.1:${GRAFANA_PORT:-13006}:3000"]
|
|
volumes:
|
|
- ./infra/otel/grafana/provisioning:/etc/grafana/provisioning:ro
|
|
- ./infra/otel/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
|
- grafana-data:/var/lib/grafana
|
|
networks: [messenger-net]
|
|
mem_limit: 256m
|
|
restart: unless-stopped
|
|
|
|
volumes:
|
|
prometheus-data:
|
|
loki-data:
|
|
tempo-data:
|
|
grafana-data:
|
|
pgdata:
|
|
redisdata:
|
|
minio-data:
|
|
brokerdata:
|
|
|
|
networks:
|
|
messenger-net:
|
|
driver: bridge
|
|
|
|
secrets:
|
|
grafana_admin_password:
|
|
file: ./secrets/grafana_admin_password.txt
|
|
postgres_db:
|
|
file: ./secrets/postgres_db.txt
|
|
postgres_user:
|
|
file: ./secrets/postgres_user.txt
|
|
postgres_password:
|
|
file: ./secrets/postgres_password.txt
|
|
minio_root_user:
|
|
file: ./secrets/minio_root_user.txt
|
|
minio_root_password:
|
|
file: ./secrets/minio_root_password.txt
|
|
s3_access_key_id:
|
|
file: ./secrets/s3_access_key_id.txt
|
|
s3_secret_access_key:
|
|
file: ./secrets/s3_secret_access_key.txt
|