@rocket.chat/houston 0.27.0-next.3 → 2.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +109 -15
  3. package/bin/houston +62 -0
  4. package/data/docs/ARCHITECTURE.md +387 -0
  5. package/data/docs/automation.md +107 -0
  6. package/data/docs/e2ee.md +76 -0
  7. package/data/docs/eks.md +258 -0
  8. package/data/docs/gui.md +282 -0
  9. package/data/docs/guide.md +642 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/loadtest.md +264 -0
  12. package/data/docs/troubleshooting.md +203 -0
  13. package/data/docs/upgrading.md +84 -0
  14. package/data/docs/voice.md +253 -0
  15. package/data/iam/engineer-policy.json +11 -0
  16. package/data/iam/engineer-rbac.yaml +42 -0
  17. package/data/iam/operator-policy.json +211 -0
  18. package/data/loadtest/badbot.js +22 -0
  19. package/data/loadtest/common.js +170 -0
  20. package/data/loadtest/custom.js +20 -0
  21. package/data/loadtest/journey.js +58 -0
  22. package/data/loadtest/login.js +18 -0
  23. package/data/loadtest/messages.js +13 -0
  24. package/data/loadtest/mixed.js +57 -0
  25. package/data/loadtest/read.js +12 -0
  26. package/data/loadtest/webhook.js +20 -0
  27. package/data/monitoring/houston-logs.json +98 -0
  28. package/data/monitoring/k6-loadtest.json +610 -0
  29. package/data/monitoring/mongodb-exporter.json +3007 -0
  30. package/data/monitoring/node-exporter-full.json +16114 -0
  31. package/data/monitoring/rocketchat-metrics.json +6471 -0
  32. package/data/presets/airgapped.yaml +16 -0
  33. package/data/presets/default.yaml +9 -0
  34. package/data/seed/avatar-0.png +0 -0
  35. package/data/seed/avatar-1.png +0 -0
  36. package/data/seed/avatar-2.png +0 -0
  37. package/data/seed/avatar-3.png +0 -0
  38. package/data/seed/avatar-4.png +0 -0
  39. package/data/seed/avatar-5.png +0 -0
  40. package/data/seed/avatar-6.png +0 -0
  41. package/data/seed/avatar-7.png +0 -0
  42. package/data/seed/seed-metrics.csv +3 -0
  43. package/data/seed/seed-preview.png +0 -0
  44. package/data/seed/seed-report.pdf +32 -0
  45. package/data/seed/seed-runbook.txt +3 -0
  46. package/data/skill/SKILL.md +399 -0
  47. package/data/versions.yaml +55 -0
  48. package/data/voice/freeswitch/drachtio.xml +52 -0
  49. package/data/voice/freeswitch/public.xml +87 -0
  50. package/data/webui/app.css +2003 -0
  51. package/data/webui/index.html +678 -0
  52. package/data/webui/js/api.js +561 -0
  53. package/data/webui/js/boot.js +44 -0
  54. package/data/webui/js/clusters-tail.js +1377 -0
  55. package/data/webui/js/clusters.js +896 -0
  56. package/data/webui/js/create.js +276 -0
  57. package/data/webui/js/detail.js +507 -0
  58. package/data/webui/js/jobs.js +636 -0
  59. package/data/webui/js/logs.js +634 -0
  60. package/data/webui/js/main.js +14 -0
  61. package/data/webui/js/options.js +408 -0
  62. package/data/webui/js/people.js +438 -0
  63. package/data/webui/js/perf.js +303 -0
  64. package/data/webui/js/render.js +438 -0
  65. package/data/webui/js/shared.js +3 -0
  66. package/data/webui/js/state.js +583 -0
  67. package/data/webui/js/theme.js +123 -0
  68. package/data/webui/js/util.js +584 -0
  69. package/dist/cli/app.js +593 -0
  70. package/dist/cli/capabilities.js +76 -0
  71. package/dist/cli/cell-widths.js +495 -0
  72. package/dist/cli/entry.js +10 -0
  73. package/dist/cli/error-panel.js +492 -0
  74. package/dist/cli/handlers/actor.js +84 -0
  75. package/dist/cli/handlers/https.js +614 -0
  76. package/dist/cli/handlers/prompt.js +299 -0
  77. package/dist/cli/handlers/users.js +226 -0
  78. package/dist/cli/handlers.js +3694 -0
  79. package/dist/cli/help.js +183 -0
  80. package/dist/cli/index.js +15 -0
  81. package/dist/cli/perf.js +814 -0
  82. package/dist/cli/render.js +254 -0
  83. package/dist/cli/serve.js +858 -0
  84. package/dist/cli/spec-data.js +2599 -0
  85. package/dist/cli/spec-types.js +8 -0
  86. package/dist/cli/usage-error.js +520 -0
  87. package/dist/cli/wire.js +70 -0
  88. package/dist/core/audit.js +346 -0
  89. package/dist/core/backup-compat.js +85 -0
  90. package/dist/core/backup.js +1639 -0
  91. package/dist/core/cluster.js +1398 -0
  92. package/dist/core/configimport.js +345 -0
  93. package/dist/core/data.js +267 -0
  94. package/dist/core/database-of.js +82 -0
  95. package/dist/core/diagnose.js +159 -0
  96. package/dist/core/doctor.js +1518 -0
  97. package/dist/core/edge/acme.js +338 -0
  98. package/dist/core/edge/engine.js +500 -0
  99. package/dist/core/edge/networks.js +174 -0
  100. package/dist/core/edge/paths.js +107 -0
  101. package/dist/core/edge/routes.js +251 -0
  102. package/dist/core/edge/routeyml.js +195 -0
  103. package/dist/core/edge/runtime.js +493 -0
  104. package/dist/core/edge/spec.js +305 -0
  105. package/dist/core/edge/types.js +202 -0
  106. package/dist/core/eks-docs.js +135 -0
  107. package/dist/core/eks.js +2240 -0
  108. package/dist/core/envvars.js +562 -0
  109. package/dist/core/eventlog.js +541 -0
  110. package/dist/core/firstrun.js +153 -0
  111. package/dist/core/journal.js +694 -0
  112. package/dist/core/kube/ask.js +231 -0
  113. package/dist/core/kube/capabilities.js +269 -0
  114. package/dist/core/kube/certmanager.js +452 -0
  115. package/dist/core/kube/chart.js +413 -0
  116. package/dist/core/kube/cluster.js +196 -0
  117. package/dist/core/kube/context.js +545 -0
  118. package/dist/core/kube/endpoints.js +448 -0
  119. package/dist/core/kube/exec.js +195 -0
  120. package/dist/core/kube/forward.js +732 -0
  121. package/dist/core/kube/grafana-ingress.js +110 -0
  122. package/dist/core/kube/ingress.js +218 -0
  123. package/dist/core/kube/manifests.js +361 -0
  124. package/dist/core/kube/monitoring.js +768 -0
  125. package/dist/core/kube/names.js +237 -0
  126. package/dist/core/kube/namespace.js +678 -0
  127. package/dist/core/kube/operator.js +941 -0
  128. package/dist/core/kube/probe.js +202 -0
  129. package/dist/core/kube/reachability.js +163 -0
  130. package/dist/core/kube/release.js +439 -0
  131. package/dist/core/kube/replicaset.js +180 -0
  132. package/dist/core/kube/scale.js +398 -0
  133. package/dist/core/kube/status.js +633 -0
  134. package/dist/core/kube/tools.js +238 -0
  135. package/dist/core/kube/transfer.js +173 -0
  136. package/dist/core/kube/workspace.js +423 -0
  137. package/dist/core/lifecycle/admin.js +64 -0
  138. package/dist/core/lifecycle/create-docker.js +1549 -0
  139. package/dist/core/lifecycle/create-k8s.js +960 -0
  140. package/dist/core/lifecycle/destroy.js +339 -0
  141. package/dist/core/lifecycle/inspect.js +636 -0
  142. package/dist/core/lifecycle/naming.js +298 -0
  143. package/dist/core/lifecycle/notes.js +862 -0
  144. package/dist/core/lifecycle/ownership.js +313 -0
  145. package/dist/core/lifecycle/payload.js +401 -0
  146. package/dist/core/lifecycle/ports.js +388 -0
  147. package/dist/core/lifecycle/preconditions.js +367 -0
  148. package/dist/core/lifecycle/pruning.js +551 -0
  149. package/dist/core/lifecycle/ready.js +818 -0
  150. package/dist/core/lifecycle/request.js +510 -0
  151. package/dist/core/lifecycle/seeding.js +281 -0
  152. package/dist/core/lifecycle/sizing.js +392 -0
  153. package/dist/core/lifecycle/state.js +286 -0
  154. package/dist/core/lifecycle/tlsplan.js +704 -0
  155. package/dist/core/lifecycle/types.js +232 -0
  156. package/dist/core/loadtest.js +1051 -0
  157. package/dist/core/migrate.js +612 -0
  158. package/dist/core/monitor.js +494 -0
  159. package/dist/core/postready.js +976 -0
  160. package/dist/core/promote.js +804 -0
  161. package/dist/core/rcapi.js +1336 -0
  162. package/dist/core/recovery.js +75 -0
  163. package/dist/core/runner/engine.js +394 -0
  164. package/dist/core/runner/host.js +298 -0
  165. package/dist/core/runner/locks.js +129 -0
  166. package/dist/core/runner/paths.js +173 -0
  167. package/dist/core/runner/ports.js +172 -0
  168. package/dist/core/runner/queries.js +612 -0
  169. package/dist/core/runner/record.js +563 -0
  170. package/dist/core/scaleseed.js +271 -0
  171. package/dist/core/seed-db.js +208 -0
  172. package/dist/core/sessions.js +472 -0
  173. package/dist/core/skill.js +326 -0
  174. package/dist/core/sso-identities.js +172 -0
  175. package/dist/core/sso.js +703 -0
  176. package/dist/core/tls-local.js +311 -0
  177. package/dist/core/tls.js +878 -0
  178. package/dist/core/topology.js +482 -0
  179. package/dist/core/upgrade.js +877 -0
  180. package/dist/core/users.js +739 -0
  181. package/dist/lib/audit.js +100 -0
  182. package/dist/lib/close-matches.js +238 -0
  183. package/dist/lib/compose.js +672 -0
  184. package/dist/lib/config.js +1398 -0
  185. package/dist/lib/context.js +18 -0
  186. package/dist/lib/errors.js +305 -0
  187. package/dist/lib/events.js +208 -0
  188. package/dist/lib/float-text.js +126 -0
  189. package/dist/lib/format.js +1320 -0
  190. package/dist/lib/home.js +325 -0
  191. package/dist/lib/journal.js +122 -0
  192. package/dist/lib/json-text.js +733 -0
  193. package/dist/lib/jsonout.js +382 -0
  194. package/dist/lib/lock.js +516 -0
  195. package/dist/lib/login-name.js +202 -0
  196. package/dist/lib/map-limit.js +29 -0
  197. package/dist/lib/mkdir-parents.js +90 -0
  198. package/dist/lib/mongo-kernel.js +67 -0
  199. package/dist/lib/monitoring.js +492 -0
  200. package/dist/lib/platform-name.js +59 -0
  201. package/dist/lib/presets/common.js +390 -0
  202. package/dist/lib/presets/composite.js +326 -0
  203. package/dist/lib/presets/e2ee.js +143 -0
  204. package/dist/lib/presets/email.js +172 -0
  205. package/dist/lib/presets/guides.js +27 -0
  206. package/dist/lib/presets/index.js +490 -0
  207. package/dist/lib/presets/keycloak.js +371 -0
  208. package/dist/lib/presets/ldap.js +1285 -0
  209. package/dist/lib/presets/livechat.js +220 -0
  210. package/dist/lib/presets/multi-instance.js +124 -0
  211. package/dist/lib/presets/oidc.js +161 -0
  212. package/dist/lib/presets/public.js +496 -0
  213. package/dist/lib/presets/registry.js +64 -0
  214. package/dist/lib/presets/s3-minio.js +300 -0
  215. package/dist/lib/presets/saml.js +149 -0
  216. package/dist/lib/presets/scenario.js +51 -0
  217. package/dist/lib/presets/types.js +86 -0
  218. package/dist/lib/presets/voice-pbx.js +320 -0
  219. package/dist/lib/presets/voice.js +345 -0
  220. package/dist/lib/presets/webhooks.js +182 -0
  221. package/dist/lib/redact.js +106 -0
  222. package/dist/lib/seed-options.js +68 -0
  223. package/dist/lib/seed-profiles.js +59 -0
  224. package/dist/lib/targz.js +1383 -0
  225. package/dist/lib/teammode.js +25 -0
  226. package/dist/lib/tempdir.js +162 -0
  227. package/dist/lib/unicode-tables.js +2335 -0
  228. package/dist/lib/version-spec.js +357 -0
  229. package/dist/lib/versions.js +463 -0
  230. package/dist/lib/yaml-dump.js +1361 -0
  231. package/dist/perf/baseline.js +168 -0
  232. package/dist/perf/constrain.js +299 -0
  233. package/dist/perf/k6.js +235 -0
  234. package/dist/perf/mongoprof.js +171 -0
  235. package/dist/perf/rcmetrics.js +191 -0
  236. package/dist/perf/report.js +386 -0
  237. package/dist/perf/resources.js +236 -0
  238. package/dist/perf/slo.js +111 -0
  239. package/dist/perf/timeline.js +187 -0
  240. package/dist/perf/timings.js +85 -0
  241. package/dist/perf/verdict.js +201 -0
  242. package/dist/seams/aws-cli.js +126 -0
  243. package/dist/seams/docker-cli.js +280 -0
  244. package/dist/seams/exec.js +861 -0
  245. package/dist/seams/fs/lock.js +528 -0
  246. package/dist/seams/kubectl.js +83 -0
  247. package/dist/seams/rc-http.js +921 -0
  248. package/dist/seed/apply.js +190 -0
  249. package/dist/seed/assets.js +76 -0
  250. package/dist/seed/check.js +391 -0
  251. package/dist/seed/client.js +172 -0
  252. package/dist/seed/executor.js +726 -0
  253. package/dist/seed/history.js +281 -0
  254. package/dist/seed/kinds.js +91 -0
  255. package/dist/seed/plan.js +432 -0
  256. package/dist/seed/receipt.js +339 -0
  257. package/dist/seed/repairs.js +75 -0
  258. package/dist/seed/verification.js +363 -0
  259. package/dist/seed/wording.js +248 -0
  260. package/dist/web/app.js +326 -0
  261. package/dist/web/jobs.js +510 -0
  262. package/dist/web/route-deps.js +211 -0
  263. package/dist/web/route-table.js +213 -0
  264. package/dist/web/routes/backup.js +244 -0
  265. package/dist/web/routes/clusters.js +303 -0
  266. package/dist/web/routes/data.js +187 -0
  267. package/dist/web/routes/edge.js +82 -0
  268. package/dist/web/routes/index.js +63 -0
  269. package/dist/web/routes/jobs.js +95 -0
  270. package/dist/web/routes/logs.js +297 -0
  271. package/dist/web/routes/meta.js +191 -0
  272. package/dist/web/routes/people.js +151 -0
  273. package/dist/web/routes/perf.js +95 -0
  274. package/dist/web/routes/repros.js +550 -0
  275. package/dist/web/routes/session.js +361 -0
  276. package/dist/web/routes/spa.js +198 -0
  277. package/dist/web/security.js +475 -0
  278. package/dist/web/signin.js +246 -0
  279. package/package.json +70 -32
  280. package/.eslintrc +0 -94
  281. package/.swcrc +0 -18
  282. package/dist/bin.js +0 -3
  283. package/dist/cli.js +0 -184
  284. package/dist/commands/createBranch.js +0 -194
  285. package/dist/outputCI.js +0 -59
  286. package/src/bin.js +0 -4
  287. package/src/cli.ts +0 -25
  288. package/src/commands/createBranch.ts +0 -28
  289. package/src/outputCI.ts +0 -12
  290. package/src-old/logs.js +0 -323
  291. package/src-old/md.js +0 -191
  292. package/src-old/release-table.js +0 -60
  293. package/src-old/set-version.js +0 -614
  294. package/src-old/utils.js +0 -15
@@ -0,0 +1,390 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.EMAIL_2FA = void 0;
37
+ exports.safeDump = safeDump;
38
+ exports.safeLoad = safeLoad;
39
+ exports.safeLoadOrdered = safeLoadOrdered;
40
+ exports.safeLoadAll = safeLoadAll;
41
+ exports.presetPorts = presetPorts;
42
+ exports.presetPort = presetPort;
43
+ exports.truthyParam = truthyParam;
44
+ exports.intParam = intParam;
45
+ exports.choiceParam = choiceParam;
46
+ exports.strParam = strParam;
47
+ exports.k8sManifests = k8sManifests;
48
+ /**
49
+ * Shared helpers for the dynamic preset builders.
50
+ *
51
+ * `--set KEY=VALUE` params arrive as raw strings, so every builder needs the same small
52
+ * coercions -- and every builder that has a Kubernetes rendering needs the same
53
+ * Deployment/Service shape, which is written once here rather than five times.
54
+ */
55
+ const YAML = __importStar(require("yaml"));
56
+ const config = __importStar(require("../config"));
57
+ const format_1 = require("../format");
58
+ /**
59
+ * `doc` as YAML in the established manifest spelling, through the `yaml` package.
60
+ *
61
+ * Four options carry the whole equivalence and each one is a divergence that was
62
+ * measured rather than assumed:
63
+ *
64
+ * - `compat: 'yaml-1.1'` -- the established emitter is a YAML 1.1 one, so `'1'`, `'true'`
65
+ * and `'on'` must be quoted or a 1.1 reader reads a number or a boolean back.
66
+ * - `singleQuote: true` -- the established spelling prefers `'...'`; the library defaults
67
+ * to `"..."`, and a manifest full of the other spelling is a diff on every line that
68
+ * needs quoting.
69
+ * - `blockQuote: false` -- the established spelling NEVER has a `|` literal block for a
70
+ * multi-line string; it has a folded single-quoted scalar. The library prefers `|`,
71
+ * which parses back to the same string and does not compare equal, and the strings
72
+ * involved are an entire HTML page and a Keycloak realm.
73
+ * - `anchorPrefix: 'id00'` -- an anchor is named `id` and three digits, `id001`. The shared
74
+ * `labels` mapping appears twice inside one Deployment, so every manifest here has one.
75
+ *
76
+ * - `doubleQuotedMinMultiLineLength: Infinity` -- the library spells a `\n` inside a
77
+ * double-quoted scalar as a real line break once the scalar is long enough; the
78
+ * established spelling is always `\n`. Without this the realm JSON renders as forty
79
+ * folded lines against four.
80
+ *
81
+ * `indentSeq: false` is the one `lib/compose.ts` already established for the same reason,
82
+ * and `lineWidth: 80` is the established default width rather than compose's `0`, because
83
+ * these documents contain scalars long enough to fold and compose's do not.
84
+ *
85
+ * WHAT THIS DOES NOT CLAIM. The output is not byte-identical to the established spelling
86
+ * for a scalar long enough to fold: the two emitters break at the same width and spell the
87
+ * break differently -- the established one writes `\` and re-escapes a leading space, the
88
+ * library lets the fold absorb it. Both parse back to the identical string, and the only
89
+ * consumer of this text is `kubectl apply -f -`, so the contract is the DOCUMENT and not
90
+ * its spelling. So these manifests compare parsed, for exactly that reason, and everything
91
+ * else -- `files`, `env`, `services`, `notes`, `post_ready` -- compares byte for byte,
92
+ * because those are written to disk and read back.
93
+ */
94
+ function safeDump(doc) {
95
+ return YAML.stringify(doc, {
96
+ compat: 'yaml-1.1',
97
+ indentSeq: false,
98
+ lineWidth: 80,
99
+ doubleQuotedMinMultiLineLength: Number.POSITIVE_INFINITY,
100
+ nullStr: 'null',
101
+ singleQuote: true,
102
+ blockQuote: false,
103
+ anchorPrefix: 'id00',
104
+ });
105
+ }
106
+ /**
107
+ * `text` read with the established safe grammar -- config.ts's YAML11_OPTIONS, the one
108
+ * reader this build has for a YAML file.
109
+ *
110
+ * The yaml library's own YAML 1.1 schema is not the established one: it reads `y`, `Y`,
111
+ * `n` and `N` as booleans, and parts ways on dotless exponents, leading-dot floats,
112
+ * sexagesimals starting with 0 and single-digit months, so a preset whose env held `Y: 2`
113
+ * had the key `true` where it is `'Y'`. And `uniqueKeys: false`, as on every YAML read in
114
+ * this build: a mapping that names a key twice keeps the LAST value, where the yaml
115
+ * library refused the document -- so a user preset with a doubled key was UNREADABLE,
116
+ * where it is a preset.
117
+ */
118
+ function safeLoad(text) {
119
+ return config.safeLoadYaml(text);
120
+ }
121
+ /**
122
+ * `safeLoad`, with every mapping read as a `Map` -- which keeps the order the document wrote
123
+ * its keys in, where a plain object lists every integer-like key (`"10"`) first. For a
124
+ * reader that prints keys in order; the keys are not stringified, so an unquoted `10` comes
125
+ * back as the number.
126
+ */
127
+ function safeLoadOrdered(text) {
128
+ return config.safeLoadYaml(text, { mapAsMap: true });
129
+ }
130
+ /**
131
+ * Every document in a `---`-separated stream, read with the established safe grammar.
132
+ *
133
+ * Splitting on the separator by hand is what a reader reaches for first and it is wrong:
134
+ * a `---` line inside a scalar is content, not a document boundary, and the scalars here
135
+ * are an HTML page and a Keycloak realm. The parser knows the difference.
136
+ */
137
+ function safeLoadAll(text) {
138
+ return YAML.parseAllDocuments(text, config.YAML11_OPTIONS).map((doc) => doc.toJS());
139
+ }
140
+ /**
141
+ * `config.PRESET_PORTS[name]`, as a value rather than as a `| undefined`.
142
+ *
143
+ * A preset with no registry entry is an error naming it, as it has always been: a preset
144
+ * that published a port nothing had reserved is the collision `PRESET_PORTS` exists to
145
+ * prevent, and answering `undefined` would put that port in the compose file anyway.
146
+ */
147
+ /**
148
+ * Email 2FA, which ldap, saml, oidc and livechat turn OFF only because a repro has no mail
149
+ * server to send the code. A soft default: composed with `email`, which brings Mailpit and
150
+ * turns it on, email's value wins. See `composite.ts`.
151
+ */
152
+ exports.EMAIL_2FA = 'OVERWRITE_SETTING_Accounts_TwoFactorAuthentication_By_Email_Enabled';
153
+ /**
154
+ * A preset's host ports in one workspace: the ones `ports` gives it, else the registry's.
155
+ *
156
+ * `ports` is REQUIRED, and sparse: `{}` is every preferred port, `{ email: [8026] }` moves
157
+ * Mailpit alone. Required so a builder that never received the workspace's ports does not
158
+ * quietly publish the preferred ones, which would open someone else's Mailpit.
159
+ */
160
+ function presetPorts(name, ports) {
161
+ const given = ports[name] ?? config.PRESET_PORTS[name];
162
+ if (given === undefined)
163
+ throw new Error(`no port is reserved for the preset ${JSON.stringify(name)}`);
164
+ return given;
165
+ }
166
+ /** One of a preset's host ports -- the first is the one a single-port preset publishes. */
167
+ function presetPort(name, index, ports) {
168
+ const all = presetPorts(name, ports);
169
+ const port = all[index];
170
+ if (port === undefined) {
171
+ throw new Error(`the preset ${JSON.stringify(name)} has no reserved port at index ${String(index)}`);
172
+ }
173
+ return port;
174
+ }
175
+ /** Read a boolean `--set` param ("1"/"true"/"yes"/"on", case-insensitive). */
176
+ function truthyParam(params, key, fallback = false) {
177
+ const value = params[key];
178
+ // Absent or `--set key=` -> the default.
179
+ if (value === null || value === undefined || String(value).trim() === '')
180
+ return fallback;
181
+ return ['1', 'true', 'yes', 'on'].includes(String(value).trim().toLowerCase());
182
+ }
183
+ /**
184
+ * Read an integer `--set` param; empty or absent -> the default.
185
+ *
186
+ * A non-numeric value raises a message the CLI shows verbatim rather than a stack trace,
187
+ * so the message itself is the contract -- including the shown text of the value, which is why
188
+ * `shownValue` is here and `String()` is not.
189
+ */
190
+ function intParam(params, key, fallback) {
191
+ const value = params[key];
192
+ if (value === null || value === undefined || value === '')
193
+ return fallback;
194
+ // `toInt`, whose TypeError or InvalidValue RangeError is the refusal -- not an ASCII pattern:
195
+ // `--set users=1_0` is 10 and `users=٣` is 3, and the ldap help's "try 130000 for scale"
196
+ // is naturally typed 130_000 -- each was refused by the pattern this replaced.
197
+ // An OutOfRange error (an infinite float from a JSON body) is neither, and is not caught.
198
+ try {
199
+ return (0, format_1.toInt)(value);
200
+ }
201
+ catch (error) {
202
+ if (error.name === 'OutOfRange')
203
+ throw error;
204
+ // The shown text of whatever arrived: a JSON body can send a list, which it brackets.
205
+ throw new Error(`--set ${key}=${(0, format_1.shownValue)(value)} expects a whole number`, {
206
+ cause: error,
207
+ });
208
+ }
209
+ }
210
+ /** Read a `--set` param that must be one of `choices`; empty or absent -> the first. */
211
+ function choiceParam(params, key, choices) {
212
+ const value = params[key];
213
+ const fallback = choices[0] ?? '';
214
+ if (value === null || value === undefined || String(value).trim() === '')
215
+ return fallback;
216
+ const chosen = String(value).trim().toLowerCase();
217
+ if (!choices.includes(chosen)) {
218
+ throw new Error(`--set ${key}=${(0, format_1.shownValue)(value)} expects one of: ${choices.join(', ')}`);
219
+ }
220
+ return chosen;
221
+ }
222
+ /** Read a string `--set` param; empty or absent -> the default. */
223
+ function strParam(params, key, fallback) {
224
+ const value = params[key];
225
+ if (value === null || value === undefined || String(value) === '')
226
+ return fallback;
227
+ return String(value);
228
+ }
229
+ /** Build the pod spec, including its optional file mount and readiness signal. */
230
+ function containerSpec(name, image, ports, env, args, mounts, readiness) {
231
+ const container = {
232
+ name,
233
+ image,
234
+ ports: ports.map(([, containerPort]) => ({ containerPort })),
235
+ };
236
+ if (env !== undefined && Object.keys(env).length > 0) {
237
+ container.env = Object.entries(env).map(([k, v]) => ({ name: k, value: String(v) }));
238
+ }
239
+ if (args !== undefined && args.length > 0)
240
+ container.args = args.map((a) => String(a));
241
+ // A readiness probe is what makes "ready endpoint" mean anything. Without one a pod is
242
+ // Ready as soon as its container starts, and every consumer downstream -- the Service's
243
+ // endpoints, the port-forward, post_ready -- trusts a signal that has not been earned.
244
+ if (readiness !== undefined && Object.keys(readiness).length > 0) {
245
+ container.readinessProbe = readiness;
246
+ }
247
+ const pod = { containers: [container] };
248
+ if (mounts !== undefined && mounts.length > 0) {
249
+ container.volumeMounts = mounts;
250
+ pod.volumes = [{ name: 'files', configMap: { name: `${name}-files` } }];
251
+ }
252
+ return pod;
253
+ }
254
+ /** Append the primary Service and any extra host-published Service. */
255
+ function appendServices(docs, name, ports, ui, labels) {
256
+ const app = labels.app;
257
+ // THE PRIMARY SERVICE CARRIES EVERY PORT THE WORKLOAD LISTENS ON, not only the ones
258
+ // published to the host. On Compose, container-to-container traffic reaches any port
259
+ // directly, so `mailpit:1025` just works. A Kubernetes Service forwards ONLY its
260
+ // declared ports -- so publishing the web UI and nothing else gave a workspace whose
261
+ // Mailpit was reachable from the browser and unreachable from Rocket.Chat, which is
262
+ // where the mail actually has to come from.
263
+ //
264
+ // Reported from a live workspace: SMTP_Host=mailpit, SMTP_Port=1025, container
265
+ // listening on 1025, Service exposing 8025 alone.
266
+ //
267
+ // The Service speaks CONTAINER ports, the way Compose's network does; the `ui-port`
268
+ // label is what says which host port publishes one.
269
+ const rest = { ...(ui ?? {}) };
270
+ const primaryUi = rest[name];
271
+ delete rest[name];
272
+ const ordered = [...ports];
273
+ if (primaryUi !== undefined) {
274
+ // The published port first: the lifecycle's forwarder reads .spec.ports[0]. A stable
275
+ // sort on a boolean key, so the rest keep their declared order.
276
+ const rank = (pair) => (pair[1] !== primaryUi[1] ? 1 : 0);
277
+ ordered.sort((a, b) => rank(a) - rank(b));
278
+ }
279
+ const primaryLabels = { ...labels };
280
+ if (primaryUi !== undefined)
281
+ primaryLabels['houston.io/ui-port'] = String(primaryUi[0]);
282
+ docs.push({
283
+ apiVersion: 'v1',
284
+ kind: 'Service',
285
+ metadata: { name, labels: primaryLabels },
286
+ spec: {
287
+ selector: { app },
288
+ ports: ordered.map(([, cport]) => ({
289
+ name: `p${String(cport)}`,
290
+ port: cport,
291
+ targetPort: cport,
292
+ })),
293
+ },
294
+ });
295
+ // Any REMAINING ui entry is a second published port on the same workload, which needs
296
+ // its own Service because a label value cannot carry a list.
297
+ for (const [svcName, [host, containerPort]] of Object.entries(rest)) {
298
+ const svcLabels = { ...labels };
299
+ svcLabels['houston.io/ui-port'] = String(host);
300
+ svcLabels['houston.io/ui-deployment'] = name;
301
+ docs.push({
302
+ apiVersion: 'v1',
303
+ kind: 'Service',
304
+ metadata: { name: svcName, labels: svcLabels },
305
+ spec: {
306
+ selector: { app },
307
+ ports: [{ name: 'http', port: containerPort, targetPort: containerPort }],
308
+ },
309
+ });
310
+ }
311
+ }
312
+ /**
313
+ * One Deployment + one Service per exposed port, from the same shape every scenario
314
+ * adapter needs.
315
+ *
316
+ * `ui` maps a Service name to the host port it should be published on; the lifecycle
317
+ * reads `houston.io/ui-port` and forwards it. `houston.io/ui-deployment` names the
318
+ * workload when the Service is not called after it -- MinIO serves an API and a console
319
+ * from one Deployment, and a label value cannot contain a comma.
320
+ *
321
+ * ONE `labels` OBJECT, SHARED. The Deployment names it twice, and the emitter writes the
322
+ * second reference as an alias; building a second identical object here would render the
323
+ * same meaning as different text.
324
+ */
325
+ function k8sManifests(options) {
326
+ const { name, image, ports, env, args, files, mounts, ui, readiness } = options;
327
+ const workspace = options.workspace ?? '__HOUSTON_NAME__';
328
+ const app = `houston-${name}`;
329
+ const labels = {
330
+ app,
331
+ 'app.kubernetes.io/managed-by': 'houston',
332
+ 'houston.io/component': name,
333
+ 'houston.io/repro': workspace,
334
+ };
335
+ const docs = [];
336
+ if (files !== undefined && Object.keys(files).length > 0) {
337
+ docs.push({
338
+ apiVersion: 'v1',
339
+ kind: 'ConfigMap',
340
+ metadata: { name: `${name}-files`, labels },
341
+ data: { ...files },
342
+ });
343
+ }
344
+ const pod = containerSpec(name, image, ports, env, args, mounts, readiness);
345
+ const spec = {
346
+ replicas: 1,
347
+ selector: { matchLabels: { app } },
348
+ template: { metadata: { labels }, spec: pod },
349
+ };
350
+ // THE CONTAINER'S OWN FILESYSTEM DIES WITH THE POD, and `stop` scales to zero. MinIO kept
351
+ // its objects AND its bucket there, so the first stop/start emptied the workspace's
352
+ // uploads for good. A claim survives a scale to zero and a data-keeping `down`, and goes
353
+ // with the namespace on `down --volumes` -- the Compose named volume's lifetime. The
354
+ // cluster's default StorageClass, as MongoDB's claim uses. Recreate, because a
355
+ // ReadWriteOnce claim is one writer's: a rolling update would start the new pod beside
356
+ // the old one holding it.
357
+ if (options.data !== undefined) {
358
+ const claim = `${name}-data`;
359
+ docs.push({
360
+ apiVersion: 'v1',
361
+ kind: 'PersistentVolumeClaim',
362
+ metadata: { name: claim, labels },
363
+ spec: {
364
+ accessModes: ['ReadWriteOnce'],
365
+ resources: { requests: { storage: options.data.size } },
366
+ },
367
+ });
368
+ const container = pod.containers[0];
369
+ container.volumeMounts = [
370
+ ...(container.volumeMounts ?? []),
371
+ { name: 'data', mountPath: options.data.path },
372
+ ];
373
+ pod.volumes = [
374
+ ...(pod.volumes ?? []),
375
+ { name: 'data', persistentVolumeClaim: { claimName: claim } },
376
+ ];
377
+ // A provisioned filesystem is root's, 0755: a non-root image could not write a byte.
378
+ if (options.data.fsGroup !== undefined)
379
+ pod.securityContext = { fsGroup: options.data.fsGroup };
380
+ spec.strategy = { type: 'Recreate' };
381
+ }
382
+ docs.push({
383
+ apiVersion: 'apps/v1',
384
+ kind: 'Deployment',
385
+ metadata: { name, labels },
386
+ spec,
387
+ });
388
+ appendServices(docs, name, ports, ui, labels);
389
+ return docs.map((doc) => safeDump(doc)).join('---\n');
390
+ }