docker-compose.yml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. # docker-compose.yml — single-host M0 stack.
  2. # Run: docker compose up -d
  3. # Then: see M0_VERIFICATION.md for the loadgen smoke test.
  4. #
  5. # Port conventions (project rule):
  6. # - app HTTP services: 8800–8899 (ingestd/routerd/deliverd-fcm/deliverd-telegram/telegramd/admind/loadgen/faketgmd)
  7. # - canonical ports stay (5432 postgres, 4222 nats, 6379 redis,
  8. # 1883 mqtt, 9090 prometheus, 3000 grafana, etc.)
  9. services:
  10. # ── Data tier ────────────────────────────────────────────────────
  11. postgres:
  12. image: timescale/timescaledb:latest-pg16
  13. environment:
  14. POSTGRES_USER: ba
  15. POSTGRES_PASSWORD: ba
  16. POSTGRES_DB: ba
  17. # No host port mapping: a host-local postgres is already on
  18. # :5432. The app services reach this one via the docker network
  19. # DNS name 'postgres'. Use `docker compose exec postgres psql ...`
  20. # to talk to it from the host.
  21. expose: ["5432"]
  22. volumes:
  23. - pgdata:/var/lib/postgresql/data
  24. healthcheck:
  25. test: ["CMD-SHELL", "pg_isready -U ba"]
  26. interval: 5s
  27. timeout: 3s
  28. retries: 10
  29. redis:
  30. image: redis:7-alpine
  31. # No host port mapping: a host-local redis is on :6379. App
  32. # services reach this one via docker DNS 'redis'.
  33. expose: ["6379"]
  34. healthcheck:
  35. test: ["CMD", "redis-cli", "ping"]
  36. interval: 5s
  37. timeout: 3s
  38. retries: 10
  39. nats:
  40. image: nats:2.10-alpine
  41. command: ["-js", "-sd", "/data", "-m", "8222"]
  42. ports: ["4222:4222", "8222:8222"] # 8222 is the monitoring HTTP
  43. volumes:
  44. - natsdata:/data
  45. healthcheck:
  46. test: ["CMD", "wget", "-qO-", "http://localhost:8222/healthz"]
  47. interval: 5s
  48. timeout: 3s
  49. retries: 20
  50. emqx:
  51. image: emqx/emqx:5.10.4
  52. ports: ["1883:1883", "18083:18083"] # MQTT + admin UI
  53. volumes:
  54. # M4: per-company ACL + auth bootstrap. acl.conf is read on
  55. # SIGHUP; the auth CSV is read on first boot. M11 promotes
  56. # this to a Postgres-backed authentication chain.
  57. - ./deploy/emqx/acl.conf:/opt/emqx/etc/acl.conf:ro
  58. - ./deploy/emqx/auth-built-in-db-bootstrap.csv:/opt/emqx/etc/auth-built-in-db-bootstrap.csv:ro
  59. # EMQX 5.x prefers env-var config over emqx.conf. The HOCON
  60. # path is emqx.conf → base.hocon → cluster.hocon → env vars
  61. # (highest precedence). The double-underscore separator in
  62. # env-var names maps to nested HOCON keys.
  63. environment:
  64. # Built-in-db authentication (one chain, password_based, plain)
  65. EMQX_AUTHENTICATION__1__BACKEND: "built_in_database"
  66. EMQX_AUTHENTICATION__1__MECHANISM: "password_based"
  67. EMQX_AUTHENTICATION__1__USER_ID_TYPE: "username"
  68. EMQX_AUTHENTICATION__1__PASSWORD_HASH_ALGORITHM__NAME: "plain"
  69. EMQX_AUTHENTICATION__1__PASSWORD_HASH_ALGORITHM__SALT_POSITION: "disable"
  70. # File-based authorization, default-deny
  71. EMQX_AUTHORIZATION__NO_MATCH: "deny"
  72. EMQX_AUTHORIZATION__DENY_ACTION: "disconnect"
  73. EMQX_AUTHORIZATION__SOURCES__1__TYPE: "file"
  74. EMQX_AUTHORIZATION__SOURCES__1__ENABLE: "true"
  75. EMQX_AUTHORIZATION__SOURCES__1__PATH: "/opt/emqx/etc/acl.conf"
  76. healthcheck:
  77. # The original `echo > /dev/tcp/...` ran under sh on
  78. # Debian-based EMQX and reported unhealthy even when the
  79. # broker was fine. Switch to `bash -c` and a TCP probe.
  80. test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/1883"]
  81. interval: 10s
  82. timeout: 5s
  83. retries: 20
  84. clickhouse:
  85. image: clickhouse/clickhouse-server:24-alpine
  86. ports: ["8123:8123", "9000:9000"]
  87. volumes:
  88. - chdata:/var/lib/clickhouse
  89. ulimits:
  90. nofile: { soft: 262144, hard: 262144 }
  91. # ── App tier ─────────────────────────────────────────────────────
  92. ingestd:
  93. build: .
  94. command: ["/app/ingestd"]
  95. environment:
  96. BA_ENV: dev
  97. BA_HTTP_ADDR: ":8800"
  98. BA_NATS_URL: nats://nats:4222
  99. BA_REDIS_URL: redis://redis:6379/0
  100. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  101. BA_INGESTD_SOURCES: "acme-001:prom-prod:s3cret-acme,globex-002:grafana:s3cret-globex"
  102. BA_INGESTD_RATE_LIMIT_PER_SOURCE: "100"
  103. BA_INGESTD_RATE_LIMIT_PER_COMPANY: "10000"
  104. # M4: MQTT subscriber. ingestd subscribes to ba/+/+/incoming
  105. # with the dedicated `ingestd` user. The auth file lists
  106. # this user (password "ingestd-broker-only") so EMQX's
  107. # built-in-db authenticates the connection.
  108. BA_INGESTD_MQTT_BROKER: "tcp://emqx:1883"
  109. BA_INGESTD_MQTT_USERNAME: "ingestd"
  110. BA_INGESTD_MQTT_PASSWORD: "ingestd-broker-only"
  111. BA_INGESTD_MQTT_SUBSCRIBE: "ba/+/+/incoming"
  112. # M5: WebSocket ingest + live tail. TAIL_TOKEN gates the
  113. # /v1/tail/ws endpoint; a static token is fine for the
  114. # dev path; M11 swaps for JWT.
  115. BA_INGESTD_TAIL_TOKEN: "tail-dev-token-please-change-in-prod"
  116. BA_INGESTD_MAX_CONCURRENT_PER_IP: "32"
  117. BA_INGESTD_DEDUPE_TTL_SECONDS: "300"
  118. ports: ["8800:8800"]
  119. depends_on:
  120. nats: { condition: service_healthy }
  121. redis: { condition: service_healthy }
  122. postgres: { condition: service_healthy }
  123. emqx: { condition: service_healthy }
  124. routerd:
  125. build: .
  126. command: ["/app/routerd"]
  127. environment:
  128. BA_ENV: dev
  129. BA_HTTP_ADDR: ":8801"
  130. BA_NATS_URL: nats://nats:4222
  131. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  132. ports: ["8801:8801"]
  133. depends_on:
  134. nats: { condition: service_healthy }
  135. postgres: { condition: service_healthy }
  136. deliverd-fcm:
  137. build: .
  138. command: ["/app/deliverd-fcm"]
  139. environment:
  140. BA_ENV: dev
  141. BA_HTTP_ADDR: ":8802"
  142. BA_NATS_URL: nats://nats:4222
  143. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  144. BA_FAKECMD_URL: "http://fakefcmd:8820"
  145. ports: ["8802:8802"]
  146. depends_on:
  147. nats: { condition: service_healthy }
  148. postgres: { condition: service_healthy }
  149. fakefcmd: { condition: service_started }
  150. deliverd-telegram:
  151. build: .
  152. command: ["/app/deliverd-telegram"]
  153. environment:
  154. BA_ENV: dev
  155. BA_HTTP_ADDR: ":8821"
  156. BA_NATS_URL: nats://nats:4222
  157. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  158. BA_TELEGRAM_BOT_TOKEN: "fake-tg-bot-token-acme-001"
  159. BA_TELEGRAM_FAKE_URL: "http://faketgmd:8830"
  160. ports: ["8821:8821"]
  161. depends_on:
  162. nats: { condition: service_healthy }
  163. postgres: { condition: service_healthy }
  164. faketgmd: { condition: service_started }
  165. telegramd:
  166. build: .
  167. command: ["/app/telegramd"]
  168. environment:
  169. BA_ENV: dev
  170. BA_HTTP_ADDR: ":8822"
  171. BA_NATS_URL: nats://nats:4222
  172. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  173. BA_TELEGRAM_FAKE_URL: "http://faketgmd:8830"
  174. ports: ["8822:8822"]
  175. depends_on:
  176. nats: { condition: service_healthy }
  177. postgres: { condition: service_healthy }
  178. faketgmd: { condition: service_started }
  179. faketgmd:
  180. build: .
  181. command: ["/app/faketgmd", "--addr", ":8830", "--timeout", "5"]
  182. ports: ["8830:8830"]
  183. fakefcmd:
  184. build: .
  185. command: ["/app/fakefcmd", "--addr", ":8820"]
  186. ports: ["8820:8820"]
  187. healthcheck:
  188. test: ["CMD", "wget", "-qO-", "http://localhost:8820/health"]
  189. interval: 5s
  190. timeout: 3s
  191. retries: 10
  192. seed:
  193. build: .
  194. command: ["/app/seed"]
  195. environment:
  196. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  197. BA_MIGRATIONS_DIR: /migrations
  198. volumes:
  199. - ./migrations:/migrations:ro
  200. depends_on:
  201. postgres: { condition: service_healthy }
  202. admind:
  203. build: .
  204. command: ["/app/admind"]
  205. environment:
  206. BA_ENV: dev
  207. BA_HTTP_ADDR: ":8803"
  208. BA_NATS_URL: nats://nats:4222
  209. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  210. ports: ["8803:8803"]
  211. depends_on:
  212. nats: { condition: service_healthy }
  213. postgres: { condition: service_healthy }
  214. # ── Observability ────────────────────────────────────────────────
  215. prometheus:
  216. image: prom/prometheus:latest
  217. command:
  218. - --config.file=/etc/prometheus/prometheus.yml
  219. volumes:
  220. - ./deploy/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
  221. ports: ["9090:9090"]
  222. depends_on: [ingestd, routerd, deliverd-fcm, deliverd-telegram, telegramd, admind]
  223. grafana:
  224. image: grafana/grafana:latest
  225. # :3000 is held by gogs (git3) on this host. Map to :3001
  226. # on the host, keep :3000 internal. M0 ports convention
  227. # says canonical ports stay; the host-port override is a
  228. # one-line exception, fully isolated to grafana.
  229. ports: ["3001:3000"]
  230. environment:
  231. GF_SECURITY_ADMIN_USER: admin
  232. GF_SECURITY_ADMIN_PASSWORD: admin
  233. depends_on: [prometheus]
  234. # ── Loadgen (one-shot smoke profile) ────────────────────
  235. loadgen-http:
  236. build: .
  237. command:
  238. - /app/loadgen-http
  239. - --target=http://ingestd:8800
  240. - --api-key=acme-001:prom-prod:s3cret-acme
  241. - --mode=normal
  242. - --rate=50
  243. - --duration=30s
  244. - --metrics=:8891
  245. profiles: ["loadgen"]
  246. depends_on:
  247. ingestd: { condition: service_started }
  248. volumes:
  249. pgdata: {}
  250. natsdata: {}
  251. chdata: {}