@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,818 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.sayReady = sayReady;
|
|
37
|
+
exports.readinessFailure = readinessFailure;
|
|
38
|
+
exports.upCompose = upCompose;
|
|
39
|
+
exports.restoreRoute = restoreRoute;
|
|
40
|
+
exports.stopPortForward = stopPortForward;
|
|
41
|
+
exports.finalize = finalize;
|
|
42
|
+
exports.crashLoopTick = crashLoopTick;
|
|
43
|
+
exports.refuseIfServingWithoutADatabase = refuseIfServingWithoutADatabase;
|
|
44
|
+
exports.waitServing = waitServing;
|
|
45
|
+
exports.waitForOneShotSetup = waitForOneShotSetup;
|
|
46
|
+
exports.repairThePortForward = repairThePortForward;
|
|
47
|
+
exports.repairTheScenarioForwards = repairTheScenarioForwards;
|
|
48
|
+
exports.warnAboutServicesWithNoEndpoints = warnAboutServicesWithNoEndpoints;
|
|
49
|
+
exports.refuseAForeignHolder = refuseAForeignHolder;
|
|
50
|
+
exports.refuseADoomedPod = refuseADoomedPod;
|
|
51
|
+
exports.waitServingKubernetes = waitServingKubernetes;
|
|
52
|
+
exports.checkLicense = checkLicense;
|
|
53
|
+
exports.waitAndFinalize = waitAndFinalize;
|
|
54
|
+
/**
|
|
55
|
+
* Waiting for a workspace to actually serve, and the last steps once it does.
|
|
56
|
+
*
|
|
57
|
+
* Tier 3. `waitServing` polls the HTTP surface; the Kubernetes branch also has to keep a
|
|
58
|
+
* port-forward alive while it waits, which is why `waitServingKubernetes` is separate rather
|
|
59
|
+
* than a flag.
|
|
60
|
+
*/
|
|
61
|
+
const receipt_1 = require("../../seed/receipt");
|
|
62
|
+
const config = __importStar(require("../../lib/config"));
|
|
63
|
+
const errors_1 = require("../../lib/errors");
|
|
64
|
+
const events_1 = require("../../lib/events");
|
|
65
|
+
const format_1 = require("../../lib/format");
|
|
66
|
+
const public_1 = require("../../lib/presets/public");
|
|
67
|
+
const versions_1 = require("../../lib/versions");
|
|
68
|
+
const exec_1 = require("../../seams/exec");
|
|
69
|
+
const diagnose_1 = require("../diagnose");
|
|
70
|
+
const edge = __importStar(require("../edge/acme"));
|
|
71
|
+
const engine_1 = require("../edge/engine");
|
|
72
|
+
const runtime_1 = require("../edge/runtime");
|
|
73
|
+
const routes_1 = require("../edge/routes");
|
|
74
|
+
const forward_1 = require("../kube/forward");
|
|
75
|
+
const namespace_1 = require("../kube/namespace");
|
|
76
|
+
const status_1 = require("../kube/status");
|
|
77
|
+
const names_1 = require("../kube/names");
|
|
78
|
+
const rcapi_1 = require("../rcapi");
|
|
79
|
+
const engine = __importStar(require("../runner/engine"));
|
|
80
|
+
const record_1 = require("../runner/record");
|
|
81
|
+
const queries_1 = require("../runner/queries");
|
|
82
|
+
const postready = __importStar(require("../postready"));
|
|
83
|
+
const topology = __importStar(require("../topology"));
|
|
84
|
+
const tls_1 = require("../tls");
|
|
85
|
+
const admin_1 = require("./admin");
|
|
86
|
+
const notes_1 = require("./notes");
|
|
87
|
+
const inspect = __importStar(require("./inspect"));
|
|
88
|
+
const seeding = __importStar(require("./seeding"));
|
|
89
|
+
const journal_1 = require("../journal");
|
|
90
|
+
const types_1 = require("./types");
|
|
91
|
+
function bag(value) {
|
|
92
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
93
|
+
? value
|
|
94
|
+
: {};
|
|
95
|
+
}
|
|
96
|
+
function isTruthy(value) {
|
|
97
|
+
if (value === null || value === undefined || value === false)
|
|
98
|
+
return false;
|
|
99
|
+
if (typeof value === 'string')
|
|
100
|
+
return value !== '';
|
|
101
|
+
if (typeof value === 'number')
|
|
102
|
+
return value !== 0;
|
|
103
|
+
if (Array.isArray(value))
|
|
104
|
+
return value.length > 0;
|
|
105
|
+
if (typeof value === 'object')
|
|
106
|
+
return Object.keys(value).length > 0;
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
function errorText(error) {
|
|
110
|
+
return error instanceof Error ? error.message : String(error);
|
|
111
|
+
}
|
|
112
|
+
/** The workspace is serving. Whether that is the END is the caller's to say. */
|
|
113
|
+
function sayReady(emit, final) {
|
|
114
|
+
if (final) {
|
|
115
|
+
(0, events_1.info)(emit, 'ready', { phase: 'done', pct: 100.0 });
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// NO PERCENTAGE, deliberately. `waitServing` has already emitted 100 by the time this
|
|
119
|
+
// runs, so naming any number here sends the bar BACKWARDS.
|
|
120
|
+
(0, events_1.info)(emit, 'the workspace is up', { phase: 'wait' });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The one place a readiness failure is worded.
|
|
125
|
+
*
|
|
126
|
+
* `known` is a diagnosis from `diagnose`, which is preferred over anything guessed: it
|
|
127
|
+
* comes from a matched log signature rather than from a restart count. The
|
|
128
|
+
* resource-pressure sentence survives only as a POSSIBILITY, and only when nothing was
|
|
129
|
+
* matched -- stated as fact it sent a reader hunting for memory they had.
|
|
130
|
+
*/
|
|
131
|
+
function readinessFailure(meta, seen, { prefix = '', known = '' } = {}) {
|
|
132
|
+
const cause = known || seen.cause || '';
|
|
133
|
+
const head = prefix || `Rocket.Chat is not becoming ready in '${meta.name}'`;
|
|
134
|
+
if (cause)
|
|
135
|
+
return new errors_1.NotReadyError(`${head} - ${cause}`);
|
|
136
|
+
const restarts = seen.restarts || 0;
|
|
137
|
+
if (restarts >= 2) {
|
|
138
|
+
return new errors_1.NotReadyError(`${head} - Rocket.Chat restarted ${String(restarts)}x and nothing in its logs ` +
|
|
139
|
+
"matches a known cause. Free memory or raise Docker's CPU+RAM if the " +
|
|
140
|
+
`box is loaded, then \`houston ready --name ${meta.name}\`; otherwise ` +
|
|
141
|
+
`\`houston logs --name ${meta.name}\` has what happened.`);
|
|
142
|
+
}
|
|
143
|
+
return new errors_1.NotReadyError(head);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* `docker compose pull` and `up -d`, the containers phase of a create.
|
|
147
|
+
*
|
|
148
|
+
* UNWOUND by a Ctrl-C: out through the create's catch-all, which clears the note, so an
|
|
149
|
+
* `up` interrupted in its pull leaves no `create_unfinished` note, where `process.exit(130)`
|
|
150
|
+
* left one for `doctor` to warn about a workspace that was never made.
|
|
151
|
+
* Nothing between here and that `catch` catches the interrupt, and the note is cleared
|
|
152
|
+
* synchronously. Only this phase: the readiness wait after it goes through catches that
|
|
153
|
+
* handle any error -- `rcRestartCount`'s among them -- which would swallow the interrupt
|
|
154
|
+
* and print one more `still booting` line before the next wait ended the run.
|
|
155
|
+
*/
|
|
156
|
+
async function upCompose(name, options) {
|
|
157
|
+
return await (0, exec_1.unwindsOnInterrupt)(async () => await composeUp(name, options));
|
|
158
|
+
}
|
|
159
|
+
async function composeUp(name, { pull, emit, streamOutput }) {
|
|
160
|
+
if (!streamOutput) {
|
|
161
|
+
// docker draws its own progress on the terminal
|
|
162
|
+
return (await engine.up(name, { pull })) ?? 1;
|
|
163
|
+
}
|
|
164
|
+
// `data.echo="docker"` marks this as ECHO rather than narrative: every line of
|
|
165
|
+
// `docker compose pull` comes through here, so a create emits several hundred
|
|
166
|
+
// "Downloading 45.09MB" events. The GUI wants them; the durable log does not.
|
|
167
|
+
const onLine = (line) => (0, events_1.info)(emit, line, { phase: 'boot', data: { echo: 'docker' } });
|
|
168
|
+
if (pull) {
|
|
169
|
+
// non-fatal, like runner.up
|
|
170
|
+
await engine.stream(name, ['pull'], onLine);
|
|
171
|
+
}
|
|
172
|
+
const rc = await engine.stream(name, ['up', '-d', '--remove-orphans'], onLine);
|
|
173
|
+
return (await engine.recreatedIfStale(name, rc)) ?? 1;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Re-register a workspace's https name with the edge. Best-effort.
|
|
177
|
+
*
|
|
178
|
+
* Never fatal: the workspace is up and usable either way, and failing a reuse over the
|
|
179
|
+
* ingress would be the wrong trade.
|
|
180
|
+
*/
|
|
181
|
+
async function restoreRoute(meta, emit = events_1.nullEmit) {
|
|
182
|
+
const extra = bag(meta.extra);
|
|
183
|
+
if (!(isTruthy(extra.tls) && meta.publicUrl))
|
|
184
|
+
return;
|
|
185
|
+
const host = meta.publicUrl.split('://').slice(-1)[0]?.split('/')[0] ?? '';
|
|
186
|
+
const local = extra.tls === tls_1.MODE_LOCAL;
|
|
187
|
+
try {
|
|
188
|
+
if (!(await (0, engine_1.running)())) {
|
|
189
|
+
await (0, runtime_1.ensureRunning)({
|
|
190
|
+
acmeEmail: local ? '' : String(extra.tls_email ?? ''),
|
|
191
|
+
acmeStaging: Boolean(extra.tls_staging),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (local)
|
|
195
|
+
await edge.issueLocalCert(host);
|
|
196
|
+
const instances = typeof extra.instances === 'number' && Number.isInteger(extra.instances)
|
|
197
|
+
? extra.instances
|
|
198
|
+
: 1;
|
|
199
|
+
await (0, routes_1.register)(meta.name, host, {
|
|
200
|
+
instances,
|
|
201
|
+
local,
|
|
202
|
+
grafana: isTruthy(extra.monitoring),
|
|
203
|
+
publicPaths: (0, public_1.publicPathsOf)(extra),
|
|
204
|
+
});
|
|
205
|
+
(0, events_1.info)(emit, `${host} is served by the edge again`, { phase: 'tls' });
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
(0, events_1.warn)(emit, `could not restore the https name ${host}: ${errorText(error)}. ` +
|
|
209
|
+
'`houston edge status` reports it.', { phase: 'tls' });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Kill a workspace's port-forward, if it is still ours to kill.
|
|
214
|
+
*
|
|
215
|
+
* Best-effort and deliberately narrow: the check is "is this process this NAMESPACE's
|
|
216
|
+
* port-forward", delegated to `forwardAlive` so there is one definition of "ours". A
|
|
217
|
+
* recycled pid belonging to ANOTHER workspace's forward is precisely the failure this
|
|
218
|
+
* avoids.
|
|
219
|
+
*/
|
|
220
|
+
async function stopPortForward(pid, { namespace = '' } = {}) {
|
|
221
|
+
if (!(await (0, forward_1.forwardAlive)(pid, { namespace })))
|
|
222
|
+
return;
|
|
223
|
+
(0, forward_1.signalForward)(pid);
|
|
224
|
+
}
|
|
225
|
+
async function finalize(meta, emit) {
|
|
226
|
+
try {
|
|
227
|
+
const auth = await (0, admin_1.login)(meta);
|
|
228
|
+
if (await (0, rcapi_1.completeSetupWizard)(meta.rootUrl, auth, (0, record_1.adminPass)(meta))) {
|
|
229
|
+
(0, events_1.info)(emit, 'setup wizard skipped — no registration needed', { phase: 'post_ready' });
|
|
230
|
+
}
|
|
231
|
+
return auth;
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
if (error instanceof exec_1.Interrupted)
|
|
235
|
+
throw error; // Ctrl-C or a stopped job: unwind
|
|
236
|
+
// finalize is best-effort
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* One poll of a boot in progress: is it slow, or is it failing?
|
|
242
|
+
*
|
|
243
|
+
* Module-level rather than a closure over `waitServing`, so a test can patch it. `seen`
|
|
244
|
+
* carries the two facts that have to survive between ticks.
|
|
245
|
+
*/
|
|
246
|
+
async function crashLoopTick(meta, emit, timeout, seen, elapsed) {
|
|
247
|
+
// Surface a crash-loop: if RC keeps restarting, boot is slow for a reason.
|
|
248
|
+
const rc = await (0, queries_1.rcRestartCount)(meta.name);
|
|
249
|
+
if (rc >= 2 && rc > seen.restarts) {
|
|
250
|
+
(0, events_1.warn)(emit, `Rocket.Chat has restarted ${String(rc)}x - checking why`, { phase: 'wait' });
|
|
251
|
+
// ASK, rather than assert. The old wording named resource pressure as the cause, and
|
|
252
|
+
// `diagnose` -- which exists for exactly this -- was never consulted anywhere on the
|
|
253
|
+
// readiness path.
|
|
254
|
+
//
|
|
255
|
+
// Giving up EARLY only when the cause is known. A boot that restarts twice and then
|
|
256
|
+
// settles is ordinary; a matched signature is evidence.
|
|
257
|
+
if (seen.cause === null) {
|
|
258
|
+
seen.cause = (await (0, diagnose_1.diagnoseFailure)(meta.name)) ?? '';
|
|
259
|
+
}
|
|
260
|
+
if (seen.cause) {
|
|
261
|
+
throw readinessFailure(meta, seen, { known: seen.cause });
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
seen.restarts = Math.max(seen.restarts, rc);
|
|
265
|
+
const pct = timeout ? Math.max(0.0, Math.min(99.0, (elapsed / timeout) * 100)) : null;
|
|
266
|
+
// `toInt(elapsed)`, which REFUSES a NaN: under `--timeout inf` or `nan` the deadline is
|
|
267
|
+
// never reached and the elapsed time is NaN, so the first tick throws `InvalidValue` and the
|
|
268
|
+
// command ends (exit 1). Math.floor printed "still booting (NaNs)" every three seconds, for
|
|
269
|
+
// ever -- a run that never wrote its `end` record.
|
|
270
|
+
(0, events_1.info)(emit, `still booting (${String((0, format_1.toInt)(elapsed))}s)`, { phase: 'wait', pct });
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* SERVING IS NOT USABLE, and this is the gap between them.
|
|
274
|
+
*
|
|
275
|
+
* Rocket.Chat answers /api/info with no database behind it, so a workspace whose mongodb
|
|
276
|
+
* had exited passed this and was reported ready, running and healthy -- while `api` and
|
|
277
|
+
* `seed` refused it and pointed the reader back at `ready`, the command that had just
|
|
278
|
+
* said yes.
|
|
279
|
+
*/
|
|
280
|
+
async function refuseIfServingWithoutADatabase(meta) {
|
|
281
|
+
const why = inspect.degradedReason((await (0, queries_1.servicesByProject)())[meta.project] ?? {});
|
|
282
|
+
if (why) {
|
|
283
|
+
throw new errors_1.NotReadyError(`'${meta.name}' is serving, but ${why} - Rocket.Chat answers /api/info ` +
|
|
284
|
+
'without a database, so this looks ready and no login will work. ' +
|
|
285
|
+
`\`docker start ${meta.project}-${types_1.ESSENTIAL_SERVICES[0] ?? ''}-1\`, or ` +
|
|
286
|
+
`\`houston up --version ${meta.rcVersion} --name ${meta.name}\` to ` +
|
|
287
|
+
'rebuild the stack.');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async function waitServing(meta, emit, timeout) {
|
|
291
|
+
const started = Date.now();
|
|
292
|
+
if (topology.ofMeta(meta) === topology.KUBERNETES) {
|
|
293
|
+
// `rcState` asks docker whether a CONTAINER is running, so `ready` on a Kubernetes
|
|
294
|
+
// workspace answered "Rocket.Chat container is not running" about a workspace whose
|
|
295
|
+
// pods were fine. It also re-establishes the port-forward, which is the whole reason
|
|
296
|
+
// `ready` is the right place to ask.
|
|
297
|
+
const served = await waitServingKubernetes(meta, emit, timeout);
|
|
298
|
+
await waitForOrigin(meta, emit, Math.max(timeout - (Date.now() - started) / 1000, 1));
|
|
299
|
+
return served;
|
|
300
|
+
}
|
|
301
|
+
const seen = { restarts: 0, cause: null };
|
|
302
|
+
let last = '';
|
|
303
|
+
const isAlive = async () => {
|
|
304
|
+
last = await (0, queries_1.rcState)(meta.name);
|
|
305
|
+
return ['running', 'restarting', 'created'].includes(last);
|
|
306
|
+
};
|
|
307
|
+
const tick = async (elapsed) => {
|
|
308
|
+
await crashLoopTick(meta, emit, timeout, seen, elapsed);
|
|
309
|
+
};
|
|
310
|
+
let served;
|
|
311
|
+
try {
|
|
312
|
+
served = await (0, rcapi_1.waitReady)(meta.rootUrl, { timeout, isAlive, onTick: tick });
|
|
313
|
+
// EVERY INSTANCE, not the front door alone. The workspace's own Traefik starts every
|
|
314
|
+
// server healthy and checks them every 10 s, so the first instance to answer made this
|
|
315
|
+
// "ready" while the others were still booting: 9-10 of 20 requests answered 502 right
|
|
316
|
+
// after it, and the admin login failed. Each instance is published on hostPort+i.
|
|
317
|
+
const instances = Number(bag(meta.extra).instances ?? 1) || 1;
|
|
318
|
+
// NAMED when one is not: "did not become ready within 59s" with the front door
|
|
319
|
+
// answering left a reader to find the stopped replica by hand.
|
|
320
|
+
const late = [];
|
|
321
|
+
let first = null;
|
|
322
|
+
for (let i = 1; instances > 1 && i <= instances; i += 1) {
|
|
323
|
+
const own = new URL(meta.rootUrl);
|
|
324
|
+
own.port = String(meta.hostPort + i);
|
|
325
|
+
const left = Math.max(timeout - (Date.now() - started) / 1000, 1);
|
|
326
|
+
try {
|
|
327
|
+
await (0, rcapi_1.waitReady)(own.origin, { timeout: left, isAlive, onTick: tick });
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
if (!(error instanceof rcapi_1.NotReady))
|
|
331
|
+
throw error;
|
|
332
|
+
first ?? (first = error);
|
|
333
|
+
late.push(`rocketchat-${String(i)} at ${own.origin}`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (first !== null) {
|
|
337
|
+
throw new rcapi_1.NotReady(`${errorText(first)}: ${late.join(', ')} ${late.length === 1 ? 'is' : 'are'} not serving`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
if (!(error instanceof rcapi_1.NotReady))
|
|
342
|
+
throw error;
|
|
343
|
+
// STOPPED IS AN ANSWER, as on Kubernetes. Rocket.Chat runs `restart: always`, so a crash
|
|
344
|
+
// comes back as `restarting`: an exited one was stopped, and its logs do not say so.
|
|
345
|
+
// `compose ps` lists running containers only, so there a stopped one is `absent`; `compose
|
|
346
|
+
// ls --all` still lists its project, every container exited (a taken-down one: none).
|
|
347
|
+
const project = last === 'absent' ? ((await (0, queries_1.projectStates)()) ?? {})[meta.project] : '';
|
|
348
|
+
if (last === 'exited' || /^exited\(\d+\)$/.test(project ?? '')) {
|
|
349
|
+
throw new errors_1.NotReadyError(`'${meta.name}' is stopped — \`houston start --name ${meta.name}\` brings it back`);
|
|
350
|
+
}
|
|
351
|
+
if (seen.cause === null) {
|
|
352
|
+
seen.cause = (await (0, diagnose_1.diagnoseFailure)(meta.name)) ?? '';
|
|
353
|
+
}
|
|
354
|
+
throw readinessFailure(meta, seen, { prefix: errorText(error) });
|
|
355
|
+
}
|
|
356
|
+
await waitForOneShotSetup(meta, emit, Math.max(timeout - (Date.now() - started) / 1000, 1));
|
|
357
|
+
await refuseIfServingWithoutADatabase(meta);
|
|
358
|
+
await waitForOrigin(meta, emit, Math.max(timeout - (Date.now() - started) / 1000, 1));
|
|
359
|
+
return served;
|
|
360
|
+
}
|
|
361
|
+
/** Internal HTTP health cannot prove the restored HTTPS route serves an application. */
|
|
362
|
+
async function waitForOrigin(meta, emit, timeout) {
|
|
363
|
+
if (meta.publicUrl === '' || !isTruthy(bag(meta.extra).tls) || bag(meta.extra).edge !== true)
|
|
364
|
+
return;
|
|
365
|
+
const publicUrl = new URL(meta.publicUrl);
|
|
366
|
+
if (publicUrl.protocol !== 'https:')
|
|
367
|
+
return;
|
|
368
|
+
try {
|
|
369
|
+
await (0, rcapi_1.waitReady)(meta.publicUrl, {
|
|
370
|
+
timeout,
|
|
371
|
+
page: true,
|
|
372
|
+
requestOptions: async (remainingMs) => {
|
|
373
|
+
const observed = await (0, tls_1.originCertificate)(publicUrl.hostname, {
|
|
374
|
+
port: Number(publicUrl.port || 443),
|
|
375
|
+
timeout: remainingMs / 1000,
|
|
376
|
+
});
|
|
377
|
+
if (observed.pem === '')
|
|
378
|
+
return null;
|
|
379
|
+
return {
|
|
380
|
+
followRedirects: false,
|
|
381
|
+
loopbackOrigin: {
|
|
382
|
+
certificate: observed.pem,
|
|
383
|
+
allowCertificateNameMismatch: observed.fallback,
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
},
|
|
387
|
+
onTick: (elapsed) => (0, events_1.info)(emit, `waiting for ${meta.publicUrl} to serve Rocket.Chat (${Math.floor(elapsed)}s)`, {
|
|
388
|
+
phase: 'wait',
|
|
389
|
+
}),
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
if (!(error instanceof rcapi_1.NotReady))
|
|
394
|
+
throw error;
|
|
395
|
+
throw new errors_1.NotReadyError(`'${meta.name}' answers internally, but its HTTPS origin ${meta.publicUrl} ` +
|
|
396
|
+
'is not serving Rocket.Chat — `houston edge status` and the edge logs say why');
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* The workspace's one-shot setup -- the MinIO bucket, the replica set -- finished, not just
|
|
401
|
+
* Rocket.Chat serving. Rocket.Chat does not wait for `minio-init`, so on rootless Podman,
|
|
402
|
+
* whose DNS flaps, `up --wait` returned while the bucket did not exist yet and the first
|
|
403
|
+
* upload failed. A setup that failed is said, with where its reason is.
|
|
404
|
+
*/
|
|
405
|
+
async function waitForOneShotSetup(meta, emit, timeout, pause = exec_1.sleep) {
|
|
406
|
+
const deadline = Date.now() + timeout * 1000;
|
|
407
|
+
let said = false;
|
|
408
|
+
for (;;) {
|
|
409
|
+
// Not mongo-init: Rocket.Chat serving proves the replica set it initiated, and a re-run
|
|
410
|
+
// after `restart` that missed a DNS lookup made a healthy workspace read as not ready.
|
|
411
|
+
const setups = (await (0, queries_1.oneShotSetups)(meta.name)).filter((one) => one.service !== 'mongo-init');
|
|
412
|
+
const failed = setups.find((one) => one.status === 'exited' && one.exitCode !== 0);
|
|
413
|
+
if (failed !== undefined) {
|
|
414
|
+
throw new errors_1.NotReadyError(`${failed.service} exited ${String(failed.exitCode)} before it finished setting up ` +
|
|
415
|
+
`'${meta.name}' — \`docker compose -p ${meta.project} logs ${failed.service}\` says ` +
|
|
416
|
+
`why, and \`houston restart --name ${meta.name}\` runs it again`);
|
|
417
|
+
}
|
|
418
|
+
const pending = setups.filter((one) => one.status !== 'exited').map((one) => one.service);
|
|
419
|
+
if (pending.length === 0)
|
|
420
|
+
return;
|
|
421
|
+
if (Date.now() >= deadline) {
|
|
422
|
+
throw new errors_1.NotReadyError(`${pending.join(', ')} has not finished setting up '${meta.name}' — ` +
|
|
423
|
+
`\`docker compose -p ${meta.project} logs ${pending[0] ?? ''}\` says where it is`);
|
|
424
|
+
}
|
|
425
|
+
if (!said) {
|
|
426
|
+
(0, events_1.info)(emit, `Rocket.Chat answers; waiting for ${pending.join(', ')} to finish`, {
|
|
427
|
+
phase: 'wait',
|
|
428
|
+
});
|
|
429
|
+
said = true;
|
|
430
|
+
}
|
|
431
|
+
await pause(2);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Re-establish the forward and record its pid. A forward dies with its pod, and `ready`
|
|
436
|
+
* is exactly when someone asks why the URL stopped answering.
|
|
437
|
+
*/
|
|
438
|
+
async function repairThePortForward(meta, emit, extra, namespace, context) {
|
|
439
|
+
const pid = await (0, forward_1.ensurePortForward)(meta.name, {
|
|
440
|
+
namespace,
|
|
441
|
+
context,
|
|
442
|
+
hostPort: meta.hostPort,
|
|
443
|
+
pid: typeof extra.port_forward_pid === 'number' ? extra.port_forward_pid : 0,
|
|
444
|
+
bindHost: (0, format_1.toText)(extra.bind_host),
|
|
445
|
+
emit,
|
|
446
|
+
});
|
|
447
|
+
if (pid && pid !== extra.port_forward_pid) {
|
|
448
|
+
await (0, record_1.updateMeta)(meta.name, (current) => {
|
|
449
|
+
current.extra.port_forward_pid = pid;
|
|
450
|
+
});
|
|
451
|
+
// AND IN MEMORY, or whoever renders from this `meta` afterwards is reading the pid we
|
|
452
|
+
// just replaced. `ready` repaired a dead forward and then printed "The URL is not
|
|
453
|
+
// published right now" underneath "is serving at <url>".
|
|
454
|
+
meta.extra.port_forward_pid = pid;
|
|
455
|
+
}
|
|
456
|
+
return pid;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* A preset's UI forwards, re-established when any of them is gone.
|
|
460
|
+
*
|
|
461
|
+
* They die with their pods, which `stop` scales to zero, and only the Rocket.Chat forward
|
|
462
|
+
* was ever repaired. So after a stop/start the SAML IdP on :8081 answered nothing:
|
|
463
|
+
* `post_ready` could not re-read its descriptor, Rocket.Chat kept the certificate of a
|
|
464
|
+
* Keycloak that had since re-imported its realm with new keys, and every SAML sign-in was
|
|
465
|
+
* `Invalid Signature` -- "Unauthorized". Restarted together, under a fresh record entry.
|
|
466
|
+
*/
|
|
467
|
+
async function repairTheScenarioForwards(meta, emit, extra, namespace, context) {
|
|
468
|
+
const recorded = Object.entries(bag(extra.scenario_forwards));
|
|
469
|
+
let gone = false;
|
|
470
|
+
for (const [port, pid] of recorded) {
|
|
471
|
+
if (!(await (0, forward_1.forwardAlive)(Number(pid), { namespace, hostPort: Number(port) })))
|
|
472
|
+
gone = true;
|
|
473
|
+
}
|
|
474
|
+
if (!gone)
|
|
475
|
+
return;
|
|
476
|
+
for (const [port, pid] of recorded) {
|
|
477
|
+
await (0, forward_1.stopForward)(Number(pid), { namespace, hostPort: Number(port) });
|
|
478
|
+
}
|
|
479
|
+
const ui = await (0, forward_1.scenarioUiForwards)(meta.name, {
|
|
480
|
+
namespace,
|
|
481
|
+
context,
|
|
482
|
+
bindHost: (0, format_1.toText)(extra.bind_host),
|
|
483
|
+
emit,
|
|
484
|
+
});
|
|
485
|
+
const fresh = Object.fromEntries(Object.entries(ui).map(([port, pid]) => [String(port), pid]));
|
|
486
|
+
await (0, record_1.updateMeta)(meta.name, (current) => {
|
|
487
|
+
current.extra.scenario_forwards = fresh;
|
|
488
|
+
});
|
|
489
|
+
meta.extra.scenario_forwards = fresh;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Reachable through the forward, and dead to every pod in the cluster.
|
|
493
|
+
*
|
|
494
|
+
* The Service is never traversed by anything on this path, and on this runtime that
|
|
495
|
+
* matters: readiness reads pod status, the port-forward targets the Deployment, and the
|
|
496
|
+
* default deployment is microservices.
|
|
497
|
+
*
|
|
498
|
+
* WARNED, not gated: endpoints churn during a rollout and a false negative here would
|
|
499
|
+
* block a boot, which is worse than the defect.
|
|
500
|
+
*/
|
|
501
|
+
async function warnAboutServicesWithNoEndpoints(meta, emit, namespace, context) {
|
|
502
|
+
const empty = await (0, status_1.servicesWithoutEndpoints)(meta.name, { context });
|
|
503
|
+
if (empty.length > 0) {
|
|
504
|
+
(0, events_1.warn)(emit, 'no ready pod is behind ' +
|
|
505
|
+
empty.join(', ') +
|
|
506
|
+
' — the URL works because the port-forward goes ' +
|
|
507
|
+
'straight to the Deployment, but nothing inside ' +
|
|
508
|
+
`the cluster can reach ${empty.length > 1 ? 'these' : 'it'}` +
|
|
509
|
+
`. \`kubectl -n ${namespace} get endpointslices\` ` +
|
|
510
|
+
'shows what is behind each Service.', { phase: 'ready' });
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* The port answers, the workspace is ready, and what answered is not Rocket.Chat.
|
|
515
|
+
*
|
|
516
|
+
* This was the only runtime that confused occupancy with identity. The Docker path has
|
|
517
|
+
* always gone through `rcapi.waitReady`, which polls /api/info; here readiness was
|
|
518
|
+
* concluded from a Ready pod plus "the port answers" and nothing ever asked Rocket.Chat
|
|
519
|
+
* anything. The port is only validated at create time and 3000+ is the most contested
|
|
520
|
+
* range on a dev box, so this is an ordinary event.
|
|
521
|
+
*
|
|
522
|
+
* Returns the new strike count.
|
|
523
|
+
*/
|
|
524
|
+
function refuseAForeignHolder(meta, foreign) {
|
|
525
|
+
// WHOSE forward is irrelevant once the workspace itself is ready. The first version
|
|
526
|
+
// raised only when our forward was dead, and the live run found the case that misses:
|
|
527
|
+
// on a dual-stack box kubectl binds `[::1]` quite happily while a squatter holds
|
|
528
|
+
// `127.0.0.1`.
|
|
529
|
+
//
|
|
530
|
+
// So the test is the workspace's own state: if Kubernetes says it is ready and the
|
|
531
|
+
// port answers with something that is not Rocket.Chat, then whatever is on that port
|
|
532
|
+
// is not this workspace. Counted rather than acted on at once, because a pod that has
|
|
533
|
+
// just passed its probe may not be serving for another moment.
|
|
534
|
+
const strikes = foreign + 1;
|
|
535
|
+
if (strikes >= types_1.tuning.FOREIGN_PORT_STRIKES) {
|
|
536
|
+
throw new errors_1.ConflictError(`port ${String(meta.hostPort)} is answering, but not with ` +
|
|
537
|
+
`Rocket.Chat, and '${meta.name}' is otherwise ready — so ` +
|
|
538
|
+
`nothing served on ${meta.rootUrl} can be trusted to be this ` +
|
|
539
|
+
`workspace. Something else holds that port. \`${(0, forward_1.holderCommand)(meta.hostPort)}\` ` +
|
|
540
|
+
'says what; note it may hold only IPv4 ' +
|
|
541
|
+
'while the port-forward has IPv6, which looks healthy from ' +
|
|
542
|
+
'houston and wrong from a browser. Free the port, or ' +
|
|
543
|
+
`\`houston down --name ${meta.name}\` then \`houston up\` for ` +
|
|
544
|
+
'one that is free.');
|
|
545
|
+
}
|
|
546
|
+
return strikes;
|
|
547
|
+
}
|
|
548
|
+
/** Stop waiting for something Kubernetes has already decided cannot happen. */
|
|
549
|
+
async function refuseADoomedPod(meta, namespace, context) {
|
|
550
|
+
// A mistyped version or an unreachable registry used to cost the full timeout and then
|
|
551
|
+
// report the timeout rather than the cause.
|
|
552
|
+
const doomed = await (0, status_1.terminalPodFailure)(meta.name, { context });
|
|
553
|
+
if (doomed !== null) {
|
|
554
|
+
const [pod, reason, message] = doomed;
|
|
555
|
+
throw new errors_1.CreateFailedError(`'${meta.name}' cannot start: pod ${pod} is ${reason}` +
|
|
556
|
+
(message ? ` — ${message}` : '') +
|
|
557
|
+
`. Nothing will change by waiting. \`kubectl -n ${namespace} ` +
|
|
558
|
+
`describe pod ${pod}\` has the detail.`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Wait for a Kubernetes workspace to serve, and make sure it is reachable.
|
|
563
|
+
*
|
|
564
|
+
* Two jobs, because on this runtime they are different questions. The pod being Ready is
|
|
565
|
+
* Kubernetes' answer; the URL answering also needs a live port-forward, and a forward
|
|
566
|
+
* dies with its pod.
|
|
567
|
+
*/
|
|
568
|
+
async function waitServingKubernetes(meta, emit, timeout) {
|
|
569
|
+
const extra = bag(meta.extra);
|
|
570
|
+
const context = isTruthy(extra[config.EXTRA_CONTEXT])
|
|
571
|
+
? String(extra[config.EXTRA_CONTEXT])
|
|
572
|
+
: names_1.CONTEXT;
|
|
573
|
+
const namespace = isTruthy(extra.namespace)
|
|
574
|
+
? String(extra.namespace)
|
|
575
|
+
: await (0, namespace_1.namespaceFor)(meta.name);
|
|
576
|
+
// Forwarded to, and set up over REST, only while it is still this workspace's own.
|
|
577
|
+
await (0, namespace_1.requireOwnNamespace)(meta.name, { context });
|
|
578
|
+
// STOPPED IS AN ANSWER, NOT A WAIT. `stop` scales Rocket.Chat to zero, and this polled out
|
|
579
|
+
// its whole timeout (five minutes by default) on a workspace never going to move, then
|
|
580
|
+
// named `kubectl get pods` -- there are none. A refused read is not "stopped": it waits.
|
|
581
|
+
const replicas = await (0, status_1.workloadReplicas)(meta.name, { context }).catch(() => null);
|
|
582
|
+
if (replicas === 0) {
|
|
583
|
+
throw new errors_1.NotReadyError(`'${meta.name}' is stopped — \`houston start --name ${meta.name}\` brings it back`);
|
|
584
|
+
}
|
|
585
|
+
const deadline = Date.now() + timeout * 1000;
|
|
586
|
+
let last = 0;
|
|
587
|
+
// Consecutive rounds where the workspace is ready and the port answers with something
|
|
588
|
+
// that is not Rocket.Chat. Grace, not tolerance: it ends in a refusal.
|
|
589
|
+
let foreign = 0;
|
|
590
|
+
// Pod churn can leave a forward serving once before it dies. Require the same pid to
|
|
591
|
+
// carry two observations before handing its URL over.
|
|
592
|
+
let stablePid = 0;
|
|
593
|
+
let current = extra;
|
|
594
|
+
while (Date.now() < deadline) {
|
|
595
|
+
if (await (0, status_1.workspaceReady)(meta.name, { context })) {
|
|
596
|
+
const pid = await repairThePortForward(meta, emit, current, namespace, context);
|
|
597
|
+
// A Ready pod is not proof that its forwarding socket answers. Confirm it instead
|
|
598
|
+
// of handing over a URL on the strength of a pid alone.
|
|
599
|
+
if (await (0, forward_1.forwardReachable)(meta.hostPort)) {
|
|
600
|
+
// OCCUPANCY IS NOT IDENTITY: ask Rocket.Chat rather than inferring it from a
|
|
601
|
+
// Ready pod and an answering port.
|
|
602
|
+
const served = await (0, rcapi_1.apiInfo)(meta.rootUrl);
|
|
603
|
+
if (served !== null) {
|
|
604
|
+
foreign = 0;
|
|
605
|
+
if (pid && pid === stablePid) {
|
|
606
|
+
await warnAboutServicesWithNoEndpoints(meta, emit, namespace, context);
|
|
607
|
+
await repairTheScenarioForwards(meta, emit, current, namespace, context);
|
|
608
|
+
(0, events_1.info)(emit, `'${meta.name}' is serving at ${meta.rootUrl}`, {
|
|
609
|
+
phase: 'ready',
|
|
610
|
+
pct: 100,
|
|
611
|
+
});
|
|
612
|
+
return { ready: true, url: meta.rootUrl };
|
|
613
|
+
}
|
|
614
|
+
stablePid = pid;
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
stablePid = 0;
|
|
618
|
+
foreign = refuseAForeignHolder(meta, foreign);
|
|
619
|
+
}
|
|
620
|
+
current = { ...current, port_forward_pid: pid };
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
foreign = 0;
|
|
624
|
+
stablePid = 0;
|
|
625
|
+
current = { ...current, port_forward_pid: pid };
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
stablePid = 0;
|
|
630
|
+
}
|
|
631
|
+
await refuseADoomedPod(meta, namespace, context);
|
|
632
|
+
const now = Date.now();
|
|
633
|
+
if (now - last > 15000) {
|
|
634
|
+
last = now;
|
|
635
|
+
(0, events_1.info)(emit, `waiting for Rocket.Chat in ${namespace}`, { phase: 'wait' });
|
|
636
|
+
}
|
|
637
|
+
// `sleep(3000)`, which an Interrupted interrupts: a bare timer here was a
|
|
638
|
+
// wait no Ctrl-C could reach, so `backup`'s unwind sat in it until the bound.
|
|
639
|
+
await (0, exec_1.sleep)(3000);
|
|
640
|
+
}
|
|
641
|
+
throw new errors_1.NotReadyError(`Rocket.Chat did not become ready within ${String(Math.trunc(timeout))}s. ` +
|
|
642
|
+
`kubectl -n ${namespace} get pods`);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Whether Rocket.Chat ACCEPTED the license houston gave it, recorded for the panel.
|
|
646
|
+
*
|
|
647
|
+
* A license is valid only at the address it was issued for: one given to a workspace whose
|
|
648
|
+
* Site_Url is anything else is installed and refused ("Url validation failed"), and the
|
|
649
|
+
* panel said "Licensed" all the same. Asked a few times, because Rocket.Chat may still be
|
|
650
|
+
* applying it when it first serves; no answer records nothing rather than a guess.
|
|
651
|
+
*
|
|
652
|
+
* Also asked, once, where Rocket.Chat 9 refuses this workspace's sign-in without a license
|
|
653
|
+
* houston did not give: one added later in Administration → Subscription lifts it, and the
|
|
654
|
+
* notes said "refused" for as long as the workspace lived. The modules it turns on are
|
|
655
|
+
* recorded too, which is what the notes read.
|
|
656
|
+
*/
|
|
657
|
+
async function checkLicense(meta, auth, emit, pause = exec_1.sleep) {
|
|
658
|
+
if (auth === null)
|
|
659
|
+
return;
|
|
660
|
+
const given = bag(meta.extra).licensed === true;
|
|
661
|
+
const pre = (0, notes_1.loginPresetOf)(meta);
|
|
662
|
+
if (!given && (0, notes_1.premiumSignIn)(pre, meta.rcVersion) === null)
|
|
663
|
+
return;
|
|
664
|
+
let answer = null;
|
|
665
|
+
for (let tries = 0; tries < (given ? 4 : 1) && answer?.valid !== true; tries += 1) {
|
|
666
|
+
if (tries > 0)
|
|
667
|
+
await pause(5000);
|
|
668
|
+
answer = await (0, rcapi_1.licenseInfo)(meta.rootUrl, auth);
|
|
669
|
+
}
|
|
670
|
+
if (answer === null)
|
|
671
|
+
return;
|
|
672
|
+
const { valid, modules } = answer;
|
|
673
|
+
if (!given) {
|
|
674
|
+
const lifted = (0, notes_1.premiumSignIn)(pre, meta.rcVersion);
|
|
675
|
+
if (valid && lifted !== null && (0, notes_1.premiumSignIn)(pre, meta.rcVersion, modules ?? []) === null)
|
|
676
|
+
(0, events_1.info)(emit, `Rocket.Chat has a license carrying ${lifted.modules}: sign-in through the ` +
|
|
677
|
+
`${lifted.through} preset is no longer refused`, { phase: 'post_ready' });
|
|
678
|
+
}
|
|
679
|
+
else if (valid) {
|
|
680
|
+
(0, events_1.info)(emit, 'Rocket.Chat accepted the license', { phase: 'post_ready' });
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
const site = await (0, rcapi_1.getSetting)(meta.rootUrl, auth, (0, record_1.adminPass)(meta), 'Site_Url');
|
|
684
|
+
(0, events_1.warn)(emit, 'Rocket.Chat refused the license: one is valid only at the address it was issued for ' +
|
|
685
|
+
`and until it expires${typeof site === 'string' && site !== '' ? `, and this workspace's Site_Url is ${site}` : ''}. ` +
|
|
686
|
+
`\`houston logs --name ${meta.name}\` shows its reason. Rocket.Chat keeps a refused ` +
|
|
687
|
+
'license refused even once the address is right (measured on 8.8.1): put it right, ' +
|
|
688
|
+
`then \`houston restart --name ${meta.name}\` and \`houston ready --name ${meta.name}\`.`, { phase: 'post_ready' });
|
|
689
|
+
}
|
|
690
|
+
// One houston did not give and Rocket.Chat does not hold is no status at all: never "refused".
|
|
691
|
+
const status = valid ? 'valid' : given ? 'refused' : undefined;
|
|
692
|
+
const extra = bag(meta.extra);
|
|
693
|
+
if (extra.license_status === status &&
|
|
694
|
+
JSON.stringify(extra.license_modules) === JSON.stringify(modules ?? undefined))
|
|
695
|
+
return;
|
|
696
|
+
const put = (into) => {
|
|
697
|
+
if (status === undefined)
|
|
698
|
+
delete into.license_status;
|
|
699
|
+
else
|
|
700
|
+
into.license_status = status;
|
|
701
|
+
if (modules === null)
|
|
702
|
+
delete into.license_modules;
|
|
703
|
+
else
|
|
704
|
+
into.license_modules = modules;
|
|
705
|
+
};
|
|
706
|
+
await (0, record_1.updateMeta)(meta.name, (current) => {
|
|
707
|
+
put(current.extra);
|
|
708
|
+
});
|
|
709
|
+
put(meta.extra);
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Site_Url onto the address a rebuild moved this workspace to, once. Rocket.Chat keeps the stored
|
|
713
|
+
* setting whatever ROOT_URL says and gives it to the browser as the address to connect to: an
|
|
714
|
+
* http oidc workspace upgraded to 9.0.0 and rebuilt onto https sat on its loading spinner. Moved
|
|
715
|
+
* only while it still names the old address, so one set by hand stays; `restore` does the same
|
|
716
|
+
* for a bundle's (`backup.retargetSiteUrl`). Unanswered, the marker stays for the next `ready`.
|
|
717
|
+
*/
|
|
718
|
+
async function followTheMove(meta, auth, emit) {
|
|
719
|
+
const from = (0, format_1.toText)(bag(meta.extra).site_url_moved_from);
|
|
720
|
+
if (from === '' || auth === null)
|
|
721
|
+
return;
|
|
722
|
+
const want = (0, record_1.externalUrl)(meta);
|
|
723
|
+
const site = await (0, rcapi_1.getSetting)(meta.rootUrl, auth, (0, record_1.adminPass)(meta), 'Site_Url');
|
|
724
|
+
if (site === null)
|
|
725
|
+
return;
|
|
726
|
+
const trim = (url) => url.replace(/\/+$/u, '');
|
|
727
|
+
if (typeof site === 'string' && trim(site) === trim(from) && trim(from) !== trim(want)) {
|
|
728
|
+
if (!(await (0, rcapi_1.setSetting)(meta.rootUrl, auth, (0, record_1.adminPass)(meta), 'Site_Url', want))) {
|
|
729
|
+
(0, events_1.warn)(emit, `Site_Url still reads ${from}, the address before this rebuild, and the browser follows ` +
|
|
730
|
+
`it: set it to ${want} (Administration, Settings, General, Site URL), or run ` +
|
|
731
|
+
`\`houston ready --name ${meta.name}\` again.`, { phase: 'post_ready' });
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
(0, events_1.info)(emit, `Site_Url moved from ${from} to ${want}, where this workspace is now served`, {
|
|
735
|
+
phase: 'post_ready',
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
await (0, record_1.updateMeta)(meta.name, (current) => {
|
|
739
|
+
delete current.extra.site_url_moved_from;
|
|
740
|
+
});
|
|
741
|
+
delete meta.extra.site_url_moved_from;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Wait for the workspace to serve, then finish it off.
|
|
745
|
+
*
|
|
746
|
+
* `final` is whether this call is the END of what the user asked for. It is for `houston
|
|
747
|
+
* ready`, which is exactly this and nothing else; `up` seeds afterwards, restore restores
|
|
748
|
+
* afterwards, and an upgrade has a rollback still to consider. All three used to announce
|
|
749
|
+
* phase `done` at 100% here and then carry on working.
|
|
750
|
+
*/
|
|
751
|
+
async function waitAndFinalize(meta, emit = events_1.nullEmit, timeout = 300.0, final = true) {
|
|
752
|
+
const started = Date.now();
|
|
753
|
+
const served = await waitServing(meta, emit, timeout);
|
|
754
|
+
const elapsed = Math.floor((Date.now() - started) / 1000);
|
|
755
|
+
const auth = await finalize(meta, emit);
|
|
756
|
+
// Before the preset's setup, which builds its callbacks and checks from Site_Url.
|
|
757
|
+
await followTheMove(meta, auth, emit);
|
|
758
|
+
// Before it too: the license Rocket.Chat holds now, not at the last `ready`, decides the advice.
|
|
759
|
+
await checkLicense(meta, auth, emit);
|
|
760
|
+
await postready.runPostReady(meta, auth, emit, { licenseGate: (0, notes_1.signInGate)(meta) });
|
|
761
|
+
// AND THE SEED THE INTERRUPTED CREATE ASKED FOR. The note says the workspace "may be
|
|
762
|
+
// running without its preset configuration or seed data" and names this command as the
|
|
763
|
+
// thing that completes it -- and this used to run post_ready, seed nothing, print
|
|
764
|
+
// "ready" and clear the note anyway.
|
|
765
|
+
//
|
|
766
|
+
// From the NOTE, not from meta: the request died with the process, and
|
|
767
|
+
// meta.extra["seed"] is written only after a seed has already succeeded.
|
|
768
|
+
let pending = (0, journal_1.pendingSeed)(meta.name);
|
|
769
|
+
const activeReceipt = (0, receipt_1.pendingReceipt)(meta.name);
|
|
770
|
+
if (activeReceipt !== null ||
|
|
771
|
+
(Object.keys(pending).length > 0 && !isTruthy(bag(meta.extra).seed))) {
|
|
772
|
+
if (activeReceipt !== null)
|
|
773
|
+
pending = {
|
|
774
|
+
...pending,
|
|
775
|
+
seed_profile: activeReceipt.plan.profile,
|
|
776
|
+
seed_scenarios: activeReceipt.plan.scenarios,
|
|
777
|
+
seed_history_days: activeReceipt.plan.historyDays,
|
|
778
|
+
};
|
|
779
|
+
(0, events_1.info)(emit, 'finishing the seed the interrupted create asked for ' +
|
|
780
|
+
`(profile: ${isTruthy(pending.seed_profile) ? String(pending.seed_profile) : 'small'})`, { phase: 'seed' });
|
|
781
|
+
try {
|
|
782
|
+
await seeding.runSeedInline(meta, isTruthy(pending.seed_profile) ? String(pending.seed_profile) : 'small', Boolean(pending.seed_stats), emit, {
|
|
783
|
+
scenarios: Array.isArray(pending.seed_scenarios)
|
|
784
|
+
? pending.seed_scenarios
|
|
785
|
+
: [],
|
|
786
|
+
historyDays: typeof pending.seed_history_days === 'number' ? pending.seed_history_days : null,
|
|
787
|
+
...(activeReceipt === null
|
|
788
|
+
? {}
|
|
789
|
+
: {
|
|
790
|
+
users: activeReceipt.plan.users,
|
|
791
|
+
channels: activeReceipt.plan.channels,
|
|
792
|
+
messages: activeReceipt.plan.messages,
|
|
793
|
+
}),
|
|
794
|
+
}, activeReceipt?.run, async () => activeReceipt !== null ||
|
|
795
|
+
(Object.keys((0, journal_1.pendingSeed)(meta.name)).length > 0 &&
|
|
796
|
+
!isTruthy(bag((await (0, record_1.readMeta)(meta.name)).extra).seed)));
|
|
797
|
+
}
|
|
798
|
+
catch (error) {
|
|
799
|
+
if (!(error instanceof errors_1.ReproError))
|
|
800
|
+
throw error;
|
|
801
|
+
// The note STAYS: a seed that could not be finished is exactly what it is for, and
|
|
802
|
+
// clearing it here would delete the only record again.
|
|
803
|
+
(0, events_1.warn)(emit, `the interrupted create's seed could not be finished (${errorText(error)}) - ` +
|
|
804
|
+
`the note stays; \`houston seed --name ${meta.name}\` retries it`, { phase: 'seed' });
|
|
805
|
+
const running = String(served.version ?? '?');
|
|
806
|
+
sayReady(emit, final);
|
|
807
|
+
return { booted_s: elapsed, running_version: running };
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
(0, journal_1.clearKind)(journal_1.CREATE_UNFINISHED, meta.name);
|
|
811
|
+
const running = String(served.version ?? '?');
|
|
812
|
+
// `baseVersion`: a CI build serves `8.10.0-develop` and is recorded as `8.10.0.dev0`.
|
|
813
|
+
if (running !== '?' && !meta.rcVersion.startsWith((0, versions_1.baseVersion)(running))) {
|
|
814
|
+
(0, events_1.warn)(emit, `running version ${running} != requested ${meta.rcVersion}`, { phase: 'wait' });
|
|
815
|
+
}
|
|
816
|
+
sayReady(emit, final);
|
|
817
|
+
return { booted_s: elapsed, running_version: running };
|
|
818
|
+
}
|