@rocket.chat/houston 0.27.0-next.3 → 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 -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,612 @@
|
|
|
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.LEGACY_SKILL_DIR = exports.LEGACY_LOG_NAME = exports.LEGACY_EDGE_PROJECT = exports.LEGACY_NAMESPACE_PREFIX = exports.LEGACY_HOME_DIRNAME = void 0;
|
|
37
|
+
exports.legacyHome = legacyHome;
|
|
38
|
+
exports.isEffectivelyEmpty = isEffectivelyEmpty;
|
|
39
|
+
exports.pending = pending;
|
|
40
|
+
exports.migrate = migrate;
|
|
41
|
+
/**
|
|
42
|
+
* Adopt a pre-rename state directory, once, without recreating anything.
|
|
43
|
+
*
|
|
44
|
+
* This tool was called rc-repro and kept its state in `~/.rc-repro`. The rename moves that to
|
|
45
|
+
* `~/.houston`. Everything here is about doing the move WITHOUT touching the containers,
|
|
46
|
+
* namespaces, certificates or volumes the old name created: those are adopted by
|
|
47
|
+
* `runner.projectName` and `kube.namespaceFor`, which read what a workspace wrote down
|
|
48
|
+
* instead of deriving it from a prefix. A migration that recreated a workspace would destroy
|
|
49
|
+
* the customer data the repro exists to hold, so nothing here calls `up`, `down`, or anything
|
|
50
|
+
* that writes to Docker or Kubernetes.
|
|
51
|
+
*
|
|
52
|
+
* Most of the state needs no rewriting at all, which is worth stating because it looks too
|
|
53
|
+
* easy: `repro.json` has ALWAYS recorded `project`, and the Kubernetes path has recorded
|
|
54
|
+
* `extra["namespace"]` since it existed. The records were never wrong -- only the readers
|
|
55
|
+
* were, and that is fixed in `runner`/`kube` rather than here. What is left is the handful
|
|
56
|
+
* of places where the old name was written into a FILE and read back.
|
|
57
|
+
*
|
|
58
|
+
* There is deliberately no journal entry and no lock. `fs.rename` is atomic, so a process
|
|
59
|
+
* killed during the move leaves either the old directory or the new one and never half of
|
|
60
|
+
* each; everything after the move is idempotent and keyed on what it finds rather than on
|
|
61
|
+
* having been told, so a killed run is simply finished by the next one. A journal `kind`
|
|
62
|
+
* would have to be taught to `journal.recover` in order to describe a side effect that
|
|
63
|
+
* cannot occur.
|
|
64
|
+
*
|
|
65
|
+
* Deliberately NOT done here: anything root-owned. The systemd unit at
|
|
66
|
+
* `/etc/systemd/system/rc-repro.service` and the CA certificate installed in the system
|
|
67
|
+
* trust store both need sudo and an informed human, and the shared edge holds :80 and :443
|
|
68
|
+
* for every workspace on the box -- taking it down as a silent side effect of somebody's
|
|
69
|
+
* first command after an upgrade is an outage nobody asked for. `doctor` names all three,
|
|
70
|
+
* with the command to fix each.
|
|
71
|
+
*/
|
|
72
|
+
const fs = __importStar(require("node:fs"));
|
|
73
|
+
const path = __importStar(require("node:path"));
|
|
74
|
+
const config = __importStar(require("../lib/config"));
|
|
75
|
+
const errors_1 = require("../lib/errors");
|
|
76
|
+
const events_1 = require("../lib/events");
|
|
77
|
+
const home_1 = require("../lib/home");
|
|
78
|
+
const format_1 = require("../lib/format");
|
|
79
|
+
const json_text_1 = require("../lib/json-text");
|
|
80
|
+
const docker_cli_1 = require("../seams/docker-cli");
|
|
81
|
+
const edgePaths = __importStar(require("./edge/paths"));
|
|
82
|
+
const edgeRuntime = __importStar(require("./edge/runtime"));
|
|
83
|
+
const edgeSpec = __importStar(require("./edge/spec"));
|
|
84
|
+
const types_1 = require("./edge/types");
|
|
85
|
+
const host_1 = require("./runner/host");
|
|
86
|
+
const paths_1 = require("./runner/paths");
|
|
87
|
+
const record_1 = require("./runner/record");
|
|
88
|
+
const skill = __importStar(require("./skill"));
|
|
89
|
+
const topology = __importStar(require("./topology"));
|
|
90
|
+
/**
|
|
91
|
+
* Where state lived before the rename, and the names that were written INTO files there
|
|
92
|
+
* and read back out again.
|
|
93
|
+
*/
|
|
94
|
+
exports.LEGACY_HOME_DIRNAME = '.rc-repro';
|
|
95
|
+
exports.LEGACY_NAMESPACE_PREFIX = 'rc-repro-';
|
|
96
|
+
exports.LEGACY_EDGE_PROJECT = 'rcrepro_edge';
|
|
97
|
+
exports.LEGACY_LOG_NAME = 'rc-repro.log';
|
|
98
|
+
exports.LEGACY_SKILL_DIR = 'rc-repro';
|
|
99
|
+
/**
|
|
100
|
+
* Files whose COMMENT lines carry the old name.
|
|
101
|
+
*
|
|
102
|
+
* Only lines beginning with "#" are rewritten: `users` holds account names and password
|
|
103
|
+
* hashes on its other lines and a blanket substitution there could rewrite somebody's
|
|
104
|
+
* username.
|
|
105
|
+
*/
|
|
106
|
+
const COMMENTED_FILES = ['sessions', 'users', 'first-run'];
|
|
107
|
+
/**
|
|
108
|
+
* The pre-rename state directory on this box, or null.
|
|
109
|
+
*
|
|
110
|
+
* Only the DEFAULT location is ever migrated. If `HOUSTON_HOME` is set -- or its
|
|
111
|
+
* pre-rename alias, which `config.env` still honours -- then an operator has said where
|
|
112
|
+
* state lives, and moving a directory they named by hand is not a decision this function
|
|
113
|
+
* gets to make on their behalf. `doctor` reports that case instead.
|
|
114
|
+
*/
|
|
115
|
+
function legacyHome() {
|
|
116
|
+
if (config.env('HOUSTON_HOME') !== '')
|
|
117
|
+
return null;
|
|
118
|
+
// `LEGACY_HOME_DIRNAME` under the user's home, and every path in this module joined
|
|
119
|
+
// component by component, a `..` kept as written (`joinPath`): `path.join` folded a
|
|
120
|
+
// `..` in HOME or the home that the kernel resolves through a symlink, so an earlier
|
|
121
|
+
// version adopted -- and emptied -- a different directory from the one earlier releases
|
|
122
|
+
// adopt.
|
|
123
|
+
const legacy = (0, home_1.joinPath)((0, home_1.pathHome)(), exports.LEGACY_HOME_DIRNAME);
|
|
124
|
+
try {
|
|
125
|
+
return fs.statSync(legacy).isDirectory() ? legacy : null;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function filesUnder(root) {
|
|
132
|
+
const out = [];
|
|
133
|
+
const walk = (dir) => {
|
|
134
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
135
|
+
const full = (0, home_1.joinPath)(dir, entry.name);
|
|
136
|
+
if (entry.isDirectory())
|
|
137
|
+
walk(full);
|
|
138
|
+
else
|
|
139
|
+
out.push(full);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
walk(root);
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Truthiness for a value read out of JSON: absent, null, `false`, `0`, `""`, `[]` and `{}`
|
|
147
|
+
* are all false.
|
|
148
|
+
*
|
|
149
|
+
* Whether `extra.namespace` is recorded is a truth test, not a presence test, so `0`,
|
|
150
|
+
* `false`, `""`, `[]` and `{}` all mean "not recorded". Enumerating only `undefined`/`null`/
|
|
151
|
+
* `""` here made a `repro.json` carrying any of the others skip a workspace earlier
|
|
152
|
+
* releases would have stamped -- and an unstamped Kubernetes workspace is one a later
|
|
153
|
+
* `down` aims at the wrong namespace.
|
|
154
|
+
*/
|
|
155
|
+
function isTruthy(value) {
|
|
156
|
+
if (value === undefined || value === null || value === false || value === '')
|
|
157
|
+
return false;
|
|
158
|
+
if (typeof value === 'number')
|
|
159
|
+
return value !== 0;
|
|
160
|
+
if (Array.isArray(value))
|
|
161
|
+
return value.length > 0;
|
|
162
|
+
if (typeof value === 'object')
|
|
163
|
+
return Object.keys(value).length > 0;
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The three failure classes the edge regeneration is allowed to report and swallow.
|
|
168
|
+
*
|
|
169
|
+
* An OS error is a Node system error (it carries `syscall`/`errno`, which a `ReproError`
|
|
170
|
+
* does not); a bad value is what a broken `spec.json` gives, which here is `JSON.parse`'s
|
|
171
|
+
* `SyntaxError`; a `TypeError` is `edgeFrom` refusing a key it does not know. Anything
|
|
172
|
+
* else is a bug in this build and belongs at the top of the process, not in a warning.
|
|
173
|
+
*/
|
|
174
|
+
function isSpecFault(error) {
|
|
175
|
+
if (error instanceof SyntaxError || error instanceof TypeError)
|
|
176
|
+
return true;
|
|
177
|
+
return error instanceof Error && 'syscall' in error && 'errno' in error;
|
|
178
|
+
}
|
|
179
|
+
/** Whether a filesystem error is "there is nothing here" rather than "I could not look". */
|
|
180
|
+
function isMissing(error) {
|
|
181
|
+
return (typeof error === 'object' && error !== null && error.code === 'ENOENT');
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Whether `path` holds nothing that would be lost by removing it.
|
|
185
|
+
*
|
|
186
|
+
* An early `config.home()` on a fresh box can mkdir the target before anything has been
|
|
187
|
+
* written into it, and refusing to migrate because of a directory this tool created itself
|
|
188
|
+
* one command ago would strand the state permanently.
|
|
189
|
+
*
|
|
190
|
+
* THE EVENT LOG COUNTS AS EMPTY, and that is the case this actually happens in.
|
|
191
|
+
* `logs/houston.log` is opened by the first command that runs at all -- so a box that ran a
|
|
192
|
+
* single `houston --version` before its state was adopted has a non-empty ~/.houston
|
|
193
|
+
* holding nothing but a record of that one command. Treating that as "state" refuses the
|
|
194
|
+
* migration forever, on the strength of a file whose entire content is the invocation that
|
|
195
|
+
* created it.
|
|
196
|
+
*
|
|
197
|
+
* A READ THAT FAILED IS NOT AN EMPTY DIRECTORY, and this is the one place this module
|
|
198
|
+
* deliberately does not reproduce the previous implementation. Its directory walk swallows
|
|
199
|
+
* a permission error and yields nothing, so it answers "empty" for a state directory it
|
|
200
|
+
* cannot read -- and the only caller then removes it. Measured: a directory holding a
|
|
201
|
+
* file, chmod 000, is "empty" there. Only a missing directory is genuinely empty here;
|
|
202
|
+
* anything else that refuses to be listed is a refusal to migrate, which the caller turns
|
|
203
|
+
* into the ConflictError telling the operator to sort the two homes out by hand.
|
|
204
|
+
*/
|
|
205
|
+
function isEffectivelyEmpty(target) {
|
|
206
|
+
let files;
|
|
207
|
+
try {
|
|
208
|
+
files = filesUnder(target);
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
return isMissing(error);
|
|
212
|
+
}
|
|
213
|
+
const logs = (0, home_1.joinPath)(target, 'logs');
|
|
214
|
+
return files.every((f) => path.dirname(f) === logs && path.basename(f).startsWith('houston.log'));
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* A file's text, with every CRLF and lone CR turned into LF.
|
|
218
|
+
*
|
|
219
|
+
* The translation happens before anything sees the string, so a file this rewrites comes
|
|
220
|
+
* back with LF endings, as it always has. Reading the bytes verbatim here would write
|
|
221
|
+
* different bytes from earlier releases for the same input file.
|
|
222
|
+
*/
|
|
223
|
+
function readText(file) {
|
|
224
|
+
return fs.readFileSync(file, 'utf8').replace(/\r\n?/gu, '\n');
|
|
225
|
+
}
|
|
226
|
+
/** Files under `home` still carrying the old name on a comment line. */
|
|
227
|
+
function staleMarkers(home) {
|
|
228
|
+
const out = [];
|
|
229
|
+
for (const leaf of COMMENTED_FILES) {
|
|
230
|
+
let text;
|
|
231
|
+
try {
|
|
232
|
+
text = readText((0, home_1.joinPath)(home, leaf));
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if ((0, format_1.splitTextLines)(text).some((ln) => ln.startsWith('#') && ln.includes('rc-repro'))) {
|
|
238
|
+
out.push(leaf);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Whether anything is left to adopt.
|
|
245
|
+
*
|
|
246
|
+
* True while the old directory is still there, and ALSO true when the move happened but
|
|
247
|
+
* the in-place fixes did not -- which is what makes an interrupted run finishable by the
|
|
248
|
+
* next one without a journal.
|
|
249
|
+
*/
|
|
250
|
+
function pending() {
|
|
251
|
+
if (legacyHome() !== null)
|
|
252
|
+
return true;
|
|
253
|
+
const home = config.home();
|
|
254
|
+
return staleMarkers(home).length > 0 || fs.existsSync((0, home_1.joinPath)(home, 'logs', exports.LEGACY_LOG_NAME));
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Rewrite the old name out of comment lines. Idempotent.
|
|
258
|
+
*
|
|
259
|
+
* Reports rather than emits: see `migrate` on why nothing here may emit.
|
|
260
|
+
*/
|
|
261
|
+
async function rewriteMarkers(home) {
|
|
262
|
+
const done = [];
|
|
263
|
+
for (const leaf of staleMarkers(home)) {
|
|
264
|
+
const target = (0, home_1.joinPath)(home, leaf);
|
|
265
|
+
const mode = fs.statSync(target).mode & 0o777;
|
|
266
|
+
// Lines with their terminators kept: the terminator travels with its line, so a file
|
|
267
|
+
// with no trailing newline does not gain one.
|
|
268
|
+
const lines = (0, format_1.splitTextLines)(readText(target), true);
|
|
269
|
+
const fixed = lines.map((ln) => ln.startsWith('#') ? ln.split('rc-repro').join('houston') : ln);
|
|
270
|
+
await (0, paths_1.atomicWrite)(target, fixed.join(''), { mode });
|
|
271
|
+
done.push(leaf);
|
|
272
|
+
}
|
|
273
|
+
// `# houston-state:` in `sessions` is the one name in this codebase that is written AND
|
|
274
|
+
// parsed back -- doctor reads it to refuse a state file written by a newer build. Left
|
|
275
|
+
// unrewritten the marker never matches and that refusal quietly stops happening, which is
|
|
276
|
+
// the failure you cannot see.
|
|
277
|
+
return done;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Move `logs/rc-repro.log*` to `logs/houston.log*`. Idempotent.
|
|
281
|
+
*
|
|
282
|
+
* A file already at the destination means an earlier run got as far as opening the new log,
|
|
283
|
+
* so the old one is kept beside it under `.pre-rename` rather than skipped: skipping would
|
|
284
|
+
* leave `pending()` true forever and re-run this on every command.
|
|
285
|
+
*/
|
|
286
|
+
function renameLogs(home) {
|
|
287
|
+
const logs = (0, home_1.joinPath)(home, 'logs');
|
|
288
|
+
let moved = 0;
|
|
289
|
+
try {
|
|
290
|
+
if (!fs.statSync(logs).isDirectory())
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return 0;
|
|
295
|
+
}
|
|
296
|
+
const names = fs
|
|
297
|
+
.readdirSync(logs)
|
|
298
|
+
.filter((n) => n.startsWith(exports.LEGACY_LOG_NAME))
|
|
299
|
+
.sort();
|
|
300
|
+
for (const name of names) {
|
|
301
|
+
const src = (0, home_1.joinPath)(logs, name);
|
|
302
|
+
let dest = (0, home_1.joinPath)(logs, name.replace(exports.LEGACY_LOG_NAME, 'houston.log'));
|
|
303
|
+
if (fs.existsSync(dest)) {
|
|
304
|
+
dest = (0, home_1.joinPath)(logs, `${name}.pre-rename`);
|
|
305
|
+
if (fs.existsSync(dest))
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
fs.renameSync(src, dest);
|
|
309
|
+
moved += 1;
|
|
310
|
+
}
|
|
311
|
+
return moved;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Record the namespace a Kubernetes workspace is ALREADY in, where it is absent.
|
|
315
|
+
*
|
|
316
|
+
* `createWorkspace` has written `extra["namespace"]` for as long as the Kubernetes runtime
|
|
317
|
+
* has existed, so this is empty for almost everybody. A workspace made before that field,
|
|
318
|
+
* though, has nothing recorded, and `namespaceFor` would derive `houston-<name>` for
|
|
319
|
+
* objects that are sitting in `rc-repro-<name>` -- sending a later `down` at a namespace
|
|
320
|
+
* that was never created while the real one keeps its pods, its PVCs and its port-forward.
|
|
321
|
+
*/
|
|
322
|
+
async function stampNamespaces() {
|
|
323
|
+
const stamped = [];
|
|
324
|
+
for (const meta of await (0, record_1.listMeta)()) {
|
|
325
|
+
const name = meta.name;
|
|
326
|
+
if (topology.ofMeta(meta) !== topology.KUBERNETES)
|
|
327
|
+
continue;
|
|
328
|
+
const extra = meta.extra;
|
|
329
|
+
const bag = typeof extra === 'object' && extra !== null && !Array.isArray(extra)
|
|
330
|
+
? extra
|
|
331
|
+
: {};
|
|
332
|
+
if (isTruthy(bag.namespace))
|
|
333
|
+
continue;
|
|
334
|
+
await (0, record_1.updateMeta)(name, (m) => {
|
|
335
|
+
// `orderedDict(m.extra)`, which keeps the record's key order and its numbers' spelling; a
|
|
336
|
+
// spread is a new object in JavaScript's order with neither.
|
|
337
|
+
m.extra = (0, json_text_1.orderedDict)(m.extra);
|
|
338
|
+
m.extra.namespace = `${exports.LEGACY_NAMESPACE_PREFIX}${name}`;
|
|
339
|
+
});
|
|
340
|
+
stamped.push(name);
|
|
341
|
+
}
|
|
342
|
+
return stamped;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Replace agent-skill copies installed under the old directory name.
|
|
346
|
+
*
|
|
347
|
+
* `skill install` writes into ~/.claude/skills/<tool>/ and ~/.agents/skills/<tool>/, so the
|
|
348
|
+
* directory name IS the tool name and a rename strands the old copy. Nothing breaks loudly:
|
|
349
|
+
* the stale SKILL.md keeps teaching agents to run `rc-repro <cmd>`, a command that no longer
|
|
350
|
+
* exists, and an agent following it fails in a way that looks like the agent's fault.
|
|
351
|
+
*
|
|
352
|
+
* Safe to do unattended, unlike the other leftovers, because these are this tool's own files
|
|
353
|
+
* in a directory it created for itself -- no sudo, nothing shared, and nothing another
|
|
354
|
+
* program is entitled to. A locally EDITED skill is left alone: `install` refuses to discard
|
|
355
|
+
* somebody's changes, and that refusal is right here too, so the old copy is kept and
|
|
356
|
+
* reported rather than silently overwritten.
|
|
357
|
+
*/
|
|
358
|
+
function adoptSkillCopies(emit) {
|
|
359
|
+
const removed = [];
|
|
360
|
+
for (const host of Object.keys(skill.HOSTS)) {
|
|
361
|
+
// ASKED FOR, not rebuilt. `skill` owns where a host's skill directory is -- the agent
|
|
362
|
+
// home it is under is private to that module for the reason its own docstring gives --
|
|
363
|
+
// so the pre-rename copy is the same question with the old name.
|
|
364
|
+
const old = skill.hostSkillDir(host, exports.LEGACY_SKILL_DIR);
|
|
365
|
+
try {
|
|
366
|
+
if (!fs.statSync(old).isDirectory())
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
skill.install(host);
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
// a locally edited skill, most likely
|
|
377
|
+
(0, events_1.warn)(emit, `${old} is stale but the new skill could not be installed ` +
|
|
378
|
+
`(${error instanceof Error ? error.message : String(error)}) — ` +
|
|
379
|
+
'`houston skill install` after resolving it');
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
// Removed with every error ignored -- `force` only forgives ENOENT, so an
|
|
383
|
+
// unreadable file inside somebody's agent directory would otherwise throw out of
|
|
384
|
+
// `migrate()` and take down the command that called it.
|
|
385
|
+
try {
|
|
386
|
+
fs.rmSync(old, { recursive: true, force: true });
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
// every error ignored
|
|
390
|
+
}
|
|
391
|
+
removed.push(old);
|
|
392
|
+
}
|
|
393
|
+
if (removed.length > 0) {
|
|
394
|
+
(0, events_1.info)(emit, `replaced ${String(removed.length)} pre-rename agent skill copy/copies`);
|
|
395
|
+
}
|
|
396
|
+
return removed;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Rewrite the edge's compose file so its ABSOLUTE paths follow the move.
|
|
400
|
+
*
|
|
401
|
+
* Two of the edge's three mounts are relative (`./dynamic`, `./certs`) and travel with the
|
|
402
|
+
* directory. The ACME store is not: it is written as an absolute path, because it is shared
|
|
403
|
+
* with workspaces and lives beside the edge rather than inside it. After the move that path
|
|
404
|
+
* names ~/.rc-repro/acme, which no longer exists -- and Docker does not fail on a missing
|
|
405
|
+
* bind source, it CREATES it, empty and root-owned. The edge would then come up with an
|
|
406
|
+
* empty ACME store pointed at production Let's Encrypt and re-request every name it already
|
|
407
|
+
* held, spending a rate limit that allows five duplicates a week, to replace certificates
|
|
408
|
+
* that were never lost.
|
|
409
|
+
*
|
|
410
|
+
* `spec.json` records everything the compose file is generated from, so this is a
|
|
411
|
+
* regeneration rather than a rewrite: the same code path `edge start` uses.
|
|
412
|
+
*/
|
|
413
|
+
async function regenerateEdgeCompose(emit) {
|
|
414
|
+
const specFile = (0, home_1.joinPath)(edgePaths.edgeDir(), edgePaths.SPEC_FILE);
|
|
415
|
+
try {
|
|
416
|
+
if (!fs.statSync(specFile).isFile())
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
catch {
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
const parsed = JSON.parse(fs.readFileSync(specFile, 'utf8'));
|
|
424
|
+
await edgeSpec.write(edgeFrom(parsed));
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
// Those three failure classes (`isSpecFault`) AND NOT WIDER. A bare `catch` here turned
|
|
428
|
+
// a defect in this function into a warning nobody's gate reads: `edgeFrom` was
|
|
429
|
+
// checking the wrong key names and rejecting every spec.json in existence, and the
|
|
430
|
+
// only evidence was a line of prose in an emit stream no test asserts on.
|
|
431
|
+
if (!isSpecFault(error))
|
|
432
|
+
throw error;
|
|
433
|
+
(0, events_1.warn)(emit, `could not regenerate the edge configuration ` +
|
|
434
|
+
`(${error instanceof Error ? error.message : String(error)}) — ` +
|
|
435
|
+
'`houston edge start` rewrites it');
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
(0, events_1.info)(emit, 'regenerated the edge configuration for its new location');
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* An `Edge` from a spec -- including the part where an unexpected key is a TypeError.
|
|
443
|
+
*
|
|
444
|
+
* A partial spread would accept a spec written by a build that has since renamed a field
|
|
445
|
+
* and silently use the default for it, which is how an edge comes back up serving a
|
|
446
|
+
* different domain than the one recorded. An unknown key is refused, as it always was.
|
|
447
|
+
*
|
|
448
|
+
* AGAINST THE ON-DISK NAMES, which are the `acme_email`/`gui_host` spelling on disk and not
|
|
449
|
+
* the `Edge` interface's. Checking the camelCase property names here rejected every
|
|
450
|
+
* spec.json a pre-rename home can contain -- and a pre-rename home is by definition one an
|
|
451
|
+
* earlier release wrote, so `edge_regenerated` was false for everybody. The compose file
|
|
452
|
+
* then kept an ACME path naming a directory the move had just deleted, which is the exact
|
|
453
|
+
* failure `regenerateEdgeCompose` exists to prevent.
|
|
454
|
+
*/
|
|
455
|
+
function edgeFrom(parsed) {
|
|
456
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
457
|
+
throw new TypeError('the edge spec is not an object');
|
|
458
|
+
}
|
|
459
|
+
const known = new Set(types_1.EDGE_FIELDS.map(([, key]) => key));
|
|
460
|
+
const unexpected = Object.keys(parsed).filter((key) => !known.has(key));
|
|
461
|
+
if (unexpected.length > 0) {
|
|
462
|
+
throw new TypeError(`unexpected edge field(s): ${unexpected.sort().join(', ')}`);
|
|
463
|
+
}
|
|
464
|
+
return (0, types_1.fromDocument)(parsed);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Move the shared edge onto its new project instead of leaving both running.
|
|
468
|
+
*
|
|
469
|
+
* The instinct is to leave a running reverse proxy alone and ask first, because :80 and
|
|
470
|
+
* :443 are visible to everything on the box. That instinct is WRONG here, and the reason is
|
|
471
|
+
* the move that just happened: the old container's bind mounts point into ~/.rc-repro, which
|
|
472
|
+
* no longer exists. It keeps serving only because Linux holds those directory inodes open
|
|
473
|
+
* for it -- and the first time anything restarts that container, Docker re-resolves the
|
|
474
|
+
* paths, creates empty directories in their place as root, and the edge comes back reporting
|
|
475
|
+
* `running` while serving no route and no certificate at all. It also restarts against an
|
|
476
|
+
* empty ACME store pointed at production Let's Encrypt, so it re-requests every name it used
|
|
477
|
+
* to hold.
|
|
478
|
+
*
|
|
479
|
+
* So there is no untouched-and-working state to protect. The migration committed the moment
|
|
480
|
+
* it moved the directory; stopping halfway leaves a proxy that is fine until it is not, with
|
|
481
|
+
* nothing on the box saying so. Finishing costs about two seconds of downtime and is the
|
|
482
|
+
* only outcome that is actually safe.
|
|
483
|
+
*
|
|
484
|
+
* Best-effort throughout: a box with no Docker and no edge has nothing to do here, and a
|
|
485
|
+
* failure must not take the command down with it -- it is reported with the two commands
|
|
486
|
+
* that finish the job by hand.
|
|
487
|
+
*/
|
|
488
|
+
async function handOverTheEdge(emit) {
|
|
489
|
+
if (!(await (0, host_1.dockerAvailable)()))
|
|
490
|
+
return '';
|
|
491
|
+
let listed;
|
|
492
|
+
try {
|
|
493
|
+
const res = await (0, docker_cli_1.docker)([
|
|
494
|
+
'ps',
|
|
495
|
+
'--filter',
|
|
496
|
+
`label=com.docker.compose.project=${exports.LEGACY_EDGE_PROJECT}`,
|
|
497
|
+
'--filter',
|
|
498
|
+
'status=running',
|
|
499
|
+
'--format',
|
|
500
|
+
'{{.Names}}',
|
|
501
|
+
], { capture: true, text: true, timeoutMs: 15000 });
|
|
502
|
+
listed = String(res.stdout ?? '');
|
|
503
|
+
}
|
|
504
|
+
catch {
|
|
505
|
+
return '';
|
|
506
|
+
}
|
|
507
|
+
const holder = listed.trim().split('\n').filter(Boolean);
|
|
508
|
+
if (holder.length === 0)
|
|
509
|
+
return '';
|
|
510
|
+
const first = holder[0];
|
|
511
|
+
(0, events_1.info)(emit, `handing the shared edge over from ${first} — its mounts point at ` +
|
|
512
|
+
'a directory that no longer exists');
|
|
513
|
+
let stopped;
|
|
514
|
+
try {
|
|
515
|
+
const stop = await (0, docker_cli_1.docker)(['compose', '-p', exports.LEGACY_EDGE_PROJECT, 'down'], {
|
|
516
|
+
capture: true,
|
|
517
|
+
text: true,
|
|
518
|
+
timeoutMs: 120000,
|
|
519
|
+
});
|
|
520
|
+
stopped = stop.exitCode === 0;
|
|
521
|
+
}
|
|
522
|
+
catch {
|
|
523
|
+
stopped = false;
|
|
524
|
+
}
|
|
525
|
+
if (!stopped) {
|
|
526
|
+
(0, events_1.warn)(emit, `could not stop ${first} — finish by hand: \`docker compose -p ` +
|
|
527
|
+
`${exports.LEGACY_EDGE_PROJECT} down\` then \`houston edge start\``);
|
|
528
|
+
return first;
|
|
529
|
+
}
|
|
530
|
+
if (!edgeSpec.installed()) {
|
|
531
|
+
(0, events_1.info)(emit, `${first} is stopped; nothing on this box needs an edge yet`);
|
|
532
|
+
return first;
|
|
533
|
+
}
|
|
534
|
+
if ((await edgeRuntime.up({ pull: false })).returncode === 0) {
|
|
535
|
+
(0, events_1.info)(emit, 'the edge is serving again on :80 and :443, as houston_edge');
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
(0, events_1.warn)(emit, `${first} is stopped but the new edge did not start — ` + '`houston edge start` says why');
|
|
539
|
+
}
|
|
540
|
+
return first;
|
|
541
|
+
}
|
|
542
|
+
/** Move a pre-rename ~/.rc-repro into place, once. */
|
|
543
|
+
function adoptLegacyHome(legacy, moved, target) {
|
|
544
|
+
if (legacy === null)
|
|
545
|
+
return moved;
|
|
546
|
+
if (fs.existsSync(target) && !isEffectivelyEmpty(target)) {
|
|
547
|
+
throw new errors_1.ConflictError(`both ${legacy} and ${target} hold state, so there is no safe move to ` +
|
|
548
|
+
`make — this tool will not merge two state directories. Keep the one ` +
|
|
549
|
+
`you want and remove or rename the other, then run this again`);
|
|
550
|
+
}
|
|
551
|
+
if (fs.existsSync(target)) {
|
|
552
|
+
// `isEffectivelyEmpty` allows an event log through, so this is a tree removal rather
|
|
553
|
+
// than an rmdir. Only ever reached for a directory that holds nothing but this tool's
|
|
554
|
+
// own log of the command that made it.
|
|
555
|
+
fs.rmSync(target, { recursive: true, force: true });
|
|
556
|
+
}
|
|
557
|
+
try {
|
|
558
|
+
fs.renameSync(legacy, target);
|
|
559
|
+
}
|
|
560
|
+
catch (error) {
|
|
561
|
+
// Cross-device is the realistic cause, and a copy would stop being atomic exactly
|
|
562
|
+
// where atomicity is the whole safety argument.
|
|
563
|
+
throw new errors_1.ValidationError(`could not move ${legacy} to ${target}: ${error instanceof Error ? error.message : String(error)}. ` +
|
|
564
|
+
`Move it by hand (\`mv ${legacy} ${target}\`) and run this again`);
|
|
565
|
+
}
|
|
566
|
+
return true;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Move the pre-rename state into place and finish any interrupted move.
|
|
570
|
+
*
|
|
571
|
+
* Safe to call on every invocation: it is a no-op once there is nothing left to do, and it
|
|
572
|
+
* never touches Docker or Kubernetes state.
|
|
573
|
+
*/
|
|
574
|
+
async function migrate(emit = events_1.nullEmit) {
|
|
575
|
+
const legacy = legacyHome();
|
|
576
|
+
const target = config.home();
|
|
577
|
+
let moved = false;
|
|
578
|
+
moved = adoptLegacyHome(legacy, moved, target);
|
|
579
|
+
// EVERY filesystem change happens before ANY message, and the order is the whole point.
|
|
580
|
+
// `events.info` tees each event into the event log, which opens logs/houston.log -- so a
|
|
581
|
+
// single "moved ..." emitted here would create the destination file and turn the log
|
|
582
|
+
// rename below into a permanent no-op, leaving logs/rc-repro.log behind and `pending()`
|
|
583
|
+
// true on every subsequent command.
|
|
584
|
+
const logsRenamed = renameLogs(target);
|
|
585
|
+
const markers = await rewriteMarkers(target);
|
|
586
|
+
const namespaces = await stampNamespaces();
|
|
587
|
+
// BEFORE the handover below starts it: the edge must not come up pointed at the directory
|
|
588
|
+
// it just moved out of.
|
|
589
|
+
const regenerated = moved ? await regenerateEdgeCompose(emit) : false;
|
|
590
|
+
if (moved)
|
|
591
|
+
(0, events_1.info)(emit, `moved ${String(legacy)} to ${target}`);
|
|
592
|
+
if (logsRenamed > 0) {
|
|
593
|
+
(0, events_1.info)(emit, `renamed ${String(logsRenamed)} event-log file(s) to houston.log`);
|
|
594
|
+
}
|
|
595
|
+
if (markers.length > 0) {
|
|
596
|
+
(0, events_1.info)(emit, `rewrote the old name out of ${markers.join(', ')}`);
|
|
597
|
+
}
|
|
598
|
+
if (namespaces.length > 0) {
|
|
599
|
+
(0, events_1.info)(emit, `recorded the existing namespace for ${namespaces.join(', ')}`);
|
|
600
|
+
}
|
|
601
|
+
return {
|
|
602
|
+
moved,
|
|
603
|
+
from: legacy ?? '',
|
|
604
|
+
to: target,
|
|
605
|
+
markers,
|
|
606
|
+
logs_renamed: logsRenamed,
|
|
607
|
+
namespaces_recorded: namespaces,
|
|
608
|
+
skills_replaced: adoptSkillCopies(emit),
|
|
609
|
+
edge_regenerated: regenerated,
|
|
610
|
+
legacy_edge: await handOverTheEdge(emit),
|
|
611
|
+
};
|
|
612
|
+
}
|