@rocket.chat/houston 0.27.0-next.2 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +108 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +669 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/troubleshooting.md +193 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +168 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +39 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3678 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +810 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2593 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +344 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +691 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1533 -0
- package/dist/core/lifecycle/create-k8s.js +939 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +635 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +726 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +753 -0
- package/dist/core/lifecycle/request.js +525 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +995 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +969 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1285 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +868 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +369 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +296 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +178 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +224 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +67 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -192
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -25
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
|
@@ -0,0 +1,493 @@
|
|
|
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.adopt = adopt;
|
|
37
|
+
exports.systemdUnit = systemdUnit;
|
|
38
|
+
exports.challengeStale = challengeStale;
|
|
39
|
+
exports.up = up;
|
|
40
|
+
exports.ensureRunning = ensureRunning;
|
|
41
|
+
exports.deleteHost = deleteHost;
|
|
42
|
+
exports.logs = logs;
|
|
43
|
+
exports.status = status;
|
|
44
|
+
/**
|
|
45
|
+
* Starting, stopping, adopting and forgetting. Tier 6 of `src/core/edge/`.
|
|
46
|
+
*
|
|
47
|
+
* Nothing in the package imports this, which is what being the top of the tiers means.
|
|
48
|
+
*/
|
|
49
|
+
const fs = __importStar(require("node:fs"));
|
|
50
|
+
const node_os_1 = require("node:os");
|
|
51
|
+
const path = __importStar(require("node:path"));
|
|
52
|
+
const compose_1 = require("../../lib/compose");
|
|
53
|
+
const errors_1 = require("../../lib/errors");
|
|
54
|
+
const home_1 = require("../../lib/home");
|
|
55
|
+
const format_1 = require("../../lib/format");
|
|
56
|
+
const json_text_1 = require("../../lib/json-text");
|
|
57
|
+
const docker_cli_1 = require("../../seams/docker-cli");
|
|
58
|
+
const exec_1 = require("../../seams/exec");
|
|
59
|
+
const paths_1 = require("../runner/paths");
|
|
60
|
+
const record_1 = require("../runner/record");
|
|
61
|
+
const tls_1 = require("../tls");
|
|
62
|
+
const acme_1 = require("./acme");
|
|
63
|
+
const engine_1 = require("./engine");
|
|
64
|
+
const networks_1 = require("./networks");
|
|
65
|
+
const paths = __importStar(require("./paths"));
|
|
66
|
+
const edgeRoutes = __importStar(require("./routes"));
|
|
67
|
+
const edgeSpec = __importStar(require("./spec"));
|
|
68
|
+
const types_1 = require("./types");
|
|
69
|
+
/**
|
|
70
|
+
* Move a workspace that runs its OWN Traefik onto the edge, without recreating it.
|
|
71
|
+
*
|
|
72
|
+
* Four steps, none of which stops Rocket.Chat or MongoDB:
|
|
73
|
+
*
|
|
74
|
+
* 1. remove ONLY the workspace's traefik container -- this is what frees 443
|
|
75
|
+
* 2. attach the edge to the workspace's network, live
|
|
76
|
+
* 3. write the route
|
|
77
|
+
* 4. rewrite the compose file so a future `up` matches reality
|
|
78
|
+
*
|
|
79
|
+
* Step 4 is a file write and is NOT applied: compose files take effect on the next `up`,
|
|
80
|
+
* so nothing restarts now. That is the difference from the first version, which called
|
|
81
|
+
* `up` here and therefore recreated every container -- minutes of downtime per workspace,
|
|
82
|
+
* and a rebuild is where an incompatibility or a lost volume would come from. Twenty
|
|
83
|
+
* workspaces is now twenty seconds.
|
|
84
|
+
*/
|
|
85
|
+
async function adopt(name) {
|
|
86
|
+
return await paths.edgeLock(async () => await adoptLocked(name));
|
|
87
|
+
}
|
|
88
|
+
async function adoptLocked(name) {
|
|
89
|
+
const meta = await (0, record_1.readMeta)(name);
|
|
90
|
+
// `orderedDict(extra)`: a copy that writes back in the record's key order and spelling, where a
|
|
91
|
+
// spread is a new object in JavaScript's order.
|
|
92
|
+
const extra = (0, json_text_1.orderedDict)(meta.extra);
|
|
93
|
+
const host = (meta.publicUrl || '').split('://').slice(-1)[0]?.split('/')[0] ?? '';
|
|
94
|
+
if (extra.tls !== tls_1.MODE_ACME || host === '') {
|
|
95
|
+
throw new errors_1.ValidationError(`'${name}' is not a --domain workspace, so there is nothing to move onto the edge`);
|
|
96
|
+
}
|
|
97
|
+
// 1. Its Traefik, and only its Traefik. `docker rm -f` on one container leaves every
|
|
98
|
+
// other service in the project running.
|
|
99
|
+
await (0, engine_1.dockerRun)(['rm', '-f', await (0, networks_1.backendContainer)(name, tls_1.SERVICE)]);
|
|
100
|
+
// 2. Live attach -- no restart of anything. Only if the edge exists yet: adoption
|
|
101
|
+
// usually runs BEFORE it starts, because freeing 443 is the whole reason it could
|
|
102
|
+
// not. `reattachAll()` picks these up after the start.
|
|
103
|
+
if (await (0, engine_1.running)())
|
|
104
|
+
await (0, networks_1.attach)(name);
|
|
105
|
+
// 3 + 4.
|
|
106
|
+
const instances = typeof extra.instances === 'number' ? extra.instances : 1;
|
|
107
|
+
const doc = await (0, record_1.readCompose)(name);
|
|
108
|
+
const services = doc.services;
|
|
109
|
+
if (services !== null && typeof services === 'object') {
|
|
110
|
+
delete services[tls_1.SERVICE];
|
|
111
|
+
}
|
|
112
|
+
extra.edge = true;
|
|
113
|
+
// It no longer publishes 443, and leaving the claim would make every later workspace
|
|
114
|
+
// allocate around a port this one does not hold.
|
|
115
|
+
extra.tls_ports = [];
|
|
116
|
+
await (0, record_1.write)(name, (0, compose_1.toYaml)(doc), { ...meta, extra });
|
|
117
|
+
await edgeRoutes.register(name, host, { instances });
|
|
118
|
+
return { name, host };
|
|
119
|
+
}
|
|
120
|
+
/** What `systemdUnit` copies from the shell that printed it, in this order. */
|
|
121
|
+
const SERVICE_ENVIRONMENT = [
|
|
122
|
+
'PATH',
|
|
123
|
+
'HOUSTON_HOME',
|
|
124
|
+
'AWS_PROFILE',
|
|
125
|
+
'AWS_REGION',
|
|
126
|
+
'AWS_DEFAULT_REGION',
|
|
127
|
+
];
|
|
128
|
+
/**
|
|
129
|
+
* The unit that keeps `houston serve` up.
|
|
130
|
+
*
|
|
131
|
+
* Printed for the operator to install, never written by houston: writing it needs root,
|
|
132
|
+
* and a tool that edits /etc/systemd on your behalf is a bigger thing to trust than one
|
|
133
|
+
* that shows you the file. It also keeps this testable as a pure string, with no
|
|
134
|
+
* privileged CI.
|
|
135
|
+
*
|
|
136
|
+
* `Restart=always` is only safe BECAUSE named accounts exist: with the old session token
|
|
137
|
+
* every restart minted a new one and killed every bookmark.
|
|
138
|
+
*
|
|
139
|
+
* It carries the PATH of the shell that printed it. systemd starts a unit with its own
|
|
140
|
+
* bare PATH, so under nvm `bin/houston`'s `exec node` failed with "node: not found"
|
|
141
|
+
* (status 127) and the unit restarted forever; docker, aws and kubectl are found the same
|
|
142
|
+
* way. AWS_PROFILE and the region go with it when set, or the GUI's EKS pages ask AWS
|
|
143
|
+
* with the default profile rather than the one the operator signed in with.
|
|
144
|
+
*/
|
|
145
|
+
function systemdUnit(execStart, user, environment = process.env) {
|
|
146
|
+
const lines = SERVICE_ENVIRONMENT.flatMap((key) => {
|
|
147
|
+
// HOUSTON_HOME too, ABSOLUTE: a unit printed from a non-default home served `User=`'s
|
|
148
|
+
// `~/.houston` -- other accounts, other workspaces -- and systemd starts it from `/`.
|
|
149
|
+
const given = environment[key] ?? '';
|
|
150
|
+
const value = key === 'HOUSTON_HOME' && given !== '' ? path.resolve(given) : given;
|
|
151
|
+
// Inside quotes systemd reads C escapes, and `%` starts a specifier.
|
|
152
|
+
const quoted = value.replace(/[\\"]/gu, '\\$&').replaceAll('%', '%%');
|
|
153
|
+
return value === '' ? [] : [`Environment="${key}=${quoted}"\n`];
|
|
154
|
+
});
|
|
155
|
+
return ('[Unit]\n' +
|
|
156
|
+
'Description=houston GUI\n' +
|
|
157
|
+
'After=docker.service\n' +
|
|
158
|
+
'Requires=docker.service\n' +
|
|
159
|
+
'\n' +
|
|
160
|
+
'[Service]\n' +
|
|
161
|
+
`User=${user}\n` +
|
|
162
|
+
lines.join('') +
|
|
163
|
+
`ExecStart=${execStart}\n` +
|
|
164
|
+
'Restart=always\n' +
|
|
165
|
+
// Without a pause systemd restarts within 100ms, and five starts in ten seconds stop it
|
|
166
|
+
// for good ("Start request repeated too quickly"). `serve --domain` exits while the edge
|
|
167
|
+
// cannot start, so one broken edge left the production GUI down after the edge was fixed.
|
|
168
|
+
'RestartSec=10\n' +
|
|
169
|
+
'\n' +
|
|
170
|
+
'[Install]\n' +
|
|
171
|
+
'WantedBy=multi-user.target\n');
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Repair stale GUI state and materialise the requested edge configuration.
|
|
175
|
+
*
|
|
176
|
+
* `acmeEmail` MATTERS. A bare edge declares no resolver -- right for `up --https`, which
|
|
177
|
+
* only ever serves local-CA names -- and a `--domain` workspace registered against it
|
|
178
|
+
* produced routes Traefik rejected with "Router uses a nonexistent certificate resolver:
|
|
179
|
+
* le", so the name 404'd while looking perfectly configured from the outside. The first
|
|
180
|
+
* workspace that needs Let's Encrypt therefore teaches the edge how to ask.
|
|
181
|
+
*/
|
|
182
|
+
/** Whether the edge asks Let's Encrypt with a challenge `acme.challenge` no longer names. */
|
|
183
|
+
function challengeStale() {
|
|
184
|
+
const now = edgeSpec.current();
|
|
185
|
+
if (now === null || !(0, acme_1.hasAcme)())
|
|
186
|
+
return false;
|
|
187
|
+
return (0, types_1.resolveEdge)(now.domain, now.acmeEmail).acmeChallenge !== now.acmeChallenge;
|
|
188
|
+
}
|
|
189
|
+
async function prepareEdge(acmeEmail, acmeStaging) {
|
|
190
|
+
// Repair a GUI route left by an older houston. That version wrote one even with no
|
|
191
|
+
// domain, producing ``Host(``)`` -- which Traefik rejects at every reload with "empty
|
|
192
|
+
// args for matcher Host", plus a certResolver a bare edge never declares. Not writing it
|
|
193
|
+
// any more does nothing for the edges that already have it, and nobody would think to
|
|
194
|
+
// look in a generated directory.
|
|
195
|
+
const gui = paths.routePath('_gui');
|
|
196
|
+
if (edgeSpec.servedDomain() === '' && fs.existsSync(gui))
|
|
197
|
+
fs.rmSync(gui, { force: true });
|
|
198
|
+
const wantAcme = acmeEmail !== '';
|
|
199
|
+
if (!edgeSpec.installed()) {
|
|
200
|
+
// Through `resolveEdge`, as the upgrade below and `serve` go: a bare `edge(...)` took the
|
|
201
|
+
// default challenge, so the first edge `up` wrote ignored `acme.challenge` and the dns-01
|
|
202
|
+
// credentials, and behind a tunnel asked for TLS-ALPN, which never validated.
|
|
203
|
+
await edgeSpec.write(wantAcme ? (0, types_1.resolveEdge)('', acmeEmail, { acmeStaging }) : (0, types_1.edge)());
|
|
204
|
+
}
|
|
205
|
+
else if (wantAcme && !(0, acme_1.hasAcme)()) {
|
|
206
|
+
// Upgrade in place: keep whatever domain `serve` gave it, add the resolver.
|
|
207
|
+
await edgeSpec.write((0, types_1.resolveEdge)(edgeSpec.servedDomain(), acmeEmail, { acmeStaging }));
|
|
208
|
+
await (0, engine_1.down)(); // so the new flags are actually applied
|
|
209
|
+
}
|
|
210
|
+
else if (wantAcme && challengeStale()) {
|
|
211
|
+
// A CHANGED `acme.challenge` reached the container only through `edge restart`: `up
|
|
212
|
+
// --domain` rebuilt the edge from the spec it was made with, so behind a tunnel (where
|
|
213
|
+
// only http-01 can validate) the next certificate failed on TLS-ALPN again, measured.
|
|
214
|
+
// Re-resolved as `edge start` does; staging as this request asks (config included), as
|
|
215
|
+
// the two branches above build it.
|
|
216
|
+
const now = edgeSpec.current();
|
|
217
|
+
if (now !== null) {
|
|
218
|
+
await edgeSpec.write((0, types_1.resolveEdge)(now.domain, now.acmeEmail, {
|
|
219
|
+
acmeStaging,
|
|
220
|
+
guiHost: now.guiHost,
|
|
221
|
+
guiPort: now.guiPort,
|
|
222
|
+
httpPort: now.httpPort,
|
|
223
|
+
httpsPort: now.httpsPort,
|
|
224
|
+
}));
|
|
225
|
+
await (0, engine_1.down)();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// A container of ours that is UP but holds no ports cannot be repaired by the `compose
|
|
229
|
+
// up -d` below: its resolved configuration has not changed, so compose leaves it exactly
|
|
230
|
+
// as it is and reports success. Remove it first, so what follows is a real attempt that
|
|
231
|
+
// either takes the ports or fails naming whoever has them.
|
|
232
|
+
const stalled = await (0, engine_1.ourContainer)();
|
|
233
|
+
if (stalled !== '' && !(await (0, engine_1.publishesPorts)(stalled)))
|
|
234
|
+
await (0, engine_1.down)();
|
|
235
|
+
}
|
|
236
|
+
/** Move every compatible pre-edge workspace off the shared HTTPS port. */
|
|
237
|
+
async function adoptLegacyPortHolders() {
|
|
238
|
+
// Workspaces from before the edge run their own Traefik on 443, which is exactly why the
|
|
239
|
+
// edge cannot start. Moving them across is now instant and touches no data, so it
|
|
240
|
+
// happens automatically rather than behind a flag -- the flag existed when doing this
|
|
241
|
+
// meant recreating every container, and asking permission for something expensive is
|
|
242
|
+
// very different from asking permission for removing one proxy container.
|
|
243
|
+
for (const held of await (0, engine_1.holdersOf443)()) {
|
|
244
|
+
try {
|
|
245
|
+
await adopt(held);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
// One workspace that will not move must not stop the others, or the edge. Whatever
|
|
249
|
+
// still holds the port is named by `portHolder()`.
|
|
250
|
+
if (!(error instanceof errors_1.ReproError) && !(error instanceof Error))
|
|
251
|
+
throw error;
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Start the edge, and return what docker said. No network to create: it joins each
|
|
258
|
+
* workspace's own.
|
|
259
|
+
*
|
|
260
|
+
* Returns the whole result rather than its return code, because the return code was all
|
|
261
|
+
* the callers ever got and a failed start is precisely the moment the output matters.
|
|
262
|
+
*/
|
|
263
|
+
async function up(options = {}) {
|
|
264
|
+
return await paths.edgeLock(async () => await upLocked(options));
|
|
265
|
+
}
|
|
266
|
+
async function upLocked({ pull = true } = {}) {
|
|
267
|
+
const other = await (0, engine_1.foreignEdge)();
|
|
268
|
+
if (other !== '') {
|
|
269
|
+
// Refuse rather than replace. `compose up` would happily take the other home's
|
|
270
|
+
// container, and the first anyone would know is every one of its names going dark.
|
|
271
|
+
throw new errors_1.ConflictError('another houston edge is already running on this machine, from a different home:\n' +
|
|
272
|
+
` ${other}\n` +
|
|
273
|
+
' Starting this one would REPLACE it and take down every https name it serves.\n' +
|
|
274
|
+
' houston is designed around one shared home per box — set HOUSTON_HOME to the ' +
|
|
275
|
+
'same\n directory as the other user, or stop that edge first:\n' +
|
|
276
|
+
` HOUSTON_HOME=${path.dirname(other)} houston edge stop`);
|
|
277
|
+
}
|
|
278
|
+
if (pull)
|
|
279
|
+
await (0, engine_1.composeRun)(['pull']); // non-fatal, exactly as `runner.up` does it
|
|
280
|
+
let res = await (0, engine_1.composeRun)(['up', '-d', '--remove-orphans']);
|
|
281
|
+
// A stopped edge restarts as the same container, so on the same systemd unit, and a unit
|
|
282
|
+
// its last run left loaded fails every start (`STALE_UNIT`). Its certificates and routes
|
|
283
|
+
// are bind mounts, so a recreated edge loses nothing.
|
|
284
|
+
if (res.returncode !== 0) {
|
|
285
|
+
const state = await (0, engine_1.dockerRun)(['inspect', paths.CONTAINER, '--format', '{{.State.Error}}']);
|
|
286
|
+
if (state.returncode === 0 && docker_cli_1.STALE_UNIT.test(state.stdout)) {
|
|
287
|
+
res = await (0, engine_1.composeRun)(['up', '-d', '--remove-orphans', '--force-recreate']);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (res.returncode === 0) {
|
|
291
|
+
// Every start, not just the first: a recreated container has none of its previous
|
|
292
|
+
// attachments, and the route files that outlived it would then all answer 502.
|
|
293
|
+
await edgeRoutes.reattachAll();
|
|
294
|
+
}
|
|
295
|
+
return res;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Start the edge lazily, on the first route that needs it.
|
|
299
|
+
*
|
|
300
|
+
* Never at install and never on plain `serve`: a laptop that never asks for a name never
|
|
301
|
+
* learns this exists. Workspace and GUI HTTPS remain unrelated.
|
|
302
|
+
*/
|
|
303
|
+
async function ensureRunning(options = {}) {
|
|
304
|
+
// Preparation and compose must see one generation. Locking only the final `up`
|
|
305
|
+
// still lets a concurrent bare start replace a newly written ACME resolver.
|
|
306
|
+
return await paths.edgeLock(async () => await ensureRunningLocked(options));
|
|
307
|
+
}
|
|
308
|
+
async function ensureRunningLocked({ acmeEmail = '', acmeStaging = false, } = {}) {
|
|
309
|
+
await prepareEdge(acmeEmail, acmeStaging);
|
|
310
|
+
if (await (0, engine_1.running)()) {
|
|
311
|
+
// RUNNING IS NOT UP TO DATE. This returned true here, and the caller had already
|
|
312
|
+
// rewritten the compose file -- `serve --domain X --email Y` calls `write(door)` first
|
|
313
|
+
// -- so a changed resolver email, a changed domain or any new flag was written to disk
|
|
314
|
+
// and never applied. The container kept the command line it was created with, `serve`
|
|
315
|
+
// reported success, and nothing said the two disagreed. Found on a box whose
|
|
316
|
+
// `acme.json` held an account for a MIStyped address while the corrected one was being
|
|
317
|
+
// passed on every restart.
|
|
318
|
+
//
|
|
319
|
+
// `docker compose up -d` is the right instrument: it is idempotent and recreates the
|
|
320
|
+
// container ONLY if the resolved configuration changed, so this costs one compose call
|
|
321
|
+
// when nothing has and does the necessary thing when something has. The adoption loop
|
|
322
|
+
// below is skipped -- nothing else can be holding :443 while this edge has it.
|
|
323
|
+
const res = await up({ pull: false });
|
|
324
|
+
return res.returncode === 0 ? (0, types_1.startResult)(true) : (0, types_1.startResult)(false, (0, engine_1.why)(res));
|
|
325
|
+
}
|
|
326
|
+
await adoptLegacyPortHolders();
|
|
327
|
+
const res = await up({ pull: false });
|
|
328
|
+
return res.returncode === 0 ? (0, types_1.startResult)(true) : (0, types_1.startResult)(false, (0, engine_1.why)(res));
|
|
329
|
+
}
|
|
330
|
+
/** Validate a destructive hostname request and return its claimed routes. */
|
|
331
|
+
async function validateHostDeletion(host, confirm) {
|
|
332
|
+
const wanted = (host || '').trim().replace(/\.+$/u, '');
|
|
333
|
+
if (wanted === '') {
|
|
334
|
+
throw new errors_1.ValidationError('name a hostname to delete: `houston edge delete <host>`. `houston edge status` ' +
|
|
335
|
+
'lists them.');
|
|
336
|
+
}
|
|
337
|
+
const gui = edgeSpec.servedDomain();
|
|
338
|
+
if (gui !== '' && (0, format_1.foldCase)(gui) === (0, format_1.foldCase)(wanted)) {
|
|
339
|
+
throw new errors_1.ConflictError(`${wanted} is the GUI's own name, so deleting it would take \`houston serve\` off ` +
|
|
340
|
+
'HTTPS while you are probably using it. Stop the edge (`houston edge stop`) if ' +
|
|
341
|
+
'that is really what you want.');
|
|
342
|
+
}
|
|
343
|
+
const routes = edgeRoutes.routesFor(wanted);
|
|
344
|
+
const live = [];
|
|
345
|
+
for (const name of routes) {
|
|
346
|
+
if (await (0, paths_1.exists)(name))
|
|
347
|
+
live.push(name);
|
|
348
|
+
}
|
|
349
|
+
if (live.length > 0) {
|
|
350
|
+
throw new errors_1.ConflictError(`${wanted} still belongs to workspace '${live.join(', ')}' — deleting its ` +
|
|
351
|
+
'certificate would leave a workspace that cannot serve its own name. `houston ' +
|
|
352
|
+
`down --name ${String(live[0])} --volumes\` first, then delete the name.`);
|
|
353
|
+
}
|
|
354
|
+
if (!confirm) {
|
|
355
|
+
throw new errors_1.ValidationError(`deleting ${wanted} removes its certificate and PRIVATE KEY and cannot be undone - ` +
|
|
356
|
+
'pass confirm=true');
|
|
357
|
+
}
|
|
358
|
+
return [wanted, routes];
|
|
359
|
+
}
|
|
360
|
+
/** Delete route, certificate, declaration, and ACME state for one hostname. */
|
|
361
|
+
async function deleteHostFiles(host, routes) {
|
|
362
|
+
// Passthrough first: the answer for a Kubernetes name is genuinely different, and saying
|
|
363
|
+
// "certificate removed" about one that was never here would be a lie in the shape this
|
|
364
|
+
// codebase keeps finding -- reporting the attempt as the outcome.
|
|
365
|
+
const through = routes.filter((name) => edgeRoutes.isPassthrough(name));
|
|
366
|
+
for (const name of routes)
|
|
367
|
+
edgeRoutes.deregister(name);
|
|
368
|
+
const crt = (0, home_1.joinPath)(paths.certsDir(), `${host}.crt`);
|
|
369
|
+
const key = (0, home_1.joinPath)(paths.certsDir(), `${host}.key`);
|
|
370
|
+
const hadCert = fs.existsSync(crt) || fs.existsSync(key);
|
|
371
|
+
fs.rmSync(crt, { force: true });
|
|
372
|
+
fs.rmSync(key, { force: true });
|
|
373
|
+
const decl = (0, home_1.joinPath)(paths.dynamicDir(), `_cert-${host}.yml`);
|
|
374
|
+
const hadDecl = fs.existsSync(decl);
|
|
375
|
+
fs.rmSync(decl, { force: true });
|
|
376
|
+
return [through, hadCert, hadDecl, await (0, acme_1.forgetAcme)(host)];
|
|
377
|
+
}
|
|
378
|
+
/** Refresh our edge's in-memory ACME store, or identify a foreign edge. */
|
|
379
|
+
async function restartAfterAcmeDelete(stores, restart) {
|
|
380
|
+
let foreign = '';
|
|
381
|
+
let restarted = null;
|
|
382
|
+
if (stores.length > 0 && restart) {
|
|
383
|
+
if (await (0, engine_1.running)()) {
|
|
384
|
+
restarted = (await (0, engine_1.down)()) === 0 && (await up({ pull: false })).returncode === 0;
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
foreign = await (0, engine_1.foreignEdge)();
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return [foreign, restarted];
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Forget `host` entirely: its routes, certificate, key, and ACME entry.
|
|
394
|
+
*
|
|
395
|
+
* Returns what actually went, per kind, so the caller reports the deletion it made instead
|
|
396
|
+
* of the one it attempted.
|
|
397
|
+
*
|
|
398
|
+
* Three refusals, and each one is a case where deleting would break something the caller
|
|
399
|
+
* can still see:
|
|
400
|
+
*
|
|
401
|
+
* * a LIVE workspace still claims the name -- `down` it first, named in the error. A
|
|
402
|
+
* route whose workspace record is gone is the orphan this command exists for, so that
|
|
403
|
+
* one proceeds.
|
|
404
|
+
* * the name is the GUI's own -- deleting it takes `serve` off the network the operator
|
|
405
|
+
* is most likely using to run this.
|
|
406
|
+
* * `confirm` is not set. A private key is not recoverable and this is the only gate.
|
|
407
|
+
*
|
|
408
|
+
* `restart` is the part that is easy to get wrong. Traefik holds its ACME store in memory
|
|
409
|
+
* and persists the whole file when a certificate changes, so an edit made underneath a
|
|
410
|
+
* running Traefik can be written back from memory later -- the entry reappears, hours
|
|
411
|
+
* after a command said it was deleted. Restarting rebuilds that memory from the edited
|
|
412
|
+
* file. Routes are files, so every other name comes back with no re-registration; that
|
|
413
|
+
* property is why a restart is affordable here.
|
|
414
|
+
*/
|
|
415
|
+
async function deleteHost(host, options = {}) {
|
|
416
|
+
return await paths.edgeLock(async () => await deleteHostLocked(host, options));
|
|
417
|
+
}
|
|
418
|
+
async function deleteHostLocked(host, { confirm = false, restart = true } = {}) {
|
|
419
|
+
const [wanted, routes] = await validateHostDeletion(host, confirm);
|
|
420
|
+
const [through, hadCert, hadDecl, stores] = await deleteHostFiles(wanted, routes);
|
|
421
|
+
// Docker is asked ONLY for an ACME deletion. A route or a local certificate is read from
|
|
422
|
+
// disk every time, so removing the file is already in effect; making a file deletion
|
|
423
|
+
// depend on a daemon to decide it need not restart would be a cost with nothing bought.
|
|
424
|
+
//
|
|
425
|
+
// `running()` is HOME-AWARE -- it matches the compose project label AND the working
|
|
426
|
+
// directory -- so `down()` here cannot reach an edge belonging to a different
|
|
427
|
+
// HOUSTON_HOME, which every home naming its project `houston_edge` would otherwise make
|
|
428
|
+
// trivially possible. That is not hypothetical: doing it by hand cost this box's owner
|
|
429
|
+
// their edge once, following an error message that did not know about it either.
|
|
430
|
+
//
|
|
431
|
+
// Which leaves the case worth REPORTING rather than guarding: ours is not running and
|
|
432
|
+
// somebody else's is. A foreign edge mounts its own home's ACME store, so the
|
|
433
|
+
// certificate just deleted was this home's copy and NOT the one being served -- and a
|
|
434
|
+
// plain "removed" would read as a name that stopped resolving.
|
|
435
|
+
const [foreign, restarted] = await restartAfterAcmeDelete(stores, restart);
|
|
436
|
+
return {
|
|
437
|
+
host: wanted,
|
|
438
|
+
routes: [...routes],
|
|
439
|
+
passthrough: through,
|
|
440
|
+
certificate: hadCert,
|
|
441
|
+
declaration: hadDecl,
|
|
442
|
+
acme: stores,
|
|
443
|
+
restarted,
|
|
444
|
+
foreign,
|
|
445
|
+
kept: fs.existsSync((0, tls_1.issuedPath)()) ? [`acme/${tls_1.ISSUED_FILE}`] : [],
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Stream or dump the edge's own log, and return the exit code.
|
|
450
|
+
*
|
|
451
|
+
* The edge is where HTTPS actually succeeds or fails, and until now there was no way to
|
|
452
|
+
* read it from houston: `edge` offered status/start/stop/restart, so the answer to "my
|
|
453
|
+
* name serves nothing" lived in a container whose name you had to know.
|
|
454
|
+
*
|
|
455
|
+
* It matters most for ACME. Traefik requests certificates in the BACKGROUND after it
|
|
456
|
+
* starts, so a name can be routed, the edge can be healthy, and issuance can still be
|
|
457
|
+
* failing -- and the only record of why is here.
|
|
458
|
+
*/
|
|
459
|
+
async function logs({ tail = 200, follow = false } = {}) {
|
|
460
|
+
const args = ['logs', `--tail=${String(tail)}`];
|
|
461
|
+
if (follow)
|
|
462
|
+
args.push('-f');
|
|
463
|
+
// NOT CAPTURED: the child inherits the terminal, so `-f` behaves like `docker compose
|
|
464
|
+
// logs -f` and compose's own errors reach the reader in its words. This went through
|
|
465
|
+
// composeRun, which captures, and dropped what it caught: `edge logs` printed nothing of
|
|
466
|
+
// the log and `-f` nothing at all.
|
|
467
|
+
//
|
|
468
|
+
// Same contract otherwise: an absent `edge/` or docker must not be a stack trace. Not
|
|
469
|
+
// reachable from the CLI, which guards on `installed()` first, and hardened anyway -- a
|
|
470
|
+
// seam that raises for one caller raises for the next one. A Ctrl-C is not a launch
|
|
471
|
+
// failure; it unwinds as the Interrupted it is.
|
|
472
|
+
try {
|
|
473
|
+
const res = await (0, docker_cli_1.compose)(['-p', paths.PROJECT, ...args], { cwd: paths.edgeDir() });
|
|
474
|
+
// `returncode`: a child a signal ended is minus that signal, the established convention.
|
|
475
|
+
return res.exitCode ?? -node_os_1.constants.signals[res.signal];
|
|
476
|
+
}
|
|
477
|
+
catch (error) {
|
|
478
|
+
if (error instanceof exec_1.Interrupted)
|
|
479
|
+
throw error;
|
|
480
|
+
return engine_1.LAUNCH_FAILURE_CODE;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/** What `doctor` and the GUI report. */
|
|
484
|
+
async function status() {
|
|
485
|
+
return {
|
|
486
|
+
installed: edgeSpec.installed(),
|
|
487
|
+
running: await (0, engine_1.running)(),
|
|
488
|
+
routes: edgeRoutes.registered(),
|
|
489
|
+
// Which workspace networks it is currently joined to. A route with no attachment is a
|
|
490
|
+
// 502 rather than an error, so the two belong side by side.
|
|
491
|
+
attached: [...(await (0, networks_1.attachedNetworks)())].sort(),
|
|
492
|
+
};
|
|
493
|
+
}
|