This commit is contained in:
+345
@@ -0,0 +1,345 @@
|
||||
name: mtusi-lab7
|
||||
|
||||
services:
|
||||
cert-bootstrap:
|
||||
image: alpine:3.21.3
|
||||
command: ['/bin/sh', '/scripts/bootstrap-certs.sh']
|
||||
volumes:
|
||||
- ./infra/certs:/certs
|
||||
- postgres_certs:/postgres-certs
|
||||
- ./scripts/bootstrap-certs.sh:/scripts/bootstrap-certs.sh:ro
|
||||
networks: [backend]
|
||||
restart: 'no'
|
||||
|
||||
postgres:
|
||||
image: postgres:16.8-alpine
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
PGSSLCERT: /certs/postgres.crt
|
||||
PGSSLKEY: /certs/postgres.key
|
||||
PGSSLROOTCERT: /certs/ca.crt
|
||||
command: ['postgres', '-c', 'ssl=on', '-c', 'ssl_cert_file=/certs/postgres.crt', '-c', 'ssl_key_file=/certs/postgres.key', '-c', 'ssl_ca_file=/certs/ca.crt']
|
||||
secrets: [postgres_password]
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- postgres_certs:/certs:ro
|
||||
networks: [backend]
|
||||
depends_on:
|
||||
cert-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', 'pg_isready -U messenger -d messenger']
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
restart: unless-stopped
|
||||
read_only: true
|
||||
security_opt: ['no-new-privileges:true']
|
||||
tmpfs: [/tmp, /run/postgresql]
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '1.00', memory: 512M}
|
||||
|
||||
redis:
|
||||
image: redis:7.4.2-alpine
|
||||
command: ['redis-server', '--appendonly', 'yes', '--appendfsync', 'everysec', '--port', '0', '--tls-port', '6380', '--tls-cert-file', '/certs/redis.crt', '--tls-key-file', '/certs/redis.key', '--tls-ca-cert-file', '/certs/ca.crt', '--tls-auth-clients', 'no']
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
- ./infra/certs:/certs:ro
|
||||
networks: [backend]
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', "redis-cli --tls --cacert /certs/ca.crt -p 6380 ping"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
restart: unless-stopped
|
||||
read_only: true
|
||||
security_opt: ['no-new-privileges:true']
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.50', memory: 256M}
|
||||
|
||||
minio:
|
||||
image: minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
|
||||
entrypoint: ['/bin/sh', '/infra/minio-entrypoint.sh']
|
||||
secrets: [minio_root_user, minio_root_password]
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
- ./infra/minio-entrypoint.sh:/infra/minio-entrypoint.sh:ro
|
||||
- ./infra/certs:/certs:ro
|
||||
environment:
|
||||
MINIO_CERTS_DIR: /certs/minio-certs
|
||||
networks: [backend]
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', 'curl --cacert /certs/ca.crt -fsS https://127.0.0.1:9000/minio/health/ready >/dev/null']
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '1.00', memory: 512M}
|
||||
|
||||
minio-bootstrap:
|
||||
image: minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
|
||||
entrypoint: ['/bin/sh', '/infra/minio-bootstrap.sh']
|
||||
environment:
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_ENDPOINT: https://minio:9000
|
||||
secrets: [minio_root_user, minio_root_password, s3_access_key_id, s3_secret_access_key]
|
||||
volumes:
|
||||
- ./infra/minio-bootstrap.sh:/infra/minio-bootstrap.sh:ro
|
||||
- ./infra/s3-policy.json:/infra/s3-policy.json:ro
|
||||
- ./infra/certs:/certs:ro
|
||||
networks: [backend]
|
||||
depends_on:
|
||||
minio:
|
||||
condition: service_healthy
|
||||
restart: 'no'
|
||||
|
||||
migrate:
|
||||
build: .
|
||||
command: ['python', 'scripts/migrate.py']
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
PGSSLMODE: verify-full
|
||||
PGSSLROOTCERT: /certs/ca.crt
|
||||
secrets: [database_url]
|
||||
volumes:
|
||||
- ./infra/certs:/certs:ro
|
||||
networks: [backend]
|
||||
depends_on:
|
||||
cert-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
restart: 'no'
|
||||
|
||||
api:
|
||||
build: .
|
||||
environment:
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: 8443
|
||||
SESSION_STORE: redis
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
CACHE_URL: rediss://redis:6380/0?ssl_cert_reqs=required&ssl_ca_certs=/certs/ca.crt
|
||||
S3_ENDPOINT: https://minio:9000
|
||||
S3_REGION: us-east-1
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
S3_CA_FILE: /certs/ca.crt
|
||||
BROKER_URL: rediss://redis:6380/1?ssl_cert_reqs=required&ssl_ca_certs=/certs/ca.crt
|
||||
BROKER_STREAM: attachment.jobs
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_CERTIFICATE: /certs/ca.crt
|
||||
OTEL_SERVICE_NAME: messenger-api
|
||||
TLS_CA_FILE: /certs/ca.crt
|
||||
TLS_CERT_FILE: /certs/api.crt
|
||||
TLS_KEY_FILE: /certs/api.key
|
||||
BAO_ADDR: https://openbao:8200
|
||||
BAO_CACERT: /certs/ca.crt
|
||||
BAO_ROLE_ID_FILE: /run/bao/role_id
|
||||
BAO_SECRET_ID_FILE: /run/bao/secret_id
|
||||
BAO_KV_PATH: lab7/service
|
||||
ARGON2_MEMORY_KIB: ${ARGON2_MEMORY_KIB:-19456}
|
||||
ARGON2_ITERATIONS: ${ARGON2_ITERATIONS:-2}
|
||||
ARGON2_PARALLELISM: ${ARGON2_PARALLELISM:-1}
|
||||
secrets: [database_url, s3_access_key_id, s3_secret_access_key]
|
||||
volumes:
|
||||
- ./infra/certs:/certs:ro
|
||||
- ./secrets/role_id:/run/bao/role_id:ro
|
||||
- ./secrets/secret_id:/run/bao/secret_id:ro
|
||||
- ./scripts/test-mtls.py:/test-mtls.py:ro
|
||||
networks: [backend]
|
||||
depends_on:
|
||||
cert-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
minio-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
redis:
|
||||
condition: service_healthy
|
||||
otel-collector:
|
||||
condition: service_started
|
||||
deploy:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
resources:
|
||||
limits: {cpus: '1.00', memory: 512M}
|
||||
security_opt: ['no-new-privileges:true']
|
||||
cap_drop: [ALL]
|
||||
read_only: true
|
||||
tmpfs: [/tmp]
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', "python -c \"import ssl,urllib.request; c=ssl.create_default_context(cafile='/certs/ca.crt'); c.load_cert_chain('/certs/lb.crt','/certs/lb.key'); urllib.request.urlopen('https://127.0.0.1:8443/health/ready',context=c,timeout=2)\""]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
restart: unless-stopped
|
||||
|
||||
worker:
|
||||
build: .
|
||||
command: ['python', 'worker.py']
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
BROKER_URL: rediss://redis:6380/1?ssl_cert_reqs=required&ssl_ca_certs=/certs/ca.crt
|
||||
BROKER_STREAM: attachment.jobs
|
||||
S3_ENDPOINT: https://minio:9000
|
||||
S3_REGION: us-east-1
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
S3_CA_FILE: /certs/ca.crt
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: https://otel-collector:4318
|
||||
OTEL_EXPORTER_OTLP_CERTIFICATE: /certs/ca.crt
|
||||
OTEL_SERVICE_NAME: messenger-worker
|
||||
BAO_ADDR: https://openbao:8200
|
||||
BAO_CACERT: /certs/ca.crt
|
||||
BAO_ROLE_ID_FILE: /run/bao/role_id
|
||||
BAO_SECRET_ID_FILE: /run/bao/secret_id
|
||||
BAO_KV_PATH: lab7/service
|
||||
secrets: [database_url, s3_access_key_id, s3_secret_access_key]
|
||||
networks: [backend]
|
||||
volumes:
|
||||
- ./infra/certs:/certs:ro
|
||||
- ./secrets/role_id:/run/bao/role_id:ro
|
||||
- ./secrets/secret_id:/run/bao/secret_id:ro
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
minio-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
redis:
|
||||
condition: service_healthy
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.75', memory: 384M}
|
||||
security_opt: ['no-new-privileges:true']
|
||||
read_only: true
|
||||
tmpfs: [/tmp]
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: unless-stopped
|
||||
|
||||
nginx:
|
||||
image: nginx:1.27.5-alpine
|
||||
ports:
|
||||
- '${APP_PORT:-8443}:8443'
|
||||
volumes:
|
||||
- ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
- ./infra/certs:/certs:ro
|
||||
networks: [frontend, backend]
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_healthy
|
||||
security_opt: ['no-new-privileges:true']
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.50', memory: 128M}
|
||||
restart: unless-stopped
|
||||
|
||||
openbao:
|
||||
image: openbao/openbao:2.2.0
|
||||
command: ['server', '-config=/etc/openbao/openbao.hcl']
|
||||
volumes:
|
||||
- openbao_data:/openbao/file
|
||||
- ./infra/openbao.hcl:/etc/openbao/openbao.hcl:ro
|
||||
- ./infra/certs:/certs:ro
|
||||
- ./infra/openbao-app-policy.hcl:/policies/app.hcl:ro
|
||||
networks: [backend]
|
||||
expose: ['8200']
|
||||
restart: unless-stopped
|
||||
security_opt: ['no-new-privileges:true']
|
||||
deploy:
|
||||
resources:
|
||||
limits: {cpus: '0.50', memory: 256M}
|
||||
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.121.0
|
||||
command: ['--config=/etc/otelcol/collector.yaml']
|
||||
volumes:
|
||||
- ./infra/otel/collector.yaml:/etc/otelcol/collector.yaml:ro
|
||||
- ./infra/certs:/certs:ro
|
||||
networks: [backend]
|
||||
restart: unless-stopped
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:v3.2.1
|
||||
command: ['--config.file=/etc/prometheus/prometheus.yml', '--storage.tsdb.path=/prometheus']
|
||||
volumes:
|
||||
- ./infra/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
- prometheus_data:/prometheus
|
||||
- ./infra/certs:/certs:ro
|
||||
networks: [backend]
|
||||
restart: unless-stopped
|
||||
|
||||
loki:
|
||||
image: grafana/loki:3.5.0
|
||||
command: ['-config.file=/etc/loki/loki.yaml']
|
||||
volumes:
|
||||
- ./infra/loki.yaml:/etc/loki/loki.yaml:ro
|
||||
- loki_data:/loki
|
||||
- ./infra/certs:/certs:ro
|
||||
networks: [backend]
|
||||
restart: unless-stopped
|
||||
|
||||
tempo:
|
||||
image: grafana/tempo:2.7.2
|
||||
command: ['-config.file=/etc/tempo/tempo.yaml']
|
||||
volumes:
|
||||
- ./infra/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
||||
- tempo_data:/var/tempo
|
||||
- ./infra/certs:/certs:ro
|
||||
networks: [backend]
|
||||
restart: unless-stopped
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:11.6.0
|
||||
ports:
|
||||
- '${GRAFANA_PORT:-3000}:3000'
|
||||
environment:
|
||||
GF_AUTH_ANONYMOUS_ENABLED: 'true'
|
||||
GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer
|
||||
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-lab-local-admin}
|
||||
volumes:
|
||||
- ./grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
- grafana_data:/var/lib/grafana
|
||||
networks: [backend, frontend]
|
||||
depends_on: [prometheus, loki, tempo]
|
||||
security_opt: ['no-new-privileges:true']
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
frontend:
|
||||
backend:
|
||||
internal: true
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
postgres_certs:
|
||||
redis_data:
|
||||
minio_data:
|
||||
prometheus_data:
|
||||
loki_data:
|
||||
tempo_data:
|
||||
grafana_data:
|
||||
openbao_data:
|
||||
|
||||
secrets:
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password
|
||||
database_url:
|
||||
file: ./secrets/database_url
|
||||
minio_root_user:
|
||||
file: ./secrets/minio_root_user
|
||||
minio_root_password:
|
||||
file: ./secrets/minio_root_password
|
||||
s3_access_key_id:
|
||||
file: ./secrets/s3_access_key_id
|
||||
s3_secret_access_key:
|
||||
file: ./secrets/s3_secret_access_key
|
||||
Reference in New Issue
Block a user