@rocket.chat/houston 0.27.0-next.2 → 2.1.8
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.
- package/LICENSE +1 -1
- package/README.md +108 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +669 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/troubleshooting.md +193 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +168 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +39 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3678 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +810 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2593 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +344 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +691 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1533 -0
- package/dist/core/lifecycle/create-k8s.js +939 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +635 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +726 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +753 -0
- package/dist/core/lifecycle/request.js +525 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +995 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +969 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1285 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +868 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +369 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +296 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +178 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +224 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +67 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -192
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -25
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.awsCli = exports.LAUNCH_FAILURE_CODE = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The one way `aws` and `eksctl` are launched.
|
|
6
|
+
*
|
|
7
|
+
* Thin, like `kubectl` and `docker-cli`: this module knows argv, a timeout, an
|
|
8
|
+
* environment and whether the caller wants the output at the end or as it arrives. It
|
|
9
|
+
* knows nothing about regions, accounts, tags, clusters or what any of those mean.
|
|
10
|
+
* `core/eks.ts` is the half that does, and `.dependency-cruiser.js` carries "nothing
|
|
11
|
+
* bypasses the seam" as a rule, because that is a claim a gate has to make rather than
|
|
12
|
+
* a comment.
|
|
13
|
+
*
|
|
14
|
+
* ## Why a seam of its own rather than the Kubernetes one
|
|
15
|
+
*
|
|
16
|
+
* One funnel for two tools would be honest enough. They are separated because the two
|
|
17
|
+
* have DIFFERENT CONTRACTS in the one dimension that matters for this module: an `aws`
|
|
18
|
+
* call is a network round trip to somebody's account, and `eksctl create cluster` is
|
|
19
|
+
* twenty minutes and real money. A seam whose only shape is "capture and return" cannot
|
|
20
|
+
* express the second, and a funnel of that shape ends up bypassed with a raw `popen` for
|
|
21
|
+
* exactly those two commands. `stream` is that case, inside the seam rather than beside it.
|
|
22
|
+
*
|
|
23
|
+
* ## It never throws
|
|
24
|
+
*
|
|
25
|
+
* The same contract `kubectl` has, for the same reason: `doctor` is the command
|
|
26
|
+
* somebody runs precisely because things are already wrong, and a preflight that raised
|
|
27
|
+
* on a missing binary would have to be wrapped at every call site. A launch failure or
|
|
28
|
+
* a timeout becomes a result with `returncode: 127`, carrying the reason on stderr.
|
|
29
|
+
*/
|
|
30
|
+
const exec_1 = require("./exec");
|
|
31
|
+
/**
|
|
32
|
+
* The synthetic code a launch failure reports.
|
|
33
|
+
*
|
|
34
|
+
* 127 is the shell's "command not found", and the kubectl seam picked it so a caller
|
|
35
|
+
* that only reads return codes still sees a distinctly hopeless one rather than a 1 it
|
|
36
|
+
* might confuse with a real refusal. Same number here, so the two seams cannot disagree.
|
|
37
|
+
*/
|
|
38
|
+
exports.LAUNCH_FAILURE_CODE = 127;
|
|
39
|
+
function shaped(argv, result) {
|
|
40
|
+
return {
|
|
41
|
+
argv: result.argv,
|
|
42
|
+
// A signalled tool has no exit code. The only thing any caller does with it is
|
|
43
|
+
// compare against zero, so a signal reports the same hopeless code a failed launch
|
|
44
|
+
// gets rather than success.
|
|
45
|
+
returncode: result.exitCode ?? exports.LAUNCH_FAILURE_CODE,
|
|
46
|
+
stdout: String(result.stdout ?? ''),
|
|
47
|
+
stderr: String(result.stderr ?? ''),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function failed(argv, error) {
|
|
51
|
+
// Not a failure to report: Ctrl-C or a stopped job, which must unwind (see exec).
|
|
52
|
+
if (error instanceof exec_1.Interrupted)
|
|
53
|
+
throw error;
|
|
54
|
+
return {
|
|
55
|
+
argv: [...argv],
|
|
56
|
+
returncode: exports.LAUNCH_FAILURE_CODE,
|
|
57
|
+
stdout: '',
|
|
58
|
+
stderr: error instanceof Error ? error.message : String(error),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async function run(argv, options = {}) {
|
|
62
|
+
try {
|
|
63
|
+
return shaped(argv, await (0, exec_1.capture)(argv, {
|
|
64
|
+
encoding: 'utf8',
|
|
65
|
+
...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
|
|
66
|
+
...(options.env !== undefined ? { env: options.env } : {}),
|
|
67
|
+
...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return failed(argv, error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Run a long command and hand over what it says WHILE it says it.
|
|
76
|
+
*
|
|
77
|
+
* Both streams are merged, because eksctl writes its progress to STDERR and reading
|
|
78
|
+
* only stdout would produce a silent twenty minutes with the progress on the floor.
|
|
79
|
+
*
|
|
80
|
+
* Lines are delivered as they arrive rather than at the end -- a progress report
|
|
81
|
+
* delivered at the end is not a progress report -- and a partial last line is flushed
|
|
82
|
+
* when the process exits, so the final message is not lost for want of a newline.
|
|
83
|
+
*/
|
|
84
|
+
async function streamLines(argv, options) {
|
|
85
|
+
let pending = '';
|
|
86
|
+
const take = (chunk) => {
|
|
87
|
+
pending += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
88
|
+
const parts = pending.split('\n');
|
|
89
|
+
// The last element is whatever came after the final newline: a partial line, or ''.
|
|
90
|
+
// It stays in the buffer until the rest of it arrives.
|
|
91
|
+
pending = parts.pop() ?? '';
|
|
92
|
+
for (const line of parts)
|
|
93
|
+
options.onLine(line);
|
|
94
|
+
};
|
|
95
|
+
let result;
|
|
96
|
+
try {
|
|
97
|
+
result = await (0, exec_1.stream)(argv, {
|
|
98
|
+
encoding: 'utf8',
|
|
99
|
+
mergeStderr: true,
|
|
100
|
+
onStdout: (chunk) => take(chunk),
|
|
101
|
+
...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
|
|
102
|
+
...(options.env !== undefined ? { env: options.env } : {}),
|
|
103
|
+
...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (pending !== '')
|
|
108
|
+
options.onLine(pending);
|
|
109
|
+
return failed(argv, error);
|
|
110
|
+
}
|
|
111
|
+
// The last line, which usually has no trailing newline and is usually the reason.
|
|
112
|
+
if (pending !== '')
|
|
113
|
+
options.onLine(pending);
|
|
114
|
+
return shaped(argv, result);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The injectable callables, on an exported OBJECT rather than as module bindings.
|
|
118
|
+
*
|
|
119
|
+
* swc compiles an export into a non-configurable getter, so `jest.spyOn` on a module
|
|
120
|
+
* binding fails outright. `seams/kubectl.ts` and `core/kube/exec.ts` hang their
|
|
121
|
+
* callables off an object for the same reason.
|
|
122
|
+
*/
|
|
123
|
+
exports.awsCli = {
|
|
124
|
+
run: (argv, options = {}) => run(argv, options),
|
|
125
|
+
stream: (argv, options) => streamLines(argv, options),
|
|
126
|
+
};
|
|
@@ -0,0 +1,280 @@
|
|
|
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.STALE_UNIT = exports.QUERY_TTL_MS = exports.DOCKER_TTL_MS = void 0;
|
|
37
|
+
exports.docker = docker;
|
|
38
|
+
exports.compose = compose;
|
|
39
|
+
exports.composeStream = composeStream;
|
|
40
|
+
exports.composeToFile = composeToFile;
|
|
41
|
+
exports.composeFromFile = composeFromFile;
|
|
42
|
+
exports.invalidateQueries = invalidateQueries;
|
|
43
|
+
exports.cachedQuery = cachedQuery;
|
|
44
|
+
exports.dockerAvailable = dockerAvailable;
|
|
45
|
+
exports.firstLine = firstLine;
|
|
46
|
+
/**
|
|
47
|
+
* The `docker` and `docker compose` command line, and the two memos in front of it.
|
|
48
|
+
*
|
|
49
|
+
* Thin by contract. This module knows argv, a working directory, and how long a docker
|
|
50
|
+
* fact stays true; it knows nothing about workspaces, presets or metadata. Everything
|
|
51
|
+
* that needs a workspace name lives in `core/runner`, which supplies the directory --
|
|
52
|
+
* that is what keeps the seam below the state owner rather than entangled with it.
|
|
53
|
+
*
|
|
54
|
+
* ## The error policy is the caller's, deliberately
|
|
55
|
+
*
|
|
56
|
+
* `runner.compose` raises when docker cannot be launched; `composeExecCapture` returns
|
|
57
|
+
* `[1, '']` instead; `firstLine` and `composeLs` return null; `dockerStats` returns an
|
|
58
|
+
* empty string. Those are four different contracts on top of one launch, and
|
|
59
|
+
* flattening them into a universal "never throws" wrapper would silently turn a refusal
|
|
60
|
+
* into an empty answer at the two sites that distinguish them. So the primitives here
|
|
61
|
+
* propagate what `exec` raises, and each adapter above applies its own.
|
|
62
|
+
*
|
|
63
|
+
* ## The two memos
|
|
64
|
+
*
|
|
65
|
+
* `QUERY_TTL_MS` (2.5 s) covers the read-only queries the dashboard poll repeats. Each
|
|
66
|
+
* open tab asks for /api/repros every 4 s, which is `docker compose ls` plus `docker ps`
|
|
67
|
+
* plus `docker info`; ten teammates with a tab open is ~40 process spawns every 4
|
|
68
|
+
* seconds on a shared box. Memoised just long enough to collapse concurrent tabs into
|
|
69
|
+
* one call, and INVALIDATED by every mutation so the UI never shows a stale state after
|
|
70
|
+
* an action -- a cache the user can notice would be worse than the spawns.
|
|
71
|
+
*
|
|
72
|
+
* `DOCKER_TTL_MS` (3 s) covers `docker info` alone. It forks a client that talks to the
|
|
73
|
+
* daemon (~35 ms) and /api/health calls it on every poll, which turns the cheap
|
|
74
|
+
* unauthenticated check into the most expensive thing the server does. Short enough
|
|
75
|
+
* that `doctor` and the badge still react to Docker stopping within a poll or two.
|
|
76
|
+
*/
|
|
77
|
+
const fs = __importStar(require("node:fs"));
|
|
78
|
+
const jsonout_1 = require("../lib/jsonout");
|
|
79
|
+
const exec_1 = require("./exec");
|
|
80
|
+
/** How long `docker info`'s answer is reused: three seconds. */
|
|
81
|
+
exports.DOCKER_TTL_MS = 3000;
|
|
82
|
+
/** How long a read-only docker query is reused: two and a half seconds. */
|
|
83
|
+
exports.QUERY_TTL_MS = 2500;
|
|
84
|
+
/**
|
|
85
|
+
* A container's `State.Error` when systemd still holds the unit of its previous run.
|
|
86
|
+
*
|
|
87
|
+
* Under the systemd cgroup driver every container runs in `docker-<id>.scope`, and a
|
|
88
|
+
* start reuses the container, so its id and its unit name. A unit left loaded by the last
|
|
89
|
+
* run -- seen on a production box after every stop -- fails each start with "Unit
|
|
90
|
+
* docker-<id>.scope was already loaded or has a fragment file" (older systemd: "already
|
|
91
|
+
* exists"). Nothing short of root clears the unit; a recreated container has a new id.
|
|
92
|
+
*/
|
|
93
|
+
exports.STALE_UNIT = /\.scope\b.*(?:already loaded|already exists)/u;
|
|
94
|
+
function options(given) {
|
|
95
|
+
return {
|
|
96
|
+
...(given.cwd !== undefined ? { cwd: given.cwd } : {}),
|
|
97
|
+
...(given.timeoutMs !== undefined ? { timeoutMs: given.timeoutMs } : {}),
|
|
98
|
+
...(given.env !== undefined ? { env: given.env } : {}),
|
|
99
|
+
...(given.mergeStderr !== undefined ? { mergeStderr: given.mergeStderr } : {}),
|
|
100
|
+
...(given.abortSignal !== undefined ? { abortSignal: given.abortSignal } : {}),
|
|
101
|
+
...(given.input === undefined ? {} : { input: given.input }),
|
|
102
|
+
encoding: given.text === false ? null : 'utf8',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Run a `docker ...` command. Raises what `exec` raises; the adapter decides.
|
|
107
|
+
*
|
|
108
|
+
* Uncaptured, docker INHERITS the terminal:
|
|
109
|
+
* that is how `pull` draws its progress, how `up`, `stop` and `down` say which container
|
|
110
|
+
* they touched, and how a failure reaches the person in docker's own words -- `Error
|
|
111
|
+
* response from daemon: ...` above houston's one-line diagnosis. This captured every call
|
|
112
|
+
* and dropped what it caught, so none of that was ever shown.
|
|
113
|
+
*
|
|
114
|
+
* Under --json the child's stdout goes to stderr instead, as `compose` sends it there in
|
|
115
|
+
* JSON mode: stdout carries JSON and nothing else.
|
|
116
|
+
*/
|
|
117
|
+
async function docker(argv, given = {}) {
|
|
118
|
+
const command = ['docker', ...argv];
|
|
119
|
+
if (given.capture === true)
|
|
120
|
+
return await (0, exec_1.capture)(command, options(given));
|
|
121
|
+
return await (0, exec_1.inherit)(command, {
|
|
122
|
+
...(given.cwd !== undefined ? { cwd: given.cwd } : {}),
|
|
123
|
+
...(given.timeoutMs !== undefined ? { timeoutMs: given.timeoutMs } : {}),
|
|
124
|
+
...(given.env !== undefined ? { env: given.env } : {}),
|
|
125
|
+
...(given.abortSignal !== undefined ? { abortSignal: given.abortSignal } : {}),
|
|
126
|
+
stdoutToStderr: (0, jsonout_1.active)(),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Run `docker compose <args>` in a directory.
|
|
131
|
+
*
|
|
132
|
+
* `timeoutMs` is opt-in and left unset by default: `up`, `pull` and `logs -f` are
|
|
133
|
+
* legitimately long-running. Bounded callers (samplers, one-shot queries) pass one so a
|
|
134
|
+
* wedged daemon cannot block a worker forever.
|
|
135
|
+
*/
|
|
136
|
+
async function compose(args, given = {}) {
|
|
137
|
+
return await docker(['compose', ...args], given);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Run `docker compose <args>` delivering combined stdout+stderr line by line.
|
|
141
|
+
*
|
|
142
|
+
* Streamed rather than captured so the GUI sees progress as it happens; the CLI keeps
|
|
143
|
+
* the blocking path, which inherits the terminal for docker's own progress rendering.
|
|
144
|
+
*/
|
|
145
|
+
async function composeStream(args, given = {}) {
|
|
146
|
+
let buffered = '';
|
|
147
|
+
const deliver = (chunk) => {
|
|
148
|
+
buffered += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
149
|
+
let newline = buffered.indexOf('\n');
|
|
150
|
+
while (newline !== -1) {
|
|
151
|
+
const line = buffered.slice(0, newline).replace(/\r$/u, '');
|
|
152
|
+
buffered = buffered.slice(newline + 1);
|
|
153
|
+
if (given.onLine !== undefined && line !== '')
|
|
154
|
+
given.onLine(line);
|
|
155
|
+
newline = buffered.indexOf('\n');
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const result = await (0, exec_1.stream)(['docker', 'compose', ...args], {
|
|
159
|
+
...options({ ...given, mergeStderr: true }),
|
|
160
|
+
onStdout: deliver,
|
|
161
|
+
});
|
|
162
|
+
// A final line with no trailing newline is still a line.
|
|
163
|
+
if (buffered.trim() !== '' && given.onLine !== undefined)
|
|
164
|
+
given.onLine(buffered.trim());
|
|
165
|
+
return result.exitCode;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Run `docker compose <args>` writing its RAW stdout to a file.
|
|
169
|
+
*
|
|
170
|
+
* Binary-safe on purpose: `mongodump --archive` emits BSON, and the text-mode decode
|
|
171
|
+
* and newline translation an ordinary capture applies would corrupt it silently -- the
|
|
172
|
+
* dump would restore with errors nobody could trace back here. Returns the exit code
|
|
173
|
+
* and stderr as text.
|
|
174
|
+
*/
|
|
175
|
+
async function composeToFile(args, destination, given = {}) {
|
|
176
|
+
const sink = fs.createWriteStream(destination);
|
|
177
|
+
try {
|
|
178
|
+
const errors = [];
|
|
179
|
+
const result = await (0, exec_1.stream)(['docker', 'compose', ...args], {
|
|
180
|
+
...options({ ...given, text: false }),
|
|
181
|
+
stdoutSink: sink,
|
|
182
|
+
onStderr: (chunk) => {
|
|
183
|
+
errors.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
return { exitCode: result.exitCode, stderr: Buffer.concat(errors).toString('utf8') };
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
await new Promise((resolve) => sink.end(resolve));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Run `docker compose <args>` with a file piped to its stdin.
|
|
194
|
+
*
|
|
195
|
+
* The counterpart of `composeToFile`, for `mongorestore --archive`. Output is merged so
|
|
196
|
+
* a caller has one blob to show when a restore fails.
|
|
197
|
+
*/
|
|
198
|
+
async function composeFromFile(args, source, given = {}) {
|
|
199
|
+
const input = fs.createReadStream(source);
|
|
200
|
+
const collected = [];
|
|
201
|
+
const result = await (0, exec_1.stream)(['docker', 'compose', ...args], {
|
|
202
|
+
...options({ ...given, text: false, mergeStderr: true }),
|
|
203
|
+
stdin: input,
|
|
204
|
+
onStdout: (chunk) => {
|
|
205
|
+
collected.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
return { exitCode: result.exitCode, output: Buffer.concat(collected).toString('utf8') };
|
|
209
|
+
}
|
|
210
|
+
const queries = new Map();
|
|
211
|
+
let dockerSeen = null;
|
|
212
|
+
/** Drop every memoised docker fact. Called after anything that changes one. */
|
|
213
|
+
function invalidateQueries() {
|
|
214
|
+
queries.clear();
|
|
215
|
+
dockerSeen = null;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Memoise one read-only query for `QUERY_TTL_MS`.
|
|
219
|
+
*
|
|
220
|
+
* Concurrent callers share the stored value only once it exists; an in-flight call is
|
|
221
|
+
* not shared -- two simultaneous misses both run.
|
|
222
|
+
*/
|
|
223
|
+
async function cachedQuery(key, produce) {
|
|
224
|
+
const now = Date.now();
|
|
225
|
+
const hit = queries.get(key);
|
|
226
|
+
if (hit !== undefined && now - hit.at < exports.QUERY_TTL_MS)
|
|
227
|
+
return hit.value;
|
|
228
|
+
const value = await produce();
|
|
229
|
+
queries.set(key, { at: now, value });
|
|
230
|
+
return value;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Whether the daemon answers. Cached briefly; `maxAgeMs: 0` forces a probe.
|
|
234
|
+
*
|
|
235
|
+
* Never raises a failure: a missing binary or a timeout is an answer of "no", which is what
|
|
236
|
+
* every caller needs during a preflight or a health poll. An interrupt is not an answer, so
|
|
237
|
+
* it passes, and nothing is cached for it.
|
|
238
|
+
*/
|
|
239
|
+
async function dockerAvailable({ maxAgeMs = exports.DOCKER_TTL_MS, env, } = {}) {
|
|
240
|
+
const now = Date.now();
|
|
241
|
+
if (maxAgeMs > 0 && dockerSeen !== null && now - dockerSeen.at < maxAgeMs)
|
|
242
|
+
return dockerSeen.ok;
|
|
243
|
+
let ok;
|
|
244
|
+
try {
|
|
245
|
+
const result = await docker(['info'], {
|
|
246
|
+
capture: true,
|
|
247
|
+
timeoutMs: 10000,
|
|
248
|
+
...(env !== undefined ? { env } : {}),
|
|
249
|
+
});
|
|
250
|
+
ok = result.exitCode === 0;
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
// Not a failure to report: Ctrl-C or a stopped job, which must unwind (see exec).
|
|
254
|
+
if (error instanceof exec_1.Interrupted)
|
|
255
|
+
throw error;
|
|
256
|
+
// A missing binary or a timeout is an answer of "no", which is what a preflight or
|
|
257
|
+
// a health poll needs -- not an exception to wrap at every call site.
|
|
258
|
+
ok = false;
|
|
259
|
+
}
|
|
260
|
+
dockerSeen = { at: now, ok };
|
|
261
|
+
return ok;
|
|
262
|
+
}
|
|
263
|
+
/** Run a command and return its trimmed stdout, or null on any failure; an interrupt passes. */
|
|
264
|
+
async function firstLine(argv, env) {
|
|
265
|
+
let result;
|
|
266
|
+
try {
|
|
267
|
+
result = await (0, exec_1.capture)(argv, {
|
|
268
|
+
encoding: 'utf8',
|
|
269
|
+
timeoutMs: 10000,
|
|
270
|
+
...(env !== undefined ? { env } : {}),
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
// Not a failure to report: Ctrl-C or a stopped job, which must unwind (see exec).
|
|
275
|
+
if (error instanceof exec_1.Interrupted)
|
|
276
|
+
throw error;
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
return result.exitCode === 0 ? String(result.stdout ?? '').trim() : null;
|
|
280
|
+
}
|