Skeleton contracts / contracts (pull_request) Canceled after 0s
226 lines
7.7 KiB
YAML
226 lines
7.7 KiB
YAML
# Lab7 level 3: TLS ingress, mTLS LB->API, TLS to stateful services, OpenBao.
|
|
# Public certs live in ./certs (committed); private keys in ./certs/private (gitignored).
|
|
x-certs: &certs
|
|
- ./certs:/certs:ro
|
|
|
|
services:
|
|
db:
|
|
image: postgres:16-alpine
|
|
restart: unless-stopped
|
|
user: postgres
|
|
command: ["sh", "-c", "cp /certs/private/db.key /tmp/db.key && chmod 600 /tmp/db.key && exec postgres -c ssl=on -c ssl_cert_file=/certs/db.crt -c ssl_key_file=/tmp/db.key"]
|
|
environment:
|
|
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set a synthetic local password in .env}
|
|
POSTGRES_DB: ${POSTGRES_DB:-messenger}
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
- ./certs:/certs:ro
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-messenger} -d ${POSTGRES_DB:-messenger}"]
|
|
interval: 3s
|
|
timeout: 3s
|
|
retries: 20
|
|
|
|
minio:
|
|
image: bitnamilegacy/minio:latest
|
|
restart: unless-stopped
|
|
user: "0:0"
|
|
environment:
|
|
MINIO_ROOT_USER: ${S3_ACCESS_KEY:-messenger}
|
|
MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY:?set a synthetic local S3 secret in .env}
|
|
MINIO_DATA_DIR: /data
|
|
MINIO_DEFAULT_BUCKETS: ${S3_BUCKET:-messenger}
|
|
MINIO_CONSOLE_PORT_NUMBER: "9001"
|
|
MINIO_SCHEME: https
|
|
volumes:
|
|
- s3data:/data
|
|
- ./certs/minio.crt:/root/.minio/certs/public.crt:ro
|
|
- ./certs/private/minio.key:/root/.minio/certs/private.key:ro
|
|
- ./certs/minio.crt:/opt/bitnami/minio/certs/public.crt
|
|
- ./certs/private/minio.key:/opt/bitnami/minio/certs/private.key
|
|
- ./certs/minio.crt:/opt/bitnami/minio-client/.minio/certs/public.crt
|
|
- ./certs/private/minio.key:/opt/bitnami/minio-client/.minio/certs/private.key
|
|
- ./certs/minio.crt:/.minio/certs/public.crt
|
|
- ./certs/private/minio.key:/.minio/certs/private.key
|
|
- ./certs/minio.crt:/certs/public.crt:ro
|
|
- ./certs/private/minio.key:/certs/private.key:ro
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:9000/minio/health/live > /dev/null || curl -kfsS https://127.0.0.1:9000/minio/health/live > /dev/null"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 30
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
restart: unless-stopped
|
|
command: ["redis-server", "--port", "0", "--tls-port", "6379",
|
|
"--tls-cert-file", "/certs/redis.crt", "--tls-key-file", "/certs/private/redis.key",
|
|
"--tls-ca-cert-file", "/certs/ca.crt", "--tls-auth-clients", "no",
|
|
"--requirepass", "${REDIS_PASSWORD:?set a synthetic local redis password in .env}"]
|
|
volumes:
|
|
- brokerdata:/data
|
|
- ./certs:/certs:ro
|
|
|
|
openbao:
|
|
image: openbao/openbao:2.2.0
|
|
restart: unless-stopped
|
|
user: "0:0"
|
|
cap_add: ["IPC_LOCK"]
|
|
volumes:
|
|
- baodata:/bao/data
|
|
- ./security/bao.hcl:/bao/config/bao.hcl:ro
|
|
- ./certs:/certs:ro
|
|
command: ["server", "-config=/bao/config/bao.hcl"]
|
|
ports:
|
|
- "8200:8200"
|
|
|
|
api1: &api
|
|
build: .
|
|
restart: unless-stopped
|
|
environment: &api_env
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8443
|
|
APP_ENV: lab
|
|
INSTANCE_ALIAS: api1
|
|
DATABASE_URL: ${DATABASE_URL:-postgresql://messenger:messenger@db:5432/messenger}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
S3_ENDPOINT: https://minio:9000
|
|
S3_BUCKET: ${S3_BUCKET:-messenger}
|
|
S3_ACCESS_KEY: ${S3_ACCESS_KEY:-messenger}
|
|
S3_SECRET_KEY: ${S3_SECRET_KEY:?set a synthetic local S3 secret in .env}
|
|
BROKER_HOST: redis
|
|
BROKER_PORT: 6379
|
|
REDIS_PASSWORD: ${REDIS_PASSWORD:?set a synthetic local redis password in .env}
|
|
TLS_CERTFILE: /certs/api.crt
|
|
TLS_KEYFILE: /certs/private/api.key
|
|
TLS_CLIENT_CA: /certs/mesh-ca.crt
|
|
TLS_REQUIRE_CLIENT: "1"
|
|
TLS_CA_FILE: /certs/ca.crt
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
|
OTEL_METRIC_EXPORT_INTERVAL: 5000
|
|
BAO_ADDR: https://openbao:8200
|
|
BAO_APPROLE_FILE: /certs/private/bao-approle.json
|
|
volumes: *certs
|
|
depends_on:
|
|
db: {condition: service_healthy}
|
|
minio: {condition: service_healthy}
|
|
redis: {condition: service_started}
|
|
openbao: {condition: service_started}
|
|
otel-collector: {condition: service_started}
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import ssl,urllib.request; c=ssl.create_default_context(cafile='/certs/ca.crt'); c.load_cert_chain('/certs/lb.crt','/certs/private/lb.key'); urllib.request.urlopen('https://api1:8443/health/ready',context=c,timeout=2)"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
|
|
api2:
|
|
<<: *api
|
|
environment:
|
|
<<: *api_env
|
|
INSTANCE_ALIAS: api2
|
|
|
|
worker:
|
|
build: .
|
|
restart: unless-stopped
|
|
command: ["python", "-m", "worker"]
|
|
environment:
|
|
DATABASE_URL: ${DATABASE_URL:-postgresql://messenger:messenger@db:5432/messenger}
|
|
S3_ENDPOINT: https://minio:9000
|
|
S3_BUCKET: ${S3_BUCKET:-messenger}
|
|
S3_ACCESS_KEY: ${S3_ACCESS_KEY:-messenger}
|
|
S3_SECRET_KEY: ${S3_SECRET_KEY:?set a synthetic local S3 secret in .env}
|
|
BROKER_HOST: redis
|
|
BROKER_PORT: 6379
|
|
REDIS_PASSWORD: ${REDIS_PASSWORD:?set a synthetic local redis password in .env}
|
|
BROKER_CONSUMER: worker-1
|
|
MAX_ATTEMPTS: ${MAX_ATTEMPTS:-5}
|
|
TLS_CA_FILE: /certs/ca.crt
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
|
BAO_ADDR: https://openbao:8200
|
|
BAO_APPROLE_FILE: /certs/private/bao-approle.json
|
|
volumes: *certs
|
|
depends_on:
|
|
db: {condition: service_healthy}
|
|
minio: {condition: service_healthy}
|
|
redis: {condition: service_started}
|
|
openbao: {condition: service_started}
|
|
|
|
otel-collector:
|
|
image: otel/opentelemetry-collector-contrib:0.90.1
|
|
restart: unless-stopped
|
|
command: ["--config=/etc/otel-collector-config.yaml"]
|
|
volumes:
|
|
- ./infra/otel-collector-config.yaml:/etc/otel-collector-config.yaml:ro
|
|
- ./certs:/certs:ro
|
|
ports:
|
|
- "4317:4317"
|
|
- "4318:4318"
|
|
depends_on:
|
|
- loki
|
|
- tempo
|
|
|
|
prometheus:
|
|
image: prom/prometheus:v3.8.1
|
|
restart: unless-stopped
|
|
command: ["--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.path=/prometheus"]
|
|
volumes:
|
|
- ./infra/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
|
- promdata:/prometheus
|
|
ports: ["9090:9090"]
|
|
|
|
loki:
|
|
image: grafana/loki:2.9.13
|
|
restart: unless-stopped
|
|
command: ["-config.file=/etc/loki/loki-config.yaml"]
|
|
volumes:
|
|
- ./infra/loki-config.yaml:/etc/loki/loki-config.yaml:ro
|
|
- lokidata:/loki
|
|
ports: ["3100:3100"]
|
|
|
|
tempo:
|
|
image: grafana/tempo:2.7.1
|
|
restart: unless-stopped
|
|
user: "0:0"
|
|
command: ["-config.file=/etc/tempo-config.yaml"]
|
|
volumes:
|
|
- ./infra/tempo-config.yaml:/etc/tempo-config.yaml:ro
|
|
- tempodata:/tmp/tempo
|
|
ports: ["3200:3200"]
|
|
|
|
grafana:
|
|
image: grafana/grafana:12.2.0
|
|
restart: unless-stopped
|
|
environment:
|
|
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD:-admin-local-only}
|
|
GF_USERS_ALLOW_SIGN_UP: "false"
|
|
volumes:
|
|
- ./infra/grafana-datasources.yml:/etc/grafana/provisioning/datasources/datasources.yml:ro
|
|
- ./infra/grafana-dashboards.yml:/etc/grafana/provisioning/dashboards/dashboards.yml:ro
|
|
- ./infra/grafana-dashboard.json:/var/lib/grafana/dashboards/messenger.json:ro
|
|
- grafanadata:/var/lib/grafana
|
|
ports: ["3000:3000"]
|
|
depends_on: [prometheus, loki, tempo]
|
|
|
|
lb:
|
|
image: nginx:1.27-alpine
|
|
restart: unless-stopped
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
- ./certs:/certs:ro
|
|
ports:
|
|
- "8443:8443"
|
|
depends_on:
|
|
api1: {condition: service_healthy}
|
|
api2: {condition: service_healthy}
|
|
|
|
volumes:
|
|
pgdata:
|
|
s3data:
|
|
brokerdata:
|
|
baodata:
|
|
promdata:
|
|
lokidata:
|
|
tempodata:
|
|
grafanadata:
|