495 lines
15 KiB
YAML
495 lines
15 KiB
YAML
name: lab7
|
|
|
|
networks:
|
|
lab:
|
|
telemetry:
|
|
internal: true
|
|
|
|
volumes:
|
|
postgres-data:
|
|
redis-data:
|
|
minio-data:
|
|
rabbit-data:
|
|
openbao-data:
|
|
tempo-data:
|
|
loki-data:
|
|
prometheus-data:
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:16.8-bookworm
|
|
user: "0:0"
|
|
restart: unless-stopped
|
|
mem_limit: 512m
|
|
cpus: "1.0"
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/db_migrator_password
|
|
volumes:
|
|
- postgres-data:/var/lib/postgresql/data
|
|
- ./infra/postgres/entry.sh:/entry.sh:ro
|
|
- ./infra/postgres/init-roles.sh:/docker-entrypoint-initdb.d/10-roles.sh:ro
|
|
- ./infra/postgres/pg_hba.conf:/etc/pg/pg_hba.conf:ro
|
|
- ./secrets/certs/postgres.crt:/certs/postgres.crt:ro
|
|
- ./secrets/certs/postgres.key:/certs/postgres.key:ro
|
|
- ./secrets/passwords/db_migrator:/run/secrets/db_migrator_password:ro
|
|
- ./secrets/passwords/db_api:/run/secrets/db_api_password:ro
|
|
- ./secrets/passwords/db_worker:/run/secrets/db_worker_password:ro
|
|
- ./secrets/passwords/db_relay:/run/secrets/db_relay_password:ro
|
|
- ./secrets/passwords/db_gc:/run/secrets/db_gc_password:ro
|
|
entrypoint: ["/bin/sh", "/entry.sh"]
|
|
networks: [lab]
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger && test -f /var/lib/postgresql/data/.roles-ready"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 30
|
|
start_period: 20s
|
|
|
|
redis:
|
|
image: redis:7.4.2-bookworm
|
|
user: "0:0"
|
|
restart: unless-stopped
|
|
mem_limit: 256m
|
|
cpus: "0.50"
|
|
volumes:
|
|
- redis-data:/data
|
|
- ./infra/redis/entry.sh:/entry.sh:ro
|
|
- ./secrets/certs/redis.crt:/certs/redis.crt:ro
|
|
- ./secrets/certs/redis.key:/certs/redis.key:ro
|
|
- ./secrets/certs/ca.crt:/certs/ca.crt:ro
|
|
- ./secrets/passwords/redis:/run/secrets/redis_password:ro
|
|
entrypoint: ["/bin/sh", "/entry.sh"]
|
|
networks: [lab]
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "redis-cli --tls --cacert /certs/ca.crt -h redis -p 6379 -a \"$$(cat /run/secrets/redis_password)\" ping | grep -q PONG"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 30
|
|
start_period: 10s
|
|
|
|
minio:
|
|
image: minio/minio:RELEASE.2024-10-02T17-50-41Z
|
|
restart: unless-stopped
|
|
mem_limit: 512m
|
|
cpus: "0.50"
|
|
command: ["server", "/data", "--address", "127.0.0.1:9000", "--console-address", "127.0.0.1:9001"]
|
|
env_file:
|
|
- ./secrets/minio.env
|
|
volumes:
|
|
- minio-data:/data
|
|
networks: [lab]
|
|
|
|
minio-tls:
|
|
image: nginx:1.27.4-alpine
|
|
restart: unless-stopped
|
|
network_mode: "service:minio"
|
|
depends_on:
|
|
- minio
|
|
volumes:
|
|
- ./infra/nginx/minio.conf:/etc/nginx/conf.d/default.conf:ro
|
|
- ./secrets/certs/minio.crt:/certs/minio.crt:ro
|
|
- ./secrets/certs/minio.key:/certs/minio.key:ro
|
|
|
|
minio-init:
|
|
image: minio/mc:RELEASE.2024-10-02T08-27-28Z
|
|
restart: "no"
|
|
entrypoint: ["/bin/sh", "/opt/minio-bootstrap.sh"]
|
|
volumes:
|
|
- ./infra/minio-bootstrap.sh:/opt/minio-bootstrap.sh:ro
|
|
- ./infra/minio:/policies:ro
|
|
- ./secrets:/secrets:ro
|
|
- ./secrets/certs/ca.crt:/certs/ca.crt:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
- minio
|
|
- minio-tls
|
|
|
|
rabbitmq:
|
|
image: rabbitmq:3.13.7-management-alpine
|
|
user: "0:0"
|
|
restart: unless-stopped
|
|
mem_limit: 512m
|
|
cpus: "0.50"
|
|
entrypoint: ["/bin/sh", "/entry.sh"]
|
|
volumes:
|
|
- rabbit-data:/var/lib/rabbitmq
|
|
- ./infra/rabbit-entry.sh:/entry.sh:ro
|
|
- ./infra/rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
|
|
- ./secrets/rabbit-definitions.json:/run/secrets/definitions.json:ro
|
|
- ./secrets/certs/ca.crt:/certs/ca.crt:ro
|
|
- ./secrets/certs/rabbitmq.crt:/certs/rabbitmq.crt:ro
|
|
- ./secrets/certs/rabbitmq.key:/certs/rabbitmq.key:ro
|
|
- ./secrets/passwords/rabbit_operator_name:/run/secrets/rabbitmq_user:ro
|
|
- ./secrets/passwords/rabbit_operator:/run/secrets/rabbitmq_password:ro
|
|
networks: [lab]
|
|
healthcheck:
|
|
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 30
|
|
start_period: 20s
|
|
|
|
openbao:
|
|
image: openbao/openbao:2.1.0
|
|
user: "0:0"
|
|
restart: unless-stopped
|
|
mem_limit: 256m
|
|
cpus: "0.50"
|
|
entrypoint: ["/bin/sh", "/entry.sh"]
|
|
cap_add:
|
|
- IPC_LOCK
|
|
volumes:
|
|
- openbao-data:/openbao/data
|
|
- ./infra/openbao/entry.sh:/entry.sh:ro
|
|
- ./infra/openbao/config.hcl:/openbao/config/config.hcl:ro
|
|
- ./secrets/certs/openbao.crt:/certs/openbao.crt:ro
|
|
- ./secrets/certs/openbao.key:/certs/openbao.key:ro
|
|
ports:
|
|
- "127.0.0.1:8200:8200"
|
|
networks: [lab]
|
|
|
|
openbao-init:
|
|
image: python:3.13.16-slim-bookworm@sha256:a1165e272e578941b84abc79e4ab38a0305cd12803a5c4247979ac7655f4d641
|
|
user: "0:0"
|
|
restart: "no"
|
|
entrypoint: ["python", "/opt/openbao_bootstrap.py"]
|
|
environment:
|
|
BAO_ADDR: https://openbao:8200
|
|
BAO_CACERT: /secrets/certs/ca.crt
|
|
SECRETS_DIR: /secrets
|
|
POLICIES_DIR: /policies
|
|
volumes:
|
|
- ./scripts/openbao_bootstrap.py:/opt/openbao_bootstrap.py:ro
|
|
- ./secrets:/secrets
|
|
- ./infra/openbao/policies:/policies:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
- openbao
|
|
|
|
tempo:
|
|
image: grafana/tempo:2.6.1
|
|
restart: unless-stopped
|
|
mem_limit: 256m
|
|
cpus: "0.50"
|
|
command: ["-config.file=/etc/tempo/tempo.yml"]
|
|
volumes:
|
|
- tempo-data:/var/tempo
|
|
- ./infra/tempo/tempo.yml:/etc/tempo/tempo.yml:ro
|
|
networks: [telemetry]
|
|
|
|
loki:
|
|
image: grafana/loki:3.3.2
|
|
restart: unless-stopped
|
|
mem_limit: 256m
|
|
cpus: "0.50"
|
|
command: ["-config.file=/etc/loki/loki.yml"]
|
|
volumes:
|
|
- loki-data:/loki
|
|
- ./infra/loki/loki.yml:/etc/loki/loki.yml:ro
|
|
networks: [telemetry]
|
|
|
|
telemetry-proxy:
|
|
image: nginx:1.27.4-alpine
|
|
restart: unless-stopped
|
|
mem_limit: 128m
|
|
cpus: "0.25"
|
|
volumes:
|
|
- ./infra/nginx/telemetry.conf:/etc/nginx/conf.d/default.conf:ro
|
|
- ./secrets/certs/telemetry.crt:/certs/telemetry.crt:ro
|
|
- ./secrets/certs/telemetry.key:/certs/telemetry.key:ro
|
|
- ./secrets/certs/ca.crt:/certs/ca.crt:ro
|
|
networks:
|
|
telemetry: {}
|
|
lab:
|
|
aliases:
|
|
- tempo.lab.internal
|
|
- loki.lab.internal
|
|
depends_on:
|
|
- tempo
|
|
- loki
|
|
|
|
otel-collector:
|
|
image: otel/opentelemetry-collector-contrib:0.115.0
|
|
restart: unless-stopped
|
|
mem_limit: 384m
|
|
cpus: "0.50"
|
|
command: ["--config=/etc/otel/collector.yaml"]
|
|
env_file:
|
|
- ./secrets/otel.env
|
|
volumes:
|
|
- ./infra/otel/collector.yaml:/etc/otel/collector.yaml:ro
|
|
- ./secrets/certs/ca.crt:/certs/ca.crt:ro
|
|
- ./secrets/certs/otel.crt:/certs/otel.crt:ro
|
|
- ./secrets/certs/otel.key:/certs/otel.key:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
- telemetry-proxy
|
|
|
|
prometheus:
|
|
image: prom/prometheus:v2.55.1
|
|
restart: unless-stopped
|
|
mem_limit: 384m
|
|
cpus: "0.50"
|
|
command:
|
|
- --config.file=/etc/prometheus/prometheus.yml
|
|
- --web.config.file=/etc/prometheus/web.yml
|
|
- --storage.tsdb.path=/prometheus
|
|
- --storage.tsdb.retention.time=7d
|
|
- --web.listen-address=:9090
|
|
volumes:
|
|
- prometheus-data:/prometheus
|
|
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
|
- ./infra/prometheus/alerts.yml:/etc/prometheus/alerts.yml:ro
|
|
- ./secrets/prometheus/web.yml:/etc/prometheus/web.yml:ro
|
|
- ./secrets/certs/ca.crt:/certs/ca.crt:ro
|
|
- ./secrets/certs/prometheus.crt:/certs/prometheus.crt:ro
|
|
- ./secrets/certs/prometheus.key:/certs/prometheus.key:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
- otel-collector
|
|
|
|
grafana:
|
|
image: grafana/grafana:11.4.0
|
|
restart: unless-stopped
|
|
mem_limit: 384m
|
|
cpus: "0.50"
|
|
entrypoint: ["/bin/sh", "/opt/entry.sh"]
|
|
environment:
|
|
GF_SERVER_PROTOCOL: https
|
|
GF_SERVER_CERT_FILE: /certs/grafana.crt
|
|
GF_SERVER_CERT_KEY: /certs/grafana.key
|
|
GF_SERVER_HTTP_PORT: "3000"
|
|
ports:
|
|
- "127.0.0.1:3000:3000"
|
|
volumes:
|
|
- ./infra/grafana/entry.sh:/opt/entry.sh:ro
|
|
- ./secrets/passwords/grafana_admin:/run/secrets/grafana_admin_password:ro
|
|
- ./secrets/certs/grafana.crt:/certs/grafana.crt:ro
|
|
- ./secrets/certs/grafana.key:/certs/grafana.key:ro
|
|
- ./secrets/grafana/datasources.yml:/etc/grafana/provisioning/datasources/datasources.yml:ro
|
|
- ./infra/grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards:ro
|
|
- ./infra/grafana/provisioning/alerting:/etc/grafana/provisioning/alerting:ro
|
|
- ./infra/grafana/dashboards:/etc/grafana/dashboards:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
- prometheus
|
|
- telemetry-proxy
|
|
|
|
haproxy:
|
|
image: haproxy:2.8.14
|
|
restart: unless-stopped
|
|
mem_limit: 256m
|
|
cpus: "0.50"
|
|
ports:
|
|
- "127.0.0.1:8443:8443"
|
|
volumes:
|
|
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
- ./secrets/haproxy:/certs:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
- api
|
|
|
|
migrate:
|
|
build: .
|
|
image: lab7-messenger:1
|
|
restart: "no"
|
|
user: "10001:10001"
|
|
mem_limit: 512m
|
|
cap_drop: ["ALL"]
|
|
security_opt: ["no-new-privileges:true"]
|
|
command: ["python", "-m", "app.migrate"]
|
|
environment: &migrate-env
|
|
APP_ROLE: migrate
|
|
RUN_MIGRATIONS: "1"
|
|
MTLS_ENABLED: "0"
|
|
OTEL_SDK_DISABLED: "1"
|
|
BAO_ADDR: https://openbao:8200
|
|
BAO_CACERT: /run/app/ca.crt
|
|
BAO_ROLE_ID_FILE: /run/app/role_id
|
|
BAO_SECRET_ID_FILE: /run/app/secret_id
|
|
BAO_KV_PATH: secret/data/messenger/migrate
|
|
TLS_CA_FILE: /run/app/ca.crt
|
|
DB_CONNECT_TIMEOUT_SECONDS: "5"
|
|
volumes:
|
|
- ./secrets/runtime/migrate:/run/app:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
openbao-init:
|
|
condition: service_completed_successfully
|
|
|
|
api:
|
|
build: .
|
|
image: lab7-messenger:1
|
|
restart: unless-stopped
|
|
init: true
|
|
mem_limit: 768m
|
|
cpus: "1.0"
|
|
cap_drop: ["ALL"]
|
|
security_opt: ["no-new-privileges:true"]
|
|
deploy:
|
|
replicas: 2
|
|
environment:
|
|
APP_ROLE: api
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: "8443"
|
|
INTERNAL_PORT: "8080"
|
|
MTLS_ENABLED: "1"
|
|
MTLS_ALLOWED_DNS: lb.lab.internal
|
|
RUN_MIGRATIONS: "0"
|
|
BAO_ADDR: https://openbao:8200
|
|
BAO_CACERT: /run/app/ca.crt
|
|
BAO_ROLE_ID_FILE: /run/app/role_id
|
|
BAO_SECRET_ID_FILE: /run/app/secret_id
|
|
BAO_KV_PATH: secret/data/messenger/api
|
|
TLS_CA_FILE: /run/app/ca.crt
|
|
TLS_CERT_FILE: /run/app/server.crt
|
|
TLS_KEY_FILE: /run/app/server.key
|
|
OTEL_SERVICE_NAME: messenger-api
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
|
OTEL_EXPORTER_OTLP_CERTIFICATE: /run/app/ca.crt
|
|
S3_ENDPOINT: https://minio:9000
|
|
S3_BUCKET: messenger-attachments
|
|
ARGON2_MEMORY_KIB: "19456"
|
|
ARGON2_ITERATIONS: "2"
|
|
ARGON2_PARALLELISM: "1"
|
|
LOGIN_RATE_LIMIT: "10"
|
|
LOGIN_RATE_WINDOW_SECONDS: "60"
|
|
MAX_JSON_BYTES: "65536"
|
|
SESSION_TTL_SECONDS: "3600"
|
|
DB_CONNECT_TIMEOUT_SECONDS: "5"
|
|
REDIS_SOCKET_TIMEOUT_SECONDS: "3"
|
|
volumes:
|
|
- ./secrets/runtime/api:/run/app:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
redis:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=3).read()"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 24
|
|
start_period: 40s
|
|
|
|
worker:
|
|
build: .
|
|
image: lab7-messenger:1
|
|
restart: unless-stopped
|
|
init: true
|
|
mem_limit: 768m
|
|
cpus: "1.0"
|
|
cap_drop: ["ALL"]
|
|
security_opt: ["no-new-privileges:true"]
|
|
command: ["python", "-m", "app.worker"]
|
|
environment:
|
|
APP_ROLE: worker
|
|
MTLS_ENABLED: "0"
|
|
RUN_MIGRATIONS: "0"
|
|
OTEL_SERVICE_NAME: messenger-worker
|
|
BAO_ADDR: https://openbao:8200
|
|
BAO_CACERT: /run/app/ca.crt
|
|
BAO_ROLE_ID_FILE: /run/app/role_id
|
|
BAO_SECRET_ID_FILE: /run/app/secret_id
|
|
BAO_KV_PATH: secret/data/messenger/worker
|
|
TLS_CA_FILE: /run/app/ca.crt
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
|
OTEL_EXPORTER_OTLP_CERTIFICATE: /run/app/ca.crt
|
|
S3_ENDPOINT: https://minio:9000
|
|
S3_BUCKET: messenger-attachments
|
|
DB_CONNECT_TIMEOUT_SECONDS: "5"
|
|
volumes:
|
|
- ./secrets/runtime/worker:/run/app:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
rabbitmq:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import pathlib; assert pathlib.Path('/tmp/worker-heartbeat').read_text().strip()=='ok'"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
start_period: 40s
|
|
|
|
relay:
|
|
build: .
|
|
image: lab7-messenger:1
|
|
restart: unless-stopped
|
|
init: true
|
|
mem_limit: 384m
|
|
cpus: "0.50"
|
|
cap_drop: ["ALL"]
|
|
security_opt: ["no-new-privileges:true"]
|
|
command: ["python", "-m", "app.relay"]
|
|
environment:
|
|
APP_ROLE: relay
|
|
MTLS_ENABLED: "0"
|
|
RUN_MIGRATIONS: "0"
|
|
OTEL_SERVICE_NAME: messenger-relay
|
|
BAO_ADDR: https://openbao:8200
|
|
BAO_CACERT: /run/app/ca.crt
|
|
BAO_ROLE_ID_FILE: /run/app/role_id
|
|
BAO_SECRET_ID_FILE: /run/app/secret_id
|
|
BAO_KV_PATH: secret/data/messenger/relay
|
|
TLS_CA_FILE: /run/app/ca.crt
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
|
OTEL_EXPORTER_OTLP_CERTIFICATE: /run/app/ca.crt
|
|
DB_CONNECT_TIMEOUT_SECONDS: "5"
|
|
volumes:
|
|
- ./secrets/runtime/relay:/run/app:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
rabbitmq:
|
|
condition: service_healthy
|
|
|
|
gc:
|
|
build: .
|
|
image: lab7-messenger:1
|
|
restart: unless-stopped
|
|
mem_limit: 384m
|
|
cpus: "0.50"
|
|
cap_drop: ["ALL"]
|
|
security_opt: ["no-new-privileges:true"]
|
|
command: ["python", "-m", "app.gc"]
|
|
environment:
|
|
APP_ROLE: gc
|
|
MTLS_ENABLED: "0"
|
|
RUN_MIGRATIONS: "0"
|
|
OTEL_SERVICE_NAME: messenger-gc
|
|
BAO_ADDR: https://openbao:8200
|
|
BAO_CACERT: /run/app/ca.crt
|
|
BAO_ROLE_ID_FILE: /run/app/role_id
|
|
BAO_SECRET_ID_FILE: /run/app/secret_id
|
|
BAO_KV_PATH: secret/data/messenger/gc
|
|
TLS_CA_FILE: /run/app/ca.crt
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
|
|
OTEL_EXPORTER_OTLP_CERTIFICATE: /run/app/ca.crt
|
|
S3_ENDPOINT: https://minio:9000
|
|
S3_BUCKET: messenger-attachments
|
|
DB_CONNECT_TIMEOUT_SECONDS: "5"
|
|
volumes:
|
|
- ./secrets/runtime/gc:/run/app:ro
|
|
networks: [lab]
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
minio-init:
|
|
condition: service_completed_successfully
|