@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.
- package/LICENSE +1 -1
- package/README.md +109 -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 +642 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/loadtest.md +264 -0
- package/data/docs/troubleshooting.md +203 -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 +170 -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 +57 -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 +3694 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +814 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2599 -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 +345 -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 +694 -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 +1549 -0
- package/dist/core/lifecycle/create-k8s.js +960 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +636 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +862 -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 +818 -0
- package/dist/core/lifecycle/request.js +510 -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 +1051 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +976 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1336 -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 +877 -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 +371 -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 +299 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +191 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +236 -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 +70 -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 -194
- package/dist/outputCI.js +0 -59
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -28
- package/src/outputCI.ts +0 -12
- 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,3694 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Command handlers: the L4 adapter from parsed CLI values to the existing TS core. */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.executeCommand = void 0;
|
|
38
|
+
exports.emitOf = emitOf;
|
|
39
|
+
exports.renderPresets = renderPresets;
|
|
40
|
+
exports.sshHint = sshHint;
|
|
41
|
+
exports.printNotes = printNotes;
|
|
42
|
+
exports.renderResources = renderResources;
|
|
43
|
+
exports.renderHuman = renderHuman;
|
|
44
|
+
exports.createExecutor = createExecutor;
|
|
45
|
+
exports.runMain = runMain;
|
|
46
|
+
const node_os_1 = require("node:os");
|
|
47
|
+
const errors_1 = require("../lib/errors");
|
|
48
|
+
const jsonout_1 = require("../lib/jsonout");
|
|
49
|
+
const format_1 = require("../lib/format");
|
|
50
|
+
const home_1 = require("../lib/home");
|
|
51
|
+
const json_text_1 = require("../lib/json-text");
|
|
52
|
+
const app_1 = require("./app");
|
|
53
|
+
const actor_1 = require("./handlers/actor");
|
|
54
|
+
const https = __importStar(require("./handlers/https"));
|
|
55
|
+
const prompt_1 = require("./handlers/prompt");
|
|
56
|
+
const users_1 = require("./handlers/users");
|
|
57
|
+
const render_1 = require("./render");
|
|
58
|
+
const error_panel_1 = require("./error-panel");
|
|
59
|
+
const context_1 = require("../lib/context");
|
|
60
|
+
const redact_1 = require("../lib/redact");
|
|
61
|
+
const compose_1 = require("../lib/compose");
|
|
62
|
+
const composite_1 = require("../lib/presets/composite");
|
|
63
|
+
const capabilities_1 = require("./capabilities");
|
|
64
|
+
const perf_1 = require("./perf");
|
|
65
|
+
const serve_1 = require("./serve");
|
|
66
|
+
function text(value) {
|
|
67
|
+
return typeof value === 'string' ? value : value === null ? '' : String(value ?? '');
|
|
68
|
+
}
|
|
69
|
+
/** A loadtest's missed `--slo` rules as the failure its exit 1 reports, or undefined. */
|
|
70
|
+
function sloMissed(data) {
|
|
71
|
+
const bag = (data ?? {});
|
|
72
|
+
if (bag.passed !== false)
|
|
73
|
+
return undefined;
|
|
74
|
+
const missed = (Array.isArray(bag.slo) ? bag.slo : [])
|
|
75
|
+
.filter((rule) => rule.ok === false)
|
|
76
|
+
.map((rule) => text(rule.raw));
|
|
77
|
+
return new errors_1.ReproError(`the run missed its --slo: ${missed.join(', ') || 'a rule'}`);
|
|
78
|
+
}
|
|
79
|
+
function number(value) {
|
|
80
|
+
return typeof value === 'number' ? value : Number(value ?? 0);
|
|
81
|
+
}
|
|
82
|
+
function bool(value) {
|
|
83
|
+
return value === true;
|
|
84
|
+
}
|
|
85
|
+
function strings(value) {
|
|
86
|
+
return Array.isArray(value) ? value.map(String) : [];
|
|
87
|
+
}
|
|
88
|
+
function stringRecord(value) {
|
|
89
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, String(item)]));
|
|
90
|
+
}
|
|
91
|
+
function emitOf(invocation, io) {
|
|
92
|
+
return (event) => {
|
|
93
|
+
if (invocation.events !== null) {
|
|
94
|
+
invocation.events.emit(event);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// A terminal event, and the INFORMATIONAL `done` ones, are the command's own
|
|
98
|
+
// final panel's to say; a `done` WARNING is printed -- it is where a service says what it
|
|
99
|
+
// finished doing. Indented two, warnings on stderr.
|
|
100
|
+
if ((0, jsonout_1.active)() || io === undefined || event.message === undefined || event.message === '')
|
|
101
|
+
return;
|
|
102
|
+
if (event.terminal === true || (event.phase === 'done' && event.level === 'info'))
|
|
103
|
+
return;
|
|
104
|
+
if (event.level === 'warn' || event.level === 'error')
|
|
105
|
+
io.writeErr(` ${event.message}\n`);
|
|
106
|
+
else
|
|
107
|
+
io.writeOut(` ${event.message}\n`);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A confirmation that aborts on "no": the question on stdout, asked again on an answer that
|
|
112
|
+
* is not yes or no, and end of input as a "no" (`./handlers/prompt`'s `confirm` says how,
|
|
113
|
+
* byte for byte). A PIPE is read too, so `echo y | houston down --volumes` works; an
|
|
114
|
+
* earlier version refused anything that was not a terminal and wrote the question to
|
|
115
|
+
* stderr.
|
|
116
|
+
*/
|
|
117
|
+
const defaultConfirm = prompt_1.confirm;
|
|
118
|
+
/**
|
|
119
|
+
* An explicit name, else the default -- WITH the CLI's actor, so a name typed without the
|
|
120
|
+
* owner prefix finds the workspace its owner made (`up --name test` makes `alice-test` once
|
|
121
|
+
* accounts exist). Only where the CLI has always resolved this way: `use`, `env`, `backup`,
|
|
122
|
+
* `backups`, `restore` and `upgrade` hand the name over as typed. `chown` joined in 2.x:
|
|
123
|
+
* earlier releases refused `chown --name test` with exit 4 while every lifecycle command
|
|
124
|
+
* took it, and a refusal is the only answer that changes.
|
|
125
|
+
*/
|
|
126
|
+
async function target(name) {
|
|
127
|
+
const naming = require('../core/lifecycle/naming');
|
|
128
|
+
const audit = require('../core/audit');
|
|
129
|
+
return await naming.resolveName(name, audit.actor());
|
|
130
|
+
}
|
|
131
|
+
/** A transport failure from the REST seam: a `RequestFailed`, of whatever kind. */
|
|
132
|
+
function isRequestFailure(error) {
|
|
133
|
+
return error.name === 'RequestFailed';
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A REST command that could not reach or authenticate to a workspace.
|
|
137
|
+
*
|
|
138
|
+
* A CONNECTION failure is NOT_READY -- exit 5, "poll again" -- and a 429 is the other "wait
|
|
139
|
+
* and it will work" (Rocket.Chat rate-limits token creation per user). Anything else stays
|
|
140
|
+
* unclassified, because waiting will not fix it. An earlier version applied this to
|
|
141
|
+
* `loadtest` only, so `api` against a workspace still coming back exited 1.
|
|
142
|
+
*
|
|
143
|
+
* THE NAME IS WHATEVER repro.json HOLDS, not necessarily a string. The record keeps a
|
|
144
|
+
* hand-edited `"name": 123` as a number, and the message formats any value, quoted and
|
|
145
|
+
* plain: `123`, `None`, `['a']`. `quotedText` assumes a string, so `token`, `pat` and `api` died
|
|
146
|
+
* on `value.includes is not a function` (or on null) with a JavaScript stack and exit 1 where
|
|
147
|
+
* the established answer is exit 5, and a list name came out as `'a'` where earlier
|
|
148
|
+
* releases print `['a']`.
|
|
149
|
+
* `shownValue` quotes and `toTextAny` spells every JSON type, and both are `quotedText`/the value
|
|
150
|
+
* itself for a string, so a real name reads exactly as before.
|
|
151
|
+
*/
|
|
152
|
+
function notAnswering(meta, error, what) {
|
|
153
|
+
const message = (0, errors_1.errorText)(error);
|
|
154
|
+
// A connection failure or a timeout, not every transport failure: a login whose body was
|
|
155
|
+
// cut short, or that redirected thirty times, is `{what} failed: ...`, exit 1, as it has
|
|
156
|
+
// always been -- and was "not answering yet", exit 5, here.
|
|
157
|
+
// `RequestFailed.kind` carries which class the failure is.
|
|
158
|
+
if (isRequestFailure(error) && error.kind !== 'other') {
|
|
159
|
+
throw new errors_1.NotReadyError(`${(0, format_1.shownValue)(meta.name)} is not answering yet, so ${what} cannot run — wait for it with ` +
|
|
160
|
+
`\`houston ready --name ${(0, format_1.toTextAny)(meta.name)}\``);
|
|
161
|
+
}
|
|
162
|
+
if (message.includes('429') || message.includes('Too Many Requests')) {
|
|
163
|
+
throw new errors_1.NotReadyError(`Rocket.Chat is rate-limiting token creation on ${(0, format_1.shownValue)(meta.name)}, so ${what} ` +
|
|
164
|
+
'cannot run yet. Its limiter resets in about a minute — try again then.');
|
|
165
|
+
}
|
|
166
|
+
throw new errors_1.ReproError(`${what} failed: ${message}`);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* `target` + `requireEngine` + `readMeta`: the opening three of the REST commands, and of
|
|
170
|
+
* `ready` and `stats`, which open exactly this way too.
|
|
171
|
+
*/
|
|
172
|
+
async function engineMetadata(name) {
|
|
173
|
+
const preconditions = require('../core/lifecycle/preconditions');
|
|
174
|
+
const record = require('../core/runner/record');
|
|
175
|
+
const resolved = await target(name);
|
|
176
|
+
await preconditions.requireEngine(resolved);
|
|
177
|
+
return await record.readMeta(resolved);
|
|
178
|
+
}
|
|
179
|
+
async function metadata(name) {
|
|
180
|
+
const record = require('../core/runner/record');
|
|
181
|
+
return await record.readMeta(await target(name));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* `versions`: resolve one version and hand back the pairing the renderer prints.
|
|
185
|
+
*
|
|
186
|
+
* A VERSION `resolve` REFUSES IS A CALLER MISTAKE, NOT A CRASH. `houston versions notaversion
|
|
187
|
+
* --offline` prints exactly `error: 'notaversion' is not a valid version (want e.g. 6.5.3)`,
|
|
188
|
+
* exits 2 and logs VALIDATION_FAILED with `trace: false`. An earlier version called `resolve`
|
|
189
|
+
* bare, so its `InvalidVersionError` reached `runCli` as an unhandled Error: a JavaScript
|
|
190
|
+
* stack, "this is unhandled", and `trace: true` in the durable log -- the event log's signal
|
|
191
|
+
* for a defect, raised by a typo.
|
|
192
|
+
*
|
|
193
|
+
* A ValidationError, as `up --version`, `upgrade --to` and `GET /api/versions/:version` raise
|
|
194
|
+
* for the same refusal: one input, one exit code. This was a plain ReproError, exit 1, so
|
|
195
|
+
* `versions not.a.version` exited 1 where `up --version not.a.version` exited 2. Only
|
|
196
|
+
* `InvalidVersionError` is translated, so a broken shipped map or a resolver bug still
|
|
197
|
+
* surfaces as unhandled.
|
|
198
|
+
*/
|
|
199
|
+
async function runVersions(args, options) {
|
|
200
|
+
const versions = require('../lib/versions');
|
|
201
|
+
const request = require('../core/lifecycle/request');
|
|
202
|
+
const version = text(args.version);
|
|
203
|
+
const offline = bool(options.offline);
|
|
204
|
+
// An invalid version is refused by `resolve` below WITHOUT asking the network first.
|
|
205
|
+
const fetcher = await request.releaseFetcher(version, offline);
|
|
206
|
+
let resolved;
|
|
207
|
+
try {
|
|
208
|
+
resolved = versions.resolve(version, {
|
|
209
|
+
offline,
|
|
210
|
+
...(fetcher === undefined ? {} : { fetcher }),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
if (error instanceof versions.InvalidVersionError)
|
|
215
|
+
throw new errors_1.ValidationError(error.message);
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
rc_version: resolved.rcVersion,
|
|
220
|
+
rc_image: resolved.rcImage,
|
|
221
|
+
mongo_tag: resolved.mongoTag,
|
|
222
|
+
mongo_flavor: resolved.mongoFlavor,
|
|
223
|
+
mongo_shell: resolved.mongoShell,
|
|
224
|
+
oplog: resolved.oplog,
|
|
225
|
+
source: resolved.source,
|
|
226
|
+
note: resolved.note,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The workspace's admin login, then the plan, before anything is written -- a login refusal a
|
|
231
|
+
* plain ReproError (exit 1), an unknown profile a ValidationError (exit 2, as the GUI's seed
|
|
232
|
+
* raises it), neither with a trace, and under `--json` an envelope.
|
|
233
|
+
*
|
|
234
|
+
* Both were called bare, so a login Rocket.Chat refused (401), one its rate limiter refused
|
|
235
|
+
* (429), one that could not connect, and a typo in `--profile` / `--seed-profile` each left
|
|
236
|
+
* the seed as an unhandled failure: a JavaScript stack, "this is unhandled", `trace: true`
|
|
237
|
+
* in the durable log.
|
|
238
|
+
*
|
|
239
|
+
* ANY login failure is "not ready" -- except a 429, which is not: Rocket.Chat's own login
|
|
240
|
+
* limiter answers it after a few failed attempts, and `ready` would report success and
|
|
241
|
+
* change nothing. Keyed on the text, as it always was. A Ctrl-C is not a login failure and
|
|
242
|
+
* is not one here. Only the plan's own refusal is translated, and nothing else the plan
|
|
243
|
+
* throws.
|
|
244
|
+
*/
|
|
245
|
+
async function seedPreamble(meta, options) {
|
|
246
|
+
const admin = require('../core/lifecycle/admin');
|
|
247
|
+
const plans = require('../seed/plan');
|
|
248
|
+
let auth;
|
|
249
|
+
try {
|
|
250
|
+
auth = await admin.login(meta);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
if (error instanceof require('../seams/exec').Interrupted) {
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
const exc = (0, errors_1.errorText)(error);
|
|
257
|
+
if (exc.includes('429') || exc.toLowerCase().includes('too many requests')) {
|
|
258
|
+
throw new errors_1.ReproError(`can't seed — Rocket.Chat's login rate limiter is refusing (${exc}). The workspace is ` +
|
|
259
|
+
'up; wait about a minute and retry, or turn the limiter off for this workspace with ' +
|
|
260
|
+
`\`houston api -n ${(0, format_1.toTextAny)(meta.name)} -X POST /settings/` +
|
|
261
|
+
`${require('../lib/config').RC_RATE_LIMITER_SETTING} ` +
|
|
262
|
+
`-d '{"value": false}'\`.`);
|
|
263
|
+
}
|
|
264
|
+
throw new errors_1.ReproError(`can't seed — workspace not ready (\`houston ready --name ${(0, format_1.toTextAny)(meta.name)}\`): ${exc}`);
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
return [
|
|
268
|
+
auth,
|
|
269
|
+
plans.planFrom(text(options.profile ?? options.seed_profile), {
|
|
270
|
+
users: options.users === null || options.users === undefined ? null : number(options.users),
|
|
271
|
+
channels: options.channels === null || options.channels === undefined
|
|
272
|
+
? null
|
|
273
|
+
: number(options.channels),
|
|
274
|
+
messages: options.messages === null || options.messages === undefined
|
|
275
|
+
? null
|
|
276
|
+
: number(options.messages),
|
|
277
|
+
scenarios: strings(options.scenario ?? options.seed_scenario),
|
|
278
|
+
historyDays: options.history_days === null || options.history_days === undefined
|
|
279
|
+
? options.seed_history_days === null || options.seed_history_days === undefined
|
|
280
|
+
? null
|
|
281
|
+
: number(options.seed_history_days)
|
|
282
|
+
: number(options.history_days),
|
|
283
|
+
}),
|
|
284
|
+
];
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
if (error instanceof plans.UnknownProfileError)
|
|
288
|
+
throw new errors_1.ValidationError(error.message);
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Seed, print the result AS IT GOES, and return the summary.
|
|
294
|
+
*
|
|
295
|
+
* It followed the GUI's inline seed instead, and printed nothing while it ran: no `Seeding
|
|
296
|
+
* 'x' (profile: ...)` line, none of the seeder's own log (the progress counts, the rooms it
|
|
297
|
+
* could not create, the 2FA and rate-limiter settings it could not change), no timing table,
|
|
298
|
+
* no readback lines. It handed checkSeed the CLI emitter, so the service's one-line summaries
|
|
299
|
+
* printed on stderr in their place -- it takes NO emit, on purpose, and the result renders
|
|
300
|
+
* from the verdict. It threw away the ResourceMonitor's report, so `--stats` printed nothing;
|
|
301
|
+
* it gated before anything was shown, in a shorter sentence, and called an unproven readback
|
|
302
|
+
* a failed one; and it returned `total_s` where the established envelope has `elapsed_s`.
|
|
303
|
+
*
|
|
304
|
+
* All of it is prose, so none of it under `--json`: the seed's summary folds into the
|
|
305
|
+
* create's envelope instead, and a failure is the envelope's error.
|
|
306
|
+
*/
|
|
307
|
+
async function runSeed(meta, options, io) {
|
|
308
|
+
const seeding = require('../core/lifecycle/seeding');
|
|
309
|
+
const locks = require('../core/runner/locks');
|
|
310
|
+
const resources = require('../perf/resources');
|
|
311
|
+
const events = require('../lib/events');
|
|
312
|
+
// UNDER THE WORKSPACE LOCK, from the login to the gate, as the GUI's seed runs. The CLI's
|
|
313
|
+
// seed once took none -- it ran straight into a backup or an upgrade holding the
|
|
314
|
+
// workspace, then lost its record when `updateMeta`'s 60 s wait timed out -- and now
|
|
315
|
+
// takes it here too, with the same default wait.
|
|
316
|
+
return await locks.reproLock(meta.name, async () => {
|
|
317
|
+
const quiet = (0, jsonout_1.active)();
|
|
318
|
+
const profile = text(options.profile ?? options.seed_profile);
|
|
319
|
+
const [auth, plan] = await seedPreamble(meta, options);
|
|
320
|
+
if (!quiet) {
|
|
321
|
+
(0, render_1.say)(io, `Seeding ${(0, format_1.shownValue)(meta.name)} (profile: ${profile} — ${String(plan.users)} users, ` +
|
|
322
|
+
`${String(plan.channels)} channels, ${String(plan.messages)} msgs/channel)…`);
|
|
323
|
+
}
|
|
324
|
+
const monitor = bool(options.stats) ? new resources.ResourceMonitor(meta.name).start() : null;
|
|
325
|
+
const started = performance.now();
|
|
326
|
+
const tokens = {};
|
|
327
|
+
let summary;
|
|
328
|
+
let report = null;
|
|
329
|
+
try {
|
|
330
|
+
summary = await seeding.seedPrepared(meta, auth, plan, events.nullEmit, tokens, quiet ? () => undefined : (message) => (0, render_1.say)(io, ` ${message}`));
|
|
331
|
+
}
|
|
332
|
+
finally {
|
|
333
|
+
// Stopped even if the seed throws: the sampler never outlives the seed.
|
|
334
|
+
if (monitor !== null)
|
|
335
|
+
report = await monitor.stop();
|
|
336
|
+
}
|
|
337
|
+
const total = (performance.now() - started) / 1000;
|
|
338
|
+
if (!quiet)
|
|
339
|
+
printSeedResult(summary, total, report, meta, io);
|
|
340
|
+
// NO emit: `checkSeed` emits the facts this renders from the returned verdict, so
|
|
341
|
+
// passing one said every line twice -- and under `--json` put a readback event and a
|
|
342
|
+
// WARNING into a stream that has never carried either.
|
|
343
|
+
const verdict = bag(summary.verification);
|
|
344
|
+
if (!quiet)
|
|
345
|
+
printSeedVerification(verdict, io, summary);
|
|
346
|
+
// `--verify-seed` gates AFTER the report is shown. UNPROVEN IS NOT PASSED, and it is not
|
|
347
|
+
// "failed: 0 mismatch(es)" either: it is a readback that could not run.
|
|
348
|
+
if (bool(options.verify ?? options.verify_seed)) {
|
|
349
|
+
if (verdict.ok === null || verdict.ok === undefined) {
|
|
350
|
+
throw new errors_1.CreateFailedError('seed verification could not run, so the seed is UNPROVEN (drop --verify-seed to ' +
|
|
351
|
+
'accept it anyway; the attempt is recorded in repro.json either way)');
|
|
352
|
+
}
|
|
353
|
+
const faults = verdict.faults;
|
|
354
|
+
if (verdict.ok !== true) {
|
|
355
|
+
throw new errors_1.CreateFailedError(`seed verification failed: ${String(Array.isArray(faults) ? faults.length : 0)} mismatch(es) ` +
|
|
356
|
+
'between the plan and the workspace (drop --verify-seed to seed anyway; the ' +
|
|
357
|
+
'readback is recorded in repro.json either way)');
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// The summary with the profile and `elapsed_s`, rounded to 2 places -- a float, which
|
|
361
|
+
// the envelope spells as one (`preserveFloatFields`). And what `--stats` measured, which
|
|
362
|
+
// was printed in prose and dropped under `--json`: the sampler ran and nobody got its
|
|
363
|
+
// numbers.
|
|
364
|
+
return {
|
|
365
|
+
...summary,
|
|
366
|
+
profile,
|
|
367
|
+
elapsed_s: Number((0, format_1.formatFixed)(total, 2)),
|
|
368
|
+
...(report === null ? {} : { resources: report }),
|
|
369
|
+
};
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
/** How long the seed took, and one row per thing seeded. */
|
|
373
|
+
function printSeedResult(s, total, report, meta, io) {
|
|
374
|
+
const timings = require('../perf/timings');
|
|
375
|
+
const d = bag(s.durations);
|
|
376
|
+
const lat = bag(s.latency);
|
|
377
|
+
(0, render_1.say)(io, `✓ seeded in ${timings.fmtMs(total * 1000)}`);
|
|
378
|
+
const seconds = (key) => Number(d[key] ?? 0);
|
|
379
|
+
const row = (label, count, dur, extra = '') => {
|
|
380
|
+
const n = Number(count);
|
|
381
|
+
const rate = dur > 0.05 && (0, format_1.isTruthy)(count) ? `${(0, format_1.formatFixed)(n / dur, 1)}/s` : '';
|
|
382
|
+
(0, render_1.say)(io, ` ${(0, render_1.ljust)(label, 9)} ${(0, format_1.toTextAny)(count).padStart(5)} ${(0, format_1.formatFixed)(dur, 1).padStart(4)}s ` +
|
|
383
|
+
`${(0, render_1.ljust)(rate, 8)} ${extra}`);
|
|
384
|
+
};
|
|
385
|
+
const latency = (0, format_1.isTruthy)(lat.count)
|
|
386
|
+
? `p50 ${timings.fmtMs(Number(lat.p50))} · p95 ${timings.fmtMs(Number(lat.p95))} · ` +
|
|
387
|
+
`p99 ${timings.fmtMs(Number(lat.p99))} ${(0, format_1.toTextAny)(s.latency_hist ?? '')}`
|
|
388
|
+
: '';
|
|
389
|
+
row('users', s.users, seconds('users'));
|
|
390
|
+
row('channels', s.channels, seconds('channels'));
|
|
391
|
+
row('messages', s.messages, seconds('messages'), latency);
|
|
392
|
+
if ((0, format_1.isTruthy)(s.threads))
|
|
393
|
+
row('threads', s.threads, 0);
|
|
394
|
+
if ((0, format_1.isTruthy)(s.reactions))
|
|
395
|
+
row('reactions', s.reactions, 0);
|
|
396
|
+
if ((0, format_1.isTruthy)(s.files))
|
|
397
|
+
row('files', s.files, 0);
|
|
398
|
+
if ((0, format_1.isTruthy)(s.total_content))
|
|
399
|
+
row('content', s.total_content, 0);
|
|
400
|
+
if ((0, format_1.isTruthy)(s.rooms_total)) {
|
|
401
|
+
const kinds = Object.entries(bag(s.rooms)).sort(([a], [b]) => (0, format_1.compareCodePoints)(a, b));
|
|
402
|
+
row('rooms', s.rooms_total, seconds('channels'), kinds.map(([kind, n]) => `${kind} ${(0, format_1.toTextAny)(n)}`).join(' · '));
|
|
403
|
+
}
|
|
404
|
+
row('DMs', s.dms, seconds('dms'));
|
|
405
|
+
if ((0, format_1.isTruthy)(s.users))
|
|
406
|
+
(0, render_1.say)(io, ' Seeded users sign in with their username as the password.');
|
|
407
|
+
const planned = bag(s.planned);
|
|
408
|
+
if (planned.rooms_total !== undefined)
|
|
409
|
+
(0, render_1.say)(io, ` Planned: ${(0, format_1.toTextAny)(planned.users)} users · ${(0, format_1.toTextAny)(planned.rooms_total)} rooms · ` +
|
|
410
|
+
`${(0, format_1.toTextAny)(planned.messages)} messages · ${(0, format_1.toTextAny)(planned.threads)} thread replies · ${(0, format_1.toTextAny)(planned.files)} files`);
|
|
411
|
+
if (Array.isArray(s.scenarios) && s.scenarios.length > 0)
|
|
412
|
+
(0, render_1.say)(io, ` Scenarios: ${s.scenarios.map(format_1.toTextAny).join(' · ')}`);
|
|
413
|
+
const history = bag(s.history);
|
|
414
|
+
if (history.days !== undefined) {
|
|
415
|
+
(0, render_1.say)(io, ` Synthetic history: ${(0, format_1.toTextAny)(history.days)} days · ${(0, format_1.toTextAny)(history.oldest)} to ${(0, format_1.toTextAny)(history.latest)}`);
|
|
416
|
+
if (Array.isArray(history.constrained) && history.constrained.length > 0)
|
|
417
|
+
(0, render_1.say)(io, ` Existing discussion anchors constrain ${String(history.constrained.length)} room(s); details are saved in the seed result.`);
|
|
418
|
+
}
|
|
419
|
+
if (Array.isArray(s.created))
|
|
420
|
+
for (const raw of s.created) {
|
|
421
|
+
const location = bag(raw);
|
|
422
|
+
const stars = Array.isArray(location.starred_by) ? location.starred_by.map(format_1.toTextAny) : [];
|
|
423
|
+
const files = Array.isArray(location.files) ? location.files.map(format_1.toTextAny) : [];
|
|
424
|
+
if (stars.length === 0 && files.length === 0 && location.kind !== 'discussion')
|
|
425
|
+
continue;
|
|
426
|
+
const details = [
|
|
427
|
+
...(stars.length > 0 ? [`personal stars: sign in as ${stars.join(', ')}`] : []),
|
|
428
|
+
...(files.length > 0 ? [`files: ${files.join(', ')}`] : []),
|
|
429
|
+
...(location.kind === 'discussion' ? [`discussion in ${(0, format_1.toTextAny)(location.parent)}`] : []),
|
|
430
|
+
];
|
|
431
|
+
(0, render_1.say)(io, ` ${(0, format_1.toTextAny)(location.name)}: ${details.join(' · ')}`);
|
|
432
|
+
}
|
|
433
|
+
renderResources(report ?? {}, io, (0, format_1.toTextAny)(meta.name));
|
|
434
|
+
}
|
|
435
|
+
/** The seed's readback, in one line when it agrees and a list when not. */
|
|
436
|
+
function printSeedVerification(verdict, io, summary) {
|
|
437
|
+
const features = bag(verdict.features);
|
|
438
|
+
const planned = bag(summary.planned);
|
|
439
|
+
const featureRows = [
|
|
440
|
+
['files', 'files', 'files'],
|
|
441
|
+
['thread_parents', 'thread_parents', 'thread roots'],
|
|
442
|
+
['reactions', 'reaction_actions', 'reactions'],
|
|
443
|
+
['pins', 'pins', 'pins'],
|
|
444
|
+
['stars', 'stars', 'stars'],
|
|
445
|
+
['mentions', 'mentions', 'mentions'],
|
|
446
|
+
['edits', 'edits', 'edits'],
|
|
447
|
+
];
|
|
448
|
+
if (Object.keys(features).length > 0)
|
|
449
|
+
(0, render_1.say)(io, ' Features (read/planned): ' +
|
|
450
|
+
featureRows
|
|
451
|
+
.map(([actual, expected, label]) => `${(0, format_1.toTextAny)(features[actual] ?? 0)}/${(0, format_1.toTextAny)(planned[expected] ?? 0)} ${label}`)
|
|
452
|
+
.join(' · '));
|
|
453
|
+
if (verdict.ok === null || verdict.ok === undefined) {
|
|
454
|
+
// NOT SILENCE: a readback that could not run at all says so, and why.
|
|
455
|
+
const reasons = bags(verdict.unreadable)
|
|
456
|
+
.filter((entry) => (0, format_1.isTruthy)(entry.why))
|
|
457
|
+
.map((entry) => (0, format_1.isTruthy)(entry.what)
|
|
458
|
+
? `${(0, format_1.toTextAny)(entry.what)}: ${(0, format_1.toTextAny)(entry.why)}`
|
|
459
|
+
: (0, format_1.toTextAny)(entry.why));
|
|
460
|
+
const why = (0, format_1.isTruthy)(verdict.why)
|
|
461
|
+
? (0, format_1.toTextAny)(verdict.why)
|
|
462
|
+
: reasons.length > 0
|
|
463
|
+
? reasons.join('; ')
|
|
464
|
+
: 'no reason recorded';
|
|
465
|
+
(0, render_1.say)(io, ` ⚠ the seed readback could not run (${why}), so nothing about this seed is verified. ` +
|
|
466
|
+
'`houston seed --name <it>` re-runs it.');
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
const faults = (0, format_1.isTruthy)(verdict.faults) ? verdict.faults : [];
|
|
470
|
+
const unreadable = (0, format_1.isTruthy)(verdict.unreadable) ? verdict.unreadable : [];
|
|
471
|
+
const extra = (0, format_1.isTruthy)(verdict.extra) ? verdict.extra : [];
|
|
472
|
+
if (verdict.ok === true && faults.length === 0 && unreadable.length === 0 && extra.length === 0) {
|
|
473
|
+
(0, render_1.say)(io, `✓ readback: ${(0, format_1.toTextAny)(verdict.checked)} rooms match the plan`);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
for (const raw of faults) {
|
|
477
|
+
const f = bag(raw);
|
|
478
|
+
(0, render_1.say)(io, ` ⚠ ${(0, format_1.toTextAny)((0, format_1.isTruthy)(f.room) ? f.room : 'users')}: wanted ${(0, format_1.toTextAny)(f.want)}, ` +
|
|
479
|
+
`found ${(0, format_1.toTextAny)(f.got)}${(0, format_1.isTruthy)(f.detail) ? ` (${(0, format_1.toTextAny)(f.detail)})` : ''}`);
|
|
480
|
+
}
|
|
481
|
+
if (extra.length > 0) {
|
|
482
|
+
(0, render_1.say)(io, ` · ${String(extra.length)} room(s) hold more than this run planned — they had content ` +
|
|
483
|
+
'already (a re-seed, a preset, a restore). Not a fault: seeding only ever adds.');
|
|
484
|
+
}
|
|
485
|
+
// Apart from the faults, and never as one: an unreadable room is a gap in the CHECK.
|
|
486
|
+
for (const raw of unreadable) {
|
|
487
|
+
const u = bag(raw);
|
|
488
|
+
(0, render_1.say)(io, ` · ${(0, format_1.toTextAny)(u.what)} could not be read back (${(0, format_1.toTextAny)(u.why)})`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/** Repeated `--set KEY=VALUE` into a preset params mapping. */
|
|
492
|
+
function parseSetParams(items) {
|
|
493
|
+
const params = {};
|
|
494
|
+
for (const item of items) {
|
|
495
|
+
const at = item.indexOf('=');
|
|
496
|
+
if (at < 0)
|
|
497
|
+
throw new errors_1.ValidationError(`--set expects KEY=VALUE, got ${(0, format_1.quotedText)(item)}`);
|
|
498
|
+
params[(0, format_1.stripText)(item.slice(0, at))] = (0, format_1.stripText)(item.slice(at + 1));
|
|
499
|
+
}
|
|
500
|
+
return params;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* `--license <file|->`: the licence TEXT from a file or stdin, never from argv, where `ps`
|
|
504
|
+
* shows it to every user on the box. Validated by the create; a read failure names the path
|
|
505
|
+
* and never the content.
|
|
506
|
+
*/
|
|
507
|
+
function licenseFrom(source) {
|
|
508
|
+
if (source === '')
|
|
509
|
+
return '';
|
|
510
|
+
const fs = require('node:fs');
|
|
511
|
+
try {
|
|
512
|
+
return fs.readFileSync(source === '-' ? 0 : source, 'utf8');
|
|
513
|
+
}
|
|
514
|
+
catch (error) {
|
|
515
|
+
throw new errors_1.ValidationError(`--license ${(0, format_1.quotedText)(source)} could not be read: ${(0, errors_1.errorText)(error)}`);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
async function runUp(invocation, io) {
|
|
519
|
+
const lifecycle = require('../core/lifecycle/create-docker');
|
|
520
|
+
const types = require('../core/lifecycle/types');
|
|
521
|
+
const envvars = require('../core/envvars');
|
|
522
|
+
const monitor = require('../core/monitor');
|
|
523
|
+
const o = invocation.options;
|
|
524
|
+
const version = text(o.version);
|
|
525
|
+
// `parseSetParams`: the request is built -- and a malformed `--set` refused -- before the
|
|
526
|
+
// create starts. Preset params, not env vars: the env parser has other rules and another
|
|
527
|
+
// error. The release lookup is the create's own, where `resolvePairing` makes it.
|
|
528
|
+
const params = parseSetParams(strings(o.set_));
|
|
529
|
+
const req = types.createReq({
|
|
530
|
+
version,
|
|
531
|
+
// Repeatable: several presets compose into one workspace, spelled one canonical way.
|
|
532
|
+
// None at all is '' rather than `default`, so a rebuild of a composed workspace can
|
|
533
|
+
// tell "not said" from "said default" and keep its presets; the create reads '' as
|
|
534
|
+
// `default` everywhere else.
|
|
535
|
+
preset: strings(o.preset).length > 0 ? (0, composite_1.compositeName)(strings(o.preset)) : '',
|
|
536
|
+
runtime: text(o.runtime),
|
|
537
|
+
deployment: text(o.deployment),
|
|
538
|
+
replicas: number(o.replicas),
|
|
539
|
+
context: text(o.context),
|
|
540
|
+
mongoOperator: bool(o.mongo_operator),
|
|
541
|
+
name: text(o.name),
|
|
542
|
+
// WHO IS CREATING IT, which is what names it on a box with accounts: without it two
|
|
543
|
+
// people running `up -v 8.5.1` derived the same workspace.
|
|
544
|
+
actor: require('../core/audit').actor(),
|
|
545
|
+
port: number(o.port),
|
|
546
|
+
rootUrl: text(o.root_url),
|
|
547
|
+
bind: text(o.bind),
|
|
548
|
+
rcImage: text(o.rc_image),
|
|
549
|
+
mongo: text(o.mongo),
|
|
550
|
+
regToken: text(o.reg_token),
|
|
551
|
+
license: licenseFrom(text(o.license)),
|
|
552
|
+
params,
|
|
553
|
+
seed: bool(o.seed),
|
|
554
|
+
// ALWAYS true: the note is this command's to close, below, and it records what a killed
|
|
555
|
+
// create's recovery reads. Taking it from `--seed` let the create clear its own note and
|
|
556
|
+
// wrote `seed_here: false` into every other.
|
|
557
|
+
seedHere: true,
|
|
558
|
+
seedProfile: text(o.seed_profile),
|
|
559
|
+
seedScenarios: strings(o.seed_scenario),
|
|
560
|
+
seedHistoryDays: o.seed_history_days === null || o.seed_history_days === undefined
|
|
561
|
+
? null
|
|
562
|
+
: number(o.seed_history_days),
|
|
563
|
+
pin: bool(o.pin),
|
|
564
|
+
wait: bool(o.wait),
|
|
565
|
+
offline: bool(o.offline),
|
|
566
|
+
noPull: bool(o.no_pull),
|
|
567
|
+
fresh: bool(o.fresh),
|
|
568
|
+
force: bool(o.force),
|
|
569
|
+
monitor: bool(o.monitor),
|
|
570
|
+
stats: bool(o.stats),
|
|
571
|
+
domain: text(o.domain),
|
|
572
|
+
acmeEmail: text(o.email),
|
|
573
|
+
https: bool(o.https),
|
|
574
|
+
ingressClass: text(o.ingress_class),
|
|
575
|
+
env: {
|
|
576
|
+
...envvars.parseSet(strings(o.env)),
|
|
577
|
+
...stringRecord(envvars.asSetting(strings(o.setting))),
|
|
578
|
+
},
|
|
579
|
+
});
|
|
580
|
+
const created = await lifecycle.createRepro(req, emitOf(invocation, io), {
|
|
581
|
+
// No streamed output, even under --json, as it has always been: compose draws on the
|
|
582
|
+
// terminal (its stdout on stderr while --json owns stdout) and none of its
|
|
583
|
+
// lines becomes an event. Streaming them under --json turned every pull and container
|
|
584
|
+
// line into an NDJSON `boot` event the established stream never carries.
|
|
585
|
+
streamOutput: false,
|
|
586
|
+
monitorAttach: monitor.attach,
|
|
587
|
+
});
|
|
588
|
+
// The record, read back for the panel and notes.
|
|
589
|
+
const createdMeta = (0, jsonout_1.active)() ? null : await metadata(String(created.name ?? req.name));
|
|
590
|
+
// THE NOTE IS OURS TO CLOSE, as it always has been: `seedHere` told the create not to, and
|
|
591
|
+
// a failed seed throws before the clear, so reaching it means the seed landed -- or none
|
|
592
|
+
// was asked for.
|
|
593
|
+
const journal = require('../core/journal');
|
|
594
|
+
if (!bool(o.seed)) {
|
|
595
|
+
journal.clearKind(journal.CREATE_UNFINISHED, String(created.name));
|
|
596
|
+
return createdMeta === null ? created : withMeta(created, createdMeta);
|
|
597
|
+
}
|
|
598
|
+
// The panel, THEN the seed. It was rendered from the return value, after the seed -- so the
|
|
599
|
+
// seed's output came before the panel, and a seed that failed (a refused login, a typo in
|
|
600
|
+
// `--seed-profile`, `--verify-seed` refusing) left a workspace that is up and serving with
|
|
601
|
+
// no panel at all: no URL, no login. Rendered here, so the value returned for a person
|
|
602
|
+
// renders nothing more.
|
|
603
|
+
if (createdMeta !== null)
|
|
604
|
+
await renderHuman(invocation, withMeta(created, createdMeta), io);
|
|
605
|
+
const seed = await runSeed(await metadata(String(created.name ?? req.name)), o, io);
|
|
606
|
+
journal.clearKind(journal.CREATE_UNFINISHED, String(created.name));
|
|
607
|
+
// Folded in, not printed beside: exactly one envelope per command.
|
|
608
|
+
return createdMeta === null ? { ...created, seed } : undefined;
|
|
609
|
+
}
|
|
610
|
+
const CONFIG_KEYS = Object.freeze({
|
|
611
|
+
'kubernetes.context': 'kubernetes_context',
|
|
612
|
+
'cluster.approved_accounts': 'cluster_approved_accounts',
|
|
613
|
+
'acme.email': 'acme_email',
|
|
614
|
+
'acme.staging': 'acme_staging',
|
|
615
|
+
'acme.challenge': 'acme_challenge',
|
|
616
|
+
'acme.dns_provider': 'acme_dns_provider',
|
|
617
|
+
bind_host: 'bind_host',
|
|
618
|
+
'gui.create_policy': 'gui.create_policy',
|
|
619
|
+
'gui.destroy_policy': 'gui.destroy_policy',
|
|
620
|
+
// Okta sign-in for the GUI. The client secret is never one of these: `config list` prints
|
|
621
|
+
// them, so it lives in `<home>/sso.env` or the environment (see `core/sso`).
|
|
622
|
+
'sso.issuer': 'sso.issuer',
|
|
623
|
+
'sso.client_id': 'sso.client_id',
|
|
624
|
+
'sso.public_url': 'sso.public_url',
|
|
625
|
+
'sso.email_domains': 'sso.email_domains',
|
|
626
|
+
'sso.provision': 'sso.provision',
|
|
627
|
+
});
|
|
628
|
+
/** The owner a workspace's record names, for a result line; '' for nobody or no record. */
|
|
629
|
+
async function recordOwner(name) {
|
|
630
|
+
const runnerRecord = require('../core/runner/record');
|
|
631
|
+
const meta = await runnerRecord.readMeta(name).catch(() => null);
|
|
632
|
+
return meta === null ? '' : runnerRecord.recordedOwner(meta);
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* The owner leads the prompt, because on a shared box the thing you most need to know first
|
|
636
|
+
* is whose data it is -- and is still said under `--yes`, where there is no prompt to read
|
|
637
|
+
* but there is a log to read afterwards.
|
|
638
|
+
*/
|
|
639
|
+
async function confirmDestruction(io, name, yes, dependencies) {
|
|
640
|
+
const ownership = require('../core/lifecycle/ownership');
|
|
641
|
+
const audit = require('../core/audit');
|
|
642
|
+
// `toTextAny` of the raw owner `ownerOf` returns, which a hand-edited record can make an
|
|
643
|
+
// int or a list.
|
|
644
|
+
const owner = await ownership.ownerOf(name);
|
|
645
|
+
const me = audit.actor();
|
|
646
|
+
const whose = (0, format_1.isTruthy)(owner) && owner !== me ? ` -- owned by ${(0, format_1.toTextAny)(owner)}` : '';
|
|
647
|
+
const warnLine = (line) => ((0, jsonout_1.active)() ? io.writeErr(`${line}\n`) : (0, render_1.say)(io, line));
|
|
648
|
+
if (!yes) {
|
|
649
|
+
if (whose !== '')
|
|
650
|
+
warnLine(`${(0, format_1.quotedText)(name)} belongs to ${(0, format_1.toTextAny)(owner)}, not you.`);
|
|
651
|
+
// No `quotedText` here: its quotes collide with the possessive.
|
|
652
|
+
const question = `This permanently deletes the data volume and record for ${name}${whose}. Continue?`;
|
|
653
|
+
if (!(await (dependencies.confirm ?? defaultConfirm)(question)))
|
|
654
|
+
throw new app_1.Aborted();
|
|
655
|
+
}
|
|
656
|
+
else if (whose !== '') {
|
|
657
|
+
warnLine(`deleting ${(0, format_1.quotedText)(name)}, owned by ${(0, format_1.toTextAny)(owner)}.`);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
/** Name every destructive target before asking once. */
|
|
661
|
+
async function confirmPrune(io, targets, stray, dependencies) {
|
|
662
|
+
const ownership = require('../core/lifecycle/ownership');
|
|
663
|
+
const audit = require('../core/audit');
|
|
664
|
+
const pruning = require('../core/lifecycle/pruning');
|
|
665
|
+
const namespaces = require('../core/kube/namespace');
|
|
666
|
+
const me = audit.actor();
|
|
667
|
+
(0, render_1.say)(io, 'These workspaces were taken down with `houston down`; their containers, kept data and ' +
|
|
668
|
+
'records will be deleted for good (stopped ones are not touched):');
|
|
669
|
+
for (const name of targets) {
|
|
670
|
+
const owner = await ownership.ownerOf(name);
|
|
671
|
+
(0, render_1.say)(io, ` - ${name}${(0, format_1.isTruthy)(owner) && owner !== me ? ` (owned by ${(0, format_1.toTextAny)(owner)})` : ''}`);
|
|
672
|
+
}
|
|
673
|
+
if (stray.length > 0) {
|
|
674
|
+
(0, render_1.say)(io, '');
|
|
675
|
+
(0, render_1.say)(io, "These Kubernetes namespaces are labelled houston's but no local record explains " +
|
|
676
|
+
'them — their data (PersistentVolumeClaims) goes too:');
|
|
677
|
+
for (const ns of stray) {
|
|
678
|
+
// The same three answers the service decides on, so the prompt cannot promise a
|
|
679
|
+
// sweep the service then refuses. Never raises: this is prompt text.
|
|
680
|
+
let owner;
|
|
681
|
+
try {
|
|
682
|
+
owner = await namespaces.namespaceOwner(ns, { context: await pruning.orphanContext() });
|
|
683
|
+
}
|
|
684
|
+
catch {
|
|
685
|
+
owner = null;
|
|
686
|
+
}
|
|
687
|
+
if (owner === null)
|
|
688
|
+
(0, render_1.say)(io, ` - ${ns} (owner could not be read — needs --force)`);
|
|
689
|
+
else if (owner !== '' && owner !== me)
|
|
690
|
+
(0, render_1.say)(io, ` - ${ns} (belongs to ${owner} — needs --force)`);
|
|
691
|
+
else
|
|
692
|
+
(0, render_1.say)(io, ` - ${ns}`);
|
|
693
|
+
}
|
|
694
|
+
(0, render_1.say)(io, ' (on a shared cluster one of these may belong to a colleague)');
|
|
695
|
+
}
|
|
696
|
+
if (!(await (dependencies.confirm ?? defaultConfirm)('Continue?')))
|
|
697
|
+
throw new app_1.Aborted();
|
|
698
|
+
}
|
|
699
|
+
async function dispatch(invocation, dependencies, io) {
|
|
700
|
+
const o = invocation.options;
|
|
701
|
+
const a = invocation.arguments;
|
|
702
|
+
const emit = emitOf(invocation, io);
|
|
703
|
+
switch (invocation.spec.path) {
|
|
704
|
+
case 'capabilities':
|
|
705
|
+
return (0, capabilities_1.capabilities)();
|
|
706
|
+
case 'up':
|
|
707
|
+
return await runUp(invocation, io);
|
|
708
|
+
case 'ready': {
|
|
709
|
+
const ready = require('../core/lifecycle/ready');
|
|
710
|
+
// `requireEngine` BEFORE the first poll. Without it a stopped daemon went straight
|
|
711
|
+
// to the poll, whose liveness check found no container and reported NOT_READY, exit 5
|
|
712
|
+
// ("Rocket.Chat container is not running") -- the code that tells a caller to poll
|
|
713
|
+
// again. The established answer is ENGINE_UNAVAILABLE, exit 3, because polling cannot
|
|
714
|
+
// start Docker. Measured by the CLI differential, docker stubbed.
|
|
715
|
+
const meta = await engineMetadata(text(o.name));
|
|
716
|
+
// Said before the first poll, on stdout, and only to a person: `--json` streams its
|
|
717
|
+
// events instead. An earlier version never said it, so a slow boot was a silent prompt
|
|
718
|
+
// until the first "still booting" line.
|
|
719
|
+
if (!(0, jsonout_1.active)())
|
|
720
|
+
io.writeOut(`Waiting for ${(0, format_1.quotedText)(meta.name)} to serve ${meta.rootUrl} ...\n`);
|
|
721
|
+
const result = {
|
|
722
|
+
...(await ready.waitAndFinalize(meta, emit, number(o.timeout))),
|
|
723
|
+
name: meta.name,
|
|
724
|
+
url: meta.publicUrl || meta.rootUrl,
|
|
725
|
+
};
|
|
726
|
+
return withMeta(result, meta);
|
|
727
|
+
}
|
|
728
|
+
case 'down': {
|
|
729
|
+
const destroy = require('../core/lifecycle/destroy');
|
|
730
|
+
const volumes = bool(o.volumes);
|
|
731
|
+
const yes = bool(o.yes);
|
|
732
|
+
// RESOLVED FIRST, as `down` does: a name that does not exist is NOT_FOUND (exit 4)
|
|
733
|
+
// whatever else is wrong with the command, and only then is the refusal asked.
|
|
734
|
+
const name = await target(text(o.name));
|
|
735
|
+
if (volumes && (0, jsonout_1.active)() && !yes) {
|
|
736
|
+
// REFUSED, not silently downgraded to keeping the volume: there is nobody to
|
|
737
|
+
// prompt, and both ways out of that are unacceptable for an irreversible verb.
|
|
738
|
+
throw new errors_1.ValidationError('--volumes deletes the data volume and the record, and --json has nobody to ' +
|
|
739
|
+
'prompt. Add --yes to confirm it in the command.');
|
|
740
|
+
}
|
|
741
|
+
if (volumes)
|
|
742
|
+
await confirmDestruction(io, name, yes, dependencies);
|
|
743
|
+
// Read BEFORE the teardown: with --volumes the record that names the owner is gone after.
|
|
744
|
+
const runnerRecord = require('../core/runner/record');
|
|
745
|
+
const was = await runnerRecord.readMeta(name).catch(() => null);
|
|
746
|
+
const owner = was === null ? '' : runnerRecord.recordedOwner(was);
|
|
747
|
+
const result = await destroy.teardown(name, { volumes, confirm: true, emit });
|
|
748
|
+
const data = { ...result, name, volumes, owner };
|
|
749
|
+
if (!(0, jsonout_1.active)() && volumes && result.removed === false) {
|
|
750
|
+
return (0, app_1.commandOutcome)(data, 5);
|
|
751
|
+
}
|
|
752
|
+
return data;
|
|
753
|
+
}
|
|
754
|
+
case 'monitor': {
|
|
755
|
+
const monitor = require('../core/monitor');
|
|
756
|
+
const name = await target(text(o.name));
|
|
757
|
+
return bool(o.off) ? await monitor.detach(name, emit) : await monitor.attach(name, emit);
|
|
758
|
+
}
|
|
759
|
+
case 'prune': {
|
|
760
|
+
const pruning = require('../core/lifecycle/pruning');
|
|
761
|
+
const shown = await pruning.prunable();
|
|
762
|
+
const stray = bool(o.orphans) ? await pruning.orphanNamespaces() : [];
|
|
763
|
+
// The CLUSTER is reclaimable separately from any workspace: with everything gone,
|
|
764
|
+
// houston's own kind control plane is 514 MiB holding nothing. ASKED ON EVERY PRUNE,
|
|
765
|
+
// before the empty check and the prompt, as it always has been (`clusterReclaimable`)
|
|
766
|
+
// -- even when there are targets and the answer goes unused. This asked only on the
|
|
767
|
+
// nothing-to-prune branch, so with kind on PATH a prune with targets ran none of `kind
|
|
768
|
+
// get clusters`, `kubectl config current-context` and the `/readyz` probe a prune has
|
|
769
|
+
// always run, and an aborted one left no `clients/` tree where earlier releases leave
|
|
770
|
+
// one.
|
|
771
|
+
let reclaimable;
|
|
772
|
+
const cluster = require('../core/kube/cluster');
|
|
773
|
+
try {
|
|
774
|
+
reclaimable = await cluster.clusterReclaimable();
|
|
775
|
+
}
|
|
776
|
+
catch {
|
|
777
|
+
// A cleanup verb must not become destructive, or fail, because a probe did.
|
|
778
|
+
reclaimable = false;
|
|
779
|
+
}
|
|
780
|
+
if (shown.length === 0 && stray.length === 0) {
|
|
781
|
+
if (!reclaimable)
|
|
782
|
+
return { targets: [], removed: [], orphans: [], cluster: false };
|
|
783
|
+
if (!bool(o.yes)) {
|
|
784
|
+
(0, render_1.say)(io, "Nothing to prune, but houston's own Kubernetes cluster is empty and can be " +
|
|
785
|
+
'given back (about 0.5 GB).');
|
|
786
|
+
if (!(await (dependencies.confirm ?? defaultConfirm)('Delete the cluster?'))) {
|
|
787
|
+
throw new app_1.Aborted();
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
const res = await pruning.prune({
|
|
791
|
+
confirm: true,
|
|
792
|
+
orphans: bool(o.orphans),
|
|
793
|
+
force: bool(o.force),
|
|
794
|
+
emit,
|
|
795
|
+
});
|
|
796
|
+
return { ...res, emptyCluster: true };
|
|
797
|
+
}
|
|
798
|
+
if (!bool(o.yes))
|
|
799
|
+
await confirmPrune(io, shown, stray, dependencies);
|
|
800
|
+
return await pruning.prune({
|
|
801
|
+
confirm: true,
|
|
802
|
+
orphans: bool(o.orphans),
|
|
803
|
+
force: bool(o.force),
|
|
804
|
+
only: shown,
|
|
805
|
+
onlyStray: stray,
|
|
806
|
+
emit,
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
case 'start':
|
|
810
|
+
case 'stop':
|
|
811
|
+
case 'restart': {
|
|
812
|
+
const state = require('../core/lifecycle/state');
|
|
813
|
+
const name = await target(text(o.name));
|
|
814
|
+
const action = invocation.spec.path;
|
|
815
|
+
if (action !== 'start')
|
|
816
|
+
return await state.setState(name, action, emit);
|
|
817
|
+
try {
|
|
818
|
+
return await state.setState(name, action, emit);
|
|
819
|
+
}
|
|
820
|
+
catch (error) {
|
|
821
|
+
// `start` answers a domain failure with a red error line and a plain exit, keeping the
|
|
822
|
+
// class's exit code, so the log has an `end` record and no `error` one; `stop` and
|
|
823
|
+
// `restart` throw through the error contract and keep that path. The line is the
|
|
824
|
+
// SERVICE'S OWN now. It was one fixed sentence for every failure -- "if it was
|
|
825
|
+
// `down`ed, use `houston up`" -- which sent a workspace that was merely stopped with
|
|
826
|
+
// its port held to recreate itself, while the core knew which it was and why.
|
|
827
|
+
if (!(error instanceof errors_1.ReproError))
|
|
828
|
+
throw error;
|
|
829
|
+
io.writeErr(`error: ${error.message}\n`);
|
|
830
|
+
return (0, app_1.commandOutcome)(undefined, error.exitCode);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
case 'use': {
|
|
834
|
+
const naming = require('../core/lifecycle/naming');
|
|
835
|
+
const target = await naming.resolveName(text(a.name));
|
|
836
|
+
await require('../core/runner/locks').updateConfig((stored) => {
|
|
837
|
+
stored.default_repro = target;
|
|
838
|
+
});
|
|
839
|
+
return { default: target };
|
|
840
|
+
}
|
|
841
|
+
case 'list': {
|
|
842
|
+
const inspect = require('../core/lifecycle/inspect');
|
|
843
|
+
const repros = await inspect.listRepros();
|
|
844
|
+
return { repros, count: repros.length };
|
|
845
|
+
}
|
|
846
|
+
case 'info': {
|
|
847
|
+
const name = await target(text(o.name));
|
|
848
|
+
if (!(0, jsonout_1.active)()) {
|
|
849
|
+
// The record alone, as the human `info` has always read it: `detail()` asks docker
|
|
850
|
+
// and the compose file, which a person reading a URL and a login does not need,
|
|
851
|
+
// and which failed where the record alone answers (see summaryPanel).
|
|
852
|
+
const record = require('../core/runner/record');
|
|
853
|
+
return withMeta({}, await record.readMeta(name));
|
|
854
|
+
}
|
|
855
|
+
const payload = require('../core/lifecycle/payload');
|
|
856
|
+
return await payload.detail(name);
|
|
857
|
+
}
|
|
858
|
+
case 'users':
|
|
859
|
+
// Printed as it goes (`handlers/users.ts`): it is `json: none`, so what it prints and
|
|
860
|
+
// the code it exits with are its whole contract.
|
|
861
|
+
await (0, users_1.usersCommand)(io, {
|
|
862
|
+
action: text(a.action),
|
|
863
|
+
name: text(a.name),
|
|
864
|
+
role: text(a.role),
|
|
865
|
+
askPassword: bool(o.ask_password),
|
|
866
|
+
}, dependencies.prompt);
|
|
867
|
+
return undefined;
|
|
868
|
+
case 'config': {
|
|
869
|
+
const config = require('../lib/config');
|
|
870
|
+
const action = text(a.action);
|
|
871
|
+
const key = text(a.key);
|
|
872
|
+
if (action === 'list') {
|
|
873
|
+
const stored = config.loadConfig();
|
|
874
|
+
return Object.fromEntries(Object.entries(CONFIG_KEYS).map(([shown, internal]) => [
|
|
875
|
+
shown,
|
|
876
|
+
Object.hasOwn(stored, internal) ? stored[internal] : null,
|
|
877
|
+
]));
|
|
878
|
+
}
|
|
879
|
+
// THE ACTION FIRST: the order earlier releases kept checked the key first, so `config
|
|
880
|
+
// frob x` answered "unknown key 'x'" about a command whose mistake was `frob`. Every
|
|
881
|
+
// refusal quotes what was typed with `quotedText`: hand-written quotes printed `'it's'`
|
|
882
|
+
// for `"it's"` and a raw tab for `'a\tb'`.
|
|
883
|
+
if (!['get', 'set', 'unset'].includes(action))
|
|
884
|
+
throw new errors_1.ValidationError(`unknown action ${(0, format_1.quotedText)(action)} (want: list | get | set | unset)`);
|
|
885
|
+
const internal = CONFIG_KEYS[key];
|
|
886
|
+
if (internal === undefined)
|
|
887
|
+
throw new errors_1.ValidationError(`unknown key ${(0, format_1.quotedText)(key)} (want: ${Object.keys(CONFIG_KEYS).join(', ')})`);
|
|
888
|
+
if (action === 'get')
|
|
889
|
+
return { key, value: config.loadConfig()[internal] ?? null };
|
|
890
|
+
if (action === 'unset') {
|
|
891
|
+
await require('../core/runner/locks').updateConfig((stored) => {
|
|
892
|
+
delete stored[internal];
|
|
893
|
+
});
|
|
894
|
+
return { key, unset: true };
|
|
895
|
+
}
|
|
896
|
+
const given = text(a.value);
|
|
897
|
+
if (given === '')
|
|
898
|
+
throw new errors_1.ValidationError(`\`config set ${key}\` needs a value`);
|
|
899
|
+
if (key === 'gui.create_policy' || key === 'gui.destroy_policy') {
|
|
900
|
+
const strict = key === 'gui.create_policy' ? 'admin' : 'owner';
|
|
901
|
+
if (given !== 'anyone' && given !== strict)
|
|
902
|
+
throw new errors_1.ValidationError(`${key} takes 'anyone' or '${strict}' (got ${(0, format_1.quotedText)(given)})`);
|
|
903
|
+
}
|
|
904
|
+
// Refused like the policies: the edge reads only these three (`forcedChallenge`), so
|
|
905
|
+
// any other value was stored and silently did nothing.
|
|
906
|
+
if (key === 'acme.challenge' && !['http', 'tlsalpn', 'dns'].includes(given)) {
|
|
907
|
+
throw new errors_1.ValidationError(`${key} takes http, tlsalpn or dns (got ${(0, format_1.quotedText)(given)})`);
|
|
908
|
+
}
|
|
909
|
+
let value = given;
|
|
910
|
+
if (key.startsWith('sso.')) {
|
|
911
|
+
const sso = require('../core/sso');
|
|
912
|
+
value = sso.checkSetting(key, given);
|
|
913
|
+
if (key === 'sso.issuer')
|
|
914
|
+
sso.requireReadyForIssuer(config.loadConfig(false));
|
|
915
|
+
}
|
|
916
|
+
if (key === 'acme.staging') {
|
|
917
|
+
// `TRUE_WORDS` + `FALSE_WORDS` after `stripText`, the empty word excluded: `y`, `t`,
|
|
918
|
+
// `n` and `f` were refused here, and `trim()` stripped a BOM `stripText` keeps and
|
|
919
|
+
// kept the separators and NEL it strips.
|
|
920
|
+
const low = (0, format_1.stripText)(given).toLowerCase();
|
|
921
|
+
if (low === '' || !(config.TRUE_WORDS.includes(low) || config.FALSE_WORDS.includes(low)))
|
|
922
|
+
throw new errors_1.ValidationError(`${key} takes true or false (got ${(0, format_1.quotedText)(given)})`);
|
|
923
|
+
value = config.truthy(given);
|
|
924
|
+
}
|
|
925
|
+
await require('../core/runner/locks').updateConfig((stored) => {
|
|
926
|
+
stored[internal] = value;
|
|
927
|
+
});
|
|
928
|
+
return { key, value };
|
|
929
|
+
}
|
|
930
|
+
case 'env': {
|
|
931
|
+
const envvars = require('../core/envvars');
|
|
932
|
+
// No `--set`, `--setting` or `--unset` typed means a read: read or write is decided on
|
|
933
|
+
// what was TYPED, not on what parsing kept. Decided on the parsed keys, a `--set
|
|
934
|
+
// __proto__=x` the parser lost turned a write into a read that printed the panel and
|
|
935
|
+
// exit 0, with nothing written.
|
|
936
|
+
if (strings(o.set_).length === 0 &&
|
|
937
|
+
strings(o.setting).length === 0 &&
|
|
938
|
+
strings(o.unset).length === 0)
|
|
939
|
+
return await envvars.current(text(o.name));
|
|
940
|
+
const sets = {
|
|
941
|
+
...envvars.parseSet(strings(o.set_)),
|
|
942
|
+
...stringRecord(envvars.asSetting(strings(o.setting))),
|
|
943
|
+
};
|
|
944
|
+
return await envvars.setEnv(text(o.name), sets, strings(o.unset), {
|
|
945
|
+
restart: !bool(o.no_restart),
|
|
946
|
+
emit,
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
case 'edge': {
|
|
950
|
+
// `https.edgeCommand`: this command is `json: none`, so what it prints and the code it
|
|
951
|
+
// exits with are its whole contract.
|
|
952
|
+
const action = text(a.action);
|
|
953
|
+
const edge = async () => await https.edgeCommand(io, action, text(a.host), { follow: bool(o.follow), tail: number(o.tail), yes: bool(o.yes) }, dependencies.confirm ?? defaultConfirm);
|
|
954
|
+
return (0, app_1.commandOutcome)(null, await edge());
|
|
955
|
+
}
|
|
956
|
+
case 'tls-status':
|
|
957
|
+
// Human-only, so its prose and exit code are the contract. Nothing serving TLS is
|
|
958
|
+
// exit 1, as it always was.
|
|
959
|
+
return (0, app_1.commandOutcome)(null, await https.tlsStatus(io, text(o.name)));
|
|
960
|
+
case 'trust-ca':
|
|
961
|
+
// Human-only, printed as it goes, exit 0 either way.
|
|
962
|
+
return (0, app_1.commandOutcome)(null, await https.trustCa(io, bool(o.uninstall), bool(o.show)));
|
|
963
|
+
case 'token': {
|
|
964
|
+
const admin = require('../core/lifecycle/admin');
|
|
965
|
+
const meta = await engineMetadata(text(o.name));
|
|
966
|
+
try {
|
|
967
|
+
const auth = await admin.login(meta);
|
|
968
|
+
return { token: auth.token, user_id: auth.userId };
|
|
969
|
+
}
|
|
970
|
+
catch (error) {
|
|
971
|
+
return notAnswering(meta, error, 'logging in');
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
case 'pat': {
|
|
975
|
+
const admin = require('../core/lifecycle/admin');
|
|
976
|
+
const rcapi = require('../core/rcapi');
|
|
977
|
+
const record = require('../core/runner/record');
|
|
978
|
+
const meta = await engineMetadata(text(o.name));
|
|
979
|
+
let auth;
|
|
980
|
+
let token;
|
|
981
|
+
try {
|
|
982
|
+
auth = await admin.login(meta);
|
|
983
|
+
token = await rcapi.generatePat(meta.rootUrl, auth, record.adminPass(meta), {
|
|
984
|
+
tokenName: text(o.label),
|
|
985
|
+
bypass2fa: bool(o.bypass_2fa),
|
|
986
|
+
workspace: meta.name,
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
catch (error) {
|
|
990
|
+
return notAnswering(meta, error, 'minting a token');
|
|
991
|
+
}
|
|
992
|
+
return {
|
|
993
|
+
token,
|
|
994
|
+
user_id: auth.userId,
|
|
995
|
+
label: text(o.label),
|
|
996
|
+
bypass_2fa: bool(o.bypass_2fa),
|
|
997
|
+
name: meta.name,
|
|
998
|
+
root_url: meta.rootUrl,
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
case 'api': {
|
|
1002
|
+
const admin = require('../core/lifecycle/admin');
|
|
1003
|
+
const rcapi = require('../core/rcapi');
|
|
1004
|
+
const record = require('../core/runner/record');
|
|
1005
|
+
// ANY method, upper-cased, as `rcapi.call` sends it: there has never been an
|
|
1006
|
+
// allowlist, so HEAD and OPTIONS are sent rather than refused.
|
|
1007
|
+
const method = text(a.method).toUpperCase();
|
|
1008
|
+
// The established order: the workspace, its engine, the login -- and only then the body.
|
|
1009
|
+
const meta = await engineMetadata(text(o.name));
|
|
1010
|
+
let auth;
|
|
1011
|
+
try {
|
|
1012
|
+
auth = await admin.login(meta);
|
|
1013
|
+
if (bool(o.pat))
|
|
1014
|
+
auth = {
|
|
1015
|
+
token: await rcapi.generatePat(meta.rootUrl, auth, record.adminPass(meta), {
|
|
1016
|
+
bypass2fa: true,
|
|
1017
|
+
workspace: meta.name,
|
|
1018
|
+
}),
|
|
1019
|
+
userId: auth.userId,
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
catch (error) {
|
|
1023
|
+
return notAnswering(meta, error, 'this API call');
|
|
1024
|
+
}
|
|
1025
|
+
let body;
|
|
1026
|
+
try {
|
|
1027
|
+
// `jsonLoads`, so the refusal quotes the established reason. And the body sent is
|
|
1028
|
+
// written back from what `jsonLoads` read, so what a double loses is kept for the
|
|
1029
|
+
// writer: `-d 12345678901234567890` went out as 12345678901234567000, and
|
|
1030
|
+
// `-d '{"b":1,"2":2}'` with the `2` first.
|
|
1031
|
+
body = text(o.data) === '' ? undefined : (0, json_text_1.loads)(text(o.data), { spelledRoot: true });
|
|
1032
|
+
}
|
|
1033
|
+
catch (error) {
|
|
1034
|
+
throw new errors_1.ValidationError(`--data is not valid JSON: ${(0, errors_1.errorText)(error)}`);
|
|
1035
|
+
}
|
|
1036
|
+
const extraHeaders = bool(o.two_fa)
|
|
1037
|
+
? await rcapi.password2faHeaders(record.adminPass(meta))
|
|
1038
|
+
: undefined;
|
|
1039
|
+
// A monotonic clock with a fractional part: `fmtMs` rounds what it is given, and a
|
|
1040
|
+
// whole-ms clock would round twice.
|
|
1041
|
+
const started = performance.now();
|
|
1042
|
+
let status;
|
|
1043
|
+
let response;
|
|
1044
|
+
try {
|
|
1045
|
+
[status, response] = await rcapi.call(meta.rootUrl, method, text(a.path), {
|
|
1046
|
+
auth,
|
|
1047
|
+
...(body === undefined ? {} : { data: body }),
|
|
1048
|
+
...(extraHeaders === undefined ? {} : { extraHeaders }),
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
catch (error) {
|
|
1052
|
+
if (!isRequestFailure(error))
|
|
1053
|
+
throw error;
|
|
1054
|
+
throw new errors_1.ReproError(`request failed: ${(0, errors_1.errorText)(error)}`);
|
|
1055
|
+
}
|
|
1056
|
+
const data = {
|
|
1057
|
+
status,
|
|
1058
|
+
text: response,
|
|
1059
|
+
auth: bool(o.pat) ? 'PAT' : 'admin',
|
|
1060
|
+
elapsed_ms: performance.now() - started,
|
|
1061
|
+
};
|
|
1062
|
+
return status >= 400 ? (0, app_1.commandOutcome)(data, 1) : data;
|
|
1063
|
+
}
|
|
1064
|
+
case 'seed': {
|
|
1065
|
+
const data = require('../core/data');
|
|
1066
|
+
const events = require('../lib/events');
|
|
1067
|
+
if ((strings(o.scenario).length > 0 ||
|
|
1068
|
+
(o.history_days !== null && o.history_days !== undefined)) &&
|
|
1069
|
+
(text(o.scale) !== '' || bool(o.clear_scale)))
|
|
1070
|
+
throw new errors_1.ValidationError('--scenario and --history-days cannot be combined with --scale or --clear-scale');
|
|
1071
|
+
// `engineMetadata` -- the name, the engine check, the record -- as `seed` has always
|
|
1072
|
+
// opened: a stopped engine is ENGINE_UNAVAILABLE, exit 3, before any login, prefill or
|
|
1073
|
+
// undo. This read the record and went on to a REST login, refused in its own words with
|
|
1074
|
+
// exit 1.
|
|
1075
|
+
const meta = await engineMetadata(text(o.name));
|
|
1076
|
+
// The two scale paths: the services run with NO emit, and the command says it all
|
|
1077
|
+
// itself -- the headline on stdout BEFORE the spec is read, so a refused spec is still
|
|
1078
|
+
// told what `--scale` is, and the totals with thousands commas. The CLI emitter was
|
|
1079
|
+
// handed down instead: the service's own warning (" - ", not " — ") went to stderr, its
|
|
1080
|
+
// "inserting"/"inserted" lines to stdout, and a refusal printed no headline at all.
|
|
1081
|
+
if (bool(o.clear_scale))
|
|
1082
|
+
return await data.clearScale(meta.name, events.nullEmit);
|
|
1083
|
+
if (text(o.scale) !== '') {
|
|
1084
|
+
(0, render_1.say)(io, 'bulk Mongo prefill: users are credential-less and messages fire no app hooks — ' +
|
|
1085
|
+
'for scale and performance tests, not feature testing.');
|
|
1086
|
+
return await data.runScale(meta.name, text(o.scale), events.nullEmit);
|
|
1087
|
+
}
|
|
1088
|
+
return await runSeed(meta, o, io);
|
|
1089
|
+
}
|
|
1090
|
+
case 'config-import': {
|
|
1091
|
+
const data = require('../core/data');
|
|
1092
|
+
const typed = text(a.settings_file);
|
|
1093
|
+
// The typed path, normalised by `joinPath`, is what is checked and what the service
|
|
1094
|
+
// reads. That drops a trailing `/` and `.` parts, so `settings.json/` IS the file -- a
|
|
1095
|
+
// plan, and an import -- where the stat of the typed text failed with ENOTDIR and
|
|
1096
|
+
// this said "no such file". The refusal quotes what was typed.
|
|
1097
|
+
const file = (0, home_1.joinPath)(typed);
|
|
1098
|
+
if (!(0, format_1.pathIsFile)(file))
|
|
1099
|
+
throw new errors_1.NotFoundError(`no such file: ${typed}`);
|
|
1100
|
+
// Each comma-separated term, stripped, or no filter for no `--only`: an EMPTY term is
|
|
1101
|
+
// kept. Dropped here, `--only ,` or `--only ' '` was an empty set, which the plan
|
|
1102
|
+
// reads as no filter at all -- so a filter that matches nothing applied the WHOLE
|
|
1103
|
+
// dump, OAuth providers and all, where a set holding only `''` applies nothing.
|
|
1104
|
+
const selected = text(o.only) === ''
|
|
1105
|
+
? null
|
|
1106
|
+
: new Set(text(o.only)
|
|
1107
|
+
.split(',')
|
|
1108
|
+
.map((part) => (0, format_1.stripText)(part)));
|
|
1109
|
+
// The engine check (`engineMetadata`) after the name and before the plan: a stopped
|
|
1110
|
+
// engine refused nothing here, and `--dry-run` printed the plan with exit 0.
|
|
1111
|
+
const meta = await engineMetadata(text(o.name));
|
|
1112
|
+
const plan = await data.importPlan(meta.name, file, selected);
|
|
1113
|
+
// DRAWN HERE, before anything is applied, as it has always been drawn: the plan box and
|
|
1114
|
+
// the secrets to set by hand come first on an apply too, so the operator sees what is
|
|
1115
|
+
// about to change before the providers are created. The renderer drew a panel of its
|
|
1116
|
+
// own words for the dry run only, and said nothing of the redacted secrets in either
|
|
1117
|
+
// mode.
|
|
1118
|
+
if (!(0, jsonout_1.active)())
|
|
1119
|
+
renderImportPlan(io, plan, bool(o.dry_run));
|
|
1120
|
+
if (bool(o.dry_run))
|
|
1121
|
+
return plan;
|
|
1122
|
+
return withMeta({ ...(await data.importApply(meta.name, file, selected, emit)) }, meta);
|
|
1123
|
+
}
|
|
1124
|
+
case 'backup': {
|
|
1125
|
+
const backup = require('../core/backup');
|
|
1126
|
+
return await backup.create(text(o.name), {
|
|
1127
|
+
out: text(o.out),
|
|
1128
|
+
note: text(o.label),
|
|
1129
|
+
live: bool(o.live),
|
|
1130
|
+
emit,
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
case 'backups': {
|
|
1134
|
+
const backup = require('../core/backup');
|
|
1135
|
+
return { backups: await backup.listBackups(text(o.name)) };
|
|
1136
|
+
}
|
|
1137
|
+
case 'restore': {
|
|
1138
|
+
const backup = require('../core/backup');
|
|
1139
|
+
return await backup.restore(text(a.bundle), {
|
|
1140
|
+
name: text(o.name),
|
|
1141
|
+
new: bool(o.new),
|
|
1142
|
+
allowUpgrade: bool(o.allow_upgrade),
|
|
1143
|
+
force: bool(o.force),
|
|
1144
|
+
emit,
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
case 'upgrade': {
|
|
1148
|
+
const upgrade = require('../core/upgrade');
|
|
1149
|
+
if (bool(o.rollback))
|
|
1150
|
+
return await upgrade.rollback(text(o.name), { bundle: text(o.bundle), emit });
|
|
1151
|
+
if (text(o.to) === '')
|
|
1152
|
+
throw new errors_1.ValidationError('no target version given — use `--to 8.6.1` (or `--rollback` to undo)');
|
|
1153
|
+
const plan = await upgrade.plan(text(o.name), text(o.to), { offline: bool(o.offline) });
|
|
1154
|
+
// The upgrade DRAWS THE PLAN FIRST, then decides, then runs. This returned the plan for
|
|
1155
|
+
// `renderHuman` to draw afterwards, so a real upgrade never showed its panel or its
|
|
1156
|
+
// warnings at all (they would have landed after the run); a refusal never said why --
|
|
1157
|
+
// no reason, no `--force` hint, and `--dry-run: nothing changed` for a plan that was
|
|
1158
|
+
// refused; and a forced plan's reason was dropped. `upgrade` has no `--json`, so
|
|
1159
|
+
// drawing here is safe. The reason goes to stderr as a failure line before the exit,
|
|
1160
|
+
// and to stdout as a warning line when `--force` carries on past it. Exit 1 after it
|
|
1161
|
+
// writes no error record, which is what an outcome with no error is.
|
|
1162
|
+
renderUpgradePlan(plan, io);
|
|
1163
|
+
if (!(0, format_1.isTruthy)(plan.allowed)) {
|
|
1164
|
+
const reason = ` ${(0, format_1.toTextAny)(plan.blocked_reason)}\n`;
|
|
1165
|
+
if (!bool(o.force)) {
|
|
1166
|
+
io.writeErr(reason);
|
|
1167
|
+
io.writeOut(' --force overrides this, but expect it to fail\n');
|
|
1168
|
+
return (0, app_1.commandOutcome)(null, 1);
|
|
1169
|
+
}
|
|
1170
|
+
io.writeOut(reason);
|
|
1171
|
+
}
|
|
1172
|
+
if (bool(o.dry_run)) {
|
|
1173
|
+
io.writeOut(' --dry-run: nothing changed\n');
|
|
1174
|
+
return null;
|
|
1175
|
+
}
|
|
1176
|
+
// The panel above said the plan's warnings; the run raises them again as it starts.
|
|
1177
|
+
const said = new Set(strings(plan.warnings));
|
|
1178
|
+
return await upgrade.run(text(o.name), text(o.to), {
|
|
1179
|
+
offline: bool(o.offline),
|
|
1180
|
+
force: bool(o.force),
|
|
1181
|
+
noBackup: bool(o.no_backup),
|
|
1182
|
+
rollbackOnFailure: !bool(o.no_rollback),
|
|
1183
|
+
emit: (event) => {
|
|
1184
|
+
if (event.level !== 'warn' || !said.has(event.message))
|
|
1185
|
+
emit(event);
|
|
1186
|
+
},
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
case 'stats':
|
|
1190
|
+
return await runStats(invocation, io);
|
|
1191
|
+
case 'loadtest': {
|
|
1192
|
+
const result = await (0, perf_1.runLoadtestCli)({
|
|
1193
|
+
name: text(o.name),
|
|
1194
|
+
scenario: text(o.scenario),
|
|
1195
|
+
endpoint: text(o.endpoint),
|
|
1196
|
+
body: text(o.body),
|
|
1197
|
+
vus: number(o.vus),
|
|
1198
|
+
usersN: number(o.users_n),
|
|
1199
|
+
duration: text(o.duration),
|
|
1200
|
+
ramp: text(o.ramp),
|
|
1201
|
+
spike: text(o.spike),
|
|
1202
|
+
live: bool(o.live),
|
|
1203
|
+
slo: text(o.slo),
|
|
1204
|
+
constrain: text(o.constrain),
|
|
1205
|
+
diag: bool(o.diag),
|
|
1206
|
+
slowms: number(o.slowms),
|
|
1207
|
+
stats: bool(o.stats),
|
|
1208
|
+
save: text(o.save),
|
|
1209
|
+
compare: text(o.compare),
|
|
1210
|
+
json: bool(o.json_out),
|
|
1211
|
+
report: bool(o.report),
|
|
1212
|
+
reportPath: text(o.report_path),
|
|
1213
|
+
}, io, undefined, (view) => {
|
|
1214
|
+
renderLoadtest(view, io);
|
|
1215
|
+
});
|
|
1216
|
+
return (0, app_1.commandOutcome)(result.data, result.exitCode, sloMissed(result.data));
|
|
1217
|
+
}
|
|
1218
|
+
case 'capacity': {
|
|
1219
|
+
const result = await (0, perf_1.runCapacityCli)({
|
|
1220
|
+
name: text(o.name),
|
|
1221
|
+
scenario: text(o.scenario),
|
|
1222
|
+
usersN: number(o.users_n),
|
|
1223
|
+
slo: text(o.slo),
|
|
1224
|
+
start: number(o.start),
|
|
1225
|
+
maxVus: number(o.max_vus),
|
|
1226
|
+
stepDuration: text(o.step_duration),
|
|
1227
|
+
constrain: text(o.constrain),
|
|
1228
|
+
json: bool(o.json_out),
|
|
1229
|
+
report: bool(o.report),
|
|
1230
|
+
reportPath: text(o.report_path),
|
|
1231
|
+
}, io);
|
|
1232
|
+
return (0, app_1.commandOutcome)(result.data, result.exitCode);
|
|
1233
|
+
}
|
|
1234
|
+
case 'logs': {
|
|
1235
|
+
const topology = require('../core/topology');
|
|
1236
|
+
const name = await target(text(o.name));
|
|
1237
|
+
// `requireEngine`: the engine THIS workspace needs, asked before its logs are, so a
|
|
1238
|
+
// stopped daemon is a preflight (exit 3) rather than whatever `docker` exits with.
|
|
1239
|
+
// The record is read on the Kubernetes path only: a damaged repro.json is exactly the
|
|
1240
|
+
// workspace whose logs somebody needs.
|
|
1241
|
+
const preconditions = require('../core/lifecycle/preconditions');
|
|
1242
|
+
await preconditions.requireEngine(name);
|
|
1243
|
+
if ((await topology.ofRepro(name)) === topology.KUBERNETES) {
|
|
1244
|
+
const meta = await metadata(name);
|
|
1245
|
+
const status = require('../core/kube/status');
|
|
1246
|
+
// Ctrl-C "is how you leave" a follow, so the command answers it itself: the read
|
|
1247
|
+
// stops, kubectl is sent SIGTERM, and the command exits with kubectl's code. That
|
|
1248
|
+
// is a death by a signal, so `returncode` is its negation: -15 for the SIGTERM (exit
|
|
1249
|
+
// 241) when the SIGINT reached houston alone, -2 (exit 254) when a terminal's Ctrl-C
|
|
1250
|
+
// killed kubectl first, with an `end` record saying so. This answered 130 with
|
|
1251
|
+
// runMain's handler, and `?? 0` read any death by a signal as a success. The listener
|
|
1252
|
+
// is this command's own from the moment kubectl runs, so runMain's steps aside;
|
|
1253
|
+
// before that -- the pod count -- a Ctrl-C is an interrupt like any other.
|
|
1254
|
+
const terminate = new AbortController();
|
|
1255
|
+
const stop = () => terminate.abort();
|
|
1256
|
+
let result;
|
|
1257
|
+
try {
|
|
1258
|
+
result = await status.logProcess(meta.name, {
|
|
1259
|
+
context: recordedContext(meta.extra),
|
|
1260
|
+
tail: number(o.tail) || 200,
|
|
1261
|
+
follow: bool(o.follow),
|
|
1262
|
+
abortSignal: terminate.signal,
|
|
1263
|
+
onSpawn: () => process.on('SIGINT', stop),
|
|
1264
|
+
// Each line echoed as it arrives, and nothing kept: every line was pushed into
|
|
1265
|
+
// an array for a result nobody reads -- `logs` has no `--json` -- so a `logs -f`
|
|
1266
|
+
// grew without bound for as long as it ran.
|
|
1267
|
+
onLine: (line) => {
|
|
1268
|
+
if (!(0, jsonout_1.active)())
|
|
1269
|
+
io.writeOut(`${line}\n`);
|
|
1270
|
+
},
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
finally {
|
|
1274
|
+
process.off('SIGINT', stop);
|
|
1275
|
+
}
|
|
1276
|
+
const code = result.exitCode ??
|
|
1277
|
+
(result.signal === null ? 0 : -node_os_1.constants.signals[result.signal]);
|
|
1278
|
+
return (0, app_1.commandOutcome)({ exit_code: code }, code);
|
|
1279
|
+
}
|
|
1280
|
+
const engine = require('../core/runner/engine');
|
|
1281
|
+
const code = await engine.logs(name, {
|
|
1282
|
+
follow: bool(o.follow),
|
|
1283
|
+
...(number(o.tail) === 0 ? {} : { tail: number(o.tail) }),
|
|
1284
|
+
});
|
|
1285
|
+
// Exit 0 whatever compose said: `logs` has always discarded that code; only the
|
|
1286
|
+
// Kubernetes branch above hands the process's own code back.
|
|
1287
|
+
return (0, app_1.commandOutcome)({ exit_code: code ?? 0 }, 0);
|
|
1288
|
+
}
|
|
1289
|
+
case 'presets': {
|
|
1290
|
+
const presets = require('../lib/presets');
|
|
1291
|
+
const list = presets.listPresets();
|
|
1292
|
+
if (!bool(o.json_out))
|
|
1293
|
+
return { presets: list };
|
|
1294
|
+
// The names the support bot reads (`data.presets[].paramsHelp`, `.error`), and no more.
|
|
1295
|
+
return {
|
|
1296
|
+
presets: list.map((p) => ({
|
|
1297
|
+
name: p.name,
|
|
1298
|
+
description: p.description,
|
|
1299
|
+
paramsHelp: p.paramsHelp,
|
|
1300
|
+
...(p.error ? { error: p.error } : {}),
|
|
1301
|
+
})),
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
case 'versions':
|
|
1305
|
+
return await runVersions(a, o);
|
|
1306
|
+
case 'audit': {
|
|
1307
|
+
const audit = require('../core/audit');
|
|
1308
|
+
const page = audit.read({
|
|
1309
|
+
actorName: text(o.actor),
|
|
1310
|
+
kind: text(o.kind),
|
|
1311
|
+
since: text(o.since),
|
|
1312
|
+
q: text(o.q),
|
|
1313
|
+
// `read(limit=max(1, n))`: `-n 0` and `-n -1` show the newest line. Passed as typed,
|
|
1314
|
+
// the read loop never ran and the answer was `nothing matched`.
|
|
1315
|
+
limit: Math.max(1, number(o.n)),
|
|
1316
|
+
});
|
|
1317
|
+
const lines = bool(o.denied)
|
|
1318
|
+
? page.lines.filter((row) => row.outcome === 'denied')
|
|
1319
|
+
: page.lines;
|
|
1320
|
+
if (bool(o.tsv) && !(0, jsonout_1.active)())
|
|
1321
|
+
for (const row of lines)
|
|
1322
|
+
io.writeOut(`${row.ts}\t${row.actor || '-'}\t${row.kind}\t${row.label}\t${row.origin || '-'}\t${row.outcome}\n`);
|
|
1323
|
+
return { ...page, lines };
|
|
1324
|
+
}
|
|
1325
|
+
case 'chown': {
|
|
1326
|
+
const ownership = require('../core/lifecycle/ownership');
|
|
1327
|
+
return await ownership.setOwner(await target(text(o.name)), text(o.to), {
|
|
1328
|
+
by: require('../core/audit').actor(),
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
case 'skill install': {
|
|
1332
|
+
const skill = require('../core/skill');
|
|
1333
|
+
return skill.install(text(o.host), { force: bool(o.force) });
|
|
1334
|
+
}
|
|
1335
|
+
case 'skill status': {
|
|
1336
|
+
const skill = require('../core/skill');
|
|
1337
|
+
return skill.state();
|
|
1338
|
+
}
|
|
1339
|
+
case 'doctor': {
|
|
1340
|
+
const doctor = require('../core/doctor');
|
|
1341
|
+
const report = await doctor.runChecks(text(o.context));
|
|
1342
|
+
const checks = Array.isArray(report.checks) ? report.checks : [];
|
|
1343
|
+
for (const row of checks)
|
|
1344
|
+
if (['warn', 'fail'].includes(String(row.status)))
|
|
1345
|
+
(0, jsonout_1.warnOnce)(`DOCTOR_${String(row.check ?? 'check')
|
|
1346
|
+
.toUpperCase()
|
|
1347
|
+
.replace(/-/gu, '_')}`, String(row.message ?? ''), { check: row.check, status: row.status });
|
|
1348
|
+
if (report.verdict === 'fail') {
|
|
1349
|
+
if ((0, jsonout_1.active)()) {
|
|
1350
|
+
// `jsonout.fail(..., warnings=jsonout.warnings_so_far())`, called directly: the
|
|
1351
|
+
// one envelope that carries what was collected, and no `error` record.
|
|
1352
|
+
throw (0, jsonout_1.failDirectly)(new errors_1.PreflightError('doctor checks failed', { details: report }), (0, jsonout_1.warningsSoFar)());
|
|
1353
|
+
}
|
|
1354
|
+
return (0, app_1.commandOutcome)(report, 1);
|
|
1355
|
+
}
|
|
1356
|
+
return report;
|
|
1357
|
+
}
|
|
1358
|
+
case 'cluster':
|
|
1359
|
+
return await runCluster(invocation, dependencies, io);
|
|
1360
|
+
case 'serve': {
|
|
1361
|
+
const served = await (0, serve_1.serve)({
|
|
1362
|
+
port: number(o.port),
|
|
1363
|
+
domain: text(o.domain),
|
|
1364
|
+
email: text(o.email),
|
|
1365
|
+
noDomain: bool(o.no_domain),
|
|
1366
|
+
bind: text(o.bind),
|
|
1367
|
+
allowHost: strings(o.allow_host),
|
|
1368
|
+
noOpen: bool(o.no_open),
|
|
1369
|
+
printService: bool(o.print_service),
|
|
1370
|
+
insecure: bool(o.insecure),
|
|
1371
|
+
trustProxy: strings(o.trust_proxy),
|
|
1372
|
+
}, dependencies.serve ?? {}, io);
|
|
1373
|
+
// The no-accounts stop is printed and exits 3 with no `error:` line.
|
|
1374
|
+
return 'refused' in served ? (0, app_1.commandOutcome)(null, served.exitCode) : served;
|
|
1375
|
+
}
|
|
1376
|
+
default:
|
|
1377
|
+
throw new errors_1.ValidationError(`handler for '${invocation.spec.path}' is not available`);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
async function runCluster(invocation, dependencies, io) {
|
|
1381
|
+
const o = invocation.options;
|
|
1382
|
+
const a = invocation.arguments;
|
|
1383
|
+
const action = text(a.action);
|
|
1384
|
+
const emit = emitOf(invocation, io);
|
|
1385
|
+
if (action === 'status') {
|
|
1386
|
+
const cluster = require('../core/cluster');
|
|
1387
|
+
// A bare name, as create/delete/keep/share take it, or --context: the same cluster.
|
|
1388
|
+
const report = await cluster.status(text(o.context) || text(a.name), emit);
|
|
1389
|
+
const unreadable = Array.isArray(report.unreadable) ? report.unreadable : [];
|
|
1390
|
+
if ((0, jsonout_1.active)()) {
|
|
1391
|
+
for (const missing of unreadable) {
|
|
1392
|
+
(0, jsonout_1.warnOnce)(`CLUSTER_UNREADABLE_${String(missing).toUpperCase()}`, `${String(missing)} could not be read; it is reported as unknown rather than as none`);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
if (report.context === '' || report.reachable === false) {
|
|
1396
|
+
const message = `cluster ${report.context || '(none)'} is not usable from here: ` +
|
|
1397
|
+
(report.context === ''
|
|
1398
|
+
? 'no context is configured'
|
|
1399
|
+
: report.gone === true
|
|
1400
|
+
? 'AWS says it no longer exists, so nothing there is billing'
|
|
1401
|
+
: 'it is not reachable');
|
|
1402
|
+
// A PreflightError: the message and no details. The envelope carried the whole ledger
|
|
1403
|
+
// row as `error.details`, which the established envelope never has.
|
|
1404
|
+
if ((0, jsonout_1.active)())
|
|
1405
|
+
throw new errors_1.PreflightError(message);
|
|
1406
|
+
if (report.context === '') {
|
|
1407
|
+
// The context line, then a failure line -- stderr, no `error:` prefix -- and a plain
|
|
1408
|
+
// exit 3, which writes no durable error record. This printed "'' cannot be read: it
|
|
1409
|
+
// is not answering" on stdout instead.
|
|
1410
|
+
(0, render_1.say)(io, 'cluster (none)');
|
|
1411
|
+
io.writeErr('No cluster configured. `houston config set kubernetes.context <name>`, ' +
|
|
1412
|
+
'or point kubectl at one.\n');
|
|
1413
|
+
return (0, app_1.commandOutcome)(undefined, 3);
|
|
1414
|
+
}
|
|
1415
|
+
// WHICH KIND OF UNREACHABLE, both sentences of it, on stderr with no `error:` prefix,
|
|
1416
|
+
// and then the advice on stdout. The renderer printed the first sentence alone on
|
|
1417
|
+
// stdout and never the advice, so a cluster AWS says is deleted -- and costs nothing
|
|
1418
|
+
// -- read as one that is down.
|
|
1419
|
+
(0, render_1.say)(io, `cluster ${report.context}`);
|
|
1420
|
+
if (report.gone === true) {
|
|
1421
|
+
// AWS gave a definite no. That is ONE verdict: the cluster is gone, nothing there is
|
|
1422
|
+
// billing, and only the kubeconfig entry is left. This printed "NOT a report that the
|
|
1423
|
+
// cluster is empty" on stderr and "no longer exists, not costing anything" on stdout,
|
|
1424
|
+
// two verdicts on one cluster, and readers believed the louder one.
|
|
1425
|
+
const short = report.context.split('/').pop() ?? report.context;
|
|
1426
|
+
io.writeErr(`${(0, format_1.quotedText)(report.context)} no longer exists in AWS — nothing there is billing. ` +
|
|
1427
|
+
'The kubeconfig entry naming it is left over; ' +
|
|
1428
|
+
`\`houston cluster forget ${short}\` removes it.\n`);
|
|
1429
|
+
return (0, app_1.commandOutcome)(undefined, 3);
|
|
1430
|
+
}
|
|
1431
|
+
io.writeErr(`${(0, format_1.quotedText)(report.context)} cannot be read: ` +
|
|
1432
|
+
`${report.reach_why || 'it is not answering'}. Nothing below could be read — ` +
|
|
1433
|
+
'this is NOT a report that the cluster is empty.\n');
|
|
1434
|
+
if (report.reach_advice)
|
|
1435
|
+
(0, render_1.say)(io, (0, format_1.stripText)(report.reach_advice));
|
|
1436
|
+
return (0, app_1.commandOutcome)(undefined, 3);
|
|
1437
|
+
}
|
|
1438
|
+
return report;
|
|
1439
|
+
}
|
|
1440
|
+
const docs = require('../core/eks-docs');
|
|
1441
|
+
if (action === 'guide') {
|
|
1442
|
+
const path = docs.guidePath() ?? '';
|
|
1443
|
+
if (bool(o.path_only))
|
|
1444
|
+
return (0, jsonout_1.active)() ? { path } : path;
|
|
1445
|
+
return { path, body: docs.guide() };
|
|
1446
|
+
}
|
|
1447
|
+
if (action === 'iam-policy') {
|
|
1448
|
+
const name = text(a.name);
|
|
1449
|
+
const names = name === '' ? Object.keys(docs.IAM_DOCUMENTS).sort() : [name];
|
|
1450
|
+
return {
|
|
1451
|
+
documents: names.map((key) => ({
|
|
1452
|
+
name: key,
|
|
1453
|
+
filename: docs.IAM_DOCUMENTS[key]?.[0] ?? '',
|
|
1454
|
+
purpose: docs.IAM_DOCUMENTS[key]?.[1] ?? '',
|
|
1455
|
+
body: docs.iamDocument(key),
|
|
1456
|
+
})),
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
const eks = require('../core/eks');
|
|
1460
|
+
if (action === 'list') {
|
|
1461
|
+
const region = text(o.region);
|
|
1462
|
+
const found = await eks.sweepClusters({
|
|
1463
|
+
...(region === '' ? {} : { regions: [region] }),
|
|
1464
|
+
ownedOnly: !bool(o.force),
|
|
1465
|
+
emit,
|
|
1466
|
+
});
|
|
1467
|
+
// One warning per region that could not be read, as the listing has always added them:
|
|
1468
|
+
// the envelope said nothing of them.
|
|
1469
|
+
if ((0, jsonout_1.active)()) {
|
|
1470
|
+
for (const bad of found.unreadable) {
|
|
1471
|
+
(0, jsonout_1.warnOnce)(`REGION_UNREADABLE_${bad.region.toUpperCase().replaceAll('-', '_')}`, `${bad.region} could not be read (${bad.why}); it is reported ` +
|
|
1472
|
+
'as unknown rather than as holding nothing');
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
return found;
|
|
1476
|
+
}
|
|
1477
|
+
if (action === 'connect') {
|
|
1478
|
+
const arn = (0, format_1.stripText)(text(a.name) || text(o.context));
|
|
1479
|
+
if (arn === '')
|
|
1480
|
+
throw new errors_1.ValidationError('`cluster connect` needs the full EKS ARN from `houston cluster list --force`.');
|
|
1481
|
+
return await eks.connectExisting(arn);
|
|
1482
|
+
}
|
|
1483
|
+
if (action === 'create') {
|
|
1484
|
+
const name = text(a.name);
|
|
1485
|
+
if (name === '')
|
|
1486
|
+
throw new errors_1.ValidationError("`cluster create` needs the cluster's name, e.g. `houston cluster create support`.");
|
|
1487
|
+
const subnets = {};
|
|
1488
|
+
for (const item of strings(o.subnet)) {
|
|
1489
|
+
const at = item.indexOf('=');
|
|
1490
|
+
if (at < 0)
|
|
1491
|
+
throw new errors_1.ValidationError(`--subnet wants \`<az>=<subnet-id>\`, got ${(0, format_1.quotedText)(item)}`);
|
|
1492
|
+
subnets[item.slice(0, at).trim()] = item.slice(at + 1).trim();
|
|
1493
|
+
}
|
|
1494
|
+
const wanted = (0, format_1.stripText)(text(o.expires)).toLowerCase();
|
|
1495
|
+
let expiresDays = eks.DEFAULT_EXPIRY_DAYS;
|
|
1496
|
+
if (['never', 'none', '0'].includes(wanted))
|
|
1497
|
+
expiresDays = null;
|
|
1498
|
+
else if (wanted !== '') {
|
|
1499
|
+
// `toInt(want)`: a sign, underscores between digits and any Unicode decimal digit are
|
|
1500
|
+
// days, and a negative is kept -- `expiryDate` clamps it to today. This
|
|
1501
|
+
// took ASCII digits alone, so a `-3` typo created the cluster in one build and was
|
|
1502
|
+
// refused in the other.
|
|
1503
|
+
try {
|
|
1504
|
+
expiresDays = (0, format_1.toInt)(wanted);
|
|
1505
|
+
}
|
|
1506
|
+
catch {
|
|
1507
|
+
throw new errors_1.ValidationError(`--expires wants a number of days or \`never\`, got ${(0, format_1.quotedText)(text(o.expires))}`);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
return await eks.createCluster(name, {
|
|
1511
|
+
region: text(o.region),
|
|
1512
|
+
// A typed 0 is refused, not replaced: only an absent value takes the default.
|
|
1513
|
+
nodes: o.nodes === undefined ? eks.DEFAULT_NODES : number(o.nodes),
|
|
1514
|
+
zone: (0, format_1.stripText)(text(o.zone)),
|
|
1515
|
+
...(Object.keys(subnets).length === 0 ? {} : { subnets }),
|
|
1516
|
+
expiresDays,
|
|
1517
|
+
emit,
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
if (action === 'delete') {
|
|
1521
|
+
const name = text(a.name);
|
|
1522
|
+
if (name === '')
|
|
1523
|
+
throw new errors_1.ValidationError("`cluster delete` needs the cluster's name, e.g. `houston cluster delete support`.");
|
|
1524
|
+
// Typed, else where the build note says it was built, else the AWS CLI's default -- and
|
|
1525
|
+
// ALWAYS named below. Without --region this looked in the default region, said "nothing
|
|
1526
|
+
// to delete", and the cluster billed on where `cluster create` had put it.
|
|
1527
|
+
const region = text(o.region) || eks.rememberedRegion(name) || (await eks.preflight()).region;
|
|
1528
|
+
// READ BEFORE ASKING: consent to destroy something that is not there is how people learn
|
|
1529
|
+
// to type `y` at a prompt that means nothing. ONLY a definite ABSENT short-circuits;
|
|
1530
|
+
// REFUSED goes on through the prompt into the guards inside `deleteCluster`, which are
|
|
1531
|
+
// the real gate either way.
|
|
1532
|
+
const seen = await eks.describeCluster(name, region);
|
|
1533
|
+
if (seen.state === require('../core/kube/ask').ABSENT) {
|
|
1534
|
+
if ((0, jsonout_1.active)())
|
|
1535
|
+
return { name, deleted: false };
|
|
1536
|
+
const context = require('../core/kube/context');
|
|
1537
|
+
const known = (await context.contexts())[0];
|
|
1538
|
+
(0, render_1.say)(io, `no EKS cluster named ${(0, format_1.quotedText)(name)} in ${region} — nothing to delete.` +
|
|
1539
|
+
' `houston cluster list` finds it in whichever region it is; then `--region <that>`.' +
|
|
1540
|
+
(known.includes(name)
|
|
1541
|
+
? ' That name is a kubeconfig context on this machine; ' +
|
|
1542
|
+
`\`houston cluster forget ${name}\` clears the entry, and ` +
|
|
1543
|
+
'only a cluster houston built in AWS can be deleted here.'
|
|
1544
|
+
: ''));
|
|
1545
|
+
return { name, deleted: false, said: true };
|
|
1546
|
+
}
|
|
1547
|
+
// The prompt is not the gate -- the TAG is -- but a 15-minute destructive operation on
|
|
1548
|
+
// somebody's AWS account still asks. Not under --json, where it has never asked.
|
|
1549
|
+
if (!bool(o.yes) && !(0, jsonout_1.active)()) {
|
|
1550
|
+
// Red on a terminal, like every word here that is about to destroy something.
|
|
1551
|
+
const question = (0, render_1.paint)(`Delete EKS cluster ${(0, format_1.quotedText)(name)} in ${region}` +
|
|
1552
|
+
'? This destroys the cluster, its nodes and its volumes.', 'red');
|
|
1553
|
+
if (!(await (dependencies.confirm ?? defaultConfirm)(question)))
|
|
1554
|
+
throw new app_1.Aborted();
|
|
1555
|
+
}
|
|
1556
|
+
const deleted = await eks.deleteCluster(name, { region, force: bool(o.force), emit });
|
|
1557
|
+
// "The command returned" is not "nothing is billing": what AWS still holds, and the
|
|
1558
|
+
// fix for each, read with the operator policy's own rights. Additive on the envelope.
|
|
1559
|
+
return deleted
|
|
1560
|
+
? { name, deleted, region, leftovers: await eks.sweepLeftovers(name, region) }
|
|
1561
|
+
: { name, deleted };
|
|
1562
|
+
}
|
|
1563
|
+
if (action === 'prepare') {
|
|
1564
|
+
const config = require('../lib/config');
|
|
1565
|
+
const context = text(o.context) || text(a.name) || config.defaultKubeContext();
|
|
1566
|
+
if (context === '')
|
|
1567
|
+
throw new errors_1.ValidationError('`cluster prepare` needs --context <name>, or a default from ' +
|
|
1568
|
+
'`houston config set kubernetes.context <name>`.');
|
|
1569
|
+
// The resolved context rides along for the renderer, out of the --json envelope.
|
|
1570
|
+
const prepared = await eks.prepareCluster(context, { emit, zone: (0, format_1.stripText)(text(o.zone)) });
|
|
1571
|
+
Object.defineProperty(prepared, '__context', { enumerable: false, value: context });
|
|
1572
|
+
return prepared;
|
|
1573
|
+
}
|
|
1574
|
+
if (action === 'forget') {
|
|
1575
|
+
const context = require('../core/kube/context');
|
|
1576
|
+
const reachability = require('../core/kube/reachability');
|
|
1577
|
+
const target = (text(a.name) || text(o.context)).trim();
|
|
1578
|
+
if (target === '')
|
|
1579
|
+
throw new errors_1.ValidationError('which context should be forgotten? `houston cluster forget ' +
|
|
1580
|
+
'<context>`, or `houston cluster list` to see what is there.');
|
|
1581
|
+
const known = target === (await context.activeContext())
|
|
1582
|
+
? target
|
|
1583
|
+
: (await context.assertContextKnown(target))[0];
|
|
1584
|
+
if (!bool(o.force) && reachability.reachOk(await reachability.reach(known)))
|
|
1585
|
+
throw new errors_1.ConflictError(`${(0, format_1.quotedText)(known)} is answering, so it is a cluster you can still use rather ` +
|
|
1586
|
+
'than a leftover entry. `houston cluster delete` takes a cluster ' +
|
|
1587
|
+
'away; `--force` forgets a working one anyway.');
|
|
1588
|
+
if (!(await context.forgetContext(known)))
|
|
1589
|
+
throw new errors_1.ConflictError(`${known} is still named by a kubeconfig — remove it by hand with ` +
|
|
1590
|
+
`\`kubectl config delete-context ${known}\``);
|
|
1591
|
+
return { context: known, forgotten: true };
|
|
1592
|
+
}
|
|
1593
|
+
if (action === 'keep') {
|
|
1594
|
+
const name = text(a.name);
|
|
1595
|
+
if (name === '')
|
|
1596
|
+
throw new errors_1.ValidationError("`cluster keep` needs the cluster's name, e.g. `houston cluster keep support --days 7`.");
|
|
1597
|
+
const days = number(o.days) || 7;
|
|
1598
|
+
if (days < 1)
|
|
1599
|
+
throw new errors_1.ValidationError('--days wants a whole number of days from today, at least 1');
|
|
1600
|
+
return await eks.keepCluster(name, { days, region: text(o.region) });
|
|
1601
|
+
}
|
|
1602
|
+
if (action === 'share') {
|
|
1603
|
+
const name = text(a.name);
|
|
1604
|
+
const user = (0, format_1.stripText)(text(o.user));
|
|
1605
|
+
if (name === '' || user === '')
|
|
1606
|
+
throw new errors_1.ValidationError("`cluster share` needs the cluster's name and --user <iam-user>, e.g. " +
|
|
1607
|
+
'`houston cluster share support --user bob`.');
|
|
1608
|
+
return await eks.shareCluster(name, { user, region: text(o.region) });
|
|
1609
|
+
}
|
|
1610
|
+
if (action === 'overview') {
|
|
1611
|
+
const cluster = require('../core/cluster');
|
|
1612
|
+
return await cluster.overview(emit);
|
|
1613
|
+
}
|
|
1614
|
+
throw new errors_1.ValidationError(`unknown cluster action '${action}'`);
|
|
1615
|
+
}
|
|
1616
|
+
function bag(value) {
|
|
1617
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
|
|
1618
|
+
}
|
|
1619
|
+
function bags(value) {
|
|
1620
|
+
return Array.isArray(value) ? value.map((item) => bag(item)) : [];
|
|
1621
|
+
}
|
|
1622
|
+
function display(value, fallback = '') {
|
|
1623
|
+
if (value === null || value === undefined || value === '')
|
|
1624
|
+
return fallback;
|
|
1625
|
+
if (typeof value === 'boolean')
|
|
1626
|
+
return String(value);
|
|
1627
|
+
return String(value);
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* `{seconds}` of a duration rounded to one place: always written with a decimal point, so an
|
|
1631
|
+
* integral one reads `0.0` / `5.0`. `display` of the same JavaScript number printed `0` /
|
|
1632
|
+
* `5` in the restore and upgrade `✓` lines. Only a number is a float; anything else is
|
|
1633
|
+
* shown as it is.
|
|
1634
|
+
*/
|
|
1635
|
+
function floatText(value) {
|
|
1636
|
+
return typeof value === 'number' ? (0, format_1.floatString)(value) : display(value);
|
|
1637
|
+
}
|
|
1638
|
+
/** `?` for anything that could not be read. Never a zero. */
|
|
1639
|
+
function unknownOr(value) {
|
|
1640
|
+
return value === null || value === undefined ? '?' : (0, format_1.toTextAny)(value);
|
|
1641
|
+
}
|
|
1642
|
+
/**
|
|
1643
|
+
* Where the cluster is and who built it, on one line under the context: the facts the
|
|
1644
|
+
* ledger reads from the cluster's own tags, so they are true on every machine.
|
|
1645
|
+
*/
|
|
1646
|
+
function renderClusterAbout(io, report) {
|
|
1647
|
+
if (!(0, format_1.isTruthy)(report.name) && !(0, format_1.isTruthy)(report.region))
|
|
1648
|
+
return;
|
|
1649
|
+
const where = (0, format_1.toText)(report.where) || 'aws';
|
|
1650
|
+
const place = where === 'local'
|
|
1651
|
+
? 'this machine'
|
|
1652
|
+
: where === 'elsewhere'
|
|
1653
|
+
? 'elsewhere'
|
|
1654
|
+
: (0, format_1.toText)(report.region) || 'local';
|
|
1655
|
+
const parts = [(0, format_1.toText)(report.name), place, (0, format_1.toText)(report.distribution)].filter((part) => part !== '');
|
|
1656
|
+
if (report.made_by_houston === true)
|
|
1657
|
+
parts.push('built by houston');
|
|
1658
|
+
else if (report.made_by_houston === false)
|
|
1659
|
+
parts.push('built by you');
|
|
1660
|
+
if ((0, format_1.isTruthy)(report.created_at))
|
|
1661
|
+
parts.push(`created ${(0, format_1.toText)(report.created_at).slice(0, 10)}`);
|
|
1662
|
+
if (typeof report.expires_in_days === 'number') {
|
|
1663
|
+
const days = report.expires_in_days;
|
|
1664
|
+
parts.push(days < 0
|
|
1665
|
+
? (0, render_1.paint)(`expired ${String(-days)} d ago (${(0, format_1.toText)(report.expires)})`, 'amber')
|
|
1666
|
+
: `expires in ${String(days)} d (${(0, format_1.toText)(report.expires)})`);
|
|
1667
|
+
}
|
|
1668
|
+
(0, render_1.say)(io, `about ${parts.join(' · ')}`);
|
|
1669
|
+
const ready = report.ready;
|
|
1670
|
+
// NOT A CHECKLIST off AWS: a local install shipped its storage class and ingress, and
|
|
1671
|
+
// "ready ... cert-manager" read as houston having set them up. It says what is there.
|
|
1672
|
+
if (where !== 'aws' && ready !== null && ready !== undefined && typeof ready === 'object') {
|
|
1673
|
+
const r = bag(ready);
|
|
1674
|
+
const facts = [];
|
|
1675
|
+
if (r.storage_class !== null)
|
|
1676
|
+
facts.push(`storage class ${(0, format_1.toText)(r.storage_class) || 'none'}`);
|
|
1677
|
+
if (r.ingress_class !== null)
|
|
1678
|
+
facts.push(`ingress ${(0, format_1.toText)(r.ingress_class) || 'none'}`);
|
|
1679
|
+
if (r.cert_manager === true)
|
|
1680
|
+
facts.push('cert-manager');
|
|
1681
|
+
if (facts.length > 0)
|
|
1682
|
+
(0, render_1.say)(io, `uses ${facts.join(' · ')}`);
|
|
1683
|
+
return;
|
|
1684
|
+
}
|
|
1685
|
+
if (ready !== null && ready !== undefined && typeof ready === 'object') {
|
|
1686
|
+
const r = bag(ready);
|
|
1687
|
+
const facts = [];
|
|
1688
|
+
if (r.storage_class !== null)
|
|
1689
|
+
facts.push(`storage ${(0, format_1.toText)(r.storage_class) || 'none'}`);
|
|
1690
|
+
if (r.ingress_class !== null)
|
|
1691
|
+
facts.push(`ingress ${(0, format_1.toText)(r.ingress_class) || 'none'}`);
|
|
1692
|
+
if (r.cert_manager === true)
|
|
1693
|
+
facts.push('cert-manager');
|
|
1694
|
+
else if (r.cert_manager === false)
|
|
1695
|
+
facts.push('no cert-manager');
|
|
1696
|
+
const zone = (0, format_1.toText)(report.zone);
|
|
1697
|
+
if (zone !== '' && r.dns_answers === true)
|
|
1698
|
+
facts.push(`DNS for *.${zone} answers`);
|
|
1699
|
+
else if (zone !== '' && r.dns_answers === false)
|
|
1700
|
+
facts.push((0, render_1.paint)(`DNS for *.${zone} does not answer yet`, 'amber'));
|
|
1701
|
+
else if (zone === '' && (0, format_1.isTruthy)(r.cname_target))
|
|
1702
|
+
facts.push('no DNS zone (`--zone` sets one)');
|
|
1703
|
+
if (facts.length > 0)
|
|
1704
|
+
(0, render_1.say)(io, `ready ${facts.join(' · ')}`);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
/** What the cluster has cost, and the one next thing to do with it. */
|
|
1708
|
+
function renderClusterNext(io, report) {
|
|
1709
|
+
if (typeof report.spend_usd === 'number')
|
|
1710
|
+
(0, render_1.say)(io, `spent ~$${report.spend_usd.toFixed(2)} so far`);
|
|
1711
|
+
// Only a full ledger can say what is next; a partial one (an older --json replayed, a
|
|
1712
|
+
// test double with three keys) gets the facts above and nothing invented below them.
|
|
1713
|
+
if (typeof report.name !== 'string' || !('ready' in report) || !('zone' in report))
|
|
1714
|
+
return;
|
|
1715
|
+
const cluster = require('../core/cluster');
|
|
1716
|
+
const next = cluster.nextStep({
|
|
1717
|
+
tools_ok: true,
|
|
1718
|
+
approved: true,
|
|
1719
|
+
account: '',
|
|
1720
|
+
clusters: [report],
|
|
1721
|
+
building: [],
|
|
1722
|
+
failed: [],
|
|
1723
|
+
default_context: (0, format_1.toText)(report.context),
|
|
1724
|
+
});
|
|
1725
|
+
(0, render_1.say)(io, `next ${next.title}`);
|
|
1726
|
+
if (next.command !== '')
|
|
1727
|
+
(0, render_1.say)(io, ` ${next.command}`);
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* The WHERE cell of `list`: the kind of cluster, in eight cells. `k8s` said nothing
|
|
1731
|
+
* about which cluster; `eks` and `kind` say what a person needs to know at a glance, and
|
|
1732
|
+
* the row's `context` says exactly which. k3s cannot be told from its name, so it stays k8s.
|
|
1733
|
+
*/
|
|
1734
|
+
function whereWord(row) {
|
|
1735
|
+
// `docker` in the table only: --json keeps the runtime's own value.
|
|
1736
|
+
if (display(row.runtime) !== 'kubernetes')
|
|
1737
|
+
return 'docker';
|
|
1738
|
+
const context = (0, format_1.toText)(row.context);
|
|
1739
|
+
if (context.startsWith('arn:aws:eks:'))
|
|
1740
|
+
return 'eks';
|
|
1741
|
+
if (context.startsWith('kind-'))
|
|
1742
|
+
return 'kind';
|
|
1743
|
+
return 'k8s';
|
|
1744
|
+
}
|
|
1745
|
+
/** One ledger row of the overview table, the words both front-ends use for a state. */
|
|
1746
|
+
/** The state word both front-ends use, green only when it is running. */
|
|
1747
|
+
function stateWord(c) {
|
|
1748
|
+
return (0, format_1.isTruthy)(c.gone)
|
|
1749
|
+
? 'gone'
|
|
1750
|
+
: c.reachable === true
|
|
1751
|
+
? (0, render_1.paint)('running', 'green')
|
|
1752
|
+
: c.reach_status === 'denied'
|
|
1753
|
+
? 'refusing'
|
|
1754
|
+
: c.reach_status === 'no-context'
|
|
1755
|
+
? 'no credentials'
|
|
1756
|
+
: 'not answering';
|
|
1757
|
+
}
|
|
1758
|
+
/** A row for a cluster that does not bill: what it is, whether it answers, what it holds. */
|
|
1759
|
+
function plainRow(c, cost) {
|
|
1760
|
+
return [
|
|
1761
|
+
(0, format_1.toText)(c.name) || (0, format_1.toText)(c.context),
|
|
1762
|
+
(0, format_1.toText)(c.distribution) || '?',
|
|
1763
|
+
stateWord(c),
|
|
1764
|
+
Array.isArray(c.workspaces) ? String(c.workspaces.length) : '?',
|
|
1765
|
+
cost,
|
|
1766
|
+
];
|
|
1767
|
+
}
|
|
1768
|
+
function overviewRow(c) {
|
|
1769
|
+
const state = stateWord(c);
|
|
1770
|
+
const types = (0, format_1.isTruthy)(c.instance_types) ? Object.entries(bag(c.instance_types)) : [];
|
|
1771
|
+
const nodes = types.length > 0
|
|
1772
|
+
? nodeShape(types.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0)))
|
|
1773
|
+
: unknownOr(c.nodes);
|
|
1774
|
+
const workspaces = Array.isArray(c.workspaces) ? String(c.workspaces.length) : '?';
|
|
1775
|
+
const cost = bag(c.cost);
|
|
1776
|
+
const perDay = (0, format_1.isTruthy)(c.gone)
|
|
1777
|
+
? 'nothing'
|
|
1778
|
+
: c.cost === null || c.cost === undefined
|
|
1779
|
+
? '?'
|
|
1780
|
+
: Number(cost.usd_hr) === 0
|
|
1781
|
+
? 'free'
|
|
1782
|
+
: `~$${(Number(cost.usd_hr) * 24).toFixed(2)}`;
|
|
1783
|
+
const days = c.expires_in_days;
|
|
1784
|
+
const expires = typeof days === 'number'
|
|
1785
|
+
? days < 0
|
|
1786
|
+
? (0, render_1.paint)(`${String(-days)} d ago`, 'amber')
|
|
1787
|
+
: days === 0
|
|
1788
|
+
? (0, render_1.paint)('today', 'amber')
|
|
1789
|
+
: `in ${String(days)} d`
|
|
1790
|
+
: '—';
|
|
1791
|
+
const built = c.made_by_houston === true ? 'houston' : c.made_by_houston === false ? 'you' : '?';
|
|
1792
|
+
return [
|
|
1793
|
+
(0, format_1.toText)(c.name) || (0, format_1.toText)(c.context),
|
|
1794
|
+
(0, format_1.toText)(c.region) || 'local',
|
|
1795
|
+
state,
|
|
1796
|
+
nodes,
|
|
1797
|
+
workspaces,
|
|
1798
|
+
perDay,
|
|
1799
|
+
expires,
|
|
1800
|
+
built,
|
|
1801
|
+
];
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* `cluster overview`: every known cluster as a table, the totals, and what to do next.
|
|
1805
|
+
*
|
|
1806
|
+
* The one answer both front-ends render (`cluster.overview`), so the terminal and the
|
|
1807
|
+
* Clusters page cannot disagree. Colour only on a terminal, and only as a signal: a running
|
|
1808
|
+
* state green, a cluster expiring within two days amber, one past its date red, and the
|
|
1809
|
+
* count of billing clusters amber -- the GUI's own rule.
|
|
1810
|
+
*/
|
|
1811
|
+
function renderClusterOverview(io, result) {
|
|
1812
|
+
const clusters = Array.isArray(result.clusters) ? result.clusters : [];
|
|
1813
|
+
const failed = Array.isArray(result.failed) ? result.failed : [];
|
|
1814
|
+
// WHERE IT LIVES decides the table: a cluster on this machine has nothing to approve,
|
|
1815
|
+
// build or pay for, so it is not in the AWS table, its totals or its next step. A
|
|
1816
|
+
// document from before `where` existed is all AWS, which is all it could hold.
|
|
1817
|
+
const where = (c) => (0, format_1.toText)(c.where) || 'aws';
|
|
1818
|
+
const plain = [
|
|
1819
|
+
['local', 'ON THIS MACHINE', 'free'],
|
|
1820
|
+
['elsewhere', 'ELSEWHERE', 'not priced'],
|
|
1821
|
+
];
|
|
1822
|
+
for (const [kind, heading, cost] of plain) {
|
|
1823
|
+
const here = clusters.filter((c) => where(c) === kind);
|
|
1824
|
+
if (here.length === 0)
|
|
1825
|
+
continue;
|
|
1826
|
+
(0, render_1.say)(io, heading);
|
|
1827
|
+
(0, render_1.writeTable)(io, ['NAME', 'KIND', 'STATE', 'WORKSPACES', 'COST'], here.map((c) => plainRow(c, cost)));
|
|
1828
|
+
(0, render_1.say)(io, '');
|
|
1829
|
+
}
|
|
1830
|
+
const rows = clusters.filter((c) => where(c) === 'aws').map(overviewRow);
|
|
1831
|
+
for (const build of failed) {
|
|
1832
|
+
rows.push([
|
|
1833
|
+
(0, format_1.toText)(build.name),
|
|
1834
|
+
(0, format_1.toText)(build.region) || '?',
|
|
1835
|
+
(0, render_1.paint)(build.present === false ? 'failed build (gone)' : 'failed build', 'amber'),
|
|
1836
|
+
'?',
|
|
1837
|
+
'?',
|
|
1838
|
+
build.present === false ? 'nothing' : '?',
|
|
1839
|
+
'—',
|
|
1840
|
+
'houston',
|
|
1841
|
+
]);
|
|
1842
|
+
}
|
|
1843
|
+
if (clusters.length === 0 && failed.length === 0) {
|
|
1844
|
+
(0, render_1.say)(io, 'no cluster known on this box — a local one appears with `houston up --runtime ' +
|
|
1845
|
+
'kubernetes`; a managed one is built with `houston cluster create`');
|
|
1846
|
+
}
|
|
1847
|
+
else if (rows.length === 0) {
|
|
1848
|
+
(0, render_1.say)(io, 'IN AWS');
|
|
1849
|
+
(0, render_1.say)(io, 'no cluster in AWS yet');
|
|
1850
|
+
}
|
|
1851
|
+
else {
|
|
1852
|
+
(0, render_1.say)(io, 'IN AWS');
|
|
1853
|
+
(0, render_1.writeTable)(io, ['NAME', 'REGION', 'STATE', 'NODES', 'WORKSPACES', 'COST/DAY', 'EXPIRES', 'BUILT BY'], rows);
|
|
1854
|
+
const t = bag(result.totals);
|
|
1855
|
+
const n = Number(t.clusters) || 0;
|
|
1856
|
+
const billing = Number(t.billable) || 0;
|
|
1857
|
+
const w = Number(t.workspaces) || 0;
|
|
1858
|
+
// PARTIAL IS SAID. A billing cluster whose rate could not be read, or whose workspace
|
|
1859
|
+
// list could not be listed, is left out of a sum -- so the sum says so, as a `?` in a
|
|
1860
|
+
// row does, rather than reading as the whole bill.
|
|
1861
|
+
const unpriced = Number(t.unpriced) || 0;
|
|
1862
|
+
const unread = Number(t.unread) || 0;
|
|
1863
|
+
const perDay = t.usd_day === null || t.usd_day === undefined
|
|
1864
|
+
? 'cost ?'
|
|
1865
|
+
: `~$${Number(t.usd_day).toFixed(2)}/day` +
|
|
1866
|
+
(unpriced > 0 ? ` + ${String(unpriced)} not priced` : '');
|
|
1867
|
+
const parts = [
|
|
1868
|
+
`${String(n)} cluster${n === 1 ? '' : 's'}`,
|
|
1869
|
+
billing > 0 ? (0, render_1.paint)(`${String(billing)} billing`, 'amber') : '0 billing',
|
|
1870
|
+
perDay,
|
|
1871
|
+
];
|
|
1872
|
+
if (t.spend_usd !== null && t.spend_usd !== undefined)
|
|
1873
|
+
parts.push(`spent so far ~$${Number(t.spend_usd).toFixed(2)}`);
|
|
1874
|
+
parts.push(`${String(w)}${unread > 0 ? '+' : ''} workspace${w === 1 && unread === 0 ? '' : 's'}`);
|
|
1875
|
+
(0, render_1.say)(io, '');
|
|
1876
|
+
(0, render_1.say)(io, parts.join(' · '));
|
|
1877
|
+
}
|
|
1878
|
+
const next = bag(result.next);
|
|
1879
|
+
(0, render_1.say)(io, `next ${(0, format_1.toText)(next.title)}`);
|
|
1880
|
+
if ((0, format_1.isTruthy)(next.why))
|
|
1881
|
+
(0, render_1.say)(io, ` ${(0, format_1.toText)(next.why)}`);
|
|
1882
|
+
if ((0, format_1.isTruthy)(next.command))
|
|
1883
|
+
(0, render_1.say)(io, ` ${(0, format_1.toText)(next.command)}`);
|
|
1884
|
+
if ((0, format_1.isTruthy)(result.unreadable))
|
|
1885
|
+
io.writeErr(`the kubeconfig could not be fully listed (${(0, format_1.toText)(result.unreadable)}) — there may be clusters missing above\n`);
|
|
1886
|
+
}
|
|
1887
|
+
/** `n`x `type` for each instance type, `unlabelled` for a node with no type label. */
|
|
1888
|
+
function nodeShape(entries) {
|
|
1889
|
+
return entries.map(([type, count]) => `${(0, format_1.toTextAny)(count)}x ${type || 'unlabelled'}`).join(', ');
|
|
1890
|
+
}
|
|
1891
|
+
/**
|
|
1892
|
+
* What the cluster is, how old, and what is running on it. An earlier version printed the
|
|
1893
|
+
* headline and the holding count and nothing else -- no age, no node types, no workspace
|
|
1894
|
+
* rows, no LoadBalancer line, and "? workspace(s)" where the established output says the
|
|
1895
|
+
* workspaces could not be listed.
|
|
1896
|
+
*/
|
|
1897
|
+
function renderClusterShape(io, report) {
|
|
1898
|
+
// `ours` is the kind-cluster switch and never true for EKS; the tag houston writes at
|
|
1899
|
+
// build time decides for a managed cluster. null (could not tell) reads as yours.
|
|
1900
|
+
const owned = (0, format_1.isTruthy)(report.ours) || report.made_by_houston === true ? "houston's own" : 'yours';
|
|
1901
|
+
(0, render_1.say)(io, `${(0, format_1.toText)(report.distribution) || 'unknown'} · ${owned} · ${unknownOr(report.nodes)} node(s)`);
|
|
1902
|
+
if (report.age_hours !== null && report.age_hours !== undefined) {
|
|
1903
|
+
// Days and hours of the age: truncated first, then floor division by 24.
|
|
1904
|
+
const whole = Math.trunc(Number(report.age_hours));
|
|
1905
|
+
const days = Math.floor(whole / 24);
|
|
1906
|
+
(0, render_1.say)(io, `up for ${String(days)}d ${String(whole - days * 24)}h`);
|
|
1907
|
+
}
|
|
1908
|
+
if ((0, format_1.isTruthy)(report.instance_types)) {
|
|
1909
|
+
// Sorted by type: the keys are distinct, so by type alone, in code-point order.
|
|
1910
|
+
const types = Object.entries(bag(report.instance_types)).sort(([left], [right]) => (0, format_1.compareCodePoints)(left, right));
|
|
1911
|
+
(0, render_1.say)(io, `nodes ${nodeShape(types)}`);
|
|
1912
|
+
}
|
|
1913
|
+
const rows = report.workspaces;
|
|
1914
|
+
if (rows === null || rows === undefined) {
|
|
1915
|
+
(0, render_1.say)(io, 'workspaces could not be listed — not the same as none');
|
|
1916
|
+
}
|
|
1917
|
+
else {
|
|
1918
|
+
const listed = bags(rows);
|
|
1919
|
+
(0, render_1.say)(io, `holding ${String(listed.length)} workspace(s), ${unknownOr(report.pvcs)} volume(s)`);
|
|
1920
|
+
for (const row of listed) {
|
|
1921
|
+
const who = (0, format_1.isTruthy)(row.owner_readable) ? (0, format_1.toText)(row.owner) : 'owner unreadable';
|
|
1922
|
+
(0, render_1.say)(io, ` ${display(row.name)} (${who || 'unowned'}, ${(0, format_1.toTextAny)(row.pvcs)} volume(s))`);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
(0, render_1.say)(io, `services ${unknownOr(report.loadbalancers)} LoadBalancer(s)` +
|
|
1926
|
+
((0, format_1.isTruthy)(report.cost) ? ' — each one is billed on a managed cluster' : ''));
|
|
1927
|
+
}
|
|
1928
|
+
/**
|
|
1929
|
+
* The shared installs, the bill, and anything that could not be read. An earlier version
|
|
1930
|
+
* printed the hourly figure alone: no per-day figure, no `stuck` line for a cluster houston
|
|
1931
|
+
* can no longer remove, no `shared` line, and neither the LOW nor the INCOMPLETE qualifier,
|
|
1932
|
+
* so an under-counted bill read as a plain estimate.
|
|
1933
|
+
*/
|
|
1934
|
+
function renderClusterCost(io, report) {
|
|
1935
|
+
if (report.manageable === false && (0, format_1.isTruthy)(report.unmanageable_why)) {
|
|
1936
|
+
(0, render_1.say)(io, `stuck ${(0, format_1.toTextAny)(report.unmanageable_why)}`);
|
|
1937
|
+
}
|
|
1938
|
+
const shared = [
|
|
1939
|
+
['operator', report.operator],
|
|
1940
|
+
['monitoring', report.monitoring],
|
|
1941
|
+
]
|
|
1942
|
+
.filter(([, on]) => (0, format_1.isTruthy)(on))
|
|
1943
|
+
.map(([name]) => name);
|
|
1944
|
+
(0, render_1.say)(io, `shared ${shared.length > 0 ? shared.join(', ') : 'none installed'}`);
|
|
1945
|
+
if ((0, format_1.isTruthy)(report.cost)) {
|
|
1946
|
+
const cost = bag(report.cost);
|
|
1947
|
+
const perHour = Number(cost.usd_hr);
|
|
1948
|
+
// The hourly rate times 24, rounded to 2 places, is a float, printed with its decimal
|
|
1949
|
+
// point: `8.9`, `3.0`.
|
|
1950
|
+
const perDay = (0, format_1.floatString)(Number((0, format_1.formatFixed)(perHour * 24, 2)));
|
|
1951
|
+
(0, render_1.say)(io, `cost ~$${(0, format_1.floatString)(perHour)}/hr (~$${perDay}/day) ESTIMATE — ` +
|
|
1952
|
+
(0, format_1.toTextAny)(cost.basis));
|
|
1953
|
+
if ((0, format_1.isTruthy)(cost.unpriced)) {
|
|
1954
|
+
(0, render_1.say)(io, ` plus ${nodeShape(Object.entries(bag(cost.unpriced)))} which this build ` +
|
|
1955
|
+
'cannot price — the figure above is LOW');
|
|
1956
|
+
}
|
|
1957
|
+
if ((0, format_1.isTruthy)(cost.incomplete)) {
|
|
1958
|
+
// A read that FAILED, not a gap in the price table.
|
|
1959
|
+
(0, render_1.say)(io, ` and ${(Array.isArray(cost.incomplete) ? cost.incomplete : []).map((item) => (0, format_1.toTextAny)(item)).join(', ')}` +
|
|
1960
|
+
' could not be counted — the figure above is INCOMPLETE, not merely approximate');
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
for (const missing of Array.isArray(report.unreadable) ? report.unreadable : []) {
|
|
1964
|
+
(0, render_1.say)(io, `unread ${(0, format_1.toTextAny)(missing)}`);
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* A path's last part once empty and `.` parts are dropped, which is not `path.basename`:
|
|
1969
|
+
* `sub/b.rcbak/` and `sub/b.rcbak/.` are `b.rcbak`, and a path of nothing but a root (or
|
|
1970
|
+
* `.`) has no name at all.
|
|
1971
|
+
*/
|
|
1972
|
+
function pathBaseName(value) {
|
|
1973
|
+
return (value
|
|
1974
|
+
.split('/')
|
|
1975
|
+
.filter((part) => part !== '' && part !== '.')
|
|
1976
|
+
.at(-1) ?? '');
|
|
1977
|
+
}
|
|
1978
|
+
/**
|
|
1979
|
+
* The upgrade's panel and warnings: `from -> to` with two spaces each side, and the MongoDB
|
|
1980
|
+
* row showing the current tag alone when it does not move. Every warning is a warning line of
|
|
1981
|
+
* two spaces and its text as given; this printed `8.5.1 -> 8.6.1`, `8.0 -> 8.0` and a `⚠ `
|
|
1982
|
+
* prefix.
|
|
1983
|
+
*/
|
|
1984
|
+
function renderUpgradePlan(plan, io) {
|
|
1985
|
+
const fromMongo = (0, format_1.toTextAny)(plan.from_mongo);
|
|
1986
|
+
(0, render_1.writePanel)(io, `upgrade: ${(0, format_1.toTextAny)(plan.name)}`, [
|
|
1987
|
+
['Rocket.Chat', `${(0, format_1.toTextAny)(plan.from_version)} -> ${(0, format_1.toTextAny)(plan.to_version)}`],
|
|
1988
|
+
[
|
|
1989
|
+
'MongoDB',
|
|
1990
|
+
fromMongo + (plan.from_mongo === plan.to_mongo ? '' : ` -> ${(0, format_1.toTextAny)(plan.to_mongo)}`),
|
|
1991
|
+
],
|
|
1992
|
+
['image', (0, compose_1.imageRef)((0, format_1.toTextAny)(plan.rc_image), (0, format_1.toTextAny)(plan.to_version))],
|
|
1993
|
+
['source', (0, format_1.toTextAny)(plan.source)],
|
|
1994
|
+
]);
|
|
1995
|
+
for (const line of Array.isArray(plan.warnings) ? plan.warnings : [])
|
|
1996
|
+
io.writeOut(` ${(0, format_1.toTextAny)(line)}\n`);
|
|
1997
|
+
}
|
|
1998
|
+
/** `backup.human`: base 1024, B to GB, a tie rounded to even. */
|
|
1999
|
+
function humanBytes(raw) {
|
|
2000
|
+
const backup = require('../core/backup');
|
|
2001
|
+
return backup.human(Number(raw ?? 0));
|
|
2002
|
+
}
|
|
2003
|
+
/**
|
|
2004
|
+
* `presets`: one box per preset, every box `min(terminal width, 88) - 4` columns inside
|
|
2005
|
+
* and its text wrapped to that -- the width is `consoleColumns(90)`, so 84 off a terminal and
|
|
2006
|
+
* under any COLUMNS from 88 up, 56 at COLUMNS=60, 36 at COLUMNS=40.
|
|
2007
|
+
*
|
|
2008
|
+
* An earlier version handed each description to `writePanel`, which grows to its widest row,
|
|
2009
|
+
* so every box was one line as long as its description -- 283 columns for `airgapped` -- and
|
|
2010
|
+
* read `params_help` and `requires_license`, which a `Preset` spells `paramsHelp` and
|
|
2011
|
+
* `requiresLicense`: no `--set` line and no `[needs license]` was ever printed. Measured
|
|
2012
|
+
* against the frozen CLI at COLUMNS=100, 60, 40 and unset.
|
|
2013
|
+
*
|
|
2014
|
+
* A description is folded onto one line (its `splitFields` words joined by single spaces) and
|
|
2015
|
+
* made ASCII before it is wrapped; a `--set` entry hangs its wrapped help under the help's
|
|
2016
|
+
* first column. A key is NOT made ASCII, and never was. The `--set` lines come in the order
|
|
2017
|
+
* the preset file wrote them, which a JavaScript object's key order is not for a key like
|
|
2018
|
+
* `"10"`; `paramsHelpItems` carries the file's order.
|
|
2019
|
+
*/
|
|
2020
|
+
function renderPresets(value, io, host = error_panel_1.PROCESS_CONSOLE) {
|
|
2021
|
+
const { paramsHelpItems } = require('../lib/presets');
|
|
2022
|
+
const inner = Math.min((0, error_panel_1.consoleColumns)(90, host), 88) - 4;
|
|
2023
|
+
io.writeOut('Presets\n\n');
|
|
2024
|
+
for (const preset of bags(value.presets)) {
|
|
2025
|
+
const lines = (0, render_1.wrapWords)((0, render_1.asciiOf)((0, format_1.splitFields)(display(preset.description)).join(' ')), inner);
|
|
2026
|
+
if (lines.length === 0)
|
|
2027
|
+
lines.push('');
|
|
2028
|
+
const help = paramsHelpItems(bag(preset.paramsHelp));
|
|
2029
|
+
if (help.length > 0) {
|
|
2030
|
+
lines.push('');
|
|
2031
|
+
const keyWidth = Math.max(...help.map(([key]) => [...key].length));
|
|
2032
|
+
const hang = ' '.repeat('--set '.length + keyWidth + 3);
|
|
2033
|
+
for (const [key, about] of help) {
|
|
2034
|
+
const padded = key + ' '.repeat(keyWidth - [...key].length);
|
|
2035
|
+
const entry = `--set ${padded} ${(0, render_1.asciiOf)((0, format_1.splitFields)(display(about)).join(' '))}`;
|
|
2036
|
+
lines.push(...(0, render_1.wrapWords)(entry, inner, { subsequentIndent: hang }));
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
const title = `${display(preset.name)}${preset.requiresLicense === true ? ' [needs license]' : ''}`;
|
|
2040
|
+
(0, render_1.writeBox)(io, title, lines, inner);
|
|
2041
|
+
io.writeOut('\n');
|
|
2042
|
+
}
|
|
2043
|
+
io.writeOut('run: houston up --version <X.Y.Z> --preset <name> [--set key=value]\n');
|
|
2044
|
+
}
|
|
2045
|
+
/**
|
|
2046
|
+
* `42s`, `1m03s`. An earlier version printed `134s` for every boot past a minute, which is
|
|
2047
|
+
* most of them.
|
|
2048
|
+
*/
|
|
2049
|
+
function fmtDuration(secs) {
|
|
2050
|
+
return secs < 60
|
|
2051
|
+
? `${String(secs)}s`
|
|
2052
|
+
: `${String(Math.floor(secs / 60))}m${String(secs % 60).padStart(2, '0')}s`;
|
|
2053
|
+
}
|
|
2054
|
+
/** How the certificate was obtained. */
|
|
2055
|
+
function tlsLabel(meta) {
|
|
2056
|
+
const labels = {
|
|
2057
|
+
// A *.houston.localhost name: no browser on another computer ever opens it.
|
|
2058
|
+
local: 'local CA, a browser on the machine running houston only (houston trust-ca)',
|
|
2059
|
+
acme: "Let's Encrypt",
|
|
2060
|
+
own: 'supplied certificate',
|
|
2061
|
+
};
|
|
2062
|
+
const kind = (0, format_1.isTruthy)(meta.extra.tls) ? (0, format_1.toTextAny)(meta.extra.tls) : '';
|
|
2063
|
+
return Object.hasOwn(labels, kind) ? labels[kind] : 'enabled';
|
|
2064
|
+
}
|
|
2065
|
+
/**
|
|
2066
|
+
* The boxed workspace summary `up`, `ready` and `info` share, drawn from the RECORD -- not
|
|
2067
|
+
* from `detail()`, which asks docker and reads the compose file, and so failed `info` (a
|
|
2068
|
+
* stack, exit 1) for a workspace whose compose file an interrupted create never wrote, where
|
|
2069
|
+
* repro.json alone answers.
|
|
2070
|
+
*
|
|
2071
|
+
* Rows in the established order and wording: MongoDB `<tag> (via the <managed_by>)` when
|
|
2072
|
+
* the runtime recorded what it built, else `<tag> (<flavor>)`, parentheses even when the
|
|
2073
|
+
* flavor is empty (every Kubernetes record); Owner from `created_by` only, which `chown`
|
|
2074
|
+
* leaves alone; TLS and Direct HTTP for a workspace with a public URL; then the caller's
|
|
2075
|
+
* rows. And the instances, in the established wording, under the box.
|
|
2076
|
+
*/
|
|
2077
|
+
function summaryPanel(meta, io, extraRows = []) {
|
|
2078
|
+
const record = require('../core/runner/record');
|
|
2079
|
+
const topology = require('../core/topology');
|
|
2080
|
+
const managedBy = meta.extra.mongo_managed_by ?? '';
|
|
2081
|
+
const mongo = (0, format_1.isTruthy)(managedBy)
|
|
2082
|
+
? `${meta.mongoTag} (via the ${(0, format_1.toTextAny)(managedBy)})`
|
|
2083
|
+
: `${meta.mongoTag} (${meta.mongoFlavor})`;
|
|
2084
|
+
const rows = [
|
|
2085
|
+
['Rocket.Chat', meta.rcVersion],
|
|
2086
|
+
['MongoDB', mongo],
|
|
2087
|
+
// The presets without the deployment: multi-instance has its own instances line below.
|
|
2088
|
+
['Preset', String(topology.axesOfMeta(meta).preset ?? meta.preset)],
|
|
2089
|
+
// externalUrl, not rootUrl: with --https the browser wants the https URL.
|
|
2090
|
+
['URL', record.externalUrl(meta)],
|
|
2091
|
+
['Login', `admin / ${record.adminPass(meta)}`],
|
|
2092
|
+
];
|
|
2093
|
+
const owner = meta.extra.created_by ?? '';
|
|
2094
|
+
if ((0, format_1.isTruthy)(owner))
|
|
2095
|
+
rows.push(['Owner', (0, format_1.toTextAny)(owner)]);
|
|
2096
|
+
if ((0, format_1.isTruthy)(meta.publicUrl))
|
|
2097
|
+
rows.push(['TLS', tlsLabel(meta)]);
|
|
2098
|
+
// houston's own way in, whenever the URL above is somebody else's (TLS, a proxy, a tunnel).
|
|
2099
|
+
if (record.externalUrl(meta) !== meta.rootUrl)
|
|
2100
|
+
rows.push(['Direct HTTP', meta.rootUrl]);
|
|
2101
|
+
rows.push(...extraRows);
|
|
2102
|
+
(0, render_1.writePanel)(io, meta.name, rows);
|
|
2103
|
+
const instances = meta.extra.instances;
|
|
2104
|
+
if ((0, format_1.isTruthy)(instances)) {
|
|
2105
|
+
io.writeOut(` instances (${(0, format_1.toTextAny)(instances)}, load-balanced by Traefik):\n`);
|
|
2106
|
+
const count = (0, format_1.toInt)(instances);
|
|
2107
|
+
for (let at = 1; at <= count; at += 1) {
|
|
2108
|
+
io.writeOut(` rocketchat-${String(at)}: http://localhost:${String(meta.hostPort + at)}\n`);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
sshHint(io, record.externalUrl(meta));
|
|
2112
|
+
}
|
|
2113
|
+
/**
|
|
2114
|
+
* Over SSH, `localhost` is the server, not the reader's computer: one line saying how to
|
|
2115
|
+
* open `url` from there. Read here, not in core: it is about this terminal.
|
|
2116
|
+
*/
|
|
2117
|
+
function sshHint(io, url) {
|
|
2118
|
+
if (!(0, format_1.isTruthy)(process.env.SSH_CONNECTION) && !(0, format_1.isTruthy)(process.env.SSH_CLIENT))
|
|
2119
|
+
return;
|
|
2120
|
+
let parsed;
|
|
2121
|
+
try {
|
|
2122
|
+
parsed = new URL(url);
|
|
2123
|
+
}
|
|
2124
|
+
catch {
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
if (!['localhost', '127.0.0.1', '[::1]'].includes(parsed.hostname))
|
|
2128
|
+
return;
|
|
2129
|
+
const port = parsed.port || (parsed.protocol === 'https:' ? '443' : '80');
|
|
2130
|
+
io.writeOut(' localhost is the machine running houston. From your computer: ' +
|
|
2131
|
+
`ssh -L ${port}:localhost:${port} <you>@<this server>, then open the URL; or create it ` +
|
|
2132
|
+
'with --domain for an address anyone can open.\n');
|
|
2133
|
+
}
|
|
2134
|
+
/**
|
|
2135
|
+
* An INDENTED line is something to paste and is never wrapped; anything else is wrapped by
|
|
2136
|
+
* `wrapWords` with hyphen breaks off, so `metrics-server` stays one word.
|
|
2137
|
+
*/
|
|
2138
|
+
function noteLines(line, width) {
|
|
2139
|
+
const text = (0, render_1.asciiOf)(line);
|
|
2140
|
+
if (text.startsWith(' ') && (0, format_1.stripText)(text) !== '')
|
|
2141
|
+
return [` ${(0, format_1.stripText)(text)}`];
|
|
2142
|
+
const wrapped = (0, render_1.wrapWords)(text, width, {
|
|
2143
|
+
initialIndent: ' ',
|
|
2144
|
+
subsequentIndent: ' ',
|
|
2145
|
+
breakOnHyphens: false,
|
|
2146
|
+
});
|
|
2147
|
+
return wrapped.length > 0 ? wrapped : [''];
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* What is in this workspace, as sections, from the record's note groups. Rows as an aligned
|
|
2151
|
+
* two-column block -- the key column as wide as the widest key BEFORE its ASCII fallback, in
|
|
2152
|
+
* code points -- prose wrapped to `min(consoleColumns(90), 88) - 6`, and commands set off and
|
|
2153
|
+
* never wrapped.
|
|
2154
|
+
*/
|
|
2155
|
+
async function printNotes(meta, io) {
|
|
2156
|
+
const notes = require('../core/lifecycle/notes');
|
|
2157
|
+
let groups = await notes.noteGroupsOf(meta);
|
|
2158
|
+
if (groups.length === 0) {
|
|
2159
|
+
const flat = Array.isArray(meta.extra.notes) ? meta.extra.notes : [];
|
|
2160
|
+
if (flat.length === 0)
|
|
2161
|
+
return;
|
|
2162
|
+
groups = [{ title: '', rows: [], body: flat, commands: [] }];
|
|
2163
|
+
}
|
|
2164
|
+
const width = Math.min((0, error_panel_1.consoleColumns)(90), 88);
|
|
2165
|
+
const head = 'what is in this workspace ';
|
|
2166
|
+
io.writeOut(`\n ${head}${'-'.repeat(Math.max(1, width - head.length - 3))}\n`);
|
|
2167
|
+
for (const group of groups) {
|
|
2168
|
+
const rows = Array.isArray(group.rows) ? group.rows : [];
|
|
2169
|
+
const body = Array.isArray(group.body) ? group.body : [];
|
|
2170
|
+
const commands = Array.isArray(group.commands) ? group.commands : [];
|
|
2171
|
+
if (rows.length + body.length + commands.length === 0)
|
|
2172
|
+
continue;
|
|
2173
|
+
io.writeOut('\n');
|
|
2174
|
+
if ((0, format_1.isTruthy)(group.title))
|
|
2175
|
+
io.writeOut(` ${(0, render_1.asciiOf)((0, format_1.toTextAny)(group.title))}\n`);
|
|
2176
|
+
if (rows.length > 0) {
|
|
2177
|
+
const keyWidth = Math.max(...rows.map(([key]) => [...(0, format_1.toTextAny)(key)].length));
|
|
2178
|
+
for (const [key, value] of rows) {
|
|
2179
|
+
const shown = (0, render_1.asciiOf)((0, format_1.toTextAny)(key));
|
|
2180
|
+
const pad = ' '.repeat(Math.max(0, keyWidth - [...shown].length));
|
|
2181
|
+
io.writeOut(` ${shown}${pad} ${(0, render_1.asciiOf)((0, format_1.toTextAny)(value))}\n`);
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
for (const line of body) {
|
|
2185
|
+
for (const out of noteLines((0, format_1.toTextAny)(line), width - 6))
|
|
2186
|
+
io.writeOut(`${out}\n`);
|
|
2187
|
+
}
|
|
2188
|
+
for (const command of commands)
|
|
2189
|
+
io.writeOut(` ${(0, render_1.asciiOf)((0, format_1.toTextAny)(command))}\n`);
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
/** `houston-<name>-rocketchat-1` -> `rocketchat` (or `rocketchat-1`). */
|
|
2193
|
+
function shortContainer(full, repro, keepIndex = false) {
|
|
2194
|
+
const prefix = `houston-${repro}-`;
|
|
2195
|
+
const trimmed = full.startsWith(prefix) ? full.slice(prefix.length) : full;
|
|
2196
|
+
return keepIndex ? trimmed : trimmed.replace(/-\d+$/u, '');
|
|
2197
|
+
}
|
|
2198
|
+
/**
|
|
2199
|
+
* Until Ctrl-C, for a loop that answers it itself by returning. The listener is registered
|
|
2200
|
+
* after `runMain`'s, which therefore steps aside, so the command returns and exits 0 with an
|
|
2201
|
+
* `end` record of 0, as it always has.
|
|
2202
|
+
*/
|
|
2203
|
+
function untilInterrupted(signals = ['SIGINT']) {
|
|
2204
|
+
let stopped = false;
|
|
2205
|
+
let stop = () => undefined;
|
|
2206
|
+
const interrupted = new Promise((resolve) => {
|
|
2207
|
+
stop = () => {
|
|
2208
|
+
stopped = true;
|
|
2209
|
+
resolve(undefined);
|
|
2210
|
+
};
|
|
2211
|
+
});
|
|
2212
|
+
for (const signal of signals)
|
|
2213
|
+
process.on(signal, stop);
|
|
2214
|
+
return {
|
|
2215
|
+
interrupted,
|
|
2216
|
+
isStopped: () => stopped,
|
|
2217
|
+
/** Resolve after `ms`, or at the interrupt, whichever is first. */
|
|
2218
|
+
sleep: (ms) => Promise.race([interrupted, new Promise((resolve) => setTimeout(resolve, ms))]),
|
|
2219
|
+
release: () => {
|
|
2220
|
+
for (const signal of signals)
|
|
2221
|
+
process.off(signal, stop);
|
|
2222
|
+
},
|
|
2223
|
+
};
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* `stats`, printed in the established shape.
|
|
2227
|
+
*
|
|
2228
|
+
* An earlier version sampled through a ResourceMonitor in every mode and printed only at the
|
|
2229
|
+
* end: `--watch` showed NOTHING until Ctrl-C and then an idle -> peak table the established
|
|
2230
|
+
* output never has, the window had no "Sampling ..." line, and Kubernetes read one sample
|
|
2231
|
+
* where it should watch, or keep each pod's peak over the window. Each branch now runs the
|
|
2232
|
+
* established loop: `--watch` prints "Live stats for ..." and a block per `docker stats`
|
|
2233
|
+
* sample every two seconds until Ctrl-C (exit 0, nothing more); the window prints "Sampling
|
|
2234
|
+
* ... for Ns..." first and the resource table after; Kubernetes prints `printPodMetrics` per
|
|
2235
|
+
* sample under `--watch`, else the peak rows once, most memory first, after the first sample
|
|
2236
|
+
* at or past the deadline.
|
|
2237
|
+
*
|
|
2238
|
+
* SIGTERM stops `--watch` cleanly too, as it always did here, where the previous
|
|
2239
|
+
* implementation dies by it with no `end` record: a known difference, and a clean stop in
|
|
2240
|
+
* both.
|
|
2241
|
+
*/
|
|
2242
|
+
async function runStats(invocation, io) {
|
|
2243
|
+
const o = invocation.options;
|
|
2244
|
+
const topology = require('../core/topology');
|
|
2245
|
+
// `requireEngine` before the runtime branch and before --watch. Without it a stopped daemon
|
|
2246
|
+
// sampled nothing and exited 0 with both streams empty -- a peak of nothing reported as
|
|
2247
|
+
// success -- where the established answer is ENGINE_UNAVAILABLE, exit 3. Measured by the
|
|
2248
|
+
// CLI differential with docker stubbed.
|
|
2249
|
+
const meta = await engineMetadata(text(o.name));
|
|
2250
|
+
const seconds = number(o.for_);
|
|
2251
|
+
const watch = bool(o.watch);
|
|
2252
|
+
if ((await topology.ofRepro(meta.name)) === topology.KUBERNETES) {
|
|
2253
|
+
await kubernetesStats(meta, seconds, watch, io);
|
|
2254
|
+
return undefined;
|
|
2255
|
+
}
|
|
2256
|
+
if (watch) {
|
|
2257
|
+
const engine = require('../core/runner/engine');
|
|
2258
|
+
const queries = require('../core/runner/queries');
|
|
2259
|
+
io.writeOut(`Live stats for ${(0, format_1.quotedText)(meta.name)} (Ctrl-C to stop)…\n`);
|
|
2260
|
+
// The whole loop, docker calls included, answers Ctrl-C itself, so a Ctrl-C at any
|
|
2261
|
+
// point of it is a clean stop.
|
|
2262
|
+
const ctrlC = untilInterrupted(['SIGINT', 'SIGTERM']);
|
|
2263
|
+
try {
|
|
2264
|
+
while (!ctrlC.isStopped()) {
|
|
2265
|
+
const ids = await Promise.race([engine.containerIds(meta.name), ctrlC.interrupted]);
|
|
2266
|
+
if (ids === undefined)
|
|
2267
|
+
break;
|
|
2268
|
+
const out = await Promise.race([queries.dockerStats(ids), ctrlC.interrupted]);
|
|
2269
|
+
if (out === undefined)
|
|
2270
|
+
break;
|
|
2271
|
+
io.writeOut('\n');
|
|
2272
|
+
for (const line of (0, format_1.splitTextLines)(out)) {
|
|
2273
|
+
const parts = line.split('\t');
|
|
2274
|
+
if (parts.length < 3)
|
|
2275
|
+
continue;
|
|
2276
|
+
const short = shortContainer(parts[0], meta.name).padEnd(14);
|
|
2277
|
+
io.writeOut(` ${short} CPU ${parts[1].padStart(7)} RAM ${parts[2]}\n`);
|
|
2278
|
+
}
|
|
2279
|
+
await ctrlC.sleep(2000);
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
finally {
|
|
2283
|
+
ctrlC.release();
|
|
2284
|
+
}
|
|
2285
|
+
return undefined;
|
|
2286
|
+
}
|
|
2287
|
+
io.writeOut(`Sampling ${(0, format_1.quotedText)(meta.name)} for ${(0, format_1.formatFixed)(seconds, 0)}s…\n`);
|
|
2288
|
+
const resources = require('../perf/resources');
|
|
2289
|
+
const monitor = new resources.ResourceMonitor(meta.name).start();
|
|
2290
|
+
await new Promise((resolve) => setTimeout(resolve, Math.max(0, seconds) * 1000));
|
|
2291
|
+
return { name: meta.name, resources: await monitor.stop() };
|
|
2292
|
+
}
|
|
2293
|
+
/** One Kubernetes sample, a blank line first. */
|
|
2294
|
+
function printPodMetrics(rows, io) {
|
|
2295
|
+
io.writeOut('\n');
|
|
2296
|
+
for (const row of rows) {
|
|
2297
|
+
const cpu = (0, format_1.formatFixed)(Number(row.cpu_millicores ?? 0), 0).padStart(6);
|
|
2298
|
+
const ram = (0, format_1.formatFixed)(Number(row.mem_bytes ?? 0) / 1e6, 1).padStart(7);
|
|
2299
|
+
io.writeOut(` ${display(row.pod).padEnd(44)} CPU ${cpu}m RAM ${ram} MB\n`);
|
|
2300
|
+
}
|
|
2301
|
+
if (rows.length === 0)
|
|
2302
|
+
io.writeOut("no pods are running in this workspace's namespace\n");
|
|
2303
|
+
}
|
|
2304
|
+
/**
|
|
2305
|
+
* Every pod in the namespace, each sample printed under `--watch`, else each pod's peak --
|
|
2306
|
+
* its sample with the most memory, carrying the highest CPU seen since -- printed once after
|
|
2307
|
+
* the first sample at or past the deadline, most memory first. Only the two-second sleep
|
|
2308
|
+
* answers Ctrl-C by returning, so a Ctrl-C while kubectl answers is an interrupt like any
|
|
2309
|
+
* other (exit 130).
|
|
2310
|
+
*/
|
|
2311
|
+
async function kubernetesStats(meta, seconds, watch, io) {
|
|
2312
|
+
const status = require('../core/kube/status');
|
|
2313
|
+
const context = recordedContext(meta.extra);
|
|
2314
|
+
const deadline = performance.now() + (watch ? 0 : Math.max(0, seconds)) * 1000;
|
|
2315
|
+
const peak = new Map();
|
|
2316
|
+
for (;;) {
|
|
2317
|
+
const rows = bags(await status.podMetrics(meta.name, { context, selector: '' }));
|
|
2318
|
+
if (watch)
|
|
2319
|
+
printPodMetrics(rows, io);
|
|
2320
|
+
else {
|
|
2321
|
+
for (const row of rows) {
|
|
2322
|
+
const previous = peak.get(display(row.pod));
|
|
2323
|
+
if (previous === undefined || Number(row.mem_bytes) > Number(previous.mem_bytes)) {
|
|
2324
|
+
peak.set(display(row.pod), { ...row });
|
|
2325
|
+
}
|
|
2326
|
+
else {
|
|
2327
|
+
previous.cpu_millicores = Math.max(Number(previous.cpu_millicores), Number(row.cpu_millicores));
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
if (performance.now() >= deadline) {
|
|
2331
|
+
const sorted = [...peak.values()].sort((left, right) => Number(right.mem_bytes) - Number(left.mem_bytes));
|
|
2332
|
+
printPodMetrics(sorted, io);
|
|
2333
|
+
return;
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
const ctrlC = untilInterrupted();
|
|
2337
|
+
try {
|
|
2338
|
+
await ctrlC.sleep(2000);
|
|
2339
|
+
if (ctrlC.isStopped())
|
|
2340
|
+
return;
|
|
2341
|
+
}
|
|
2342
|
+
finally {
|
|
2343
|
+
ctrlC.release();
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
/**
|
|
2348
|
+
* Short names, keeping the instance index only where a base name repeats (multi-instance
|
|
2349
|
+
* rocketchat-1/-2/-3) so no row overwrites another, sorted by that name.
|
|
2350
|
+
*/
|
|
2351
|
+
function renderResources(value, io, repro) {
|
|
2352
|
+
const entries = Object.entries(bag(value));
|
|
2353
|
+
if (entries.length === 0)
|
|
2354
|
+
return;
|
|
2355
|
+
const bases = entries.map(([full]) => shortContainer(full, repro));
|
|
2356
|
+
const repeated = new Set(bases.filter((base, index) => bases.indexOf(base) !== index));
|
|
2357
|
+
const labelled = new Map();
|
|
2358
|
+
for (const [full, raw] of entries) {
|
|
2359
|
+
const base = shortContainer(full, repro);
|
|
2360
|
+
labelled.set(repeated.has(base) ? shortContainer(full, repro, true) : base, bag(raw));
|
|
2361
|
+
}
|
|
2362
|
+
io.writeOut('\nResource cost (idle -> peak):\n');
|
|
2363
|
+
for (const name of [...labelled.keys()].sort()) {
|
|
2364
|
+
const row = labelled.get(name);
|
|
2365
|
+
const peakMem = Number(row.peak_mem ?? 0);
|
|
2366
|
+
const delta = (peakMem - Number(row.idle_mem ?? 0)) / 1e6;
|
|
2367
|
+
io.writeOut(` ${name.padEnd(14)} CPU ${(0, format_1.formatFixed)(Number(row.idle_cpu ?? 0), 0)}% -> ` +
|
|
2368
|
+
`${(0, format_1.formatFixed)(Number(row.peak_cpu ?? 0), 0)}% RAM ${(0, format_1.formatFixed)(peakMem / 1e6, 0)} MB ` +
|
|
2369
|
+
`(+${(0, format_1.formatFixed)(delta, 0)})\n`);
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
/** '2xx 1158 · 429 61 · 5xx 41', the non-zero buckets only. */
|
|
2373
|
+
function statusBreakdown(summary) {
|
|
2374
|
+
const status = bag((0, format_1.orElse)(summary.status, {}));
|
|
2375
|
+
return ['2xx', '429', '4xx', '5xx', 'other']
|
|
2376
|
+
.filter((key) => (0, format_1.isTruthy)(status[key]))
|
|
2377
|
+
.map((key) => `${key} ${String(Math.trunc(Number(status[key])))}`)
|
|
2378
|
+
.join(' · ');
|
|
2379
|
+
}
|
|
2380
|
+
/**
|
|
2381
|
+
* A summary metric as its format spells it, or '-' when it was not measured -- a zero-request
|
|
2382
|
+
* run has no latency or checks keys, and 0ms would be a confident lie.
|
|
2383
|
+
*/
|
|
2384
|
+
function summaryMetric(summary, key, spec) {
|
|
2385
|
+
const value = summary[key];
|
|
2386
|
+
if (value === null || value === undefined)
|
|
2387
|
+
return '-';
|
|
2388
|
+
const n = Number(value);
|
|
2389
|
+
switch (spec) {
|
|
2390
|
+
case 'ms':
|
|
2391
|
+
return `${(0, format_1.formatFixed)(n, 0)}ms`;
|
|
2392
|
+
case '.0f':
|
|
2393
|
+
return (0, format_1.formatFixed)(n, 0);
|
|
2394
|
+
case '.1f':
|
|
2395
|
+
return (0, format_1.formatFixed)(n, 1);
|
|
2396
|
+
case '.2%':
|
|
2397
|
+
return `${(0, format_1.formatFixed)(n * 100, 2)}%`;
|
|
2398
|
+
case '.0%':
|
|
2399
|
+
return `${(0, format_1.formatFixed)(n * 100, 0)}%`;
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
/** 'spike 10:100', 'ramp 10:200' or '50 VUs'. */
|
|
2403
|
+
function loadShapeOf(ctx) {
|
|
2404
|
+
if ((0, format_1.isTruthy)(ctx.spike))
|
|
2405
|
+
return `spike ${(0, format_1.toTextAny)(ctx.spike)}`;
|
|
2406
|
+
if ((0, format_1.isTruthy)(ctx.ramp))
|
|
2407
|
+
return `ramp ${(0, format_1.toTextAny)(ctx.ramp)}`;
|
|
2408
|
+
return `${(0, format_1.toTextAny)((0, format_1.dictGetChecked)(ctx, 'vus', '?'))} VUs`;
|
|
2409
|
+
}
|
|
2410
|
+
/** The per-step latency table, in the journey's order. */
|
|
2411
|
+
function renderSteps(steps, io) {
|
|
2412
|
+
if (Object.keys(steps).length === 0)
|
|
2413
|
+
return;
|
|
2414
|
+
const baseline = require('../perf/baseline');
|
|
2415
|
+
const { fmtMs } = require('../perf/timings');
|
|
2416
|
+
const ms = (value) => fmtMs((0, format_1.isTruthy)(value) ? Number(value) : 0).padStart(7);
|
|
2417
|
+
io.writeOut('\nPer-step latency:\n');
|
|
2418
|
+
io.writeOut(` ${(0, render_1.ljust)('step', 8)} ${'count'.padStart(6)} ${'p50'.padStart(7)} ${'p95'.padStart(7)} ${'p99'.padStart(7)}\n`);
|
|
2419
|
+
for (const step of baseline.stepOrder(steps)) {
|
|
2420
|
+
const row = bag(steps[step]);
|
|
2421
|
+
io.writeOut(` ${(0, render_1.ljust)(step, 8)} ${(0, format_1.formatFixed)(Number((0, format_1.dictGetChecked)(row, 'count', 0)), 0).padStart(6)} ` +
|
|
2422
|
+
`${ms(row.p50)} ${ms(row.p95)} ${ms(row.p99)}\n`);
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* The panel, the per-step table, and the SLO lines -- with 'SLO gate:' only when there were
|
|
2427
|
+
* rules to gate on.
|
|
2428
|
+
*/
|
|
2429
|
+
function renderLoadtestPanel(ctx, summary, slo, io) {
|
|
2430
|
+
const { fmtActual } = require('../perf/slo');
|
|
2431
|
+
const rows = [
|
|
2432
|
+
[
|
|
2433
|
+
'throughput',
|
|
2434
|
+
`${summaryMetric(summary, 'rps', '.1f')} req/s (${summaryMetric(summary, 'count', '.0f')} requests)`,
|
|
2435
|
+
],
|
|
2436
|
+
[
|
|
2437
|
+
'latency',
|
|
2438
|
+
`p50 ${summaryMetric(summary, 'p50', 'ms')} p90 ${summaryMetric(summary, 'p90', 'ms')} ` +
|
|
2439
|
+
`p95 ${summaryMetric(summary, 'p95', 'ms')} p99 ${summaryMetric(summary, 'p99', 'ms')}`,
|
|
2440
|
+
],
|
|
2441
|
+
[
|
|
2442
|
+
'',
|
|
2443
|
+
`avg ${summaryMetric(summary, 'avg', 'ms')} min ${summaryMetric(summary, 'min', 'ms')} ` +
|
|
2444
|
+
`max ${summaryMetric(summary, 'max', 'ms')}`,
|
|
2445
|
+
],
|
|
2446
|
+
[
|
|
2447
|
+
'errors',
|
|
2448
|
+
`${summaryMetric(summary, 'error_rate', '.2%')} checks ${summaryMetric(summary, 'checks_rate', '.0%')} ok`,
|
|
2449
|
+
],
|
|
2450
|
+
];
|
|
2451
|
+
const breakdown = statusBreakdown(summary);
|
|
2452
|
+
if (breakdown !== '')
|
|
2453
|
+
rows.push(['responses', breakdown]);
|
|
2454
|
+
if ((0, format_1.isTruthy)(ctx.constrained))
|
|
2455
|
+
rows.push(['constrained', (0, format_1.toTextAny)(ctx.constrained)]);
|
|
2456
|
+
let load = `${loadShapeOf(ctx)} / ${(0, format_1.toTextAny)(ctx.duration)}`;
|
|
2457
|
+
if ((0, format_1.isTruthy)(ctx.users))
|
|
2458
|
+
load += `, ${(0, format_1.toTextAny)(ctx.users)} users`;
|
|
2459
|
+
(0, render_1.writePanel)(io, `loadtest ${(0, format_1.toTextAny)((0, format_1.dictGetChecked)(ctx, 'label', ctx.scenario))} (${load})`, rows);
|
|
2460
|
+
renderSteps(bag((0, format_1.orElse)(summary.steps, {})), io);
|
|
2461
|
+
if (slo.length === 0)
|
|
2462
|
+
return;
|
|
2463
|
+
io.writeOut('\n');
|
|
2464
|
+
for (const rule of slo) {
|
|
2465
|
+
const detail = !(0, format_1.isTruthy)((0, format_1.dictGetChecked)(rule, 'measured', true))
|
|
2466
|
+
? 'not measured'
|
|
2467
|
+
: `actual ${fmtActual(String(rule.key), Number(rule.actual))}`;
|
|
2468
|
+
io.writeOut(` ${(0, format_1.isTruthy)(rule.ok) ? '✓' : '✗'} ${(0, format_1.toTextAny)(rule.key)} ${(0, format_1.toTextAny)(rule.op)} ` +
|
|
2469
|
+
`${(0, format_1.toTextAny)(rule.raw)} (${detail})\n`);
|
|
2470
|
+
}
|
|
2471
|
+
io.writeOut(`\nSLO gate: ${slo.every((rule) => (0, format_1.isTruthy)(rule.ok)) ? 'PASS' : 'FAIL'}\n`);
|
|
2472
|
+
}
|
|
2473
|
+
/** The p95 sparkline, RC's internals, the slow queries, and the verdict. */
|
|
2474
|
+
function renderDiagnosis(diag, io) {
|
|
2475
|
+
const { fmtMs } = require('../perf/timings');
|
|
2476
|
+
const timeline = require('../perf/timeline');
|
|
2477
|
+
if (diag.timeline !== null) {
|
|
2478
|
+
io.writeOut('\n');
|
|
2479
|
+
for (const line of timeline.renderAscii(diag.timeline))
|
|
2480
|
+
io.writeOut(` ${line}\n`);
|
|
2481
|
+
}
|
|
2482
|
+
const rcm = diag.rcmetrics;
|
|
2483
|
+
if (Object.keys(rcm).length > 0) {
|
|
2484
|
+
io.writeOut('\nRC internals during the test:\n');
|
|
2485
|
+
for (const service of Object.keys(rcm).sort(format_1.compareCodePoints)) {
|
|
2486
|
+
const m = bag(rcm[service]);
|
|
2487
|
+
const bits = [];
|
|
2488
|
+
// The histogram's per-interval peak over the run; the instantaneous gauge as fallback.
|
|
2489
|
+
const peak = (0, format_1.orElse)(m.eventloop_lag_max_s, m.eventloop_lag_s);
|
|
2490
|
+
const p99 = m.eventloop_lag_p99_s;
|
|
2491
|
+
if ((0, format_1.isTruthy)(peak)) {
|
|
2492
|
+
let lag = `event-loop lag peak ${fmtMs(Number(bag(peak).max) * 1000)}`;
|
|
2493
|
+
if ((0, format_1.isTruthy)(p99))
|
|
2494
|
+
lag += ` / p99 ${fmtMs(Number(bag(p99).max) * 1000)}`;
|
|
2495
|
+
bits.push(lag);
|
|
2496
|
+
}
|
|
2497
|
+
if ((0, format_1.isTruthy)(m.heap_used_bytes)) {
|
|
2498
|
+
bits.push(`heap ${(0, format_1.formatFixed)(Number(bag(m.heap_used_bytes).max) / 1e6, 0)}MB`);
|
|
2499
|
+
}
|
|
2500
|
+
if ((0, format_1.isTruthy)(m.ddp_users)) {
|
|
2501
|
+
bits.push(`ddp users ${(0, format_1.formatFixed)(Number(bag(m.ddp_users).max), 0)}`);
|
|
2502
|
+
}
|
|
2503
|
+
if (bits.length > 0)
|
|
2504
|
+
io.writeOut(` ${(0, render_1.ljust)(service, 14)} ${bits.join(' ')}\n`);
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
const mongo = diag.mongo;
|
|
2508
|
+
if (mongo !== null && (0, format_1.isTruthy)(mongo.slow)) {
|
|
2509
|
+
io.writeOut(`\nSlow MongoDB queries (${(0, format_1.toTextAny)(mongo.total)} profiled, ` +
|
|
2510
|
+
`${(0, format_1.toTextAny)(mongo.collscan)} COLLSCAN):\n`);
|
|
2511
|
+
for (const slow of bags(mongo.slow)) {
|
|
2512
|
+
io.writeOut(` ${fmtMs(Number(slow.millis)).padStart(7)} ${(0, format_1.toTextAny)(slow.ns)} ${(0, format_1.toTextAny)(slow.op)} ` +
|
|
2513
|
+
`[${(0, format_1.toTextAny)((0, format_1.orElse)(slow.plan, '?'))}] docs ${(0, format_1.toTextAny)(slow.docs)}/ret ${(0, format_1.toTextAny)(slow.ret)}\n`);
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
if (diag.verdict.length > 0) {
|
|
2517
|
+
io.writeOut('\nVerdict:\n');
|
|
2518
|
+
for (const line of diag.verdict) {
|
|
2519
|
+
const wrapped = (0, render_1.wrapWords)((0, render_1.asciiOf)(line), 84, { subsequentIndent: ' ' });
|
|
2520
|
+
io.writeOut(` - ${wrapped[0] ?? ''}\n`);
|
|
2521
|
+
for (const more of wrapped.slice(1))
|
|
2522
|
+
io.writeOut(` ${more}\n`);
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
/** Throughput to one place, the error rate a percentage, latency as ms. */
|
|
2527
|
+
function compareValue(metric, value) {
|
|
2528
|
+
const { fmtMs } = require('../perf/timings');
|
|
2529
|
+
if (metric.includes('rps'))
|
|
2530
|
+
return (0, format_1.formatFixed)(value, 1);
|
|
2531
|
+
if (metric.includes('error'))
|
|
2532
|
+
return `${(0, format_1.formatFixed)(value * 100, 2)}%`;
|
|
2533
|
+
return fmtMs(value);
|
|
2534
|
+
}
|
|
2535
|
+
/** The baseline it was measured against, then one aligned row a metric. */
|
|
2536
|
+
function renderComparison(rows, base, io) {
|
|
2537
|
+
const ctx = bag((0, format_1.orElse)(base.ctx, {}));
|
|
2538
|
+
const saved = [...(0, format_1.toTextAny)((0, format_1.dictGetChecked)(base, 'saved_at', ''))].slice(0, 19).join('');
|
|
2539
|
+
io.writeOut(`\nvs baseline ${(0, format_1.shownValue)((0, format_1.dictGetChecked)(base, 'label', '?'))} ` +
|
|
2540
|
+
`(${(0, format_1.toTextAny)((0, format_1.dictGetChecked)(ctx, 'label', (0, format_1.dictGetChecked)(ctx, 'scenario', '?')))}, saved ${saved}):\n`);
|
|
2541
|
+
const width = Math.max(0, ...rows.map((row) => [...String(row.metric)].length));
|
|
2542
|
+
for (const row of rows) {
|
|
2543
|
+
const metric = String(row.metric);
|
|
2544
|
+
const before = compareValue(metric, Number(row.before));
|
|
2545
|
+
const after = compareValue(metric, Number(row.after));
|
|
2546
|
+
const line = ` ${(0, render_1.ljust)(metric, width)} ${before.padStart(8)} -> ${(0, render_1.ljust)(after, 8)} ` +
|
|
2547
|
+
`${(0, format_1.formatSigned)(Number(row.pct), 0).padStart(6)}%`;
|
|
2548
|
+
io.writeOut((0, format_1.isTruthy)(row.flag) ? `${line} <- regression\n` : `${line}\n`);
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
/**
|
|
2552
|
+
* A blank line after k6's own output, the panel, the spike line, the diagnosis when --diag
|
|
2553
|
+
* armed it, the comparison, and the resource cost.
|
|
2554
|
+
*
|
|
2555
|
+
* An earlier version was a sketch of it: its title lost ', N users' and the 'spike'/'ramp'
|
|
2556
|
+
* word, the avg/min/max, checks and responses rows were missing, latency was `toFixed`
|
|
2557
|
+
* (210.5 -> 211ms, and never seconds), the SLO lines printed the raw actual and 'SLO gate:
|
|
2558
|
+
* PASS' was said on every run, the per-step table, the spike line, the sparkline, RC's
|
|
2559
|
+
* internals, the slow queries and the wrapped verdict were absent, and the comparison read
|
|
2560
|
+
* keys its rows do not have, so it printed names and no values.
|
|
2561
|
+
*/
|
|
2562
|
+
function renderLoadtest(view, io) {
|
|
2563
|
+
const { fmtMs } = require('../perf/timings');
|
|
2564
|
+
io.writeOut('\n');
|
|
2565
|
+
renderLoadtestPanel(view.ctx, view.summary, view.slo, io);
|
|
2566
|
+
const spike = view.spike;
|
|
2567
|
+
if (spike !== null) {
|
|
2568
|
+
const recovered = spike.recovered_after_s;
|
|
2569
|
+
io.writeOut(` spike: baseline p95 ${fmtMs(spike.baseline_p95)} -> peak ${fmtMs(spike.spike_p95)} -> ` +
|
|
2570
|
+
(recovered !== null
|
|
2571
|
+
? `recovered ~${String(recovered)}s after load dropped`
|
|
2572
|
+
: 'NOT recovered within the run') +
|
|
2573
|
+
'\n');
|
|
2574
|
+
}
|
|
2575
|
+
if (view.diag !== null)
|
|
2576
|
+
renderDiagnosis(view.diag, io);
|
|
2577
|
+
if (view.compare.length > 0 && view.base !== null)
|
|
2578
|
+
renderComparison(view.compare, view.base, io);
|
|
2579
|
+
renderResources(view.resources, io, view.name);
|
|
2580
|
+
}
|
|
2581
|
+
/**
|
|
2582
|
+
* A result that carries the workspace's record for the human renderer, which draws the
|
|
2583
|
+
* panel and notes from it. Not enumerable, so no JSON envelope sees it.
|
|
2584
|
+
*/
|
|
2585
|
+
function withMeta(result, meta) {
|
|
2586
|
+
Object.defineProperty(result, '__meta', { enumerable: false, value: meta });
|
|
2587
|
+
return result;
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* The record a result carries, or -- for a result some other caller built -- one read off
|
|
2591
|
+
* its own snake_case fields, as a record document would hold them.
|
|
2592
|
+
*/
|
|
2593
|
+
function metaOf(value) {
|
|
2594
|
+
const carried = value?.__meta;
|
|
2595
|
+
if (carried !== undefined)
|
|
2596
|
+
return carried;
|
|
2597
|
+
const record = require('../core/runner/record');
|
|
2598
|
+
return record.fromDocument(bag(value));
|
|
2599
|
+
}
|
|
2600
|
+
/**
|
|
2601
|
+
* The import plan, as it is drawn before the dry run's rows or the apply: a blank line,
|
|
2602
|
+
* the width-64 box with its three established rows -- the oauth one only when the dump names
|
|
2603
|
+
* a provider -- and the redacted secrets the operator must set by hand.
|
|
2604
|
+
*/
|
|
2605
|
+
function renderImportPlan(io, plan, dryRun) {
|
|
2606
|
+
const counts = bag(plan.counts);
|
|
2607
|
+
const lines = [
|
|
2608
|
+
`apply ${display(counts.apply, '0')} customized setting(s)`,
|
|
2609
|
+
`skip ${display(counts.redacted, '0')} redacted secret(s), ` +
|
|
2610
|
+
`${display(counts.denied, '0')} identity/environment setting(s)`,
|
|
2611
|
+
];
|
|
2612
|
+
const services = Array.isArray(plan.oauth_services) ? plan.oauth_services.map(format_1.toTextAny) : [];
|
|
2613
|
+
if (services.length > 0)
|
|
2614
|
+
lines.push(`oauth pre-create: ${services.join(', ')}`);
|
|
2615
|
+
io.writeOut('\n');
|
|
2616
|
+
(0, render_1.writeBox)(io, `config import${dryRun ? ' (dry run)' : ''}`, lines, 64);
|
|
2617
|
+
const redacted = Array.isArray(plan.redacted) ? plan.redacted.map(format_1.toTextAny) : [];
|
|
2618
|
+
if (redacted.length > 0) {
|
|
2619
|
+
io.writeOut(` set these by hand (redacted in the dump): ${redacted.join(', ')}\n`);
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
/** Human output is an explicit part of every command, never a generic object dump. */
|
|
2623
|
+
async function renderHuman(invocation, value, io) {
|
|
2624
|
+
const path = invocation.spec.path;
|
|
2625
|
+
const result = bag(value);
|
|
2626
|
+
const action = display(invocation.arguments.action);
|
|
2627
|
+
if (value === undefined || path === 'serve' || path === 'logs' || path === 'capabilities')
|
|
2628
|
+
return;
|
|
2629
|
+
switch (path) {
|
|
2630
|
+
case 'up': {
|
|
2631
|
+
// The create's result: the panel and notes from the record.
|
|
2632
|
+
const meta = metaOf(value);
|
|
2633
|
+
if ((0, format_1.isTruthy)(result.waited)) {
|
|
2634
|
+
io.writeOut('✓ ready\n');
|
|
2635
|
+
const booted = result.booted_s;
|
|
2636
|
+
summaryPanel(meta, io, booted === undefined || booted === null
|
|
2637
|
+
? []
|
|
2638
|
+
: [['Booted in', fmtDuration(Number(booted))]]);
|
|
2639
|
+
io.writeOut(` next: houston logs --name ${meta.name} -f\n`);
|
|
2640
|
+
}
|
|
2641
|
+
else {
|
|
2642
|
+
io.writeOut('✓ starting\n');
|
|
2643
|
+
summaryPanel(meta, io);
|
|
2644
|
+
io.writeOut(` ready when serving : houston ready --name ${meta.name}\n`);
|
|
2645
|
+
io.writeOut(` follow logs : houston logs --name ${meta.name} -f\n`);
|
|
2646
|
+
}
|
|
2647
|
+
await printNotes(meta, io);
|
|
2648
|
+
return;
|
|
2649
|
+
}
|
|
2650
|
+
case 'ready': {
|
|
2651
|
+
const meta = metaOf(value);
|
|
2652
|
+
io.writeOut('✓ ready\n');
|
|
2653
|
+
summaryPanel(meta, io, [['Booted in', fmtDuration(Number(result.booted_s))]]);
|
|
2654
|
+
io.writeOut(` next: houston logs --name ${meta.name} -f\n`);
|
|
2655
|
+
await printNotes(meta, io);
|
|
2656
|
+
return;
|
|
2657
|
+
}
|
|
2658
|
+
case 'down': {
|
|
2659
|
+
// The nouns depend on the runtime: a Kubernetes workspace has a namespace and a
|
|
2660
|
+
// PersistentVolumeClaim, not containers and a Docker volume.
|
|
2661
|
+
const name = display(result.name, display(invocation.options.name));
|
|
2662
|
+
const kube = result.runtime === 'kubernetes';
|
|
2663
|
+
if (invocation.options.volumes === true && result.removed === false) {
|
|
2664
|
+
io.writeOut(`${(0, format_1.quotedText)(name)} was NOT removed — see above. \`houston list\` still shows it, ` +
|
|
2665
|
+
'which is correct: the record is deliberately kept.\n');
|
|
2666
|
+
}
|
|
2667
|
+
else if (invocation.options.volumes === true) {
|
|
2668
|
+
const what = kube
|
|
2669
|
+
? 'namespace, PersistentVolumeClaim and record'
|
|
2670
|
+
: 'containers, data volume, and record';
|
|
2671
|
+
const owner = display(result.owner);
|
|
2672
|
+
io.writeOut(`✓ ${(0, format_1.quotedText)(name)} removed (${what}${owner === '' ? '' : `; owned by ${owner}`}).\n`);
|
|
2673
|
+
}
|
|
2674
|
+
else {
|
|
2675
|
+
const kept = kube ? 'the namespace and its PersistentVolumeClaim are kept' : 'data kept';
|
|
2676
|
+
// The kept record knows the version: `<same>` sent the reader to `list` to look it up.
|
|
2677
|
+
const runnerRecord = require('../core/runner/record');
|
|
2678
|
+
const was = await runnerRecord.readMeta(name).catch(() => null);
|
|
2679
|
+
const owner = was === null ? '' : runnerRecord.recordedOwner(was);
|
|
2680
|
+
io.writeOut(`✓ ${(0, format_1.quotedText)(name)} down (${kept}${owner === '' ? '' : `; owned by ${owner}`}).\n`);
|
|
2681
|
+
io.writeOut(` bring it back: houston up --version ${was?.rcVersion || '<same>'} --name ${name}\n`);
|
|
2682
|
+
io.writeOut(' delete for good: add --volumes (`houston prune` deletes every taken-down ' +
|
|
2683
|
+
'workspace, not just this one)\n');
|
|
2684
|
+
// ON A CLOUD CLUSTER the kept disk is a bill: small, but it outlives the cluster
|
|
2685
|
+
// if the cluster goes first, and `cluster delete` refuses while it exists.
|
|
2686
|
+
const request = require('../core/lifecycle/request');
|
|
2687
|
+
if (kube && request.savedDefaultIsBillable(display(result.context))) {
|
|
2688
|
+
io.writeOut(' its 8 GB disk keeps billing (about $0.64 a month) and `houston cluster delete` ' +
|
|
2689
|
+
`will refuse while it exists — \`houston down --name ${name} --volumes\` removes it\n`);
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
return;
|
|
2693
|
+
}
|
|
2694
|
+
case 'monitor': {
|
|
2695
|
+
// The established output, line for line. The detach line says when Prometheus_Enabled
|
|
2696
|
+
// was NOT reset, the shared-stack note is the established sentence, and a blank line
|
|
2697
|
+
// comes between the attach line and its notes: each was missing or reworded.
|
|
2698
|
+
const shown = (0, format_1.quotedText)(display(result.name, display(invocation.options.name)));
|
|
2699
|
+
if (invocation.options.off === true) {
|
|
2700
|
+
const kept = (0, format_1.isTruthy)(result.rc_setting_reset)
|
|
2701
|
+
? ''
|
|
2702
|
+
: ' (metrics setting left as-is — workspace not reachable)';
|
|
2703
|
+
io.writeOut(`✓ monitoring detached from ${shown}${kept}\n`);
|
|
2704
|
+
if (result.stack_removed === false) {
|
|
2705
|
+
io.writeOut('the shared monitoring stack stays up — other workspaces on this cluster are ' +
|
|
2706
|
+
'still using it\n');
|
|
2707
|
+
}
|
|
2708
|
+
return;
|
|
2709
|
+
}
|
|
2710
|
+
io.writeOut(`✓ monitoring attached to ${shown}\n`);
|
|
2711
|
+
io.writeOut('\n');
|
|
2712
|
+
for (const note of Array.isArray(result.notes) ? result.notes : []) {
|
|
2713
|
+
io.writeOut(`${display(note)}\n`);
|
|
2714
|
+
}
|
|
2715
|
+
return;
|
|
2716
|
+
}
|
|
2717
|
+
case 'prune': {
|
|
2718
|
+
const removed = Array.isArray(result.removed) ? result.removed.map(String) : [];
|
|
2719
|
+
const orphans = Array.isArray(result.orphans) ? result.orphans.map(String) : [];
|
|
2720
|
+
if (removed.length > 0)
|
|
2721
|
+
io.writeOut(`✓ pruned ${String(removed.length)}: ${removed.join(', ')}\n`);
|
|
2722
|
+
if (orphans.length > 0)
|
|
2723
|
+
io.writeOut(`✓ removed ${String(orphans.length)} orphaned namespace(s): ${orphans.join(', ')}\n`);
|
|
2724
|
+
if (result.emptyCluster === true) {
|
|
2725
|
+
// Nothing but the cluster was on offer.
|
|
2726
|
+
io.writeOut(result.cluster === true
|
|
2727
|
+
? '✓ the cluster is gone — the next Kubernetes workspace creates a new one.\n'
|
|
2728
|
+
: 'Nothing to prune.\n');
|
|
2729
|
+
return;
|
|
2730
|
+
}
|
|
2731
|
+
if (removed.length === 0 && orphans.length === 0)
|
|
2732
|
+
io.writeOut('Nothing to prune.\n');
|
|
2733
|
+
if (result.cluster === true) {
|
|
2734
|
+
io.writeOut('✓ the cluster is gone too — the next Kubernetes workspace creates a new one.\n');
|
|
2735
|
+
}
|
|
2736
|
+
return;
|
|
2737
|
+
}
|
|
2738
|
+
case 'start':
|
|
2739
|
+
case 'stop':
|
|
2740
|
+
case 'restart': {
|
|
2741
|
+
const name = display(result.name, display(invocation.options.name));
|
|
2742
|
+
// Whose it is, because without --name this acted on the default the whole home shares.
|
|
2743
|
+
const owned = await recordOwner(name);
|
|
2744
|
+
const notes = [
|
|
2745
|
+
...(owned === '' ? [] : [`owned by ${owned}`]),
|
|
2746
|
+
...(path === 'stop' ? ['resume with `houston start`'] : []),
|
|
2747
|
+
];
|
|
2748
|
+
const suffix = notes.length === 0 ? '' : ` (${notes.join('; ')})`;
|
|
2749
|
+
// The `✓` line and nothing more: `start` and `restart` have always ignored
|
|
2750
|
+
// `needs_ready`, which is the GUI's to act on; the scaling-back-up warning already
|
|
2751
|
+
// names `houston ready`. This added ` run: houston ready --name X` on Kubernetes.
|
|
2752
|
+
io.writeOut(`✓ ${(0, format_1.quotedText)(name)} ${path === 'start' ? 'started' : path === 'stop' ? 'stopped' : 'restarted'}${suffix}.\n`);
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2755
|
+
case 'use': {
|
|
2756
|
+
const name = display(result.default);
|
|
2757
|
+
const owned = await recordOwner(name);
|
|
2758
|
+
io.writeOut(`✓ default workspace is now ${(0, format_1.quotedText)(name)}` +
|
|
2759
|
+
`${owned === '' ? '' : ` (owned by ${owned})`}. Commands run without --name act on ` +
|
|
2760
|
+
'it, for everyone using this houston home.\n');
|
|
2761
|
+
return;
|
|
2762
|
+
}
|
|
2763
|
+
case 'list': {
|
|
2764
|
+
const repros = bags(result.repros);
|
|
2765
|
+
if (repros.length === 0) {
|
|
2766
|
+
io.writeOut('No workspaces yet. Create one with `houston up --version <X.Y.Z>`.\n');
|
|
2767
|
+
return;
|
|
2768
|
+
}
|
|
2769
|
+
// `list`'s established tests and widths: truthiness for the default and pinned marks,
|
|
2770
|
+
// the owner column and the public URL (a pinned of 1 or "yes" was no pin here), and
|
|
2771
|
+
// `ljust` pads by code point, where padEnd counted UTF-16 units and left a cell holding
|
|
2772
|
+
// an astral character one space short.
|
|
2773
|
+
const shared = repros.some((row) => (0, format_1.isTruthy)(row.created_by));
|
|
2774
|
+
io.writeOut(`NAME ${shared ? 'OWNER ' : ''}RC MONGO WHERE PORT STATE URL\n`);
|
|
2775
|
+
for (const row of repros) {
|
|
2776
|
+
const mark = (0, format_1.isTruthy)(row.default) ? '*' : (0, format_1.isTruthy)(row.pinned) ? '·' : ' ';
|
|
2777
|
+
const owner = (0, format_1.isTruthy)(row.created_by) ? display(row.created_by) : '-';
|
|
2778
|
+
io.writeOut(`${mark}${(0, render_1.ljust)(display(row.name), 19)} ${shared ? `${(0, render_1.ljust)(owner, 12)} ` : ''}` +
|
|
2779
|
+
`${(0, render_1.ljust)(display(row.rc_version), 9)} ${(0, render_1.ljust)(display(row.mongo_tag), 7)} ` +
|
|
2780
|
+
`${(0, render_1.ljust)(whereWord(row), 8)} ` +
|
|
2781
|
+
`${(0, render_1.ljust)(display(row.host_port), 6)} ${(0, render_1.ljust)(display(row.state), 10)} ` +
|
|
2782
|
+
`${(0, format_1.isTruthy)(row.open_url) ? display(row.open_url) : display(row.root_url)}\n`);
|
|
2783
|
+
}
|
|
2784
|
+
io.writeOut('\n* = default workspace · = pinned\n');
|
|
2785
|
+
return;
|
|
2786
|
+
}
|
|
2787
|
+
case 'info': {
|
|
2788
|
+
const meta = metaOf(value);
|
|
2789
|
+
summaryPanel(meta, io);
|
|
2790
|
+
io.writeOut(` api : houston api --name ${meta.name} GET /api/v1/me\n`);
|
|
2791
|
+
io.writeOut(` curl : ${meta.rootUrl}/api/info\n`);
|
|
2792
|
+
await printNotes(meta, io);
|
|
2793
|
+
return;
|
|
2794
|
+
}
|
|
2795
|
+
case 'users':
|
|
2796
|
+
// Printed by the handler as it went (`handlers/users.ts`): nothing is left to render.
|
|
2797
|
+
return;
|
|
2798
|
+
case 'edge':
|
|
2799
|
+
// Printed by the handler as it went (`handlers/https.ts`): nothing is left to render.
|
|
2800
|
+
return;
|
|
2801
|
+
case 'config':
|
|
2802
|
+
// `toTextAny(value)`: a stored boolean reads `False`, not `false`, which is the whole
|
|
2803
|
+
// difference between "set to false" and "unset" on this screen.
|
|
2804
|
+
if (action === 'get')
|
|
2805
|
+
io.writeOut(result.value === null ? '\n' : `${(0, format_1.toTextAny)(result.value)}\n`);
|
|
2806
|
+
else if (action === 'list') {
|
|
2807
|
+
for (const [key, item] of Object.entries(result)) {
|
|
2808
|
+
io.writeOut(` ${key.padEnd(20)} ${item === null ? '(unset)' : (0, format_1.toTextAny)(item)}\n`);
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
else if (action === 'unset')
|
|
2812
|
+
io.writeOut(`✓ ${display(result.key)} unset.\n`);
|
|
2813
|
+
// `toTextAny` of what was stored: a coerced acme.staging reads `True`/`False`, where
|
|
2814
|
+
// `String()` printed `true`.
|
|
2815
|
+
else
|
|
2816
|
+
io.writeOut(`✓ ${display(result.key)} = ${(0, format_1.toTextAny)(result.value)}\n`);
|
|
2817
|
+
return;
|
|
2818
|
+
case 'env':
|
|
2819
|
+
// The established output, line for line. An earlier version marked a drifted row `!!
|
|
2820
|
+
// NOT RUNNING` and printed neither drift warning after the panel, so the one state this
|
|
2821
|
+
// read exists to catch — a recorded value the container is not running — was shown in a
|
|
2822
|
+
// narrower panel with nothing saying what to do about it; it printed no `could not be
|
|
2823
|
+
// read` note, no `--setting`/`--set` examples, and no `verify:` line after an applied
|
|
2824
|
+
// write. `if name` is the name as TYPED: a name-less read shows the examples without
|
|
2825
|
+
// `--name`.
|
|
2826
|
+
if (Array.isArray(result.env)) {
|
|
2827
|
+
(0, render_1.writePanel)(io, `env: ${display(result.name)}`, bags(result.env).map((row) => [
|
|
2828
|
+
display(row.key),
|
|
2829
|
+
`${display(row.value)}${(0, format_1.isTruthy)(row.override) ? ' <- yours' : ''}${(0, format_1.isTruthy)(row.drift) ? ' !! NOT IN THE RUNNING CONTAINER' : ''}`,
|
|
2830
|
+
]));
|
|
2831
|
+
const name = display(result.name);
|
|
2832
|
+
const drift = Array.isArray(result.drift) ? result.drift.map((key) => (0, format_1.toTextAny)(key)) : [];
|
|
2833
|
+
if (drift.length > 0) {
|
|
2834
|
+
io.writeOut(` ${String(drift.length)} recorded value(s) are NOT what the container is running: ` +
|
|
2835
|
+
`${drift.join(', ')}\n`);
|
|
2836
|
+
io.writeOut(` Rocket.Chat is using the old value. \`houston env --set ${drift[0] ?? ''}=<value> ` +
|
|
2837
|
+
`--name ${name}\` re-applies and recreates the container.\n`);
|
|
2838
|
+
}
|
|
2839
|
+
else if (!(0, format_1.isTruthy)(result.live_read ?? true)) {
|
|
2840
|
+
io.writeOut(' the container could not be read, so this is the recorded configuration and ' +
|
|
2841
|
+
'not a statement about what is running.\n');
|
|
2842
|
+
}
|
|
2843
|
+
const removed = Array.isArray(result.removed)
|
|
2844
|
+
? result.removed.map((key) => (0, format_1.toTextAny)(key))
|
|
2845
|
+
: [];
|
|
2846
|
+
const overrides = Array.isArray(result.overrides)
|
|
2847
|
+
? result.overrides.map((key) => (0, format_1.toTextAny)(key)).filter((key) => !removed.includes(key))
|
|
2848
|
+
: [];
|
|
2849
|
+
if (overrides.length > 0)
|
|
2850
|
+
io.writeOut(` your overrides: ${overrides.join(', ')}\n`);
|
|
2851
|
+
if (removed.length > 0)
|
|
2852
|
+
io.writeOut(` removed by you: ${removed.join(', ')}\n`);
|
|
2853
|
+
if (overrides.length === 0 && removed.length === 0) {
|
|
2854
|
+
io.writeOut(' no overrides — this is the preset/base environment.\n');
|
|
2855
|
+
}
|
|
2856
|
+
const named = display(invocation.options.name) === '' ? '' : ` --name ${name}`;
|
|
2857
|
+
io.writeOut(` a Rocket.Chat setting: houston env --setting Some_Setting_Id=value${named}\n`);
|
|
2858
|
+
io.writeOut(` a raw env var: houston env --set KEY=VALUE${named}\n`);
|
|
2859
|
+
}
|
|
2860
|
+
else {
|
|
2861
|
+
io.writeOut(`✓ env ${result.restarted === false ? 'written (not yet applied)' : 'applied'} on ${(0, format_1.quotedText)(display(result.name))}.\n`);
|
|
2862
|
+
for (const row of bags(result.overrides)) {
|
|
2863
|
+
io.writeOut(` ${display(row.key)} = ${row.removed === true ? '(removed)' : display(row.value)}\n`);
|
|
2864
|
+
}
|
|
2865
|
+
if (result.restarted !== false)
|
|
2866
|
+
io.writeOut(` verify: houston env --name ${display(result.name)}\n`);
|
|
2867
|
+
else
|
|
2868
|
+
io.writeOut(' to apply it: re-run the same `houston env` without --no-restart\n');
|
|
2869
|
+
}
|
|
2870
|
+
return;
|
|
2871
|
+
case 'tls-status':
|
|
2872
|
+
case 'trust-ca':
|
|
2873
|
+
// Printed by the handler as it went (`handlers/https.ts`).
|
|
2874
|
+
return;
|
|
2875
|
+
case 'token':
|
|
2876
|
+
io.writeOut(`-H "X-Auth-Token: ${display(result.token)}" -H "X-User-Id: ${display(result.user_id)}"\n`);
|
|
2877
|
+
return;
|
|
2878
|
+
case 'api':
|
|
2879
|
+
// The body is echoed with a newline of its own, so a body that already ends in one is
|
|
2880
|
+
// followed by a blank line; this added one only when the body lacked it. And the time
|
|
2881
|
+
// is `fmtMs`, which is seconds with two decimals from a second up -- `in 1.30s` --
|
|
2882
|
+
// where this always printed whole milliseconds.
|
|
2883
|
+
io.writeOut(`HTTP ${display(result.status)} [${display(result.auth)}${invocation.options.two_fa === true ? '+2fa' : ''}] ` +
|
|
2884
|
+
`in ${require('../perf/timings').fmtMs(Number(result.elapsed_ms))}\n${display(result.text)}\n`);
|
|
2885
|
+
return;
|
|
2886
|
+
case 'pat':
|
|
2887
|
+
// `toTextAny` of each, so the flag reads `True`/`False` where `display` wrote
|
|
2888
|
+
// `true`/`false` on every successful mint, and a record's name that is not text reads
|
|
2889
|
+
// as `toTextAny` spells it.
|
|
2890
|
+
io.writeOut(`# Personal Access Token for ${(0, format_1.toTextAny)(result.name)} (${(0, format_1.toTextAny)(result.root_url)}) — ` +
|
|
2891
|
+
`bypass_2fa=${(0, format_1.toTextAny)(result.bypass_2fa)}\n`);
|
|
2892
|
+
io.writeOut(`-H "X-Auth-Token: ${display(result.token)}" -H "X-User-Id: ${display(result.user_id)}"\n`);
|
|
2893
|
+
return;
|
|
2894
|
+
case 'seed': {
|
|
2895
|
+
// The REST seed is rendered as it runs (`runSeed`); only the two scale paths print from
|
|
2896
|
+
// their result, each count with thousands commas and the room quoted by `quotedText`.
|
|
2897
|
+
const commas = require('../core/scaleseed').withCommas;
|
|
2898
|
+
if (invocation.options.clear_scale === true) {
|
|
2899
|
+
io.writeOut(`✓ removed ${commas(Number(result.users))} scale users and ` +
|
|
2900
|
+
`${commas(Number(result.messages))} scale messages\n`);
|
|
2901
|
+
}
|
|
2902
|
+
else if (display(invocation.options.scale) !== '') {
|
|
2903
|
+
if (Object.hasOwn(result, 'users'))
|
|
2904
|
+
io.writeOut(`✓ inserted ${commas(Number(result.users))} users\n`);
|
|
2905
|
+
if (Object.hasOwn(result, 'messages'))
|
|
2906
|
+
io.writeOut(`✓ inserted ${commas(Number(result.messages))} messages into ` +
|
|
2907
|
+
`${(0, format_1.shownValue)(result.room)}\n`);
|
|
2908
|
+
}
|
|
2909
|
+
return;
|
|
2910
|
+
}
|
|
2911
|
+
case 'config-import': {
|
|
2912
|
+
// The plan box was drawn by the handler, before the apply (`renderImportPlan`).
|
|
2913
|
+
if (invocation.options.dry_run === true) {
|
|
2914
|
+
// Each id padded to 48 CODE POINTS, then ` = ` and its value, where `padEnd`
|
|
2915
|
+
// counted an astral id's UTF-16 units.
|
|
2916
|
+
for (const item of bags(result.apply))
|
|
2917
|
+
io.writeOut(` ${(0, render_1.ljust)(display(item.id), 48)} = ${display(item.value)}\n`);
|
|
2918
|
+
return;
|
|
2919
|
+
}
|
|
2920
|
+
// Which settings Rocket.Chat refused, the first ten by id, and the restart they may
|
|
2921
|
+
// need. This said "⚠ 12 setting(s) rejected" and nothing else, so the operator could
|
|
2922
|
+
// not tell WHICH settings the workspace does not have.
|
|
2923
|
+
if ((0, format_1.isTruthy)(result.failed)) {
|
|
2924
|
+
const failures = Array.isArray(result.failures) ? result.failures.map(format_1.toTextAny) : [];
|
|
2925
|
+
io.writeOut(` ${display(result.failed)} setting(s) rejected: ${failures.slice(0, 10).join(', ')}` +
|
|
2926
|
+
`${Number(result.failed) > 10 ? ' ...' : ''}\n`);
|
|
2927
|
+
}
|
|
2928
|
+
io.writeOut(`✓ imported ${display(result.applied, '0')} setting(s), skipped ${display(result.skipped, '0')}\n`);
|
|
2929
|
+
io.writeOut(` some settings need an RC restart to fully take effect: houston restart --name ${metaOf(value).name}\n`);
|
|
2930
|
+
return;
|
|
2931
|
+
}
|
|
2932
|
+
case 'backup': {
|
|
2933
|
+
const manifest = bag(result.manifest);
|
|
2934
|
+
io.writeOut(`✓ backed up ${(0, format_1.quotedText)(display(result.name))} (${display(manifest.rc_version)}) — ${humanBytes(result.bytes)}\n`);
|
|
2935
|
+
io.writeOut(` ${display(result.path)}\n`);
|
|
2936
|
+
// The sidecar warning line prints its text as given -- two spaces, no `⚠` -- and the
|
|
2937
|
+
// hint has TWO spaces after `roll back to it:`. This printed `⚠ ` and one.
|
|
2938
|
+
if (Array.isArray(manifest.sidecar_volumes) && manifest.sidecar_volumes.length > 0)
|
|
2939
|
+
io.writeOut(` sidecar data is NOT included: ${manifest.sidecar_volumes.map(String).join(', ')}\n`);
|
|
2940
|
+
// Restore with no --name goes back INTO this workspace, dropping what it holds now.
|
|
2941
|
+
io.writeOut(` roll back to it: houston restore ${display(result.path)} ` +
|
|
2942
|
+
`(replaces ${display(result.name)}'s data; add --new for a separate copy)\n`);
|
|
2943
|
+
return;
|
|
2944
|
+
}
|
|
2945
|
+
case 'backups': {
|
|
2946
|
+
// `backups`: the bundle's FILE NAME, not its path; the label when it has one; and the
|
|
2947
|
+
// warning that a bundle predates the workspace now holding its name, which is the line
|
|
2948
|
+
// that stops a restore loading an earlier workspace's data.
|
|
2949
|
+
const rows = bags(result.backups);
|
|
2950
|
+
if (rows.length === 0)
|
|
2951
|
+
io.writeOut('no backups yet — make one with `houston backup`\n');
|
|
2952
|
+
for (const row of rows) {
|
|
2953
|
+
const file = display(row.path).replace(/^.*\//su, ''); // `Path(r['path']).name`
|
|
2954
|
+
if ((0, format_1.isTruthy)(row.error)) {
|
|
2955
|
+
io.writeOut(` ${file} UNREADABLE: ${(0, format_1.toTextAny)(row.error)}\n`);
|
|
2956
|
+
continue;
|
|
2957
|
+
}
|
|
2958
|
+
const label = (0, format_1.isTruthy)(row.label) ? ` (${(0, format_1.toTextAny)(row.label)})` : '';
|
|
2959
|
+
io.writeOut(` ${file}\n`);
|
|
2960
|
+
io.writeOut(` ${(0, format_1.toTextAny)(row.repro)} RC ${(0, format_1.toTextAny)(row.rc_version)} ` +
|
|
2961
|
+
`${humanBytes(row.bytes)} ${(0, format_1.toTextAny)(row.created_at)}${label}\n`);
|
|
2962
|
+
if ((0, format_1.isTruthy)(row.predates_workspace)) {
|
|
2963
|
+
io.writeOut(' ^ from an EARLIER workspace of this name, not the one running now — ' +
|
|
2964
|
+
"restoring it loads that workspace's data\n");
|
|
2965
|
+
}
|
|
2966
|
+
}
|
|
2967
|
+
return;
|
|
2968
|
+
}
|
|
2969
|
+
case 'restore':
|
|
2970
|
+
// `restore`: the bundle's FILE NAME, `pathBaseName(bundle)`, where this printed the
|
|
2971
|
+
// whole path the service returned (`sub/b.rcbak`, the `~`-expanded home); and the
|
|
2972
|
+
// upgrade-direction line as a warning line, two spaces and no `⚠`, with its second
|
|
2973
|
+
// clause, which this dropped.
|
|
2974
|
+
io.writeOut(`✓ ${result.created === true ? 'created and restored' : 'restored'} ${(0, format_1.quotedText)(display(result.name))} from ${pathBaseName(display(result.bundle))} in ${floatText(result.restore_seconds)}s\n`);
|
|
2975
|
+
if (result.direction === 'upgrade')
|
|
2976
|
+
io.writeOut(` ${display(result.from_version)} data now runs on ${display(result.to_version)} — ` +
|
|
2977
|
+
'Rocket.Chat has migrated it\n');
|
|
2978
|
+
if (display(result.url) !== '') {
|
|
2979
|
+
io.writeOut(` ${display(result.url)}\n`);
|
|
2980
|
+
sshHint(io, display(result.url));
|
|
2981
|
+
}
|
|
2982
|
+
return;
|
|
2983
|
+
case 'upgrade': {
|
|
2984
|
+
if (invocation.options.rollback === true) {
|
|
2985
|
+
io.writeOut(`✓ ${(0, format_1.quotedText)(display(result.name))} rolled back to ${display(result.rolled_back_to)}\n`);
|
|
2986
|
+
return;
|
|
2987
|
+
}
|
|
2988
|
+
// The plan was drawn by the command before it ran (`renderUpgradePlan`); a dry run or
|
|
2989
|
+
// a refusal has nothing more to say.
|
|
2990
|
+
if (value === null)
|
|
2991
|
+
return;
|
|
2992
|
+
io.writeOut(`✓ ${(0, format_1.quotedText)(display(result.name))} upgraded ${display(result.from_version)} -> ${display(result.to_version)} in ${floatText(result.boot_seconds)}s\n`);
|
|
2993
|
+
// The rest of the upgrade's output, none of which was printed: the running version ONLY
|
|
2994
|
+
// WHEN IT DISAGREES, as a prefix, because `/api/info` reports the minor alone; the
|
|
2995
|
+
// migration errors under the header that counts them; and the way back whenever a
|
|
2996
|
+
// pre-upgrade backup was taken.
|
|
2997
|
+
const running = result.running_version;
|
|
2998
|
+
if ((0, format_1.isTruthy)(running) &&
|
|
2999
|
+
running !== '?' &&
|
|
3000
|
+
!(0, format_1.toTextAny)(result.to_version).startsWith((0, format_1.toTextAny)(running)))
|
|
3001
|
+
io.writeOut(` but Rocket.Chat reports ${(0, format_1.toTextAny)(running)} — the upgrade did not land ` +
|
|
3002
|
+
'the image you asked for\n');
|
|
3003
|
+
const errors = Array.isArray(result.migration_errors) ? result.migration_errors : [];
|
|
3004
|
+
if (errors.length > 0) {
|
|
3005
|
+
io.writeOut(` ${String(errors.length)} migration error(s) in the boot log:\n`);
|
|
3006
|
+
for (const line of errors)
|
|
3007
|
+
io.writeOut(` ${(0, format_1.toTextAny)(line)}\n`);
|
|
3008
|
+
}
|
|
3009
|
+
if ((0, format_1.isTruthy)(result.backup))
|
|
3010
|
+
io.writeOut(` roll back: houston upgrade --rollback --name ${(0, format_1.toTextAny)(result.name)}\n`);
|
|
3011
|
+
return;
|
|
3012
|
+
}
|
|
3013
|
+
case 'stats':
|
|
3014
|
+
renderResources(result.resources, io, display(result.name, display(invocation.options.name)));
|
|
3015
|
+
return;
|
|
3016
|
+
case 'loadtest':
|
|
3017
|
+
// Drawn once the run was measured, before anything was saved, by `runLoadtestCli`.
|
|
3018
|
+
return;
|
|
3019
|
+
case 'capacity':
|
|
3020
|
+
// Drawn as it ran, header to report, by `runCapacityCli`.
|
|
3021
|
+
return;
|
|
3022
|
+
case 'presets':
|
|
3023
|
+
renderPresets(result, io);
|
|
3024
|
+
return;
|
|
3025
|
+
case 'versions':
|
|
3026
|
+
io.writeOut(`Rocket.Chat ${display(result.rc_version)}\n`);
|
|
3027
|
+
io.writeOut(` image : ${(0, compose_1.imageRef)(display(result.rc_image), display(result.rc_version))}\n`);
|
|
3028
|
+
io.writeOut(` mongo : ${display(result.mongo_tag)} (flavor: ${display(result.mongo_flavor)}, shell: ${display(result.mongo_shell)})\n`);
|
|
3029
|
+
io.writeOut(` oplog url : ${result.oplog === true ? 'yes' : 'no (deprecated in 8.x)'}\n`);
|
|
3030
|
+
io.writeOut(` resolved via : ${display(result.source)}\n`);
|
|
3031
|
+
if (display(result.note) !== '')
|
|
3032
|
+
io.writeOut(` note : ${display(result.note)}\n`);
|
|
3033
|
+
return;
|
|
3034
|
+
case 'audit': {
|
|
3035
|
+
const rows = bags(result.lines);
|
|
3036
|
+
if (rows.length === 0) {
|
|
3037
|
+
io.writeOut(`nothing matched in ${display(result.path)}\n`);
|
|
3038
|
+
return;
|
|
3039
|
+
}
|
|
3040
|
+
if (invocation.options.tsv === true)
|
|
3041
|
+
return;
|
|
3042
|
+
// `audit`: the actor column is as wide as the widest actor SHOWN, where an earlier
|
|
3043
|
+
// version padded none, so `-` stood two spaces from its kind beside `alice`'s column.
|
|
3044
|
+
// Widths, the kind's 14 and the timestamp's first 19, count code points, as `ljust`
|
|
3045
|
+
// does and `padEnd`/`slice` do not. The truncation hint is the established sentence,
|
|
3046
|
+
// which names the file; an earlier version shortened it.
|
|
3047
|
+
const width = rows.reduce((widest, row) => Math.max(widest, [...display(row.actor, '-')].length), 0);
|
|
3048
|
+
for (const row of [...rows].reverse()) {
|
|
3049
|
+
const origin = row.origin === 'session' ? '' : ` [${display(row.origin, 'legacy')}]`;
|
|
3050
|
+
io.writeOut(`${[...display(row.ts)].slice(0, 19).join('')} ${(0, render_1.ljust)(display(row.actor, '-'), width)} ` +
|
|
3051
|
+
`${(0, render_1.ljust)(display(row.kind), 14)} ${display(row.label)}${origin}${row.outcome === 'denied' ? ' DENIED' : ''}\n`);
|
|
3052
|
+
}
|
|
3053
|
+
if (result.truncated === true)
|
|
3054
|
+
io.writeOut(` (stopped early: ${display(result.path)} is large. Narrow it with --since or ` +
|
|
3055
|
+
'--actor, or ship it somewhere with an index.)\n');
|
|
3056
|
+
return;
|
|
3057
|
+
}
|
|
3058
|
+
case 'chown':
|
|
3059
|
+
// ` (was <from>)` only when `from` is truthy: `from` is the raw previous owner, so an
|
|
3060
|
+
// int 0 or a null says nothing and a `true` or a list prints as `toTextAny` spells it.
|
|
3061
|
+
io.writeOut(`✓ ${(0, format_1.quotedText)(display(result.name))} now belongs to ${display(result.to)}${(0, format_1.isTruthy)(result.from) ? ` (was ${(0, format_1.toTextAny)(result.from)})` : ''}\n`);
|
|
3062
|
+
return;
|
|
3063
|
+
case 'skill install':
|
|
3064
|
+
for (const row of bags(result.hosts))
|
|
3065
|
+
io.writeOut(` ${display(row.action).padEnd(9)} ${display(row.path)}\n`);
|
|
3066
|
+
io.writeOut(` version ${display(result.version)}\n`);
|
|
3067
|
+
return;
|
|
3068
|
+
case 'skill status':
|
|
3069
|
+
for (const [host, raw] of Object.entries(bag(result.hosts)).sort(([left], [right]) => left.localeCompare(right))) {
|
|
3070
|
+
const row = bag(raw);
|
|
3071
|
+
io.writeOut(` ${host.padEnd(8)} ${display(row.status).padEnd(9)} ${display(row.path)}\n`);
|
|
3072
|
+
}
|
|
3073
|
+
if (result.current !== true)
|
|
3074
|
+
io.writeOut(' `houston skill install` writes the copy this build ships.\n');
|
|
3075
|
+
return;
|
|
3076
|
+
case 'doctor':
|
|
3077
|
+
for (const row of bags(result.checks)) {
|
|
3078
|
+
const mark = row.status === 'ok' ? '✓' : row.status === 'warn' ? '⚠' : '✗';
|
|
3079
|
+
io.writeOut(`${mark} ${display(row.message)}\n`);
|
|
3080
|
+
}
|
|
3081
|
+
if (Object.keys(bag(result.repros)).length > 0) {
|
|
3082
|
+
const repros = bag(result.repros);
|
|
3083
|
+
io.writeOut(` workspaces: ${display(repros.total)} total, ${display(repros.running)} running\n`);
|
|
3084
|
+
}
|
|
3085
|
+
io.writeOut(`\n${result.verdict === 'fail' ? 'Not ready — fix the ✗ item(s) above.' : result.verdict === 'warn' ? 'Usable, with warnings above.' : 'All good — houston is ready.'}\n`);
|
|
3086
|
+
return;
|
|
3087
|
+
case 'cluster':
|
|
3088
|
+
if (action === 'guide') {
|
|
3089
|
+
io.writeOut(`${display(result.body, display(value))}${display(result.body, display(value)).endsWith('\n') ? '' : '\n'}`);
|
|
3090
|
+
}
|
|
3091
|
+
else if (action === 'iam-policy') {
|
|
3092
|
+
const documents = bags(result.documents);
|
|
3093
|
+
const wanted = display(invocation.arguments.name);
|
|
3094
|
+
// Trailing newlines trimmed, then one: one newline, whatever the document ends with.
|
|
3095
|
+
if (wanted !== '' && documents.length === 1)
|
|
3096
|
+
(0, render_1.say)(io, display(documents[0]?.body).replace(/\n+$/u, ''));
|
|
3097
|
+
else {
|
|
3098
|
+
// THE MENU, as it has always been drawn: the heading, each purpose wrapped at 74 by
|
|
3099
|
+
// `wrapWords`, and the commands that use them. This build printed the rows alone, each
|
|
3100
|
+
// purpose on one line.
|
|
3101
|
+
(0, render_1.say)(io, 'permissions documents houston ships, each verified by using it:');
|
|
3102
|
+
for (const document of documents) {
|
|
3103
|
+
(0, render_1.say)(io, ` ${(0, render_1.ljust)(display(document.name), 9)} ${display(document.filename)}`);
|
|
3104
|
+
for (const line of (0, render_1.wrapWords)(display(document.purpose), 74))
|
|
3105
|
+
(0, render_1.say)(io, ` ${line}`);
|
|
3106
|
+
}
|
|
3107
|
+
(0, render_1.say)(io, '');
|
|
3108
|
+
(0, render_1.say)(io, ' houston cluster iam-policy operator > operator-policy.json');
|
|
3109
|
+
(0, render_1.say)(io, ' aws iam create-policy --policy-name houston-cluster-operator \\');
|
|
3110
|
+
(0, render_1.say)(io, ' --policy-document file://operator-policy.json');
|
|
3111
|
+
(0, render_1.say)(io, ' houston cluster iam-policy rbac | kubectl apply -f -');
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
else if (action === 'list') {
|
|
3115
|
+
// A warning line adds no glyph, each row ends in when it was made and when it is due,
|
|
3116
|
+
// and the hint says how to price one.
|
|
3117
|
+
const clusters = bags(result.clusters);
|
|
3118
|
+
if (clusters.length > 0) {
|
|
3119
|
+
(0, render_1.say)(io, `${String(clusters.length)} cluster(s) — every one of these is billing`);
|
|
3120
|
+
for (const row of clusters) {
|
|
3121
|
+
const when = Array.from((0, format_1.toText)(row.created)).slice(0, 10).join('');
|
|
3122
|
+
const due = (0, format_1.isTruthy)(row.expires) ? ` · expires ${(0, format_1.toTextAny)(row.expires)}` : '';
|
|
3123
|
+
(0, render_1.say)(io, ` ${(0, render_1.ljust)((0, format_1.toTextAny)(row.region), 15)} ${(0, render_1.ljust)((0, format_1.toTextAny)(row.name), 24)} ` +
|
|
3124
|
+
`${(0, render_1.ljust)((0, format_1.toText)(row.status) || '?', 9)} ` +
|
|
3125
|
+
`${(0, format_1.isTruthy)(row.ours) ? 'houston' : "not houston's"} created ${when || '?'}${due}`);
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
// NO REASSURING LINE WHEN NOTHING WAS SWEPT, and "houston" in it unless --force
|
|
3129
|
+
// widened the sweep. Then, said last and plainly, every region that could NOT be
|
|
3130
|
+
// read and why, and the fallback region list: this build stopped at the summary
|
|
3131
|
+
// and called nothing found in 21 unread regions a clean report.
|
|
3132
|
+
const regions = Array.isArray(result.regions) ? result.regions : [];
|
|
3133
|
+
if (clusters.length === 0 && regions.length > 0)
|
|
3134
|
+
(0, render_1.say)(io, `no ${bool(invocation.options.force) ? '' : 'houston '}clusters found in ` +
|
|
3135
|
+
`${String(regions.length)} region(s)`);
|
|
3136
|
+
const unreadable = bags(result.unreadable);
|
|
3137
|
+
if (unreadable.length > 0) {
|
|
3138
|
+
(0, render_1.say)(io, `${String(unreadable.length)} region(s) could NOT be read — this report does not ` +
|
|
3139
|
+
'cover them:');
|
|
3140
|
+
for (const bad of unreadable)
|
|
3141
|
+
(0, render_1.say)(io, ` ${(0, render_1.ljust)((0, format_1.toTextAny)(bad.region), 15)} ${(0, format_1.toTextAny)(bad.why)}`);
|
|
3142
|
+
}
|
|
3143
|
+
if ((0, format_1.isTruthy)(result.fallback))
|
|
3144
|
+
(0, render_1.say)(io, 'swept a built-in region list because the account could not be asked which are ' +
|
|
3145
|
+
`enabled (${(0, format_1.toTextAny)(result.fallback)})`);
|
|
3146
|
+
// ENDS WITH WHAT TO DO NEXT, as every cluster action does: pricing the first one
|
|
3147
|
+
// found -- by its own name, which is enough -- or, with none, how to get one.
|
|
3148
|
+
(0, render_1.say)(io, clusters.length > 0
|
|
3149
|
+
? `next houston cluster status --context ${(0, format_1.toTextAny)(clusters[0]?.name)}`
|
|
3150
|
+
: 'next houston cluster guide');
|
|
3151
|
+
}
|
|
3152
|
+
else if (action === 'connect') {
|
|
3153
|
+
(0, render_1.say)(io, `connected ${display(result.context)} in account ${display(result.account)}`);
|
|
3154
|
+
if (result.reachable === true) {
|
|
3155
|
+
(0, render_1.say)(io, 'Kubernetes responds; workspace permissions and preparation still need checking.');
|
|
3156
|
+
(0, render_1.say)(io, `next houston cluster status --context ${display(result.context)}`);
|
|
3157
|
+
(0, render_1.say)(io, `then houston up --version <version> --name <ticket> --context ${display(result.context)}`);
|
|
3158
|
+
}
|
|
3159
|
+
else
|
|
3160
|
+
(0, render_1.say)(io, `Kubernetes access is not ready: ${display(result.access_reason)}. Check the EKS access entry for ${display(result.principal)}.`);
|
|
3161
|
+
}
|
|
3162
|
+
else if (action === 'prepare') {
|
|
3163
|
+
// The context it RESOLVED, not --context as typed (empty when the default was used),
|
|
3164
|
+
// and the adopted and next-command lines.
|
|
3165
|
+
const context = display(value.__context);
|
|
3166
|
+
(0, render_1.say)(io, `${context} is ready to serve a workspace`);
|
|
3167
|
+
(0, render_1.say)(io, ` storage ${display(result.storage_class)}`);
|
|
3168
|
+
(0, render_1.say)(io, ` ingress ${display(result.ingress_class)}`);
|
|
3169
|
+
(0, render_1.say)(io, ' certs cert-manager installed');
|
|
3170
|
+
if ((0, format_1.isTruthy)(result.already)) {
|
|
3171
|
+
const adopted = (Array.isArray(result.already) ? result.already : []).map((item) => (0, format_1.toTextAny)(item));
|
|
3172
|
+
(0, render_1.say)(io, ` adopted ${adopted.join(', ')} — left as they were`);
|
|
3173
|
+
}
|
|
3174
|
+
// A cluster with a zone names the workspace <name>.<zone> by itself.
|
|
3175
|
+
if ((0, format_1.isTruthy)(result.cname_target))
|
|
3176
|
+
(0, render_1.say)(io, ' then: houston up --version 8.5.1 --name t1 --runtime kubernetes ' +
|
|
3177
|
+
`--context ${context}${(0, format_1.isTruthy)(result.zone) ? '' : ' --domain <hostname>'}`);
|
|
3178
|
+
const short = (display(result.context) || context).split('/').pop() ?? context;
|
|
3179
|
+
(0, render_1.say)(io, `next houston up --version <version> --name <ticket> --context ${short}`);
|
|
3180
|
+
}
|
|
3181
|
+
else if (action === 'forget') {
|
|
3182
|
+
io.writeOut(`forgot ${display(result.context)} — the cluster itself was not touched\n`);
|
|
3183
|
+
(0, render_1.say)(io, 'next houston cluster overview');
|
|
3184
|
+
}
|
|
3185
|
+
else if (action === 'overview')
|
|
3186
|
+
renderClusterOverview(io, result);
|
|
3187
|
+
else if (action === 'share') {
|
|
3188
|
+
(0, render_1.say)(io, `${display(result.principal)} may run workspaces on ${(0, format_1.quotedText)(display(result.name))}` +
|
|
3189
|
+
((0, format_1.isTruthy)(result.already) ? ' (the access entry was already there)' : ''));
|
|
3190
|
+
(0, render_1.say)(io, ' they run, once and then per ticket:');
|
|
3191
|
+
for (const line of Array.isArray(result.lines) ? result.lines : [])
|
|
3192
|
+
(0, render_1.say)(io, ` ${display(line)}`);
|
|
3193
|
+
(0, render_1.say)(io, 'next houston cluster overview');
|
|
3194
|
+
}
|
|
3195
|
+
else if (action === 'keep') {
|
|
3196
|
+
(0, render_1.say)(io, `kept ${(0, format_1.quotedText)(display(result.name))} until ${display(result.expires)} ` +
|
|
3197
|
+
`(${display(result.days)} d) — a reminder tag; \`houston doctor\` and ` +
|
|
3198
|
+
'`houston cluster overview` say so once it passes');
|
|
3199
|
+
(0, render_1.say)(io, 'next houston cluster overview');
|
|
3200
|
+
}
|
|
3201
|
+
else if (action === 'create') {
|
|
3202
|
+
// The expiry or its absence, and the line people copy. NOT "cluster 'X' is up in R":
|
|
3203
|
+
// createCluster emits that as an event and emitOf prints every event, so the summary
|
|
3204
|
+
// repeated it one line under the first.
|
|
3205
|
+
const name = display(invocation.arguments.name);
|
|
3206
|
+
if ((0, format_1.isTruthy)(result.expires))
|
|
3207
|
+
(0, render_1.say)(io, ` tagged as wanted until ${(0, format_1.toTextAny)(result.expires)} — ` +
|
|
3208
|
+
'`houston doctor` says so once that passes');
|
|
3209
|
+
else
|
|
3210
|
+
(0, render_1.say)(io, ' no expiry set — nothing will remind you this is running');
|
|
3211
|
+
const prepared = bag(result.prepared);
|
|
3212
|
+
(0, render_1.say)(io, ' point a workspace at it: houston up --version 8.5.1 ' +
|
|
3213
|
+
`--name TICKET-1234 --context ${name}` +
|
|
3214
|
+
((0, format_1.isTruthy)(prepared.zone) ? '' : ' --domain <hostname>'));
|
|
3215
|
+
if ((0, format_1.isTruthy)(prepared.cname_target)) {
|
|
3216
|
+
const zone = (0, format_1.toText)(prepared.zone) || '<your zone>';
|
|
3217
|
+
(0, render_1.say)(io, `next point *.${zone} at ${(0, format_1.toText)(prepared.cname_target)} (a CNAME, once, at your DNS provider), then:`);
|
|
3218
|
+
(0, render_1.say)(io, ` houston up --version <version> --name <ticket> --context ${name}`);
|
|
3219
|
+
}
|
|
3220
|
+
else {
|
|
3221
|
+
(0, render_1.say)(io, `next houston up --version <version> --name <ticket> --context ${name}`);
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
else if (action === 'delete') {
|
|
3225
|
+
if (result.said !== true)
|
|
3226
|
+
io.writeOut(result.deleted === true
|
|
3227
|
+
? `cluster ${(0, format_1.quotedText)(display(result.name))} is gone\n`
|
|
3228
|
+
: `no cluster named ${(0, format_1.quotedText)(display(result.name))} to delete\n`);
|
|
3229
|
+
if (result.deleted === true && (0, format_1.isTruthy)(result.leftovers)) {
|
|
3230
|
+
const left = bag(result.leftovers);
|
|
3231
|
+
const found = Array.isArray(left.found) ? left.found : [];
|
|
3232
|
+
const unreadable = Array.isArray(left.unreadable) ? left.unreadable : [];
|
|
3233
|
+
const region = display(result.region);
|
|
3234
|
+
if (found.length === 0 && unreadable.length === 0) {
|
|
3235
|
+
(0, render_1.say)(io, `nothing in ${region} is billing — AWS holds no volume, load balancer, NAT gateway, address or stack of it`);
|
|
3236
|
+
}
|
|
3237
|
+
else {
|
|
3238
|
+
// Tied to this cluster by a tag: with the command. Not tied: to check, without
|
|
3239
|
+
// one -- in a region that holds colleagues' clusters, a command for something
|
|
3240
|
+
// nothing ties to this cluster is a command that can break theirs.
|
|
3241
|
+
const tied = found.filter((row) => row.certain !== false);
|
|
3242
|
+
const loose = found.filter((row) => row.certain === false);
|
|
3243
|
+
if (tied.length > 0)
|
|
3244
|
+
(0, render_1.say)(io, `left behind in ${region} — each one bills until it is removed:`);
|
|
3245
|
+
for (const row of tied) {
|
|
3246
|
+
(0, render_1.say)(io, ` ${display(row.kind)} ${display(row.id)} ${display(row.detail)}`);
|
|
3247
|
+
(0, render_1.say)(io, ` ${display(row.fix)}`);
|
|
3248
|
+
}
|
|
3249
|
+
if (loose.length > 0)
|
|
3250
|
+
(0, render_1.say)(io, `in ${region}, not tied to this cluster by any tag — check before deleting:`);
|
|
3251
|
+
for (const row of loose)
|
|
3252
|
+
(0, render_1.say)(io, ` ${display(row.kind)} ${display(row.id)} ${display(row.detail)}`);
|
|
3253
|
+
for (const row of unreadable) {
|
|
3254
|
+
(0, render_1.say)(io, ` ${display(row.kind)}: could not be read (${display(row.why)}) — check it in AWS`);
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
(0, render_1.say)(io, 'next houston cluster list # every region, so nothing is missed');
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
else {
|
|
3261
|
+
// A reachable cluster: runCluster answered the other two stops itself.
|
|
3262
|
+
(0, render_1.say)(io, `cluster ${display(result.context, '(none)')}`);
|
|
3263
|
+
renderClusterAbout(io, result);
|
|
3264
|
+
renderClusterShape(io, result);
|
|
3265
|
+
renderClusterCost(io, result);
|
|
3266
|
+
renderClusterNext(io, result);
|
|
3267
|
+
}
|
|
3268
|
+
return;
|
|
3269
|
+
case 'serve':
|
|
3270
|
+
case 'logs':
|
|
3271
|
+
case 'capabilities':
|
|
3272
|
+
return;
|
|
3273
|
+
default:
|
|
3274
|
+
throw new Error(`human renderer missing for ${path}`);
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
function createExecutor(io, dependencies = {}) {
|
|
3278
|
+
return async (invocation) => {
|
|
3279
|
+
// Published once per command, as the root callback publishes it, so the service layer
|
|
3280
|
+
// audits, names and gates by who is running this without every call passing it down.
|
|
3281
|
+
const [actor, origin] = (0, actor_1.cliActorAndOrigin)();
|
|
3282
|
+
return await (0, context_1.runWithContext)({ actor, origin }, async () => await execute(invocation));
|
|
3283
|
+
};
|
|
3284
|
+
async function execute(invocation) {
|
|
3285
|
+
const result = await dispatch(invocation, dependencies, io);
|
|
3286
|
+
const data = typeof result === 'object' &&
|
|
3287
|
+
result !== null &&
|
|
3288
|
+
result.commandOutcome === true
|
|
3289
|
+
? result.data
|
|
3290
|
+
: result;
|
|
3291
|
+
if (!(0, jsonout_1.active)())
|
|
3292
|
+
await renderHuman(invocation, data, io);
|
|
3293
|
+
return result;
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
const processIo = {
|
|
3297
|
+
writeOut: (value) => process.stdout.write(value),
|
|
3298
|
+
writeErr: (value) => process.stderr.write(value),
|
|
3299
|
+
};
|
|
3300
|
+
/** Production executor, loaded lazily by tools/cli.js after Commander has parsed argv. */
|
|
3301
|
+
exports.executeCommand = createExecutor(processIo);
|
|
3302
|
+
/** 128 + SIGINT: the exit status when Ctrl-C stops a command. */
|
|
3303
|
+
const INTERRUPTED = 130;
|
|
3304
|
+
/**
|
|
3305
|
+
* Resolves once `stream` holds nothing unwritten: every queued byte has reached the reader,
|
|
3306
|
+
* or the stream has failed. A failure is left to the stream's 'error' listener, which Node
|
|
3307
|
+
* calls before 'close' -- so `runMain`'s EPIPE answer is given before this resolves.
|
|
3308
|
+
*/
|
|
3309
|
+
function flushed(stream) {
|
|
3310
|
+
if (stream.destroyed || (stream.errored === null && stream.writableLength === 0)) {
|
|
3311
|
+
return Promise.resolve();
|
|
3312
|
+
}
|
|
3313
|
+
return new Promise((resolve) => {
|
|
3314
|
+
const closed = () => resolve();
|
|
3315
|
+
stream.once('close', closed);
|
|
3316
|
+
if (stream.errored !== null)
|
|
3317
|
+
return;
|
|
3318
|
+
// An empty write's callback runs once everything queued before it has been written.
|
|
3319
|
+
stream.write('', (error) => {
|
|
3320
|
+
if (error !== null && error !== undefined)
|
|
3321
|
+
return;
|
|
3322
|
+
stream.off('close', closed);
|
|
3323
|
+
resolve();
|
|
3324
|
+
});
|
|
3325
|
+
});
|
|
3326
|
+
}
|
|
3327
|
+
/**
|
|
3328
|
+
* The CLI's main: the command, inside the durable record of it.
|
|
3329
|
+
*
|
|
3330
|
+
* An earlier version wrote no `start`/`end` line for a CLI command at all -- only `serve`
|
|
3331
|
+
* leased the sink -- so the event log held nothing a CLI run did. Logging never stops the
|
|
3332
|
+
* command: every step here is best-effort.
|
|
3333
|
+
*
|
|
3334
|
+
* CTRL-C IS AN EXIT, NOT A DEATH. With no SIGINT listener, Node dies by the signal: no `end`
|
|
3335
|
+
* record, and a signalled wait status where the established answer is exit 130. That answer
|
|
3336
|
+
* was MEASURED, with real processes of the previous implementation, SIGINT sent once each
|
|
3337
|
+
* was blocked: `ready --name <ws> --timeout 60` polling, with and without `--json`, and
|
|
3338
|
+
* `logs --name <ws> --follow` waiting on its child, each exit 130 with NOTHING on stdout or
|
|
3339
|
+
* stderr beyond what the command had already printed (no envelope under `--json`) and a last
|
|
3340
|
+
* record of `end`, exit 130. An interrupt raised inside the command is a silent exit 130. A
|
|
3341
|
+
* command that listens for SIGINT itself keeps it -- `stats --watch` and `serve` stop and
|
|
3342
|
+
* exit 0, as they always have, and a question is `Aborted.` (see `interruptible`) -- so this
|
|
3343
|
+
* handler steps aside for any SIGINT listener registered after it.
|
|
3344
|
+
*
|
|
3345
|
+
* On a terminal the Ctrl-C also kills the child a command is waiting on, and Node can hand
|
|
3346
|
+
* JS that death before this handler's SIGINT: `logs` returned 0 and the `finally` below
|
|
3347
|
+
* removed the handler first, so the run was recorded as `end` 0 (14 of 300 pty runs). The
|
|
3348
|
+
* exec seam now holds such a death back long enough for the interrupt to land first; see
|
|
3349
|
+
* `INTERRUPT_GRACE_MS` in src/seams/exec.ts.
|
|
3350
|
+
*
|
|
3351
|
+
* AND WHAT IT STOPS, IT STOPS AS IT ALWAYS HAS. The handler used to be `process.exit(130)`,
|
|
3352
|
+
* which skips everything an interrupt must run on its way out: the child it was waiting on
|
|
3353
|
+
* was left running (it is owed 0.25 s, then a SIGKILL), a flock(1) waiter left to take the
|
|
3354
|
+
* lock later, and every `finally` the command had. The interrupt is now the exec seam's
|
|
3355
|
+
* (`interrupt` in src/seams/exec.ts): the waits it can reach -- children, the lock wait, HTTP
|
|
3356
|
+
* requests, rcapi's sleeps -- are taken over, a child killed after that grace
|
|
3357
|
+
* (`POPEN_SIGINT_WAIT_MS`). Inside a body that asked to be UNWOUND (`unwindsOnInterrupt`,
|
|
3358
|
+
* where the cleanup is) they raise Interrupted, the command's `finally` and `catch`
|
|
3359
|
+
* blocks run, and `runCli` answers it with exit 130 and nothing more. Anywhere else the
|
|
3360
|
+
* process ends once the waits are stopped, with the `end` record as before. Either way a run
|
|
3361
|
+
* that took a Ctrl-C ends 130 here, whatever a `catch` it passed through made of it.
|
|
3362
|
+
*
|
|
3363
|
+
* NOT REPRODUCED, on purpose: the previous implementation's `interrupted` line -- written to
|
|
3364
|
+
* STDOUT, as every warning line is -- for an interrupt raised before argv is parsed. Measured
|
|
3365
|
+
* by racing the signal against the `start` record, that window is under 10 ms. Nothing
|
|
3366
|
+
* between this function's `start` record and the command yields to the event loop, where Node
|
|
3367
|
+
* delivers a signal, so here the same race is answered inside the command, silently.
|
|
3368
|
+
*
|
|
3369
|
+
* Not armed before the event log, as the previous implementation was not: there a Ctrl-C
|
|
3370
|
+
* during startup is a stack trace and a death by SIGINT, with no record at all. SIGTERM and
|
|
3371
|
+
* SIGHUP are left alone, as they always have been: both die by those, with no `end` record.
|
|
3372
|
+
*
|
|
3373
|
+
* A READER THAT HAS GONE AWAY IS AN EXIT TOO. `houston audit -n 5000 | head -1`
|
|
3374
|
+
* closes the pipe while the table is still being written. The established answer fails the
|
|
3375
|
+
* write there and then, and exits 1 with nothing on stderr and an `end` 1 record. Node
|
|
3376
|
+
* records the failure on the stream and emits it as an 'error' event later, and
|
|
3377
|
+
* with no listener that was an unhandled 'error': a 25-line stack on stderr, landing AFTER
|
|
3378
|
+
* the `end` record had said 0, since the rest of the command ran first. So a stream's EPIPE
|
|
3379
|
+
* is answered here as Ctrl-C is: `end` 1 and exit 1, silently, whenever it lands. And the
|
|
3380
|
+
* `end` record waits for stdout and stderr to hold nothing unwritten (`flushed`): an echo
|
|
3381
|
+
* returns once its bytes are in the pipe, a Node write can still be queued when the command
|
|
3382
|
+
* returns, and a queued write that fails must be answered as the EPIPE it is, not recorded as
|
|
3383
|
+
* a success first.
|
|
3384
|
+
*
|
|
3385
|
+
* ANY OTHER FAILED WRITE IS AN UNHANDLED ERROR. Only EPIPE is answered as an exit; the rest
|
|
3386
|
+
* is thrown on, so `houston list > file` on a full disk, or a terminal that hung up, reaches
|
|
3387
|
+
* `main`'s catch-all. On stdout that is the stack trace, `end` 1, an `error` REPRO_ERROR record
|
|
3388
|
+
* with `trace`, "error: No space left on device - this is unhandled, ..." (no envelope
|
|
3389
|
+
* under --json, since writing it fails too, and no error line after it), and then the failure
|
|
3390
|
+
* to flush stdout at shutdown: "error: could not flush stdout: ..." and exit 120. On
|
|
3391
|
+
* stderr the stack trace itself cannot be printed, so the exception leaves `main` before its
|
|
3392
|
+
* `end` record is written: none is, and the status is 120. This build rethrew anything but
|
|
3393
|
+
* EPIPE from the 'error' listener: a Node stack, exit 1, and `start` alone in the log.
|
|
3394
|
+
*
|
|
3395
|
+
* A FAILED WRITE BEFORE THE COMMAND IS SWALLOWED, AND COUNTED AT EXIT. Outside the command,
|
|
3396
|
+
* every write is inside a handler that lets nothing through: the pre-rename adoption's, and
|
|
3397
|
+
* `reportBeforeCommand`'s. So a stderr that is a closed pipe during the adoption stops the
|
|
3398
|
+
* MIGRATION at its first message -- the skill copies and the edge handover after it do not
|
|
3399
|
+
* run -- and the command then runs to the end, and a startup refusal still exits with its
|
|
3400
|
+
* code; either way the flush of the stream at shutdown fails, and the status is 120. This
|
|
3401
|
+
* build had no listener before the command's own: the adoption moved the directory and died
|
|
3402
|
+
* of an unhandled 'error' event, exit 1, with no marker claimed and no log.
|
|
3403
|
+
* `keepWriteFailures` now records such a failure from the first line, the adoption's messages
|
|
3404
|
+
* throw on a failed write, and every way out goes through `atShutdown`.
|
|
3405
|
+
*/
|
|
3406
|
+
async function runMain(argv) {
|
|
3407
|
+
// ORDER IS THE WHOLE FIX: the pre-rename adoption first, since
|
|
3408
|
+
// it moves `~/.rc-repro` onto this path and one log line would make the destination
|
|
3409
|
+
// non-empty; then the ownership check, which must judge the home adoption produced; and
|
|
3410
|
+
// only then the event log, which is the first write. A build about to be refused must
|
|
3411
|
+
// not have written to the home on its way to being refused.
|
|
3412
|
+
//
|
|
3413
|
+
// The version FIRST of all: adoption reinstalls a pre-rename agent skill, and the sidecar
|
|
3414
|
+
// it writes records the version that wrote it. The version must be known from the first
|
|
3415
|
+
// line; here it was still jsonout's placeholder until runCli set it, so an adopted
|
|
3416
|
+
// skill said "houston_version": "0.0.0" on disk, outside HOUSTON_HOME, for good.
|
|
3417
|
+
(0, jsonout_1.setHoustonVersion)(require('../../package.json').version);
|
|
3418
|
+
// From the first write on, a failed one is kept rather than thrown: see "A FAILED WRITE
|
|
3419
|
+
// BEFORE THE COMMAND" above.
|
|
3420
|
+
keepWriteFailures();
|
|
3421
|
+
await adoptPreRenameState();
|
|
3422
|
+
try {
|
|
3423
|
+
const lock = require('../lib/lock');
|
|
3424
|
+
const config = require('../lib/config');
|
|
3425
|
+
// THE MARKER WINDOW: a home the previous implementation left is validated and
|
|
3426
|
+
// promoted here, before the ownership check judges it, and the caller is told once --
|
|
3427
|
+
// on stderr, so a `--json` stdout stays one envelope. A failure is a refusal like any
|
|
3428
|
+
// other before the command, and leaves the home exactly as it was.
|
|
3429
|
+
const promote = require('../core/promote');
|
|
3430
|
+
const adopted = await promote.adoptRetiredHome(config.home());
|
|
3431
|
+
if (adopted !== null)
|
|
3432
|
+
writeStderr(`${adopted}\n`);
|
|
3433
|
+
lock.requireThisImplementation(config.home());
|
|
3434
|
+
}
|
|
3435
|
+
catch (error) {
|
|
3436
|
+
if (error instanceof errors_1.ReproError)
|
|
3437
|
+
return atShutdown((0, app_1.reportBeforeCommand)(error, argv));
|
|
3438
|
+
throw error;
|
|
3439
|
+
}
|
|
3440
|
+
// Whether this build was dispatched for this command, for the event log -- and the
|
|
3441
|
+
// dispatch variables removed from the environment, now that the claim has read them, so
|
|
3442
|
+
// no child process inherits them.
|
|
3443
|
+
const via = require('../lib/lock').consumeDispatch();
|
|
3444
|
+
const eventlog = require('../core/eventlog');
|
|
3445
|
+
// Rotated before this run's first write when the log is over its cap: so a run's `start`
|
|
3446
|
+
// lands in a fresh file, never in the one about to become `.1`.
|
|
3447
|
+
await eventlog.rotateIfOver();
|
|
3448
|
+
const began = performance.now();
|
|
3449
|
+
let unregister = () => undefined;
|
|
3450
|
+
// Whether this run's `start` was written, and so whether it gets an `end`: when any of
|
|
3451
|
+
// these three throws there is no `start`, and no `end` either. What throws in practice is
|
|
3452
|
+
// the actor, from an accounts file that cannot be read -- measured with `users` a
|
|
3453
|
+
// directory: the established log holds ONE `error` record for `up --help` and nothing for
|
|
3454
|
+
// `--help`, where this build wrote an `end` for each, a run with an exit code and no
|
|
3455
|
+
// command to count it against.
|
|
3456
|
+
let recorded = false;
|
|
3457
|
+
// The `end` record is written once, by whichever way out the run takes first.
|
|
3458
|
+
let ended = false;
|
|
3459
|
+
const end = (code) => {
|
|
3460
|
+
if (ended)
|
|
3461
|
+
return;
|
|
3462
|
+
ended = true;
|
|
3463
|
+
try {
|
|
3464
|
+
if (recorded)
|
|
3465
|
+
eventlog.ended(code, (performance.now() - began) / 1000);
|
|
3466
|
+
}
|
|
3467
|
+
catch {
|
|
3468
|
+
/* best-effort */
|
|
3469
|
+
}
|
|
3470
|
+
try {
|
|
3471
|
+
unregister();
|
|
3472
|
+
}
|
|
3473
|
+
catch {
|
|
3474
|
+
/* best-effort */
|
|
3475
|
+
}
|
|
3476
|
+
};
|
|
3477
|
+
// Whether this handler answered a Ctrl-C: the run then ends 130.
|
|
3478
|
+
const ctrlC = { answered: false };
|
|
3479
|
+
const interrupted = () => {
|
|
3480
|
+
// A listener registered after this one is the command's own, and answers the signal. It
|
|
3481
|
+
// is still listed while this runs: emit calls a copy, in the order they were registered.
|
|
3482
|
+
const listeners = process.listeners('SIGINT');
|
|
3483
|
+
if (listeners[listeners.length - 1] !== interrupted)
|
|
3484
|
+
return;
|
|
3485
|
+
ctrlC.answered = true;
|
|
3486
|
+
require('../seams/exec').interrupt(() => {
|
|
3487
|
+
end(INTERRUPTED);
|
|
3488
|
+
process.exit(atShutdown(INTERRUPTED));
|
|
3489
|
+
});
|
|
3490
|
+
};
|
|
3491
|
+
// A failed write: see "A READER THAT HAS GONE AWAY" and "ANY OTHER FAILED WRITE" above.
|
|
3492
|
+
// A failure from before the command -- the adoption's, a refusal's -- was swallowed where it
|
|
3493
|
+
// happened and counts at exit; only a write the command makes is answered here.
|
|
3494
|
+
const earlier = { stdout: failureOf('stdout'), stderr: failureOf('stderr') };
|
|
3495
|
+
const writeFailed = (stream, error) => {
|
|
3496
|
+
if (error === earlier[stream])
|
|
3497
|
+
return;
|
|
3498
|
+
unwritten[stream] ?? (unwritten[stream] = error);
|
|
3499
|
+
if (error.code === 'EPIPE') {
|
|
3500
|
+
end(1);
|
|
3501
|
+
// Unless the usage panel was written: that path answers the pipe itself with exit 1,
|
|
3502
|
+
// and the flush at shutdown is not pacified.
|
|
3503
|
+
const rich = stream === 'stderr' && (0, app_1.usagePanelWritten)();
|
|
3504
|
+
process.exit(atShutdown(1, { pacified: !rich }));
|
|
3505
|
+
}
|
|
3506
|
+
if (stream === 'stdout')
|
|
3507
|
+
reportUnwritableStdout(error, argv, end);
|
|
3508
|
+
process.exit(atShutdown(1));
|
|
3509
|
+
};
|
|
3510
|
+
const stdoutFailed = (error) => writeFailed('stdout', error);
|
|
3511
|
+
const stderrFailed = (error) => writeFailed('stderr', error);
|
|
3512
|
+
// In the same synchronous step as the `start` record, and BEFORE it: Node delivers a signal
|
|
3513
|
+
// only at the next turn of the event loop, so from here on every Ctrl-C is answered after
|
|
3514
|
+
// the `start` record and with an `end` one. Armed after it, a signal in the few
|
|
3515
|
+
// microseconds between was a death with no `end` record (measured: 5 of 5 when sent the
|
|
3516
|
+
// instant the record landed).
|
|
3517
|
+
process.on('SIGINT', interrupted);
|
|
3518
|
+
process.stdout.on('error', stdoutFailed);
|
|
3519
|
+
process.stderr.on('error', stderrFailed);
|
|
3520
|
+
try {
|
|
3521
|
+
unregister = eventlog.installEventlogSink();
|
|
3522
|
+
eventlog.configure({ via });
|
|
3523
|
+
eventlog.started((0, redact_1.redactArgv)(argv).join(' '), (0, actor_1.cliActorAndOrigin)()[0]);
|
|
3524
|
+
recorded = true;
|
|
3525
|
+
}
|
|
3526
|
+
catch {
|
|
3527
|
+
/* logging must never stop the command */
|
|
3528
|
+
}
|
|
3529
|
+
let code = 1;
|
|
3530
|
+
try {
|
|
3531
|
+
code = await (0, app_1.runCli)(argv, { execute: exports.executeCommand });
|
|
3532
|
+
if (ctrlC.answered)
|
|
3533
|
+
code = INTERRUPTED;
|
|
3534
|
+
await flushed(process.stdout);
|
|
3535
|
+
await flushed(process.stderr);
|
|
3536
|
+
// A failure a stream has recorded and not yet emitted is still this run's: the write
|
|
3537
|
+
// failed inside the command.
|
|
3538
|
+
if (process.stdout.errored !== null)
|
|
3539
|
+
stdoutFailed(process.stdout.errored);
|
|
3540
|
+
if (process.stderr.errored !== null)
|
|
3541
|
+
stderrFailed(process.stderr.errored);
|
|
3542
|
+
return atShutdown(code);
|
|
3543
|
+
}
|
|
3544
|
+
finally {
|
|
3545
|
+
process.off('SIGINT', interrupted);
|
|
3546
|
+
process.stdout.off('error', stdoutFailed);
|
|
3547
|
+
process.stderr.off('error', stderrFailed);
|
|
3548
|
+
// And before `end`, so a run's `end` follows its `start` wherever the rotation put it.
|
|
3549
|
+
if (recorded)
|
|
3550
|
+
await eventlog.rotateIfOver();
|
|
3551
|
+
end(code);
|
|
3552
|
+
if (ctrlC.answered) {
|
|
3553
|
+
// The unwind is done, and the process exits here: a killed child's pipes, or a request
|
|
3554
|
+
// the interrupt abandoned, must not hold the process open after it.
|
|
3555
|
+
await require('../seams/exec').interruptSettled();
|
|
3556
|
+
process.exit(atShutdown(code));
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
/** The exit status when stdout or stderr cannot be flushed at shutdown, as it has always been. */
|
|
3561
|
+
const FLUSH_FAILED = 120;
|
|
3562
|
+
/** The error a failed write is reported as: `Broken pipe` for EPIPE, else `fileErrorOf`'s. */
|
|
3563
|
+
function writeErrorText(error) {
|
|
3564
|
+
if (error.code !== 'EPIPE')
|
|
3565
|
+
return (0, format_1.fileErrorOf)(error);
|
|
3566
|
+
const broken = new Error('Broken pipe');
|
|
3567
|
+
broken.name = 'BrokenPipe';
|
|
3568
|
+
return broken;
|
|
3569
|
+
}
|
|
3570
|
+
/**
|
|
3571
|
+
* The first failed write on each stream, whose bytes count as still buffered at shutdown.
|
|
3572
|
+
* Kept here because a Node stdio stream does not keep it: `errored` is set by the failing write
|
|
3573
|
+
* and cleared again once its 'error' event has been emitted.
|
|
3574
|
+
*/
|
|
3575
|
+
const unwritten = {
|
|
3576
|
+
stdout: null,
|
|
3577
|
+
stderr: null,
|
|
3578
|
+
};
|
|
3579
|
+
/** Record, never throw, a failed write on either stream: once per process. */
|
|
3580
|
+
function keepWriteFailures() {
|
|
3581
|
+
if (keepingWriteFailures)
|
|
3582
|
+
return;
|
|
3583
|
+
keepingWriteFailures = true;
|
|
3584
|
+
process.stdout.on('error', (error) => {
|
|
3585
|
+
unwritten.stdout ?? (unwritten.stdout = error);
|
|
3586
|
+
});
|
|
3587
|
+
process.stderr.on('error', (error) => {
|
|
3588
|
+
unwritten.stderr ?? (unwritten.stderr = error);
|
|
3589
|
+
});
|
|
3590
|
+
}
|
|
3591
|
+
let keepingWriteFailures = false;
|
|
3592
|
+
/** A stream's failure, recorded or still waiting to be emitted. */
|
|
3593
|
+
function failureOf(stream) {
|
|
3594
|
+
return unwritten[stream] ?? process[stream].errored;
|
|
3595
|
+
}
|
|
3596
|
+
/** A line on stderr, unless stderr has failed: then there is nowhere to say it. */
|
|
3597
|
+
function writeStderr(text) {
|
|
3598
|
+
if (failureOf('stderr') === null)
|
|
3599
|
+
process.stderr.write(text);
|
|
3600
|
+
}
|
|
3601
|
+
/**
|
|
3602
|
+
* The status the process exits with once the program has chosen `code`.
|
|
3603
|
+
*
|
|
3604
|
+
* Both streams are flushed on the way out, and a stream whose earlier write failed still
|
|
3605
|
+
* holds those bytes, so the flush fails again and the status is 120 whatever the program
|
|
3606
|
+
* chose. For stdout that is said first, on stderr; for stderr it cannot be. Once a broken
|
|
3607
|
+
* pipe has been answered as an exit (`pacified`), both streams swallow EPIPE at that flush
|
|
3608
|
+
* and nothing else.
|
|
3609
|
+
*/
|
|
3610
|
+
function atShutdown(code, { pacified = false } = {}) {
|
|
3611
|
+
// Once: the process shuts down once, however many ways out reach here.
|
|
3612
|
+
if (shutdownStatus !== null)
|
|
3613
|
+
return shutdownStatus;
|
|
3614
|
+
const unflushed = (stream) => {
|
|
3615
|
+
const failure = failureOf(stream);
|
|
3616
|
+
return failure !== null && !(pacified && failure.code === 'EPIPE') ? failure : null;
|
|
3617
|
+
};
|
|
3618
|
+
const stdout = unflushed('stdout');
|
|
3619
|
+
const stderr = unflushed('stderr');
|
|
3620
|
+
if (stdout !== null) {
|
|
3621
|
+
const raised = writeErrorText(stdout);
|
|
3622
|
+
writeStderr(`error: could not flush stdout: ${raised.message}\n`);
|
|
3623
|
+
}
|
|
3624
|
+
shutdownStatus = stdout !== null || stderr !== null ? FLUSH_FAILED : code;
|
|
3625
|
+
return shutdownStatus;
|
|
3626
|
+
}
|
|
3627
|
+
let shutdownStatus = null;
|
|
3628
|
+
/**
|
|
3629
|
+
* `main`'s catch-all, for a write to stdout that failed with anything but EPIPE: the
|
|
3630
|
+
* stack trace, `end` 1, the `error` record, and the report -- whose envelope, under --json,
|
|
3631
|
+
* is one more write to the stdout that just failed, so it throws before the error line.
|
|
3632
|
+
*/
|
|
3633
|
+
function reportUnwritableStdout(error, argv, end) {
|
|
3634
|
+
const raised = writeErrorText(error);
|
|
3635
|
+
const message = `${raised.message} - this is unhandled, and the stack trace is on stderr. ` +
|
|
3636
|
+
'If it names a file under HOUSTON_HOME, that file is the problem.';
|
|
3637
|
+
writeStderr(`${error.stack ?? String(error)}\n`);
|
|
3638
|
+
end(1);
|
|
3639
|
+
try {
|
|
3640
|
+
require('../core/eventlog').failed(errors_1.ReproError.code, message, {
|
|
3641
|
+
stackTraceOnStderr: true,
|
|
3642
|
+
});
|
|
3643
|
+
}
|
|
3644
|
+
catch {
|
|
3645
|
+
/* never let logging change the exit */
|
|
3646
|
+
}
|
|
3647
|
+
if (!(0, jsonout_1.active)() && !argv.includes('--json'))
|
|
3648
|
+
writeStderr(`error: ${message}\n`);
|
|
3649
|
+
}
|
|
3650
|
+
/**
|
|
3651
|
+
* Move a pre-rename state directory into place, once, before anything reads it. Best-effort
|
|
3652
|
+
* and never fatal -- a box this cannot migrate must still run `doctor`, the command that
|
|
3653
|
+
* explains why. Progress goes to stderr, always: `--json` has not been parsed yet, and stdout
|
|
3654
|
+
* is the envelope's.
|
|
3655
|
+
*/
|
|
3656
|
+
async function adoptPreRenameState(io = processIo) {
|
|
3657
|
+
try {
|
|
3658
|
+
const migrate = require('../core/migrate');
|
|
3659
|
+
if (!migrate.pending())
|
|
3660
|
+
return;
|
|
3661
|
+
await migrate.migrate((event) => {
|
|
3662
|
+
io.writeErr(event.level === 'warn' || event.level === 'error'
|
|
3663
|
+
? `${event.message}\n`
|
|
3664
|
+
: ` ${event.message}\n`);
|
|
3665
|
+
// A failed write throws, which ends the migration at this message.
|
|
3666
|
+
const failed = io === processIo ? failureOf('stderr') : null;
|
|
3667
|
+
if (failed !== null)
|
|
3668
|
+
throw writeErrorText(failed);
|
|
3669
|
+
});
|
|
3670
|
+
}
|
|
3671
|
+
catch (error) {
|
|
3672
|
+
if (error instanceof errors_1.ReproError) {
|
|
3673
|
+
io.writeErr(`${error.message}\n`);
|
|
3674
|
+
// The warning line fails inside the refusal's handler, and nothing above catches it:
|
|
3675
|
+
// the run ends here, before the marker and the log, and fails to flush stderr.
|
|
3676
|
+
if (io === processIo && failureOf('stderr') !== null)
|
|
3677
|
+
process.exit(atShutdown(1));
|
|
3678
|
+
}
|
|
3679
|
+
// anything else: never let this stop a command running
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
/**
|
|
3683
|
+
* The recorded `EXTRA_CONTEXT` when it is truthy, else `names.CONTEXT`: the context a
|
|
3684
|
+
* Kubernetes workspace was created in, or houston's own cluster. An earlier version read
|
|
3685
|
+
* `kubernetes_context` -- the BOX's default-context config key, which no record carries -- so
|
|
3686
|
+
* `logs` and `stats` always passed an empty context and asked whatever kubectl's current
|
|
3687
|
+
* context happened to be.
|
|
3688
|
+
*/
|
|
3689
|
+
function recordedContext(extra) {
|
|
3690
|
+
const config = require('../lib/config');
|
|
3691
|
+
const names = require('../core/kube/names');
|
|
3692
|
+
const recorded = extra[config.EXTRA_CONTEXT];
|
|
3693
|
+
return (0, format_1.storedText)((0, format_1.isTruthy)(recorded) ? recorded : names.CONTEXT);
|
|
3694
|
+
}
|