docker-compose.yml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. ports: ["8800:8800"]
  113. depends_on:
  114. nats: { condition: service_healthy }
  115. redis: { condition: service_healthy }
  116. postgres: { condition: service_healthy }
  117. emqx: { condition: service_healthy }
  118. routerd:
  119. build: .
  120. command: ["/app/routerd"]
  121. environment:
  122. BA_ENV: dev
  123. BA_HTTP_ADDR: ":8801"
  124. BA_NATS_URL: nats://nats:4222
  125. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  126. ports: ["8801:8801"]
  127. depends_on:
  128. nats: { condition: service_healthy }
  129. postgres: { condition: service_healthy }
  130. deliverd-fcm:
  131. build: .
  132. command: ["/app/deliverd-fcm"]
  133. environment:
  134. BA_ENV: dev
  135. BA_HTTP_ADDR: ":8802"
  136. BA_NATS_URL: nats://nats:4222
  137. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  138. BA_FAKECMD_URL: "http://fakefcmd:8820"
  139. ports: ["8802:8802"]
  140. depends_on:
  141. nats: { condition: service_healthy }
  142. postgres: { condition: service_healthy }
  143. fakefcmd: { condition: service_started }
  144. deliverd-telegram:
  145. build: .
  146. command: ["/app/deliverd-telegram"]
  147. environment:
  148. BA_ENV: dev
  149. BA_HTTP_ADDR: ":8821"
  150. BA_NATS_URL: nats://nats:4222
  151. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  152. BA_TELEGRAM_BOT_TOKEN: "fake-tg-bot-token-acme-001"
  153. BA_TELEGRAM_FAKE_URL: "http://faketgmd:8830"
  154. ports: ["8821:8821"]
  155. depends_on:
  156. nats: { condition: service_healthy }
  157. postgres: { condition: service_healthy }
  158. faketgmd: { condition: service_started }
  159. telegramd:
  160. build: .
  161. command: ["/app/telegramd"]
  162. environment:
  163. BA_ENV: dev
  164. BA_HTTP_ADDR: ":8822"
  165. BA_NATS_URL: nats://nats:4222
  166. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  167. BA_TELEGRAM_FAKE_URL: "http://faketgmd:8830"
  168. ports: ["8822:8822"]
  169. depends_on:
  170. nats: { condition: service_healthy }
  171. postgres: { condition: service_healthy }
  172. faketgmd: { condition: service_started }
  173. faketgmd:
  174. build: .
  175. command: ["/app/faketgmd", "--addr", ":8830", "--timeout", "5"]
  176. ports: ["8830:8830"]
  177. fakefcmd:
  178. build: .
  179. command: ["/app/fakefcmd", "--addr", ":8820"]
  180. ports: ["8820:8820"]
  181. healthcheck:
  182. test: ["CMD", "wget", "-qO-", "http://localhost:8820/health"]
  183. interval: 5s
  184. timeout: 3s
  185. retries: 10
  186. seed:
  187. build: .
  188. command: ["/app/seed"]
  189. environment:
  190. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  191. BA_MIGRATIONS_DIR: /migrations
  192. volumes:
  193. - ./migrations:/migrations:ro
  194. depends_on:
  195. postgres: { condition: service_healthy }
  196. admind:
  197. build: .
  198. command: ["/app/admind"]
  199. environment:
  200. BA_ENV: dev
  201. BA_HTTP_ADDR: ":8803"
  202. BA_NATS_URL: nats://nats:4222
  203. BA_POSTGRES_DSN: postgres://ba:ba@postgres:5432/ba?sslmode=disable
  204. ports: ["8803:8803"]
  205. depends_on:
  206. nats: { condition: service_healthy }
  207. postgres: { condition: service_healthy }
  208. # ── Observability ────────────────────────────────────────────────
  209. prometheus:
  210. image: prom/prometheus:latest
  211. command:
  212. - --config.file=/etc/prometheus/prometheus.yml
  213. volumes:
  214. - ./deploy/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
  215. ports: ["9090:9090"]
  216. depends_on: [ingestd, routerd, deliverd-fcm, deliverd-telegram, telegramd, admind]
  217. grafana:
  218. image: grafana/grafana:latest
  219. # :3000 is held by gogs (git3) on this host. Map to :3001
  220. # on the host, keep :3000 internal. M0 ports convention
  221. # says canonical ports stay; the host-port override is a
  222. # one-line exception, fully isolated to grafana.
  223. ports: ["3001:3000"]
  224. environment:
  225. GF_SECURITY_ADMIN_USER: admin
  226. GF_SECURITY_ADMIN_PASSWORD: admin
  227. depends_on: [prometheus]
  228. # ── Loadgen (one-shot smoke profile) ────────────────────
  229. loadgen-http:
  230. build: .
  231. command:
  232. - /app/loadgen-http
  233. - --target=http://ingestd:8800
  234. - --api-key=acme-001:prom-prod:s3cret-acme
  235. - --mode=normal
  236. - --rate=50
  237. - --duration=30s
  238. - --metrics=:8891
  239. profiles: ["loadgen"]
  240. depends_on:
  241. ingestd: { condition: service_started }
  242. volumes:
  243. pgdata: {}
  244. natsdata: {}
  245. chdata: {}