@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,500 @@
|
|
|
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.edgeDocker = exports.LAUNCH_FAILURE_CODE = void 0;
|
|
37
|
+
exports.holdersOf443 = holdersOf443;
|
|
38
|
+
exports.dockerRun = dockerRun;
|
|
39
|
+
exports.composeRun = composeRun;
|
|
40
|
+
exports.composeCapture = composeCapture;
|
|
41
|
+
exports.bridgeAddress = bridgeAddress;
|
|
42
|
+
exports.down = down;
|
|
43
|
+
exports.ourContainer = ourContainer;
|
|
44
|
+
exports.repairRootlessIngress = repairRootlessIngress;
|
|
45
|
+
exports.publishesPorts = publishesPorts;
|
|
46
|
+
exports.running = running;
|
|
47
|
+
exports.portHolder = portHolder;
|
|
48
|
+
exports.foreignEdge = foreignEdge;
|
|
49
|
+
exports.why = why;
|
|
50
|
+
/**
|
|
51
|
+
* Docker, for the edge. Tier 1 of `src/core/edge/`.
|
|
52
|
+
*
|
|
53
|
+
* Everything here goes through `seams/docker-cli.ts`, and this module is the adapter that
|
|
54
|
+
* gives invocation failures the edge's contract: invocation adapters NEVER RAISE, the caller
|
|
55
|
+
* reads the return code. The lifecycle lock and checked ingress repair can still refuse
|
|
56
|
+
* an operation.
|
|
57
|
+
*
|
|
58
|
+
* That contract is not decoration. `houston edge stop` on a fresh home answered with a
|
|
59
|
+
* stack trace naming a path under HOUSTON_HOME, because `cwd` is `edgeDir()` and a home
|
|
60
|
+
* that has never had an edge has no such directory. 127 is what a shell reports for
|
|
61
|
+
* "could not run it", and the reason travels on stderr where `why()` already looks.
|
|
62
|
+
*/
|
|
63
|
+
const node_net_1 = require("node:net");
|
|
64
|
+
const errors_1 = require("../../lib/errors");
|
|
65
|
+
const format_1 = require("../../lib/format");
|
|
66
|
+
const docker_cli_1 = require("../../seams/docker-cli");
|
|
67
|
+
const host_1 = require("../runner/host");
|
|
68
|
+
const record_1 = require("../runner/record");
|
|
69
|
+
const ports_1 = require("../runner/ports");
|
|
70
|
+
const paths = __importStar(require("./paths"));
|
|
71
|
+
const paths_1 = require("./paths");
|
|
72
|
+
/** The synthetic code a launch failure reports; the same 127 every other seam uses. */
|
|
73
|
+
exports.LAUNCH_FAILURE_CODE = 127;
|
|
74
|
+
/**
|
|
75
|
+
* Workspaces running their OWN Traefik on 443.
|
|
76
|
+
*
|
|
77
|
+
* They predate the edge, and they are why it cannot start: a machine has one port 443,
|
|
78
|
+
* and theirs already has it. Read from the record rather than from docker, so this answers
|
|
79
|
+
* the same whether they are running or merely `down`.
|
|
80
|
+
*/
|
|
81
|
+
async function holdersOf443() {
|
|
82
|
+
const out = [];
|
|
83
|
+
for (const meta of await (0, record_1.listMeta)()) {
|
|
84
|
+
const extra = meta.extra;
|
|
85
|
+
if (extra.edge === true)
|
|
86
|
+
continue;
|
|
87
|
+
const ports = Array.isArray(extra.tls_ports) ? extra.tls_ports : [];
|
|
88
|
+
if (ports.some((port) => Number.parseInt(String(port), 10) === 443))
|
|
89
|
+
out.push(meta.name);
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
/** Run one docker command. NEVER RAISES; the caller reads the return code. */
|
|
94
|
+
async function dockerRun(args, { timeoutMs = 30000 } = {}) {
|
|
95
|
+
const argv = ['docker', ...args];
|
|
96
|
+
try {
|
|
97
|
+
const res = await (0, docker_cli_1.docker)(args, { capture: true, text: true, timeoutMs });
|
|
98
|
+
return {
|
|
99
|
+
argv,
|
|
100
|
+
returncode: res.exitCode ?? exports.LAUNCH_FAILURE_CODE,
|
|
101
|
+
stdout: String(res.stdout ?? ''),
|
|
102
|
+
stderr: String(res.stderr ?? ''),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
return {
|
|
107
|
+
argv,
|
|
108
|
+
returncode: exports.LAUNCH_FAILURE_CODE,
|
|
109
|
+
stdout: '',
|
|
110
|
+
stderr: error instanceof Error ? error.message : String(error),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* `docker compose` in the edge's own project. NEVER RAISES; read the return code.
|
|
116
|
+
*
|
|
117
|
+
* An explicit `-p`: the project must NOT be derived from the directory name, or it would
|
|
118
|
+
* depend on where `<home>` happens to be.
|
|
119
|
+
*/
|
|
120
|
+
async function composeRun(args, { timeoutMs } = {}) {
|
|
121
|
+
const argv = ['docker', 'compose', '-p', paths_1.PROJECT, ...args];
|
|
122
|
+
try {
|
|
123
|
+
const res = await (0, docker_cli_1.compose)(['-p', paths_1.PROJECT, ...args], {
|
|
124
|
+
cwd: paths.edgeDir(),
|
|
125
|
+
capture: true,
|
|
126
|
+
text: true,
|
|
127
|
+
...(timeoutMs === undefined ? {} : { timeoutMs }),
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
argv,
|
|
131
|
+
returncode: res.exitCode ?? exports.LAUNCH_FAILURE_CODE,
|
|
132
|
+
stdout: String(res.stdout ?? ''),
|
|
133
|
+
stderr: String(res.stderr ?? ''),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
return {
|
|
138
|
+
argv,
|
|
139
|
+
returncode: exports.LAUNCH_FAILURE_CODE,
|
|
140
|
+
stdout: '',
|
|
141
|
+
stderr: error instanceof Error ? error.message : String(error),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** `docker compose` in the edge project, captured. '' if it could not run. */
|
|
146
|
+
async function composeCapture(args) {
|
|
147
|
+
const res = await composeRun(args, { timeoutMs: 30000 });
|
|
148
|
+
if (res.returncode === exports.LAUNCH_FAILURE_CODE && res.stdout === '' && res.stderr !== '') {
|
|
149
|
+
// Could not run it at all: '' for this, as it has always been, which is what makes
|
|
150
|
+
// `acmeFailure` report nothing rather than report the launch error as a Traefik log.
|
|
151
|
+
return '';
|
|
152
|
+
}
|
|
153
|
+
return res.stdout + res.stderr;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The Docker bridge gateway, or '' if it cannot be determined.
|
|
157
|
+
*
|
|
158
|
+
* What the GUI binds when an edge is in front of it: the edge reaches it here (via
|
|
159
|
+
* host.docker.internal, which resolves to this), and nothing off the box can -- verified
|
|
160
|
+
* reachable from a container and refused from 127.0.0.1. That is strictly better than
|
|
161
|
+
* 0.0.0.0, which would publish the control plane to the whole network just so one
|
|
162
|
+
* container could reach it.
|
|
163
|
+
*
|
|
164
|
+
* Read rather than hardcoded to 172.17.0.1: that is only the DEFAULT bridge subnet, and a
|
|
165
|
+
* box with a custom `bip` or an occupied 172.17/16 gets a different one.
|
|
166
|
+
*/
|
|
167
|
+
async function bridgeAddress() {
|
|
168
|
+
const out = await dockerRun([
|
|
169
|
+
'network',
|
|
170
|
+
'inspect',
|
|
171
|
+
'bridge',
|
|
172
|
+
'--format',
|
|
173
|
+
'{{(index .IPAM.Config 0).Gateway}}',
|
|
174
|
+
]);
|
|
175
|
+
const gateway = out.returncode === 0 ? out.stdout.trim() : '';
|
|
176
|
+
// ONLY IF THIS MACHINE CAN LISTEN THERE. A VM engine (Docker Desktop, a Podman machine)
|
|
177
|
+
// keeps its bridge inside the VM, so the gateway is no address of this host and the GUI
|
|
178
|
+
// could not bind it; such an engine forwards host.docker.internal to the host's loopback
|
|
179
|
+
// instead. Asked by binding, not by listing interfaces: a Docker host's docker0 is DOWN
|
|
180
|
+
// until a container uses it, and listing would wrongly call its gateway absent.
|
|
181
|
+
if (gateway !== '' && !(await (0, ports_1.portFree)(0, gateway)))
|
|
182
|
+
return '127.0.0.1';
|
|
183
|
+
return gateway;
|
|
184
|
+
}
|
|
185
|
+
/** Stop the edge. Routes are files and survive this, so starting it again restores
|
|
186
|
+
* every name with no re-registration. */
|
|
187
|
+
async function down() {
|
|
188
|
+
return await paths.edgeLock(async () => (await composeRun(['down', '--remove-orphans'])).returncode);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The id of a RUNNING edge container belonging to THIS home, or ''.
|
|
192
|
+
*
|
|
193
|
+
* Split out from `running()` so the two questions stay separate: whether a container of
|
|
194
|
+
* ours is up, and whether it is actually serving. Conflating them is what let a Traefik
|
|
195
|
+
* holding no ports be reported as a working edge.
|
|
196
|
+
*/
|
|
197
|
+
async function ourContainer() {
|
|
198
|
+
const out = await dockerRun([
|
|
199
|
+
'ps',
|
|
200
|
+
'--filter',
|
|
201
|
+
`label=com.docker.compose.project=${paths_1.PROJECT}`,
|
|
202
|
+
'--filter',
|
|
203
|
+
'status=running',
|
|
204
|
+
'--format',
|
|
205
|
+
'{{.ID}}',
|
|
206
|
+
]);
|
|
207
|
+
if (out.returncode !== 0)
|
|
208
|
+
return '';
|
|
209
|
+
for (const cid of out.stdout.split(/\s+/u).filter((entry) => entry !== '')) {
|
|
210
|
+
const where = await dockerRun([
|
|
211
|
+
'inspect',
|
|
212
|
+
cid,
|
|
213
|
+
'--format',
|
|
214
|
+
'{{index .Config.Labels "com.docker.compose.project.working_dir"}}',
|
|
215
|
+
]);
|
|
216
|
+
if (where.returncode === 0 && where.stdout.trim() === paths.edgeDir())
|
|
217
|
+
return cid;
|
|
218
|
+
}
|
|
219
|
+
return '';
|
|
220
|
+
}
|
|
221
|
+
/** The inspected IPv4 of the edge's own ingress network, or unknown. */
|
|
222
|
+
async function ingressAddress(cid) {
|
|
223
|
+
const seen = await dockerRun(['inspect', cid, '--format', '{{json .NetworkSettings.Networks}}']);
|
|
224
|
+
if (seen.returncode !== 0) {
|
|
225
|
+
return { value: null, reason: `could not inspect ingress: ${why(seen)}` };
|
|
226
|
+
}
|
|
227
|
+
try {
|
|
228
|
+
const parsed = JSON.parse(seen.stdout);
|
|
229
|
+
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
230
|
+
const ingress = parsed[`${paths_1.PROJECT}_default`];
|
|
231
|
+
if (ingress !== null && typeof ingress === 'object' && !Array.isArray(ingress)) {
|
|
232
|
+
const address = ingress.IPAddress;
|
|
233
|
+
if (typeof address === 'string' && (0, node_net_1.isIPv4)(address)) {
|
|
234
|
+
return { value: address, reason: '' };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return { value: null, reason: `inspect has no valid IPv4 for ${paths_1.PROJECT}_default` };
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
return { value: null, reason: 'ingress inspect was not valid JSON' };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/** Actual IPv4 interface addresses from the command proven in the edge image. */
|
|
245
|
+
async function namespaceAddresses(cid) {
|
|
246
|
+
const seen = await dockerRun(['exec', cid, 'ip', 'addr', 'show'], {
|
|
247
|
+
timeoutMs: 5000,
|
|
248
|
+
});
|
|
249
|
+
if (seen.returncode !== 0) {
|
|
250
|
+
return { value: null, reason: `could not read actual ingress addresses: ${why(seen)}` };
|
|
251
|
+
}
|
|
252
|
+
const lines = seen.stdout.split('\n').filter((line) => line.trim() !== '');
|
|
253
|
+
if (lines.length === 0)
|
|
254
|
+
return { value: null, reason: 'actual address output was empty' };
|
|
255
|
+
const addresses = new Set();
|
|
256
|
+
let hasInterface = false;
|
|
257
|
+
const malformed = { value: null, reason: 'actual address output was malformed' };
|
|
258
|
+
for (const line of lines) {
|
|
259
|
+
if (/^[1-9]\d*:\s+\S+:\s+<[^>]+>\s+mtu\s+\d+(?:\s.*)?$/u.test(line)) {
|
|
260
|
+
hasInterface = true;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (!hasInterface || !/^\s/u.test(line))
|
|
264
|
+
return malformed;
|
|
265
|
+
const text = line.trim();
|
|
266
|
+
if (/^inet\s/u.test(text)) {
|
|
267
|
+
const match = /^inet\s+([0-9.]+)\/(\d+)(?:\s+brd\s+([0-9.]+))?\s+scope\s+(?:host|global|link)(?:\s+\S+)*$/u.exec(text);
|
|
268
|
+
if (match === null ||
|
|
269
|
+
match[1] === undefined ||
|
|
270
|
+
match[2] === undefined ||
|
|
271
|
+
!(0, node_net_1.isIPv4)(match[1]) ||
|
|
272
|
+
Number(match[2]) > 32 ||
|
|
273
|
+
(match[3] !== undefined && !(0, node_net_1.isIPv4)(match[3]))) {
|
|
274
|
+
return malformed;
|
|
275
|
+
}
|
|
276
|
+
addresses.add(match[1]);
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (/^inet6\s/u.test(text)) {
|
|
280
|
+
const match = /^inet6\s+([0-9a-f:.]+)\/(\d+)\s+scope\s+(?:host|global|link|site)(?:\s+\S+)*$/iu.exec(text);
|
|
281
|
+
if (match === null ||
|
|
282
|
+
match[1] === undefined ||
|
|
283
|
+
match[2] === undefined ||
|
|
284
|
+
!(0, node_net_1.isIPv6)(match[1]) ||
|
|
285
|
+
Number(match[2]) > 128) {
|
|
286
|
+
return malformed;
|
|
287
|
+
}
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (/^link\/(?:loopback|ether)\s+(?:[0-9a-f]{2}:){5}[0-9a-f]{2}(?:\s+brd\s+(?:[0-9a-f]{2}:){5}[0-9a-f]{2})?$/iu.test(text) ||
|
|
291
|
+
/^valid_lft\s+(?:forever|\d+sec)\s+preferred_lft\s+(?:forever|\d+sec)$/u.test(text)) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
return malformed;
|
|
295
|
+
}
|
|
296
|
+
return addresses.size > 0
|
|
297
|
+
? { value: addresses, reason: '' }
|
|
298
|
+
: { value: null, reason: 'actual address output contained no IPv4 addresses' };
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Repair only a proven missing rootless-Podman ingress address after a network change.
|
|
302
|
+
*
|
|
303
|
+
* Podman can retain the edge's own network in inspect after losing its actual interface.
|
|
304
|
+
* The published rootless forwarder then accepts TCP but cannot reach Traefik. A restart
|
|
305
|
+
* rebuilds this container's namespace and forwarder without changing routes or certs.
|
|
306
|
+
*
|
|
307
|
+
* Call with edgeLock held. Docker, rootful Podman, unknown probes and workspace-only
|
|
308
|
+
* address loss leave the existing behavior alone. A known broken ingress briefly stops
|
|
309
|
+
* THIS home's shared edge exactly once; a failed or unverified repair raises its reason.
|
|
310
|
+
*/
|
|
311
|
+
async function repairRootlessIngress() {
|
|
312
|
+
const host = await (0, host_1.engine)();
|
|
313
|
+
if (host === null || host.kind !== 'podman' || !host.rootless)
|
|
314
|
+
return;
|
|
315
|
+
const cid = await ourContainer();
|
|
316
|
+
if (cid === '')
|
|
317
|
+
return;
|
|
318
|
+
const address = await ingressAddress(cid);
|
|
319
|
+
if (address.value === null)
|
|
320
|
+
return;
|
|
321
|
+
const actual = await namespaceAddresses(cid);
|
|
322
|
+
if (actual.value === null || actual.value.has(address.value))
|
|
323
|
+
return;
|
|
324
|
+
// Re-read both ownership and ingress after the first observation. A replaced edge,
|
|
325
|
+
// unreadable probe, or legitimate address change cannot authorise restarting stale ID.
|
|
326
|
+
if ((await ourContainer()) !== cid)
|
|
327
|
+
return;
|
|
328
|
+
const currentAddress = await ingressAddress(cid);
|
|
329
|
+
if (currentAddress.value === null)
|
|
330
|
+
return;
|
|
331
|
+
const currentActual = await namespaceAddresses(cid);
|
|
332
|
+
if (currentActual.value === null || currentActual.value.has(currentAddress.value))
|
|
333
|
+
return;
|
|
334
|
+
const restarted = await dockerRun(['restart', cid]);
|
|
335
|
+
if (restarted.returncode !== 0) {
|
|
336
|
+
throw new errors_1.DockerError(`Podman edge ingress repair failed for ${cid}: ${why(restarted)}`);
|
|
337
|
+
}
|
|
338
|
+
if ((await ourContainer()) !== cid) {
|
|
339
|
+
throw new errors_1.DockerError(`Podman edge ingress repair lost ownership of ${cid}`);
|
|
340
|
+
}
|
|
341
|
+
const repairedAddress = await ingressAddress(cid);
|
|
342
|
+
const repairedActual = await namespaceAddresses(cid);
|
|
343
|
+
if (repairedAddress.value === null ||
|
|
344
|
+
repairedActual.value === null ||
|
|
345
|
+
!repairedActual.value.has(repairedAddress.value)) {
|
|
346
|
+
const reason = repairedAddress.value === null
|
|
347
|
+
? repairedAddress.reason
|
|
348
|
+
: repairedActual.value === null
|
|
349
|
+
? repairedActual.reason
|
|
350
|
+
: `inspected address ${repairedAddress.value} is still absent from the container`;
|
|
351
|
+
throw new errors_1.DockerError(`Podman edge ingress repair did not restore ${paths_1.PROJECT}_default on ${cid}: ${reason}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Whether container `cid` actually HOLDS :80 and :443.
|
|
356
|
+
*
|
|
357
|
+
* Up is not the same as serving, and the gap is not theoretical: a container can start
|
|
358
|
+
* while another process owns its ports, and Docker then runs it with the bindings simply
|
|
359
|
+
* absent. That is a Traefik answering on nothing -- it cannot serve a single name -- and
|
|
360
|
+
* `running()` used to call it running. `edge status` then said "State running" over an
|
|
361
|
+
* edge that was serving nothing, which is the one shape of wrong answer this file exists
|
|
362
|
+
* to avoid: every workspace with a name depends on this component, and nothing else in
|
|
363
|
+
* the tool would have contradicted it.
|
|
364
|
+
*/
|
|
365
|
+
async function publishesPorts(cid) {
|
|
366
|
+
const seen = await dockerRun(['inspect', cid, '--format', '{{json .NetworkSettings.Ports}}']);
|
|
367
|
+
if (seen.returncode !== 0)
|
|
368
|
+
return true; // cannot tell: do not invent a failure
|
|
369
|
+
let ports;
|
|
370
|
+
try {
|
|
371
|
+
const parsed = JSON.parse(seen.stdout.trim() || '{}');
|
|
372
|
+
ports =
|
|
373
|
+
parsed !== null && typeof parsed === 'object' ? parsed : {};
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
// A truth test on each of `80/tcp` and `443/tcp`, so a port EXPOSED with no binding --
|
|
379
|
+
// `"443/tcp": []` -- holds nothing, as `null` does. Only null, undefined and false
|
|
380
|
+
// counted as unbound here, so doctor called that edge running and exited 0 where the
|
|
381
|
+
// established answer is NOT running, exit 1.
|
|
382
|
+
return [80, 443].every((port) => (0, format_1.isTruthy)(ports[`${String(port)}/tcp`]));
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Whether THIS home's edge is running.
|
|
386
|
+
*
|
|
387
|
+
* The project label alone is not enough. Every HOUSTON_HOME uses the same compose project
|
|
388
|
+
* name, so a container started from a different home matched and this returned true --
|
|
389
|
+
* while `installed()`, which reads the current home, returned false. `ensureRunning()`
|
|
390
|
+
* then skipped writing any configuration, the routes went into a directory nothing was
|
|
391
|
+
* watching, and every name 404'd with `edge status` reporting "no edge yet" beside a
|
|
392
|
+
* running edge.
|
|
393
|
+
*/
|
|
394
|
+
async function running() {
|
|
395
|
+
const cid = await ourContainer();
|
|
396
|
+
return cid !== '' && (await publishesPorts(cid));
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* What is holding `port`, named, or '' if nothing is.
|
|
400
|
+
*
|
|
401
|
+
* The edge failing to bind is the one startup error that is genuinely somebody else's
|
|
402
|
+
* fault, and "the edge did not start" is useless on its own -- hit twice while building
|
|
403
|
+
* this, once from a stale front door left by an older houston and once from an unrelated
|
|
404
|
+
* Traefik. Docker can name a container; anything else is at least identified as not-us.
|
|
405
|
+
*/
|
|
406
|
+
async function portHolder(port = 443) {
|
|
407
|
+
const out = await dockerRun(['ps', '--format', '{{.Names}}\t{{.Ports}}']);
|
|
408
|
+
if (out.returncode === 0) {
|
|
409
|
+
const mine = await running();
|
|
410
|
+
for (const line of out.stdout.split('\n')) {
|
|
411
|
+
const [name, ports] = [line.split('\t')[0] ?? '', line.split('\t').slice(1).join('\t')];
|
|
412
|
+
if (!ports.includes(`:${String(port)}->`))
|
|
413
|
+
continue;
|
|
414
|
+
// Skipping by NAME alone hid the most confusing case of all: an edge from a
|
|
415
|
+
// different HOUSTON_HOME has exactly our container name, so it was excluded as
|
|
416
|
+
// "us" and reported as "something outside Docker".
|
|
417
|
+
if (name === paths_1.CONTAINER && mine)
|
|
418
|
+
continue;
|
|
419
|
+
if (name === paths_1.CONTAINER)
|
|
420
|
+
return `an edge from another houston home, usually houston run with sudo or as another user (${(0, format_1.quotedText)(name)})`;
|
|
421
|
+
const proj = await dockerRun([
|
|
422
|
+
'inspect',
|
|
423
|
+
name,
|
|
424
|
+
'--format',
|
|
425
|
+
'{{index .Config.Labels "com.docker.compose.project"}}',
|
|
426
|
+
]);
|
|
427
|
+
const label = proj.returncode === 0 ? proj.stdout.trim() : '';
|
|
428
|
+
// The project MATTERS, because it is what `docker compose -p ... down` takes.
|
|
429
|
+
// Naming only the container sent somebody at our own project, which is the one
|
|
430
|
+
// command that cannot free the port.
|
|
431
|
+
if (label !== '' && label !== paths_1.PROJECT) {
|
|
432
|
+
// `quotedText`'s quotes, so a project named `it's-proj` is double-quoted, as it has
|
|
433
|
+
// always been printed.
|
|
434
|
+
return `the container ${(0, format_1.quotedText)(name)} (compose project ${(0, format_1.quotedText)(label)})`;
|
|
435
|
+
}
|
|
436
|
+
return `the container ${(0, format_1.quotedText)(name)}`;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return (await (0, ports_1.portFree)(port)) ? '' : 'something outside Docker';
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* The working directory of an edge belonging to a DIFFERENT HOUSTON_HOME.
|
|
443
|
+
*
|
|
444
|
+
* Compose keys a project by NAME, and every home uses the same one, so `docker compose -p
|
|
445
|
+
* houston_edge up -d` REPLACES another home's container rather than failing -- silently
|
|
446
|
+
* taking down every https name that edge was serving. Observed doing exactly that while
|
|
447
|
+
* testing.
|
|
448
|
+
*
|
|
449
|
+
* It matters more than the "one shared home" assumption suggests, because the default home
|
|
450
|
+
* is `~/.houston`: on a box where two people each run houston as themselves, the second
|
|
451
|
+
* `up --https` quietly steals the first one's ingress.
|
|
452
|
+
*/
|
|
453
|
+
async function foreignEdge() {
|
|
454
|
+
const out = await dockerRun([
|
|
455
|
+
'ps',
|
|
456
|
+
'--filter',
|
|
457
|
+
`label=com.docker.compose.project=${paths_1.PROJECT}`,
|
|
458
|
+
'--filter',
|
|
459
|
+
'status=running',
|
|
460
|
+
'--format',
|
|
461
|
+
'{{.ID}}',
|
|
462
|
+
]);
|
|
463
|
+
for (const cid of out.stdout.split(/\s+/u).filter((entry) => entry !== '')) {
|
|
464
|
+
const where = await dockerRun([
|
|
465
|
+
'inspect',
|
|
466
|
+
cid,
|
|
467
|
+
'--format',
|
|
468
|
+
'{{index .Config.Labels "com.docker.compose.project.working_dir"}}',
|
|
469
|
+
]);
|
|
470
|
+
const found = where.stdout.trim();
|
|
471
|
+
if (found !== '' && found !== paths.edgeDir())
|
|
472
|
+
return found;
|
|
473
|
+
}
|
|
474
|
+
return '';
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* The line that explains a docker failure, not the first 500 characters of noise.
|
|
478
|
+
*
|
|
479
|
+
* Same rule as the kube seam's `why`, and for the same reason: compose puts its
|
|
480
|
+
* diagnostics FIRST and its error LAST, so taking a prefix reliably shows the least
|
|
481
|
+
* useful part.
|
|
482
|
+
*/
|
|
483
|
+
function why(res, limit = 500) {
|
|
484
|
+
const text = [res.stderr, res.stdout].filter((part) => part !== '').join('\n');
|
|
485
|
+
const lines = text
|
|
486
|
+
.split('\n')
|
|
487
|
+
.map((line) => line.trim())
|
|
488
|
+
.filter((line) => line !== '');
|
|
489
|
+
for (const line of [...lines].reverse()) {
|
|
490
|
+
const low = line.toLowerCase();
|
|
491
|
+
if (low.startsWith('error') || low.includes('error:') || low.includes('cannot')) {
|
|
492
|
+
return line.slice(0, limit);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return lines.length > 0
|
|
496
|
+
? lines[lines.length - 1].slice(0, limit)
|
|
497
|
+
: 'docker said nothing';
|
|
498
|
+
}
|
|
499
|
+
/** The injectable callables, for the same swc reason every other seam adapter has one. */
|
|
500
|
+
exports.edgeDocker = { run: dockerRun, compose: composeRun, capture: composeCapture };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.workspaceNetwork = workspaceNetwork;
|
|
4
|
+
exports.backendContainer = backendContainer;
|
|
5
|
+
exports.containerAddresses = containerAddresses;
|
|
6
|
+
exports.attachedNetworks = attachedNetworks;
|
|
7
|
+
exports.attach = attach;
|
|
8
|
+
exports.attachNetwork = attachNetwork;
|
|
9
|
+
exports.containerNetwork = containerNetwork;
|
|
10
|
+
exports.detach = detach;
|
|
11
|
+
exports.releaseVanished = releaseVanished;
|
|
12
|
+
/**
|
|
13
|
+
* The Docker networks the edge joins. Tier 2 of `src/core/edge/`.
|
|
14
|
+
*/
|
|
15
|
+
const record_1 = require("../runner/record");
|
|
16
|
+
const engine_1 = require("./engine");
|
|
17
|
+
const paths_1 = require("./paths");
|
|
18
|
+
/** The network compose creates for a workspace: `<project>_default`. */
|
|
19
|
+
async function workspaceNetwork(name) {
|
|
20
|
+
return `${await (0, record_1.projectName)(name)}_default`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The container compose creates for one of a workspace's services.
|
|
24
|
+
*
|
|
25
|
+
* A CONTAINER name, not a service alias, and that distinction is the whole reason routes
|
|
26
|
+
* work. The edge is attached to many workspace networks, each containing a service called
|
|
27
|
+
* `rocketchat`; asking for `rocketchat` from there resolved 6/6 to one particular
|
|
28
|
+
* workspace. Container names are unique across every network, so they cannot be confused.
|
|
29
|
+
*/
|
|
30
|
+
async function backendContainer(name, service) {
|
|
31
|
+
return `${await (0, record_1.projectName)(name)}-${service}-1`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Every IP the edge container currently holds, one per network it has joined.
|
|
35
|
+
*
|
|
36
|
+
* This is what `serve --domain` trusts for X-Forwarded-*, and it has to be the EXACT set
|
|
37
|
+
* rather than a subnet: the edge reaches the host from an address on a workspace network,
|
|
38
|
+
* and that /16 also contains the customer-image Rocket.Chat containers. A CIDR here would
|
|
39
|
+
* hand X-Forwarded-For to every workspace.
|
|
40
|
+
*
|
|
41
|
+
* Re-read rather than cached: the set changes as the edge joins networks.
|
|
42
|
+
*/
|
|
43
|
+
async function containerAddresses() {
|
|
44
|
+
const out = await (0, engine_1.dockerRun)([
|
|
45
|
+
'inspect',
|
|
46
|
+
paths_1.CONTAINER,
|
|
47
|
+
'--format',
|
|
48
|
+
'{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}',
|
|
49
|
+
]);
|
|
50
|
+
if (out.returncode !== 0)
|
|
51
|
+
return [];
|
|
52
|
+
return out.stdout.split(/\s+/u).filter((address) => address !== '');
|
|
53
|
+
}
|
|
54
|
+
/** Workspace networks the edge is currently joined to. */
|
|
55
|
+
async function attachedNetworks() {
|
|
56
|
+
const out = await (0, engine_1.dockerRun)([
|
|
57
|
+
'inspect',
|
|
58
|
+
paths_1.CONTAINER,
|
|
59
|
+
'--format',
|
|
60
|
+
'{{range $k,$v := .NetworkSettings.Networks}}{{$k}}\n{{end}}',
|
|
61
|
+
]);
|
|
62
|
+
if (out.returncode !== 0)
|
|
63
|
+
return new Set();
|
|
64
|
+
return new Set(out.stdout
|
|
65
|
+
.split('\n')
|
|
66
|
+
.map((line) => line.trim())
|
|
67
|
+
.filter((line) => line !== ''));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Join the edge to `name`'s own network, live. Idempotent.
|
|
71
|
+
*
|
|
72
|
+
* This is what replaces recreating the workspace. `docker network connect` acts on a
|
|
73
|
+
* RUNNING container -- verified: reachable immediately afterwards, with the target's
|
|
74
|
+
* StartedAt unchanged. Nothing stops, nothing is rebuilt, no volume is touched, so doing
|
|
75
|
+
* this to twenty workspaces costs twenty seconds rather than twenty rebuilds.
|
|
76
|
+
*
|
|
77
|
+
* Joining the EDGE to the workspace's network (rather than the workspace to a shared one)
|
|
78
|
+
* is what preserves isolation: each workspace keeps the private network compose already
|
|
79
|
+
* gave it, and verified that w1 could reach w2 neither by name nor by IP with the edge
|
|
80
|
+
* attached to both.
|
|
81
|
+
*/
|
|
82
|
+
async function attach(name) {
|
|
83
|
+
return await (0, paths_1.edgeLock)(async () => {
|
|
84
|
+
const net = await workspaceNetwork(name);
|
|
85
|
+
if (!(await attachedNetworks()).has(net)) {
|
|
86
|
+
// A workspace that has never been `up`ed has no network yet; not an error, the attach
|
|
87
|
+
// simply happens after it is created.
|
|
88
|
+
const joined = await (0, engine_1.dockerRun)(['network', 'connect', net, paths_1.CONTAINER]);
|
|
89
|
+
if (joined.returncode !== 0)
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
await (0, engine_1.repairRootlessIngress)();
|
|
93
|
+
return true;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Join the edge to a Docker network BY NAME. Idempotent.
|
|
98
|
+
*
|
|
99
|
+
* `attach` joins a network derived from a WORKSPACE name, which is every network the edge
|
|
100
|
+
* has ever needed -- until a cluster turned out to be one too. A kind cluster's node is a
|
|
101
|
+
* container on kind's own Docker network, so its NodePort is reachable from the host and
|
|
102
|
+
* NOT from a container on the default bridge, which is where the edge lives. Measured
|
|
103
|
+
* exactly that way: `172.18.0.2:30925` answered from the host and from a container on the
|
|
104
|
+
* `kind` network, and was unreachable from one on `bridge`.
|
|
105
|
+
*
|
|
106
|
+
* Kept separate from `attach` rather than generalising it: that function's whole contract
|
|
107
|
+
* is "the network compose made for this workspace", and its name is what makes the
|
|
108
|
+
* container-name routing rule readable.
|
|
109
|
+
*/
|
|
110
|
+
async function attachNetwork(net) {
|
|
111
|
+
if (net === '')
|
|
112
|
+
return true;
|
|
113
|
+
return await (0, paths_1.edgeLock)(async () => {
|
|
114
|
+
if (!(await attachedNetworks()).has(net)) {
|
|
115
|
+
const joined = await (0, engine_1.dockerRun)(['network', 'connect', net, paths_1.CONTAINER]);
|
|
116
|
+
if (joined.returncode !== 0)
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
await (0, engine_1.repairRootlessIngress)();
|
|
120
|
+
return true;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The first Docker network `container` is on, or ''.
|
|
125
|
+
*
|
|
126
|
+
* Used to find out where a cluster's node lives, so the edge can join it. Read rather than
|
|
127
|
+
* assumed: kind's default network is called `kind`, but a cluster created with a different
|
|
128
|
+
* config need not be on it.
|
|
129
|
+
*/
|
|
130
|
+
async function containerNetwork(container) {
|
|
131
|
+
const out = await (0, engine_1.dockerRun)([
|
|
132
|
+
'inspect',
|
|
133
|
+
container,
|
|
134
|
+
'--format',
|
|
135
|
+
'{{range $k,$v := .NetworkSettings.Networks}}{{$k}} {{end}}',
|
|
136
|
+
]);
|
|
137
|
+
if (out.returncode !== 0)
|
|
138
|
+
return '';
|
|
139
|
+
const names = out.stdout.split(/\s+/u).filter((entry) => entry !== '');
|
|
140
|
+
return names[0] ?? '';
|
|
141
|
+
}
|
|
142
|
+
/** Leave `name`'s network. A missing network is harmless; a failed ingress repair raises. */
|
|
143
|
+
async function detach(name) {
|
|
144
|
+
await (0, paths_1.edgeLock)(async () => {
|
|
145
|
+
const left = await (0, engine_1.dockerRun)([
|
|
146
|
+
'network',
|
|
147
|
+
'disconnect',
|
|
148
|
+
'-f',
|
|
149
|
+
await workspaceNetwork(name),
|
|
150
|
+
paths_1.CONTAINER,
|
|
151
|
+
]);
|
|
152
|
+
if (left.returncode === 0)
|
|
153
|
+
await (0, engine_1.repairRootlessIngress)();
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Let go of a VANISHED workspace's network: leave it, then remove it once no container of
|
|
158
|
+
* the workspace is left. With the edge attached, compose could not remove it ("Resource is
|
|
159
|
+
* still in use") and it outlived even `edge stop`. A container still there keeps it, so a
|
|
160
|
+
* workspace whose record alone went keeps a network to start on. Best-effort.
|
|
161
|
+
*/
|
|
162
|
+
async function releaseVanished(name) {
|
|
163
|
+
await detach(name);
|
|
164
|
+
const project = await (0, record_1.projectName)(name);
|
|
165
|
+
const left = await (0, engine_1.dockerRun)([
|
|
166
|
+
'ps',
|
|
167
|
+
'-aq',
|
|
168
|
+
'--filter',
|
|
169
|
+
`label=com.docker.compose.project=${project}`,
|
|
170
|
+
]);
|
|
171
|
+
if (left.returncode !== 0 || left.stdout.trim() !== '')
|
|
172
|
+
return;
|
|
173
|
+
await (0, engine_1.dockerRun)(['network', 'rm', await workspaceNetwork(name)]);
|
|
174
|
+
}
|