Files
mtusi2026lab7/compose.yaml
T

794 lines
19 KiB
YAML

{
"name": "mtusi-lab7",
"services": {
"postgres": {
"image": "postgres:17.6-alpine",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"environment": {
"POSTGRES_USER": "messenger",
"POSTGRES_DB": "messenger",
"POSTGRES_PASSWORD_FILE": "/run/secrets/postgres_password"
},
"command": [
"sh",
"-ec",
"cp /tls/service.key /tmp/postgres.key; chown postgres:postgres /tmp/postgres.key; chmod 600 /tmp/postgres.key; exec docker-entrypoint.sh postgres -c ssl=on -c ssl_cert_file=/tls/service.crt -c ssl_key_file=/tmp/postgres.key -c hba_file=/etc/pg_hba.conf"
],
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/postgres/service.crt:/tls/service.crt:ro",
"./secrets/postgres/service.key:/tls/service.key:ro",
"pgdata:/var/lib/postgresql/data",
"./secrets/postgres_password:/run/secrets/postgres_password:ro",
"./secrets/roles.sql:/docker-entrypoint-initdb.d/roles.sql:ro",
"./infra/security/pg_hba.conf:/etc/pg_hba.conf:ro"
],
"healthcheck": {
"test": [
"CMD",
"pg_isready",
"-U",
"messenger"
],
"interval": "3s",
"timeout": "2s",
"retries": 30
}
},
"valkey": {
"image": "valkey/valkey:8.1.3-alpine",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"command": [
"valkey-server",
"/etc/valkey.conf"
],
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/valkey/service.crt:/tls/service.crt:ro",
"./secrets/valkey/service.key:/tls/service.key:ro",
"valkeydata:/data",
"./secrets/valkey.conf:/etc/valkey.conf:ro"
]
},
"broker": {
"image": "valkey/valkey:8.1.3-alpine",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"command": [
"valkey-server",
"/etc/valkey.conf"
],
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/broker/service.crt:/tls/service.crt:ro",
"./secrets/broker/service.key:/tls/service.key:ro",
"brokerdata:/data",
"./secrets/broker.conf:/etc/valkey.conf:ro"
]
},
"s3": {
"image": "chrislusf/seaweedfs:4.00",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"entrypoint": [
"weed"
],
"command": [
"server",
"-dir=/data",
"-ip=127.0.0.1",
"-ip.bind=127.0.0.1",
"-master.volumeSizeLimitMB=1024",
"-volume.max=16",
"-volume.preStopSeconds=0",
"-filer",
"-s3",
"-s3.ip.bind=127.0.0.1",
"-s3.port=9000",
"-s3.config=/run/secrets/s3_config"
],
"volumes": [
"s3data:/data",
"./secrets/s3_config:/run/secrets/s3_config:ro",
"./infra/seaweedfs/master.toml:/etc/seaweedfs/master.toml:ro"
],
"networks": {
"s3-private": {
"aliases": [
"s3-storage"
]
}
}
},
"openbao": {
"image": "ghcr.io/openbao/openbao:2.7.1",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"command": [
"server",
"-config=/bao/config/config.hcl"
],
"environment": {
"SKIP_SETCAP": "true"
},
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/openbao/service.crt:/tls/service.crt:ro",
"./secrets/openbao/service.key:/tls/service.key:ro",
"baodata:/openbao/file",
"./infra/openbao/config.hcl:/bao/config/config.hcl:ro"
],
"ports": [
"127.0.0.1:18200:8200"
],
"depends_on": {
"bao-volume-init": {
"condition": "service_completed_successfully"
}
}
},
"migrate": {
"build": {
"context": ".",
"target": "migrate"
},
"environment": {
"DATABASE_URL_FILE": "/run/secrets/database_url"
},
"volumes": [
"./secrets/database_url:/run/secrets/database_url:ro",
"./secrets/ca.crt:/tls/ca.crt:ro"
],
"depends_on": {
"postgres": {
"condition": "service_healthy"
}
},
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
}
},
"s3-init": {
"build": {
"context": ".",
"target": "s3init"
},
"environment": {
"S3_ENDPOINT": "https://s3:9443",
"S3_REGION": "us-east-1",
"S3_BUCKET": "messenger-attachments",
"S3_ACCESS_KEY_ID_FILE": "/run/secrets/id",
"S3_SECRET_ACCESS_KEY_FILE": "/run/secrets/key",
"SSL_CERT_FILE": "/tls/ca.crt"
},
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/s3_admin_access_key_id:/run/secrets/id:ro",
"./secrets/s3_admin_secret_access_key:/run/secrets/key:ro"
],
"depends_on": [
"s3-gateway"
],
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
}
},
"api": {
"build": {
"context": ".",
"target": "api"
},
"env_file": ".env",
"environment": {
"BAO_ROLE": "api",
"GOMEMLIMIT": "800MiB",
"APP_MAX_HEAP_BYTES": "805306368"
},
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/api/service.crt:/tls/service.crt:ro",
"./secrets/api/service.key:/tls/service.key:ro",
"./infra/security/runtime.py:/runtime.py:ro"
],
"tmpfs": [
"/run/app-secrets:uid=65534,gid=65534,mode=0700",
"/tmp:size=128m,mode=1777"
],
"user": "65534:65534",
"cap_drop": [
"ALL"
],
"security_opt": [
"no-new-privileges:true"
],
"read_only": true,
"deploy": {
"resources": {
"limits": {
"memory": "1G",
"cpus": "1.0"
}
},
"replicas": 2
},
"depends_on": {
"migrate": {
"condition": "service_completed_successfully"
},
"s3-init": {
"condition": "service_completed_successfully"
}
},
"restart": "unless-stopped",
"entrypoint": [
"python3",
"/runtime.py",
"launch",
"/app/messenger"
],
"stop_grace_period": "15s",
"healthcheck": {
"disable": true
}
},
"worker": {
"build": {
"context": ".",
"dockerfile": "worker/Dockerfile"
},
"env_file": ".env",
"environment": {
"BAO_ROLE": "worker"
},
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/worker/service.crt:/tls/service.crt:ro",
"./secrets/worker/service.key:/tls/service.key:ro",
"./infra/security/runtime.py:/runtime.py:ro"
],
"tmpfs": [
"/run/app-secrets:uid=65534,gid=65534,mode=0700",
"/tmp:size=128m,mode=1777"
],
"user": "65534:65534",
"cap_drop": [
"ALL"
],
"security_opt": [
"no-new-privileges:true"
],
"read_only": true,
"deploy": {
"resources": {
"limits": {
"memory": "1G",
"cpus": "1.0"
}
}
},
"depends_on": {
"migrate": {
"condition": "service_completed_successfully"
},
"s3-init": {
"condition": "service_completed_successfully"
}
},
"restart": "unless-stopped",
"entrypoint": [
"python",
"/runtime.py",
"launch",
"python",
"-u",
"main.py"
],
"stop_grace_period": "15s"
},
"dispatcher": {
"build": {
"context": ".",
"dockerfile": "worker/Dockerfile"
},
"env_file": ".env",
"environment": {
"BAO_ROLE": "dispatcher"
},
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/dispatcher/service.crt:/tls/service.crt:ro",
"./secrets/dispatcher/service.key:/tls/service.key:ro",
"./infra/security/runtime.py:/runtime.py:ro"
],
"tmpfs": [
"/run/app-secrets:uid=65534,gid=65534,mode=0700",
"/tmp:size=128m,mode=1777"
],
"user": "65534:65534",
"cap_drop": [
"ALL"
],
"security_opt": [
"no-new-privileges:true"
],
"read_only": true,
"deploy": {
"resources": {
"limits": {
"memory": "1G",
"cpus": "1.0"
}
}
},
"depends_on": {
"migrate": {
"condition": "service_completed_successfully"
},
"s3-init": {
"condition": "service_completed_successfully"
}
},
"restart": "unless-stopped",
"entrypoint": [
"python",
"/runtime.py",
"launch",
"python",
"-u",
"main.py",
"dispatch"
],
"stop_grace_period": "15s"
},
"lb": {
"image": "haproxy:3.2.9-alpine",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"volumes": [
"./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro",
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/lb/service.pem:/tls/lb.pem:ro"
],
"ports": [
"127.0.0.1:8443:8443"
],
"depends_on": [
"api"
]
},
"otel-collector": {
"image": "otel/opentelemetry-collector-contrib:0.137.0",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"command": [
"--config=/etc/config.yaml"
],
"volumes": [
"./infra/otel/collector.yaml:/etc/config.yaml:ro",
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/otel-collector/service.crt:/tls/service.crt:ro",
"./secrets/otel-collector/service.key:/tls/service.key:ro"
]
},
"loki": {
"image": "grafana/loki:3.5.5",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"command": [
"-config.file=/etc/config.yaml"
],
"volumes": [
"./infra/otel/loki.yaml:/etc/config.yaml:ro",
"./secrets/ca.crt:/tls/ca.crt:ro",
"lokidata:/loki"
]
},
"tempo": {
"image": "grafana/tempo:2.8.2",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"command": [
"-config.file=/etc/config.yaml"
],
"volumes": [
"./infra/otel/tempo.yaml:/etc/config.yaml:ro",
"./secrets/ca.crt:/tls/ca.crt:ro",
"tempodata:/var/tempo"
],
"user": "0:0"
},
"prometheus": {
"image": "prom/prometheus:v3.5.0",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"command": [
"--config.file=/etc/config.yaml",
"--web.listen-address=127.0.0.1:9090",
"--storage.tsdb.retention.time=3d"
],
"volumes": [
"./infra/otel/prometheus.yaml:/etc/config.yaml:ro",
"./secrets/ca.crt:/tls/ca.crt:ro",
"prometheusdata:/prometheus",
"./secrets/prometheus/service.crt:/tls/service.crt:ro",
"./secrets/prometheus/service.key:/tls/service.key:ro"
]
},
"grafana": {
"image": "grafana/grafana:12.2.0",
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"memory": "256M",
"cpus": "0.5"
}
}
},
"environment": {
"GF_SERVER_HTTP_ADDR": "127.0.0.1",
"GF_AUTH_ANONYMOUS_ENABLED": "true",
"GF_AUTH_ANONYMOUS_ORG_ROLE": "Viewer",
"GF_AUTH_DISABLE_LOGIN_FORM": "true",
"GF_ANALYTICS_REPORTING_ENABLED": "false",
"SSL_CERT_FILE": "/tls/ca.crt"
},
"volumes": [
"grafanadata:/var/lib/grafana",
"./infra/grafana/provisioning:/etc/grafana/provisioning:ro",
"./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro",
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/grafana-datasources.yaml:/etc/grafana/provisioning/datasources/sources.yaml:ro"
],
"ports": [
"127.0.0.1:13007:3443"
]
},
"s3-tls": {
"build": "./infra/security",
"network_mode": "service:s3",
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/s3/service.crt:/tls/service.crt:ro",
"./secrets/s3/service.key:/tls/service.key:ro"
],
"command": [
"9443:9000"
],
"depends_on": [
"s3"
],
"restart": "unless-stopped",
"cap_drop": [
"ALL"
],
"security_opt": [
"no-new-privileges:true"
],
"read_only": true,
"deploy": {
"resources": {
"limits": {
"memory": "64M",
"cpus": "0.25"
}
}
}
},
"otel-collector-tls": {
"build": "./infra/security",
"network_mode": "service:otel-collector",
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/otel-collector/service.crt:/tls/service.crt:ro",
"./secrets/otel-collector/service.key:/tls/service.key:ro"
],
"command": [
"4438:4318",
"8899:8889",
"8898:8888"
],
"depends_on": [
"otel-collector"
],
"restart": "unless-stopped",
"cap_drop": [
"ALL"
],
"security_opt": [
"no-new-privileges:true"
],
"read_only": true,
"deploy": {
"resources": {
"limits": {
"memory": "64M",
"cpus": "0.25"
}
}
},
"environment": {
"TLS_ALLOWED_IDS": "spiffe://lab7/api,spiffe://lab7/worker,spiffe://lab7/dispatcher,spiffe://lab7/prometheus"
}
},
"loki-tls": {
"build": "./infra/security",
"network_mode": "service:loki",
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/loki/service.crt:/tls/service.crt:ro",
"./secrets/loki/service.key:/tls/service.key:ro"
],
"command": [
"3443:3100"
],
"depends_on": [
"loki"
],
"restart": "unless-stopped",
"cap_drop": [
"ALL"
],
"security_opt": [
"no-new-privileges:true"
],
"read_only": true,
"deploy": {
"resources": {
"limits": {
"memory": "64M",
"cpus": "0.25"
}
}
},
"environment": {
"TLS_ALLOWED_IDS": "spiffe://lab7/otel-collector,spiffe://lab7/grafana"
}
},
"tempo-tls": {
"build": "./infra/security",
"network_mode": "service:tempo",
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/tempo/service.crt:/tls/service.crt:ro",
"./secrets/tempo/service.key:/tls/service.key:ro"
],
"command": [
"3443:3200",
"4438:4318"
],
"depends_on": [
"tempo"
],
"restart": "unless-stopped",
"cap_drop": [
"ALL"
],
"security_opt": [
"no-new-privileges:true"
],
"read_only": true,
"deploy": {
"resources": {
"limits": {
"memory": "64M",
"cpus": "0.25"
}
}
},
"environment": {
"TLS_ALLOWED_IDS": "spiffe://lab7/otel-collector,spiffe://lab7/grafana"
}
},
"prometheus-tls": {
"build": "./infra/security",
"network_mode": "service:prometheus",
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/prometheus/service.crt:/tls/service.crt:ro",
"./secrets/prometheus/service.key:/tls/service.key:ro"
],
"command": [
"9443:9090"
],
"depends_on": [
"prometheus"
],
"restart": "unless-stopped",
"cap_drop": [
"ALL"
],
"security_opt": [
"no-new-privileges:true"
],
"read_only": true,
"deploy": {
"resources": {
"limits": {
"memory": "64M",
"cpus": "0.25"
}
}
},
"environment": {
"TLS_ALLOWED_IDS": "spiffe://lab7/grafana"
}
},
"grafana-tls": {
"build": "./infra/security",
"network_mode": "service:grafana",
"volumes": [
"./secrets/ca.crt:/tls/ca.crt:ro",
"./secrets/grafana/service.crt:/tls/service.crt:ro",
"./secrets/grafana/service.key:/tls/service.key:ro"
],
"command": [
"3443:3000"
],
"depends_on": [
"grafana"
],
"restart": "unless-stopped",
"cap_drop": [
"ALL"
],
"security_opt": [
"no-new-privileges:true"
],
"read_only": true,
"deploy": {
"resources": {
"limits": {
"memory": "64M",
"cpus": "0.25"
}
}
}
},
"s3-gateway": {
"image": "haproxy:3.2.9-alpine",
"volumes": [
"./infra/s3-gateway/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro"
],
"networks": {
"default": {
"aliases": [
"s3"
]
},
"s3-private": {}
},
"depends_on": [
"s3-tls"
],
"restart": "unless-stopped",
"deploy": {
"resources": {
"limits": {
"cpus": "0.25",
"memory": "64M"
}
}
}
},
"bao-volume-init": {
"image": "ghcr.io/openbao/openbao:2.7.1",
"user": "0:0",
"entrypoint": [
"sh",
"-ec",
"chown 100:1000 /openbao/file"
],
"volumes": [
"baodata:/openbao/file"
],
"deploy": {
"resources": {
"limits": {
"cpus": "0.25",
"memory": "64M"
}
}
}
}
},
"volumes": {
"pgdata": {},
"valkeydata": {},
"brokerdata": {},
"s3data": {},
"baodata": {},
"lokidata": {},
"tempodata": {},
"prometheusdata": {},
"grafanadata": {}
},
"networks": {
"s3-private": {
"internal": true
}
}
}