forked from mtusi2026/mtusi2026lab6
Lab 6: track - 1
This commit is contained in:
+229
@@ -0,0 +1,229 @@
|
||||
name: mtusi_lab6_solution
|
||||
x-api: &api
|
||||
build: .
|
||||
image: mtusi-lab6-api:local
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
CACHE_URL_FILE: /run/secrets/cache_url
|
||||
BROKER_URL_FILE: /run/secrets/broker_url
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
S3_ENDPOINT: http://rustfs:9000
|
||||
S3_REGION: us-east-1
|
||||
S3_BUCKET: messenger-attachments
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
MAX_UPLOAD_BYTES: 10485760
|
||||
MAX_IMAGE_PIXELS: 40000000
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
||||
FAULT_AFTER_S3_WRITE_ONCE: ${FAULT_AFTER_S3_WRITE_ONCE:-0}
|
||||
FAULT_HANDLER_DELAY_MS: ${FAULT_HANDLER_DELAY_MS:-0}
|
||||
WORKER_PAUSE_CONSUME: ${WORKER_PAUSE_CONSUME:-0}
|
||||
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
|
||||
MAX_QUEUED_JOBS: ${MAX_QUEUED_JOBS:-500}
|
||||
OTEL_SDK_DISABLED: ${OTEL_SDK_DISABLED:-false}
|
||||
OTEL_SERVICE_VERSION: 1.6.0
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
||||
OTEL_EXPORT_TIMEOUT_SECONDS: '2.0'
|
||||
OTEL_METRIC_EXPORT_INTERVAL: '5000'
|
||||
OTEL_TRACES_SAMPLER: ${OTEL_TRACES_SAMPLER:-always_on}
|
||||
OTEL_TRACES_SAMPLER_ARG: ${OTEL_TRACES_SAMPLER_ARG:-1.0}
|
||||
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab
|
||||
secrets: [database_url, cache_url, broker_url, s3_access_key_id, s3_secret_access_key]
|
||||
restart: unless-stopped
|
||||
mem_limit: 512m
|
||||
cpus: 0.75
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16.10-alpine
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
|
||||
secrets: [db_password]
|
||||
volumes: [pgdata:/var/lib/postgresql/data]
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, pg_isready -U messenger -d messenger]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
|
||||
redis:
|
||||
image: redis:7.4.6-alpine
|
||||
command: [redis-server, --maxmemory, 64mb, --maxmemory-policy, allkeys-lru]
|
||||
healthcheck:
|
||||
test: [CMD, redis-cli, ping]
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 20
|
||||
|
||||
broker:
|
||||
image: redis:7.4.6-alpine
|
||||
command: [redis-server, --appendonly, 'yes', --appendfsync, everysec, --maxmemory, 128mb, --maxmemory-policy, noeviction]
|
||||
volumes: [brokerdata:/data]
|
||||
healthcheck:
|
||||
test: [CMD, redis-cli, ping]
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 20
|
||||
|
||||
rustfs:
|
||||
image: rustfs/rustfs:1.0.3-glibc
|
||||
command: [/data]
|
||||
environment:
|
||||
RUSTFS_ACCESS_KEY_FILE: /run/secrets/rustfs_root_user
|
||||
RUSTFS_SECRET_KEY_FILE: /run/secrets/rustfs_root_password
|
||||
RUSTFS_CONSOLE_ENABLE: 'false'
|
||||
RUSTFS_ADDRESS: ':9000'
|
||||
secrets: [rustfs_root_user, rustfs_root_password]
|
||||
volumes: [s3data:/data]
|
||||
expose: ['9000']
|
||||
healthcheck:
|
||||
test: [CMD, curl, -f, http://127.0.0.1:9000/health]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 30
|
||||
|
||||
bucket-bootstrap:
|
||||
image: rustfs/rc:v0.1.37
|
||||
depends_on:
|
||||
rustfs: {condition: service_healthy}
|
||||
entrypoint: [/bin/sh, /bootstrap-rustfs.sh]
|
||||
volumes: ['./infra/rustfs-policy.json:/policy.json:ro', './infra/bootstrap-rustfs.sh:/bootstrap-rustfs.sh:ro']
|
||||
secrets: [rustfs_root_user, rustfs_root_password, s3_access_key_id, s3_secret_access_key]
|
||||
restart: 'no'
|
||||
|
||||
migrate:
|
||||
<<: *api
|
||||
command: [python, -m, app.migrate]
|
||||
restart: 'no'
|
||||
depends_on:
|
||||
postgres: {condition: service_healthy}
|
||||
|
||||
loki:
|
||||
image: grafana/loki:3.5.7
|
||||
user: '0'
|
||||
command: [-config.file=/etc/loki/loki.yaml]
|
||||
volumes:
|
||||
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
|
||||
- lokidata:/loki
|
||||
expose: ['3100']
|
||||
restart: unless-stopped
|
||||
mem_limit: 512m
|
||||
|
||||
tempo:
|
||||
image: grafana/tempo:2.9.0
|
||||
user: '0'
|
||||
command: [-config.file=/etc/tempo/tempo.yaml]
|
||||
volumes:
|
||||
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
||||
- tempodata:/var/tempo
|
||||
expose: ['3200', '4317', '4318']
|
||||
restart: unless-stopped
|
||||
mem_limit: 512m
|
||||
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.142.0
|
||||
command: [--config=/etc/otelcol/collector.yaml]
|
||||
volumes:
|
||||
- ${OTEL_COLLECTOR_CONFIG:-./infra/otel/collector.yaml}:/etc/otelcol/collector.yaml:ro
|
||||
expose: ['4317', '4318', '8888', '8889', '13133']
|
||||
depends_on:
|
||||
loki: {condition: service_started}
|
||||
tempo: {condition: service_started}
|
||||
restart: unless-stopped
|
||||
mem_limit: 256m
|
||||
cpus: 0.50
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:v3.5.0
|
||||
user: '0'
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=7d
|
||||
volumes:
|
||||
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
- ./infra/prometheus/alerts.yml:/etc/prometheus/alerts.yml:ro
|
||||
- promdata:/prometheus
|
||||
expose: ['9090']
|
||||
depends_on:
|
||||
otel-collector: {condition: service_started}
|
||||
restart: unless-stopped
|
||||
mem_limit: 512m
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:12.2.1
|
||||
environment:
|
||||
GF_SECURITY_ADMIN_USER: admin
|
||||
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
|
||||
GF_USERS_ALLOW_SIGN_UP: 'false'
|
||||
GF_ANALYTICS_REPORTING_ENABLED: 'false'
|
||||
secrets: [grafana_admin_password]
|
||||
ports: ['127.0.0.1:${GRAFANA_PORT:-3000}:3000']
|
||||
volumes:
|
||||
- ./infra/grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
- grafanadata:/var/lib/grafana
|
||||
depends_on:
|
||||
prometheus: {condition: service_started}
|
||||
loki: {condition: service_started}
|
||||
tempo: {condition: service_started}
|
||||
restart: unless-stopped
|
||||
mem_limit: 384m
|
||||
|
||||
api:
|
||||
<<: *api
|
||||
command: [gunicorn, --bind, 0.0.0.0:8080, --workers, '1', --threads, '2', --timeout, '35', --graceful-timeout, '5', app.main:app]
|
||||
scale: ${API_REPLICAS:-2}
|
||||
depends_on:
|
||||
migrate: {condition: service_completed_successfully}
|
||||
redis: {condition: service_healthy}
|
||||
broker: {condition: service_healthy}
|
||||
bucket-bootstrap: {condition: service_completed_successfully}
|
||||
healthcheck:
|
||||
test: [CMD, python, -c, "import urllib.request; urllib.request.urlopen('http://localhost:8080/health/ready', timeout=3)"]
|
||||
interval: 2s
|
||||
timeout: 4s
|
||||
retries: 3
|
||||
|
||||
worker:
|
||||
<<: *api
|
||||
command: [python, -m, app.worker]
|
||||
depends_on:
|
||||
migrate: {condition: service_completed_successfully}
|
||||
broker: {condition: service_healthy}
|
||||
bucket-bootstrap: {condition: service_completed_successfully}
|
||||
healthcheck:
|
||||
disable: true
|
||||
deploy:
|
||||
replicas: 1
|
||||
|
||||
lb:
|
||||
image: haproxy:3.0.11-alpine
|
||||
ports: ['127.0.0.1:${APP_PORT:-8081}:8080']
|
||||
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
|
||||
depends_on:
|
||||
api: {condition: service_healthy}
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
s3data:
|
||||
brokerdata:
|
||||
promdata:
|
||||
lokidata:
|
||||
tempodata:
|
||||
grafanadata:
|
||||
|
||||
secrets:
|
||||
db_password: {file: ./secrets/db_password}
|
||||
database_url: {file: ./secrets/database_url}
|
||||
cache_url: {file: ./secrets/cache_url}
|
||||
broker_url: {file: ./secrets/broker_url}
|
||||
rustfs_root_user: {file: ./secrets/rustfs_root_user}
|
||||
rustfs_root_password: {file: ./secrets/rustfs_root_password}
|
||||
s3_access_key_id: {file: ./secrets/s3_access_key_id}
|
||||
s3_secret_access_key: {file: ./secrets/s3_secret_access_key}
|
||||
grafana_admin_password: {file: ./secrets/grafana_admin_password}
|
||||
Reference in New Issue
Block a user