Files
mtusi2026lab6-fork/compose.yaml
T

231 lines
8.1 KiB
YAML

services:
api1:
build: .
image: mtusi-messenger-api:6.0.0
environment: &api-env
DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?Create a local .env first}@db:5432/${POSTGRES_DB:-messenger}
CACHE_URL: redis://redis:6379/0
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
S3_ENDPOINT: ${S3_ENDPOINT:-http://minio:9000}
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_REGION: ${S3_REGION:-us-east-1}
S3_ACCESS_KEY: ${S3_ACCESS_KEY:?Create local S3 credentials}
S3_SECRET_KEY: ${S3_SECRET_KEY:?Create local S3 credentials}
BROKER_URL: ${BROKER_URL:-redis://redis-broker:6379/0}
ATTACHMENT_QUEUE: attachment.jobs.v1
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
OTEL_SERVICE_NAME: messenger-api
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4317}
OTEL_RESOURCE_ATTRIBUTES: ${OTEL_RESOURCE_ATTRIBUTES:-deployment.environment.name=lab}
depends_on:
migrate: {condition: service_completed_successfully}
s3-bootstrap: {condition: service_completed_successfully}
db: {condition: service_started}
redis: {condition: service_started}
redis-broker: {condition: service_healthy}
otel-collector: {condition: service_started}
mem_limit: 512m
cpus: 1.0
stop_grace_period: 15s
restart: unless-stopped
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=3)"]
interval: 5s
timeout: 4s
retries: 5
start_period: 15s
api2:
build: .
image: mtusi-messenger-api:6.0.0
environment: *api-env
depends_on:
migrate: {condition: service_completed_successfully}
s3-bootstrap: {condition: service_completed_successfully}
db: {condition: service_started}
redis: {condition: service_started}
redis-broker: {condition: service_healthy}
otel-collector: {condition: service_started}
mem_limit: 512m
cpus: 1.0
stop_grace_period: 15s
restart: unless-stopped
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=3)"]
interval: 5s
timeout: 4s
retries: 5
start_period: 15s
migrate:
build: .
image: mtusi-messenger-api:6.0.0
command: ["alembic", "upgrade", "head"]
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?Create a local .env first}@db:5432/${POSTGRES_DB:-messenger}
depends_on:
db: {condition: service_started}
restart: "no"
lb:
image: nginx:1.27.5-alpine
ports:
- "${APP_PORT:-8080}:8080"
volumes:
- ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on: [api1, api2]
mem_limit: 128m
cpus: 0.5
restart: unless-stopped
db:
image: postgres:16.4-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER:-messenger}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Create a local .env first}
POSTGRES_DB: ${POSTGRES_DB:-messenger}
volumes: ["postgres_data:/var/lib/postgresql/data"]
mem_limit: 1g
cpus: 1.0
restart: unless-stopped
redis:
image: redis:7.4.2-alpine
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always"]
volumes: ["redis_data:/data"]
mem_limit: 256m
cpus: 0.5
restart: unless-stopped
redis-broker:
image: redis:7.4.2-alpine
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always"]
volumes: ["broker_data:/data"]
expose: ["6379"]
mem_limit: 256m
cpus: 0.5
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 4s
retries: 12
worker:
build: .
image: mtusi-messenger-api:6.0.0
command: ["python", "-m", "src.worker"]
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?Create a local .env first}@db:5432/${POSTGRES_DB:-messenger}
S3_ENDPOINT: ${S3_ENDPOINT:-http://minio:9000}
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_REGION: ${S3_REGION:-us-east-1}
S3_ACCESS_KEY: ${S3_ACCESS_KEY:?Create local S3 credentials}
S3_SECRET_KEY: ${S3_SECRET_KEY:?Create local S3 credentials}
BROKER_URL: ${BROKER_URL:-redis://redis-broker:6379/0}
ATTACHMENT_QUEUE: attachment.jobs.v1
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
OTEL_SERVICE_NAME: messenger-worker
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4317}
OTEL_RESOURCE_ATTRIBUTES: ${OTEL_RESOURCE_ATTRIBUTES:-deployment.environment.name=lab}
depends_on:
migrate: {condition: service_completed_successfully}
s3-bootstrap: {condition: service_completed_successfully}
redis-broker: {condition: service_healthy}
db: {condition: service_started}
otel-collector: {condition: service_started}
mem_limit: 512m
cpus: 1.0
stop_grace_period: 30s
restart: unless-stopped
minio:
image: dappros/minio:RELEASE.2025-09-07T16-13-09Z
command: ["server", "/data", "--address", ":9000", "--console-address", ":9001"]
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?Create local MinIO credentials}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?Create local MinIO credentials}
volumes: ["minio_data:/data"]
expose: ["9000"]
mem_limit: 768m
cpus: 1.0
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-fsS", "http://127.0.0.1:9000/minio/health/ready"]
interval: 5s
timeout: 3s
retries: 10
s3-bootstrap:
image: ghcr.io/golithus/mc:RELEASE.2025-08-13T08-35-41Z@sha256:dde55ccc0bc9e65dc582c8e652d652eea1438c6e60d774524f4da15d7b26a900
entrypoint: ["/bin/sh", "/bootstrap.sh"]
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?Create local MinIO credentials}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?Create local MinIO credentials}
S3_ACCESS_KEY: ${S3_ACCESS_KEY:?Create local S3 credentials}
S3_SECRET_KEY: ${S3_SECRET_KEY:?Create local S3 credentials}
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
volumes: ["./infra/minio-bootstrap.sh:/bootstrap.sh:ro"]
depends_on:
minio: {condition: service_healthy}
restart: "no"
otel-collector:
image: otel/opentelemetry-collector-contrib:0.165.0
command: ["--config=/etc/otelcol-contrib/collector.yaml"]
volumes: ["./infra/otel/collector.yaml:/etc/otelcol-contrib/collector.yaml:ro"]
depends_on: [prometheus, loki, tempo]
expose: ["4317", "4318", "8889", "13133"]
mem_limit: 256m
cpus: 0.5
restart: unless-stopped
prometheus:
image: prom/prometheus:v3.5.0
command: ["--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.path=/prometheus", "--storage.tsdb.retention.time=7d", "--storage.tsdb.retention.size=2GB"]
volumes: ["./infra/otel/prometheus.yml:/etc/prometheus/prometheus.yml:ro", "prometheus_data:/prometheus"]
expose: ["9090"]
mem_limit: 512m
cpus: 0.5
restart: unless-stopped
loki:
image: grafana/loki:3.5.0
command: ["-config.file=/etc/loki/loki.yaml"]
volumes: ["./infra/otel/loki.yaml:/etc/loki/loki.yaml:ro", "loki_data:/loki"]
expose: ["3100"]
mem_limit: 512m
cpus: 0.5
restart: unless-stopped
tempo:
image: grafana/tempo:2.8.0
command: ["-config.file=/etc/tempo/tempo.yaml"]
volumes: ["./infra/otel/tempo.yaml:/etc/tempo/tempo.yaml:ro", "tempo_data:/var/tempo"]
expose: ["3200", "4317", "4318"]
mem_limit: 512m
cpus: 0.5
restart: unless-stopped
grafana:
image: grafana/grafana:12.1.1
environment:
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD:?Create local Grafana credentials}
ports: ["127.0.0.1:${GRAFANA_PORT:-3000}:3000"]
volumes: ["grafana_data:/var/lib/grafana", "./infra/otel/grafana/provisioning:/etc/grafana/provisioning:ro"]
depends_on: [prometheus, loki, tempo]
mem_limit: 256m
cpus: 0.5
restart: unless-stopped
volumes:
postgres_data:
redis_data:
minio_data:
broker_data:
prometheus_data:
loki_data:
tempo_data:
grafana_data: