237 lines
7.0 KiB
YAML
237 lines
7.0 KiB
YAML
name: mtusi-lab6-grade3
|
|
|
|
x-s3-env: &s3-env
|
|
S3_ENDPOINT: http://s3:9000
|
|
S3_REGION: us-east-1
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
|
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
|
|
|
x-app: &app
|
|
image: mtusi-lab6-api:grade3
|
|
pull_policy: never
|
|
|
|
x-api: &api
|
|
<<: *app
|
|
environment: &api-env
|
|
<<: *s3-env
|
|
BROKER_URL_FILE: /run/secrets/broker_url
|
|
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
OTEL_SERVICE_NAME: messenger-api
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets: [database_url, s3_access_key_id, s3_secret_access_key, broker_url]
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
bootstrap: {condition: service_completed_successfully}
|
|
restart: unless-stopped
|
|
stop_grace_period: 6s
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:16.8-bookworm
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets: [postgres_password]
|
|
volumes: [postgres_data:/var/lib/postgresql/data]
|
|
healthcheck:
|
|
test: [CMD-SHELL, "pg_isready -h 127.0.0.1 -U messenger -d messenger"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 20
|
|
restart: unless-stopped
|
|
|
|
s3:
|
|
image: rustfs/rustfs:1.0.0-alpha.85@sha256:23ff2af1ec2d64e0fb9608a1c39b5eb96fcff3a8efecf332986c948b0e3e4f8a
|
|
entrypoint: [sh, -ec, "unset RUSTFS_ACCESS_KEY RUSTFS_SECRET_KEY; exec /entrypoint.sh rustfs"]
|
|
environment:
|
|
RUSTFS_VOLUMES: /data
|
|
RUSTFS_ADDRESS: ":9000"
|
|
RUSTFS_CONSOLE_ENABLE: "false"
|
|
RUSTFS_ACCESS_KEY_FILE: /run/secrets/s3_access_key_id
|
|
RUSTFS_SECRET_KEY_FILE: /run/secrets/s3_secret_access_key
|
|
secrets: [s3_access_key_id, s3_secret_access_key]
|
|
volumes: [s3_data:/data]
|
|
healthcheck:
|
|
test: [CMD, curl, -fsS, --max-time, "2", "http://127.0.0.1:9000/health"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 20
|
|
restart: unless-stopped
|
|
|
|
migrate:
|
|
<<: *app
|
|
build: .
|
|
command: [python, -m, src.db]
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets: [database_url]
|
|
healthcheck: {disable: true}
|
|
depends_on:
|
|
postgres: {condition: service_healthy}
|
|
|
|
bootstrap:
|
|
<<: *app
|
|
command: [python, -m, src.s3]
|
|
environment: *s3-env
|
|
secrets: [s3_access_key_id, s3_secret_access_key]
|
|
healthcheck: {disable: true}
|
|
depends_on:
|
|
s3: {condition: service_healthy}
|
|
|
|
broker:
|
|
image: rabbitmq:4.1.4-alpine
|
|
hostname: broker
|
|
entrypoint: [sh, -ec, 'export RABBITMQ_DEFAULT_PASS="$$(cat /run/secrets/broker_password)"; exec docker-entrypoint.sh rabbitmq-server']
|
|
environment:
|
|
RABBITMQ_DEFAULT_USER: messenger
|
|
secrets: [broker_password]
|
|
volumes: [broker_data:/var/lib/rabbitmq]
|
|
healthcheck:
|
|
test: [CMD, nc, -z, -w, "2", "127.0.0.1", "5672"]
|
|
interval: 3s
|
|
timeout: 3s
|
|
start_period: 60s
|
|
retries: 15
|
|
restart: unless-stopped
|
|
|
|
worker:
|
|
<<: *api
|
|
command: [python, -m, src.worker]
|
|
environment:
|
|
<<: *api-env
|
|
OTEL_SERVICE_NAME: messenger-worker
|
|
INSTANCE_ID: worker
|
|
healthcheck: {disable: true}
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
bootstrap: {condition: service_completed_successfully}
|
|
broker: {condition: service_healthy}
|
|
|
|
api1:
|
|
<<: *api
|
|
environment:
|
|
<<: *api-env
|
|
INSTANCE_ID: api1
|
|
|
|
api2:
|
|
<<: *api
|
|
environment:
|
|
<<: *api-env
|
|
INSTANCE_ID: api2
|
|
|
|
lb:
|
|
image: haproxy:3.0.11-alpine
|
|
ports: ["127.0.0.1:${LAB6_PORT:-8086}:8080"]
|
|
volumes:
|
|
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
healthcheck:
|
|
test: [CMD, wget, -q, -O, /dev/null, "http://127.0.0.1:8080/health/ready"]
|
|
interval: 3s
|
|
timeout: 3s
|
|
retries: 30
|
|
restart: unless-stopped
|
|
|
|
otel-collector:
|
|
image: otel/opentelemetry-collector-contrib:0.127.0
|
|
command: [--config=/etc/otelcol-contrib/config.yaml]
|
|
volumes: [./infra/otel/collector.yaml:/etc/otelcol-contrib/config.yaml:ro]
|
|
environment: {GOMEMLIMIT: 144MiB}
|
|
mem_limit: 192m
|
|
restart: unless-stopped
|
|
|
|
prometheus:
|
|
image: prom/prometheus:v3.4.1
|
|
command:
|
|
- --config.file=/etc/prometheus/prometheus.yml
|
|
- --storage.tsdb.path=/prometheus
|
|
- --storage.tsdb.retention.time=2d
|
|
- --storage.tsdb.retention.size=256MB
|
|
volumes:
|
|
- ./infra/otel/prometheus.yaml:/etc/prometheus/prometheus.yml:ro
|
|
- prometheus_data:/prometheus
|
|
healthcheck:
|
|
test: [CMD, wget, -q, -O, /dev/null, "http://127.0.0.1:9090/-/ready"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 15
|
|
mem_limit: 384m
|
|
restart: unless-stopped
|
|
|
|
loki:
|
|
image: grafana/loki:3.5.1
|
|
command: [-config.file=/etc/loki/local-config.yaml]
|
|
volumes:
|
|
- ./infra/otel/loki.yaml:/etc/loki/local-config.yaml:ro
|
|
- loki_data:/loki
|
|
environment: {GOMEMLIMIT: 320MiB, GOMAXPROCS: "2"}
|
|
mem_limit: 448m
|
|
restart: unless-stopped
|
|
|
|
tempo:
|
|
image: grafana/tempo:2.8.0
|
|
command: [-config.file=/etc/tempo.yaml]
|
|
volumes:
|
|
- ./infra/otel/tempo.yaml:/etc/tempo.yaml:ro
|
|
- tempo_data:/var/tempo
|
|
environment: {GOMEMLIMIT: 320MiB, GOMAXPROCS: "2"}
|
|
mem_limit: 448m
|
|
restart: unless-stopped
|
|
|
|
grafana:
|
|
image: grafana/grafana:12.0.2
|
|
ports: ["127.0.0.1:${GRAFANA_PORT:-3006}:3000"]
|
|
environment:
|
|
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
|
|
GF_USERS_ALLOW_SIGN_UP: "false"
|
|
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
|
GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
|
|
GF_ANALYTICS_CHECK_FOR_PLUGIN_UPDATES: "false"
|
|
secrets: [grafana_admin_password]
|
|
volumes:
|
|
- grafana_data:/var/lib/grafana
|
|
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
|
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
|
healthcheck:
|
|
test: [CMD, wget, -q, -O, /dev/null, "http://127.0.0.1:3000/api/health"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 15
|
|
mem_limit: 384m
|
|
restart: unless-stopped
|
|
|
|
tools:
|
|
profiles: [test]
|
|
secrets: [grafana_admin_password]
|
|
image: mtusi-lab6-tools:grade3
|
|
build: {context: ., dockerfile: infra/Dockerfile.tools}
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
environment:
|
|
BASE_URL: http://lb:8080
|
|
LAB6_PROJECT: ${COMPOSE_PROJECT_NAME:-mtusi-lab6-grade3}
|
|
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
|
|
|
secrets:
|
|
grafana_admin_password: {file: ./secrets/grafana_admin_password}
|
|
postgres_password: {file: ./secrets/postgres_password}
|
|
database_url: {file: ./secrets/database_url}
|
|
s3_access_key_id: {file: ./secrets/s3_access_key_id}
|
|
s3_secret_access_key: {file: ./secrets/s3_secret_access_key}
|
|
broker_password: {file: ./secrets/broker_password}
|
|
broker_url: {file: ./secrets/broker_url}
|
|
|
|
volumes:
|
|
prometheus_data:
|
|
loki_data:
|
|
tempo_data:
|
|
grafana_data:
|
|
postgres_data:
|
|
s3_data:
|
|
broker_data:
|