mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-12-06 19:24:41 +00:00
212 lines
8.2 KiB
YAML
212 lines
8.2 KiB
YAML
# CI-only data-plane overlay.
|
|
#
|
|
# The live host runs the long-lived data-plane services (timescaledb, mosquitto,
|
|
# redis, mosquitto-reloader) as a separate meshcore-infra project on the shared
|
|
# bridge network. GitHub-hosted runners have no such project, so the compose
|
|
# validation and empty-volume smoke test need the definitions here.
|
|
#
|
|
# Never use this file for a real deployment; it exists purely so `ci.yml` can
|
|
# merge a self-contained stack with `docker compose -f docker-compose.yml
|
|
# -f docker-compose.ci.yml`.
|
|
|
|
services:
|
|
link-worker:
|
|
build:
|
|
args:
|
|
USE_AZURE_UBUNTU_MIRROR: "true"
|
|
|
|
hopreach:
|
|
build:
|
|
args:
|
|
USE_AZURE_UBUNTU_MIRROR: "true"
|
|
|
|
# The CI receiver uses an owned HTTP sink; no external alert destination is contacted.
|
|
alert-forward-sink:
|
|
image: ${BACKEND_IMAGE:-meshcore-analytics-backend:local}
|
|
command: ["node", "--input-type=module", "-e", "import http from 'node:http';http.createServer((q,r)=>{q.resume();q.on('end',()=>{r.writeHead(204);r.end();});}).listen(8080,'0.0.0.0');"]
|
|
read_only: true
|
|
cap_drop: [ALL]
|
|
mem_limit: "64m"
|
|
healthcheck:
|
|
test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:8080').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 15
|
|
|
|
alert-receiver:
|
|
environment:
|
|
ALERT_FORWARD_URL: http://alert-forward-sink:8080
|
|
depends_on:
|
|
alert-forward-sink:
|
|
condition: service_healthy
|
|
|
|
alert-receiver-bootstrap:
|
|
image: ${BACKEND_IMAGE:-meshcore-analytics-backend:local}
|
|
restart: "no"
|
|
read_only: true
|
|
cap_drop: [ALL]
|
|
mem_limit: "64m"
|
|
environment:
|
|
ALERT_RECEIVER_TOKEN: ${ALERT_RECEIVER_TOKEN:?CI receiver token required}
|
|
depends_on:
|
|
alert-receiver:
|
|
condition: service_started
|
|
alert-forward-sink:
|
|
condition: service_healthy
|
|
command: ["node", "--input-type=module", "-e", "const base='http://alert-receiver:8080';for(let i=0;i<120;i++){try{const r=await fetch(base+'/alerts',{method:'POST',headers:{authorization:'Bearer '+process.env.ALERT_RECEIVER_TOKEN,'content-type':'application/json'},body:JSON.stringify({source:'ci',status:'resolved',check:'owned forwarding bootstrap'})});if(r.status===202)break;if(i===119)throw Error('CI alert admission failed');}catch(e){if(i===119)throw e;}await new Promise(r=>setTimeout(r,500));}for(let i=0;i<120;i++){const r=await fetch(base+'/readyz');if(r.ok){console.log('CI receiver forwarding proof ready');process.exit(0);}await new Promise(r=>setTimeout(r,500));}throw Error('CI alert forwarding did not become ready');"]
|
|
|
|
alertmanager:
|
|
depends_on:
|
|
alert-receiver-bootstrap:
|
|
condition: service_completed_successfully
|
|
volumes:
|
|
- ./logging/alertmanager.ci.yml:/etc/alertmanager/alertmanager.yml:ro
|
|
|
|
timescaledb:
|
|
image: timescale/timescaledb@sha256:22e8a5ae7aef121d1537afe946dd7cc5deeeb63ab36ce19849d671bd3b663509
|
|
logging: &json-log-limits
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
mem_limit: "4g"
|
|
memswap_limit: "4g"
|
|
# POSIX dynamic shared memory for parallel maintenance; avoid Docker's 64m default.
|
|
shm_size: "1g"
|
|
stop_grace_period: 2m
|
|
# The image currently tunes timescaledb.max_background_workers to 16.
|
|
# Leave headroom for the Timescale launcher/schedulers, logical replication,
|
|
# and a policy worker so scheduled jobs do not fail their first launch.
|
|
command:
|
|
- postgres
|
|
- -c
|
|
- max_connections=300
|
|
- -c
|
|
- max_worker_processes=${POSTGRES_MAX_WORKER_PROCESSES:-24}
|
|
- -c
|
|
- max_parallel_workers_per_gather=0
|
|
environment:
|
|
POSTGRES_DB: ${POSTGRES_DB:-meshcore}
|
|
POSTGRES_USER: ${POSTGRES_USER:-meshcore}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD required}
|
|
volumes:
|
|
- ./backend/src/db/schema/base.sql:/docker-entrypoint-initdb.d/001_schema.sql:ro
|
|
# A fresh CI volume has no operator-provisioned roles, and
|
|
# 072_backend_grants.sql fails closed without them. Run the same shipped
|
|
# operator scripts a real deployment runs, rather than skipping the check.
|
|
- ./scripts/bootstrap-backend-roles.sql:/docker-entrypoint-initdb.d/002_backend_roles.sql:ro
|
|
- ./scripts/bootstrap-reader-roles.sql:/docker-entrypoint-initdb.d/003_reader_roles.sql:ro
|
|
# The backend connects to a second database for owner auth; a fresh volume
|
|
# never creates it. owner-auth.sql is mounted outside initdb so it is not
|
|
# applied to the main database.
|
|
- ./backend/src/db/owner-auth.sql:/opt/bootstrap/owner-auth.sql:ro
|
|
- ./scripts/bootstrap-owner-db.sh:/docker-entrypoint-initdb.d/004_owner_db.sh:ro
|
|
healthcheck:
|
|
# The entrypoint's temporary init server accepts Unix-socket connections
|
|
# before base.sql finishes, but db-migrate connects over TCP. Probe TCP
|
|
# so dependants wait for init scripts and the final server to be ready.
|
|
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U ${POSTGRES_USER:-meshcore} -d ${POSTGRES_DB:-meshcore}"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 10
|
|
start_period: 30s
|
|
|
|
mosquitto:
|
|
image: eclipse-mosquitto@sha256:9cfdd46ad59f3e3e5f592f6baf57ab23e1ad00605509d0f5c1e9b179c5314d87
|
|
logging: *json-log-limits
|
|
mem_limit: "128m"
|
|
memswap_limit: "128m"
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pgrep mosquitto >/dev/null && nc -z 127.0.0.1 9001"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 5
|
|
start_period: 10s
|
|
volumes:
|
|
- ./mosquitto:/mosquitto/config
|
|
- mosquitto_data:/mosquitto/data
|
|
- mosquitto_log:/mosquitto/log
|
|
|
|
mosquitto-reloader:
|
|
image: ${MOSQUITTO_RELOADER_IMAGE:-meshcore-analytics-mosquitto-reloader:local}
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile.mosquitto-reloader
|
|
args:
|
|
SOURCE_REVISION: ${SOURCE_REVISION:-local}
|
|
restart: "no"
|
|
logging: *json-log-limits
|
|
mem_limit: "64m"
|
|
memswap_limit: "64m"
|
|
pid: "service:mosquitto"
|
|
# Match the broker UID inside the shared PID namespace so SIGHUP can be
|
|
# delivered without granting CAP_KILL or root.
|
|
user: "1883:1883"
|
|
cap_drop:
|
|
- ALL
|
|
security_opt:
|
|
- no-new-privileges:true
|
|
read_only: true
|
|
environment:
|
|
MQTT_SELF_ENROLLMENT: ${MQTT_SELF_ENROLLMENT:-false}
|
|
OWNER_ACL_RELOAD_TOKEN: ${JWT_SECRET:?JWT_SECRET required}
|
|
MOSQUITTO_LOG_PATH: /mosquitto/log/mosquitto.log
|
|
volumes:
|
|
- ./mosquitto:/mosquitto/config
|
|
- mosquitto_log:/mosquitto/log
|
|
depends_on:
|
|
mosquitto:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-q", "-O", "/dev/null", "-T", "2", "http://127.0.0.1:8080/healthz"]
|
|
interval: 30s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
redis:
|
|
image: redis@sha256:8b81dd37ff027bec4e516d41acfbe9fe2460070dc6d4a4570a2ac5b9d59df065
|
|
logging: *json-log-limits
|
|
mem_limit: "512m"
|
|
memswap_limit: "512m"
|
|
command:
|
|
- redis-server
|
|
- --requirepass
|
|
- ${REDIS_PASSWORD:?REDIS_PASSWORD required}
|
|
- --maxmemory
|
|
- 448mb
|
|
- --maxmemory-policy
|
|
- noeviction
|
|
- --appendonly
|
|
- "yes"
|
|
- --appendfsync
|
|
- everysec
|
|
environment:
|
|
REDIS_PASSWORD: ${REDIS_PASSWORD}
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "redis-cli -a $REDIS_PASSWORD --no-auth-warning ping"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 5
|
|
|
|
|
|
backend:
|
|
# The empty-volume smoke stack has no owner-auth database or ACL file, so it
|
|
# explicitly opts into the now-opt-in shadow mode. Production defaults to
|
|
# enforce/apply and sets both explicitly in its .env.
|
|
environment:
|
|
OWNER_AUTHORIZATION_MODE: shadow
|
|
OWNER_ACL_MODE: shadow
|
|
|
|
mqtt-ingest:
|
|
environment:
|
|
OWNER_AUTHORIZATION_MODE: shadow
|
|
OWNER_ACL_MODE: shadow
|
|
|
|
db-migrate:
|
|
# A fresh volume is seeded from `schema/base.sql` by the init hook, so the
|
|
# runner legitimately starts against a non-empty database with no ledger.
|
|
# This exact approval lets it verify that database against the shipped base
|
|
# schema and initialise the ledger; it never applies to a real deployment,
|
|
# and a database that has drifted from base.sql stays refused.
|
|
environment:
|
|
MIGRATION_BASE_SCHEMA_BOOTSTRAP_APPROVAL: bootstrap-ledger-from-base-schema
|