Files
mtusi2026lab6/compose.yaml

259 lines
6.3 KiB
YAML

services:
postgres:
image: postgres:16.6-bookworm
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 5s
timeout: 3s
retries: 15
restart: unless-stopped
networks:
- backend
redis:
image: redis:7.4.2-alpine
command: ["redis-server", "--appendonly", "yes", "--save", "60", "1000"]
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
restart: unless-stopped
networks:
- backend
rabbitmq:
image: rabbitmq:4.0.5-management-alpine
environment:
RABBITMQ_DEFAULT_USER: ${RABBITMQ_USER}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD}
volumes:
- rabbitmq_data:/var/lib/rabbitmq
healthcheck:
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
interval: 10s
timeout: 5s
retries: 10
restart: unless-stopped
networks:
- backend
seaweedfs:
image: chrislusf/seaweedfs:4.46
command: ["mini", "-dir=/data"]
environment:
AWS_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY}
S3_BUCKET: ${S3_BUCKET}
volumes:
- seaweedfs_data:/data
ports:
- "127.0.0.1:8334:8333"
restart: unless-stopped
networks:
- backend
migrate:
build:
context: .
dockerfile: Dockerfile
env_file: .env
command: ["alembic", "upgrade", "head"]
depends_on:
postgres:
condition: service_healthy
healthcheck:
disable: true
restart: "no"
networks:
- backend
api:
build:
context: .
dockerfile: Dockerfile
env_file: .env
environment:
OTEL_SERVICE_NAME: messenger-api
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab
expose:
- "8080"
healthcheck:
test:
- CMD
- python
- -c
- "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/live', timeout=3)"
interval: 10s
timeout: 5s
retries: 10
start_period: 30s
depends_on:
migrate:
condition: service_completed_successfully
seaweedfs:
condition: service_started
redis:
condition: service_healthy
otel-collector:
condition: service_started
restart: unless-stopped
networks:
- backend
outbox-publisher:
build:
context: .
dockerfile: Dockerfile
env_file: .env
command: ["python", "-m", "app.services.outbox_publisher"]
depends_on:
migrate:
condition: service_completed_successfully
rabbitmq:
condition: service_healthy
healthcheck:
disable: true
restart: unless-stopped
networks:
- backend
worker:
build:
context: .
dockerfile: Dockerfile
env_file: .env
environment:
OTEL_SERVICE_NAME: messenger-worker
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab
cpus: 1.0
mem_limit: 1g
command: ["python", "-m", "app.worker"]
depends_on:
migrate:
condition: service_completed_successfully
seaweedfs:
condition: service_started
rabbitmq:
condition: service_healthy
otel-collector:
condition: service_started
healthcheck:
disable: true
restart: unless-stopped
networks:
- backend
nginx:
image: nginx:1.27.4-alpine
ports:
- "127.0.0.1:18082:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
api:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1/health/live || exit 1"]
interval: 10s
timeout: 3s
retries: 10
restart: unless-stopped
networks:
- backend
otel-collector:
image: otel/opentelemetry-collector-contrib:0.116.1
command: ["--config=/etc/otelcol-contrib/config.yaml"]
volumes:
- ./observability/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml:ro
depends_on:
- prometheus
- loki
- tempo
restart: unless-stopped
networks:
- backend
prometheus:
image: prom/prometheus:v2.55.1
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--storage.tsdb.retention.time=7d"
volumes:
- ./observability/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
ports:
- "127.0.0.1:19090:9090"
restart: unless-stopped
networks:
- backend
loki:
image: grafana/loki:3.3.2
command: ["-config.file=/etc/loki/local-config.yaml"]
volumes:
- ./observability/loki-config.yaml:/etc/loki/local-config.yaml:ro
- loki_data:/loki
restart: unless-stopped
networks:
- backend
tempo:
image: grafana/tempo:2.6.1
command: ["-config.file=/etc/tempo/tempo.yaml"]
volumes:
- ./observability/tempo-config.yaml:/etc/tempo/tempo.yaml:ro
- tempo_data:/var/tempo
restart: unless-stopped
networks:
- backend
grafana:
image: grafana/grafana:11.4.0
environment:
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-change_me}
GF_USERS_ALLOW_SIGN_UP: "false"
volumes:
- grafana_data:/var/lib/grafana
- ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources:ro
- ./grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards:ro
- ./grafana/dashboards:/var/lib/grafana/dashboards:ro
ports:
- "127.0.0.1:13000:3000"
depends_on:
- prometheus
- loki
- tempo
restart: unless-stopped
networks:
- backend
volumes:
postgres_data:
redis_data:
rabbitmq_data:
seaweedfs_data:
prometheus_data:
loki_data:
tempo_data:
grafana_data:
networks:
backend:
driver: bridge