@infosupport/huddle-cli 0.0.0-experiment-128.65.1 → 0.0.0-experiment-109.66.1
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/README.md +59 -1
- package/dist/api.js +52 -14
- package/dist/config.js +145 -6
- package/dist/control-address.js +160 -0
- package/dist/control-probe.js +174 -0
- package/dist/experiment.js +18 -7
- package/dist/firewall.js +168 -3
- package/dist/images.js +16 -8
- package/dist/index.js +222 -17
- package/dist/init.js +372 -84
- package/dist/logs.js +213 -0
- package/dist/migrate.js +120 -75
- package/dist/node.js +667 -0
- package/dist/sbx-host-ca.js +237 -0
- package/dist/sbx-host.js +36 -0
- package/dist/sbx.js +206 -0
- package/dist/start.js +49 -2
- package/package.json +11 -3
package/dist/logs.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// `huddle logs` — the two halves' output, from one command.
|
|
3
|
+
//
|
|
4
|
+
// Huddle runs as two processes (docs/ADR-huddle-node-split.md) and each keeps
|
|
5
|
+
// its output somewhere else: Huddle Node appends stdout+stderr to
|
|
6
|
+
// ~/.huddle/node.log, the gateway container has whatever `docker logs` holds.
|
|
7
|
+
// Knowing that is not something an operator should have to look up, so this
|
|
8
|
+
// command reads both and says which is which.
|
|
9
|
+
//
|
|
10
|
+
// Reading is deliberately local: the log of a Node that failed to start is
|
|
11
|
+
// exactly the log you need, and asking the API for it would need the process
|
|
12
|
+
// this command exists to diagnose.
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.parseLines = parseLines;
|
|
18
|
+
exports.tailFile = tailFile;
|
|
19
|
+
exports.runLogs = runLogs;
|
|
20
|
+
const fs_1 = __importDefault(require("fs"));
|
|
21
|
+
const child_process_1 = require("child_process");
|
|
22
|
+
const node_1 = require("./node");
|
|
23
|
+
const runtime_1 = require("./runtime");
|
|
24
|
+
const utils_1 = require("./utils");
|
|
25
|
+
const GATEWAY_CONTAINER = 'huddle';
|
|
26
|
+
function parseLines(raw) {
|
|
27
|
+
if (raw === undefined)
|
|
28
|
+
return 200;
|
|
29
|
+
const n = Number(raw);
|
|
30
|
+
if (!Number.isInteger(n) || n < 1 || n > 100_000) {
|
|
31
|
+
throw new Error(`Invalid --lines "${raw}": use a whole number between 1 and 100000.`);
|
|
32
|
+
}
|
|
33
|
+
return n;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The last `lines` lines of a file, read from the END.
|
|
37
|
+
*
|
|
38
|
+
* node.log is append-only across restarts, so it grows without bound — reading
|
|
39
|
+
* the whole thing into memory to throw away all but the tail is exactly the
|
|
40
|
+
* wrong shape for the one file this command exists to read. Chunks are read
|
|
41
|
+
* backwards until enough newlines have been seen.
|
|
42
|
+
*/
|
|
43
|
+
function tailFile(file, lines) {
|
|
44
|
+
let fd;
|
|
45
|
+
try {
|
|
46
|
+
fd = fs_1.default.openSync(file, 'r');
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null; // never started, or the log was cleaned up
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const size = fs_1.default.fstatSync(fd).size;
|
|
53
|
+
const chunk = 64 * 1024;
|
|
54
|
+
let pos = size;
|
|
55
|
+
let found = 0;
|
|
56
|
+
let text = '';
|
|
57
|
+
while (pos > 0 && found <= lines) {
|
|
58
|
+
const len = Math.min(chunk, pos);
|
|
59
|
+
pos -= len;
|
|
60
|
+
const buf = Buffer.alloc(len);
|
|
61
|
+
fs_1.default.readSync(fd, buf, 0, len, pos);
|
|
62
|
+
const part = buf.toString('utf8');
|
|
63
|
+
found += (part.match(/\n/g) ?? []).length;
|
|
64
|
+
text = part + text;
|
|
65
|
+
}
|
|
66
|
+
const all = text.split('\n');
|
|
67
|
+
// A trailing newline makes the last element empty; drop it so `--lines 1`
|
|
68
|
+
// shows the last real line rather than a blank.
|
|
69
|
+
if (all[all.length - 1] === '')
|
|
70
|
+
all.pop();
|
|
71
|
+
return all.slice(-lines).join('\n');
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
fs_1.default.closeSync(fd);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function printNodeLog(lines) {
|
|
78
|
+
const pid = (0, node_1.readNodePid)();
|
|
79
|
+
const state = pid === null
|
|
80
|
+
? (0, utils_1.dim)('(no pid file — not started by `huddle init`)')
|
|
81
|
+
: (0, node_1.isNodePidAlive)() ? (0, utils_1.dim)(`(pid ${pid}, running)`) : (0, utils_1.yellow)(`(pid ${pid}, NOT running)`);
|
|
82
|
+
console.log((0, utils_1.bold)(`── Huddle Node — ${(0, utils_1.cyan)(node_1.NODE_LOG_FILE)} ${state}`));
|
|
83
|
+
const tail = tailFile(node_1.NODE_LOG_FILE, lines);
|
|
84
|
+
if (tail === null) {
|
|
85
|
+
console.log((0, utils_1.dim)(' No log file yet. `huddle init` starts Node and creates it;'));
|
|
86
|
+
console.log((0, utils_1.dim)(' `huddle node` runs it in the foreground and prints here instead.'));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
console.log(tail.trim() ? tail : (0, utils_1.dim)(' (empty)'));
|
|
90
|
+
}
|
|
91
|
+
// The engine command, or null with a printed reason. Not being able to reach an
|
|
92
|
+
// engine must not fail `huddle logs`: node.log is often the half that explains
|
|
93
|
+
// why, and it has already been printed by the time this runs.
|
|
94
|
+
function engineCommand() {
|
|
95
|
+
try {
|
|
96
|
+
return (0, runtime_1.resolveRuntime)().name;
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
console.log((0, utils_1.dim)(` No container runtime available: ${err.message.split('\n')[0]}`));
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// `docker logs` and not the API: the gateway's own startup failures are the
|
|
104
|
+
// interesting case, and those never reach an HTTP endpoint.
|
|
105
|
+
async function printGatewayLog(lines) {
|
|
106
|
+
console.log('');
|
|
107
|
+
console.log((0, utils_1.bold)('── huddle-gateway'));
|
|
108
|
+
const engine = engineCommand();
|
|
109
|
+
if (!engine)
|
|
110
|
+
return;
|
|
111
|
+
console.log((0, utils_1.dim)(` ${engine} logs ${GATEWAY_CONTAINER}`));
|
|
112
|
+
await new Promise((resolve) => {
|
|
113
|
+
const child = (0, child_process_1.spawn)(engine, ['logs', '--tail', String(lines), GATEWAY_CONTAINER], {
|
|
114
|
+
stdio: ['ignore', 'inherit', 'inherit'],
|
|
115
|
+
});
|
|
116
|
+
child.on('error', (err) => {
|
|
117
|
+
console.log((0, utils_1.red)(` Could not run ${engine}: ${err.message}`));
|
|
118
|
+
resolve();
|
|
119
|
+
});
|
|
120
|
+
child.on('close', () => resolve());
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Follow both halves at once: `tail -f` on node.log, `docker logs -f` on the
|
|
125
|
+
* gateway, each line prefixed so two interleaved streams stay readable. Ends on
|
|
126
|
+
* Ctrl-C like every other follower.
|
|
127
|
+
*/
|
|
128
|
+
async function followBoth(lines, wantNode, wantGateway) {
|
|
129
|
+
const children = [];
|
|
130
|
+
if (wantNode) {
|
|
131
|
+
console.log((0, utils_1.dim)(`── following ${node_1.NODE_LOG_FILE}`));
|
|
132
|
+
// Start at the END of the file and print the tail once, so following does
|
|
133
|
+
// not replay a log that has been growing across every restart.
|
|
134
|
+
let pos = 0;
|
|
135
|
+
try {
|
|
136
|
+
pos = fs_1.default.statSync(node_1.NODE_LOG_FILE).size;
|
|
137
|
+
}
|
|
138
|
+
catch { /* not created yet */ }
|
|
139
|
+
const initial = tailFile(node_1.NODE_LOG_FILE, lines);
|
|
140
|
+
if (initial?.trim())
|
|
141
|
+
console.log(prefix('node', initial));
|
|
142
|
+
// Polling, not fs.watch: on Windows a file appended to by a detached process
|
|
143
|
+
// does not reliably raise watch events, and a 500ms poll on one file costs
|
|
144
|
+
// nothing next to being silently stuck.
|
|
145
|
+
const timer = setInterval(() => {
|
|
146
|
+
let size;
|
|
147
|
+
try {
|
|
148
|
+
size = fs_1.default.statSync(node_1.NODE_LOG_FILE).size;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (size <= pos) {
|
|
154
|
+
pos = Math.min(pos, size);
|
|
155
|
+
return;
|
|
156
|
+
} // truncated or unchanged
|
|
157
|
+
const buf = Buffer.alloc(size - pos);
|
|
158
|
+
const fd = fs_1.default.openSync(node_1.NODE_LOG_FILE, 'r');
|
|
159
|
+
try {
|
|
160
|
+
fs_1.default.readSync(fd, buf, 0, buf.length, pos);
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
fs_1.default.closeSync(fd);
|
|
164
|
+
}
|
|
165
|
+
pos = size;
|
|
166
|
+
const text = buf.toString('utf8').replace(/\n$/, '');
|
|
167
|
+
if (text)
|
|
168
|
+
console.log(prefix('node', text));
|
|
169
|
+
}, 500);
|
|
170
|
+
process.on('SIGINT', () => clearInterval(timer));
|
|
171
|
+
}
|
|
172
|
+
const engine = wantGateway ? engineCommand() : null;
|
|
173
|
+
if (engine) {
|
|
174
|
+
console.log((0, utils_1.dim)(`── following ${engine} logs -f ${GATEWAY_CONTAINER}`));
|
|
175
|
+
const child = (0, child_process_1.spawn)(engine, ['logs', '-f', '--tail', String(lines), GATEWAY_CONTAINER], {
|
|
176
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
177
|
+
});
|
|
178
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
179
|
+
stream?.on('data', (b) => {
|
|
180
|
+
const text = b.toString('utf8').replace(/\n$/, '');
|
|
181
|
+
if (text)
|
|
182
|
+
console.log(prefix('gateway', text));
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
child.on('error', (err) => console.log((0, utils_1.red)(` Could not run ${engine}: ${err.message}`)));
|
|
186
|
+
children.push(child);
|
|
187
|
+
}
|
|
188
|
+
await new Promise((resolve) => {
|
|
189
|
+
process.on('SIGINT', () => {
|
|
190
|
+
for (const c of children)
|
|
191
|
+
c.kill();
|
|
192
|
+
resolve();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function prefix(who, text) {
|
|
197
|
+
const tag = who === 'node' ? (0, utils_1.cyan)('[node] ') : (0, utils_1.dim)('[gateway]');
|
|
198
|
+
return text.split('\n').map((l) => `${tag} ${l}`).join('\n');
|
|
199
|
+
}
|
|
200
|
+
async function runLogs(opts) {
|
|
201
|
+
const lines = parseLines(opts.lines);
|
|
202
|
+
// Neither flag means both halves; either flag means only that one.
|
|
203
|
+
const wantNode = opts.node === true || opts.gateway !== true;
|
|
204
|
+
const wantGateway = opts.gateway === true || opts.node !== true;
|
|
205
|
+
if (opts.follow) {
|
|
206
|
+
await followBoth(lines, wantNode, wantGateway);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (wantNode)
|
|
210
|
+
printNodeLog(lines);
|
|
211
|
+
if (wantGateway)
|
|
212
|
+
await printGatewayLog(lines);
|
|
213
|
+
}
|
package/dist/migrate.js
CHANGED
|
@@ -19,6 +19,8 @@ const path_1 = __importDefault(require("path"));
|
|
|
19
19
|
const utils_1 = require("./utils");
|
|
20
20
|
const runtime_1 = require("./runtime");
|
|
21
21
|
const init_1 = require("./init");
|
|
22
|
+
const node_1 = require("./node");
|
|
23
|
+
const api_1 = require("./api");
|
|
22
24
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
25
|
// Conventions
|
|
24
26
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -152,7 +154,7 @@ function pickHuddleNetKey(compose, markedNetwork, preferred) {
|
|
|
152
154
|
// add the Huddle egress network + proxy env, and (with --docker-socket) mount the
|
|
153
155
|
// filtered Docker socket. Any second, non-internal network is flagged as a
|
|
154
156
|
// blocker — it would be an unfiltered route out that bypasses Huddle.
|
|
155
|
-
function buildInjectedService(svc, name, compose, ctx, warnings, blockers) {
|
|
157
|
+
function buildInjectedService(svc, name, compose, ctx, warnings, blockers, socketContainers) {
|
|
156
158
|
for (const netKey of serviceNetworkKeys(svc)) {
|
|
157
159
|
if (netKey === ctx.markedNetwork)
|
|
158
160
|
continue;
|
|
@@ -162,11 +164,18 @@ function buildInjectedService(svc, name, compose, ctx, warnings, blockers) {
|
|
|
162
164
|
'Remove it or make it internal — a second non-internal network bypasses Huddle.');
|
|
163
165
|
}
|
|
164
166
|
}
|
|
167
|
+
// The MITM CA is mounted, not fetched. Huddle Node holds the CA on the host and
|
|
168
|
+
// the gateway only gets it read-only, so there is no endpoint in the gateway to
|
|
169
|
+
// download it from — and adding one would be a devcontainer→Huddle path we
|
|
170
|
+
// deliberately do not have. A read-only bind is also what Huddle's own
|
|
171
|
+
// containers get, just seeded differently.
|
|
172
|
+
const volumes = [`${ctx.hostCaPath}:${ctx.caPath}:ro`];
|
|
165
173
|
const injected = {
|
|
166
174
|
// Keep the service on its own network AND add the Huddle egress network.
|
|
167
175
|
// Map form is robust regardless of Compose's list merge semantics.
|
|
168
176
|
networks: { [ctx.markedNetwork]: null, [ctx.huddleNetKey]: null },
|
|
169
177
|
environment: huddleProxyEnv(ctx.caPath, ctx.dockerSocket),
|
|
178
|
+
volumes,
|
|
170
179
|
};
|
|
171
180
|
if (ctx.dockerSocket) {
|
|
172
181
|
const cn = svc.container_name;
|
|
@@ -175,13 +184,15 @@ function buildInjectedService(svc, name, compose, ctx, warnings, blockers) {
|
|
|
175
184
|
'at a stable path. Set a fixed container_name or drop --docker-socket for this service.');
|
|
176
185
|
}
|
|
177
186
|
else {
|
|
178
|
-
|
|
187
|
+
volumes.push(`${ctx.socketDir}/${cn}:/var/run/huddle`);
|
|
188
|
+
socketContainers.push(cn);
|
|
179
189
|
}
|
|
180
190
|
}
|
|
181
191
|
return injected;
|
|
182
192
|
}
|
|
183
193
|
function buildOverride(compose, opts = {}) {
|
|
184
194
|
const caPath = opts.caPath ?? exports.DEFAULT_CA_PATH;
|
|
195
|
+
const hostCaPath = opts.hostCaPath ?? path_1.default.join((0, node_1.nodeCaDir)(), 'ca.crt');
|
|
185
196
|
const internalNet = opts.internalNet ?? init_1.INTERNAL_NET;
|
|
186
197
|
const socketDir = opts.socketDir ?? init_1.HOST_SOCKET_DIR;
|
|
187
198
|
const warnings = [];
|
|
@@ -201,11 +212,19 @@ function buildOverride(compose, opts = {}) {
|
|
|
201
212
|
if (services.length === 0) {
|
|
202
213
|
warnings.push(`No service is attached to the marked network "${markedNetwork}"; the override wires nothing.`);
|
|
203
214
|
}
|
|
204
|
-
const ctx = {
|
|
215
|
+
const ctx = {
|
|
216
|
+
markedNetwork,
|
|
217
|
+
huddleNetKey,
|
|
218
|
+
caPath,
|
|
219
|
+
hostCaPath,
|
|
220
|
+
socketDir,
|
|
221
|
+
dockerSocket: !!opts.dockerSocket,
|
|
222
|
+
};
|
|
205
223
|
const overrideServices = {};
|
|
224
|
+
const socketContainers = [];
|
|
206
225
|
for (const name of services) {
|
|
207
226
|
const svc = (compose.services?.[name] ?? {});
|
|
208
|
-
overrideServices[name] = buildInjectedService(svc, name, compose, ctx, warnings, blockers);
|
|
227
|
+
overrideServices[name] = buildInjectedService(svc, name, compose, ctx, warnings, blockers, socketContainers);
|
|
209
228
|
}
|
|
210
229
|
const override = {
|
|
211
230
|
services: overrideServices,
|
|
@@ -215,7 +234,7 @@ function buildOverride(compose, opts = {}) {
|
|
|
215
234
|
[huddleNetKey]: { external: true, name: internalNet },
|
|
216
235
|
},
|
|
217
236
|
};
|
|
218
|
-
return { markedNetwork, services, override, warnings, blockers };
|
|
237
|
+
return { markedNetwork, services, override, warnings, blockers, socketContainers };
|
|
219
238
|
}
|
|
220
239
|
function tokenize(input) {
|
|
221
240
|
const out = [];
|
|
@@ -292,67 +311,76 @@ function rejectUnsupportedYaml(lines) {
|
|
|
292
311
|
throw unsupportedYaml('a YAML alias (`*`)');
|
|
293
312
|
}
|
|
294
313
|
}
|
|
314
|
+
function atIndent(c, indent) {
|
|
315
|
+
return c.pos < c.lines.length && c.lines[c.pos].indent === indent;
|
|
316
|
+
}
|
|
317
|
+
// Cap the mutual recursion (parseNode ↔ parseMapping/parseSequence) so a deeply
|
|
318
|
+
// nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
|
|
319
|
+
function parseNode(c, indent, depth) {
|
|
320
|
+
if (depth > MAX_YAML_DEPTH) {
|
|
321
|
+
throw new Error(`YAML nesting exceeds ${MAX_YAML_DEPTH} levels; refusing to parse this compose file.`);
|
|
322
|
+
}
|
|
323
|
+
if (c.pos >= c.lines.length || c.lines[c.pos].indent < indent)
|
|
324
|
+
return null;
|
|
325
|
+
return isSeqItem(c.lines[c.pos].text) ? parseSequence(c, indent, depth) : parseMapping(c, indent, depth);
|
|
326
|
+
}
|
|
327
|
+
function parseMapping(c, indent, depth) {
|
|
328
|
+
const map = {};
|
|
329
|
+
while (atIndent(c, indent) && !isSeqItem(c.lines[c.pos].text)) {
|
|
330
|
+
const { text } = c.lines[c.pos];
|
|
331
|
+
const colon = findKeyColon(text);
|
|
332
|
+
// Not a mapping line where we expected one — stop and let the caller cope.
|
|
333
|
+
if (colon < 0)
|
|
334
|
+
break;
|
|
335
|
+
const key = unquote(text.slice(0, colon).trim());
|
|
336
|
+
const rest = text.slice(colon + 1).trim();
|
|
337
|
+
c.pos++;
|
|
338
|
+
map[key] = parseMappingValue(c, rest, indent, depth);
|
|
339
|
+
}
|
|
340
|
+
return map;
|
|
341
|
+
}
|
|
342
|
+
/** The value belonging to `key:` — inline, the indented block below it, or none. */
|
|
343
|
+
function parseMappingValue(c, rest, indent, depth) {
|
|
344
|
+
if (rest !== '')
|
|
345
|
+
return parseScalar(rest);
|
|
346
|
+
if (c.pos < c.lines.length && c.lines[c.pos].indent > indent) {
|
|
347
|
+
return parseNode(c, c.lines[c.pos].indent, depth + 1);
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
function parseSequence(c, indent, depth) {
|
|
352
|
+
const arr = [];
|
|
353
|
+
while (atIndent(c, indent) && isSeqItem(c.lines[c.pos].text)) {
|
|
354
|
+
arr.push(parseSequenceItem(c, indent, depth));
|
|
355
|
+
}
|
|
356
|
+
return arr;
|
|
357
|
+
}
|
|
358
|
+
function parseSequenceItem(c, indent, depth) {
|
|
359
|
+
const line = c.lines[c.pos];
|
|
360
|
+
const afterDash = line.text.replace(/^-\s*/, '');
|
|
361
|
+
// A bare `-`: the item is the indented block on the following lines.
|
|
362
|
+
if (afterDash === '') {
|
|
363
|
+
c.pos++;
|
|
364
|
+
return c.pos < c.lines.length && c.lines[c.pos].indent > indent
|
|
365
|
+
? parseNode(c, c.lines[c.pos].indent, depth + 1)
|
|
366
|
+
: null;
|
|
367
|
+
}
|
|
368
|
+
// Inline map item: "- key: value". Re-interpret the remainder as a mapping
|
|
369
|
+
// that starts at a virtual indent past the dash. parseMapping consumes this
|
|
370
|
+
// same line, so the cursor deliberately does not advance here.
|
|
371
|
+
if (findKeyColon(afterDash) >= 0) {
|
|
372
|
+
const virtualIndent = indent + (line.text.length - afterDash.length);
|
|
373
|
+
c.lines[c.pos] = { indent: virtualIndent, text: afterDash };
|
|
374
|
+
return parseMapping(c, virtualIndent, depth + 1);
|
|
375
|
+
}
|
|
376
|
+
c.pos++;
|
|
377
|
+
return parseScalar(afterDash);
|
|
378
|
+
}
|
|
295
379
|
function parseYaml(input) {
|
|
296
380
|
const lines = tokenize(input);
|
|
297
381
|
rejectUnsupportedYaml(lines);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
// nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
|
|
301
|
-
function parseNode(indent, depth) {
|
|
302
|
-
if (depth > MAX_YAML_DEPTH) {
|
|
303
|
-
throw new Error(`YAML nesting exceeds ${MAX_YAML_DEPTH} levels; refusing to parse this compose file.`);
|
|
304
|
-
}
|
|
305
|
-
if (pos >= lines.length || lines[pos].indent < indent)
|
|
306
|
-
return null;
|
|
307
|
-
return isSeqItem(lines[pos].text) ? parseSequence(indent, depth) : parseMapping(indent, depth);
|
|
308
|
-
}
|
|
309
|
-
function parseMapping(indent, depth) {
|
|
310
|
-
const map = {};
|
|
311
|
-
while (pos < lines.length && lines[pos].indent === indent && !isSeqItem(lines[pos].text)) {
|
|
312
|
-
const { text } = lines[pos];
|
|
313
|
-
const colon = findKeyColon(text);
|
|
314
|
-
if (colon < 0) {
|
|
315
|
-
// Not a mapping line where we expected one — stop and let the caller cope.
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
const key = unquote(text.slice(0, colon).trim());
|
|
319
|
-
const rest = text.slice(colon + 1).trim();
|
|
320
|
-
pos++;
|
|
321
|
-
if (rest !== '') {
|
|
322
|
-
map[key] = parseScalar(rest);
|
|
323
|
-
}
|
|
324
|
-
else if (pos < lines.length && lines[pos].indent > indent) {
|
|
325
|
-
map[key] = parseNode(lines[pos].indent, depth + 1);
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
map[key] = null;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return map;
|
|
332
|
-
}
|
|
333
|
-
function parseSequence(indent, depth) {
|
|
334
|
-
const arr = [];
|
|
335
|
-
while (pos < lines.length && lines[pos].indent === indent && isSeqItem(lines[pos].text)) {
|
|
336
|
-
const afterDash = lines[pos].text.replace(/^-\s*/, '');
|
|
337
|
-
if (afterDash === '') {
|
|
338
|
-
pos++;
|
|
339
|
-
arr.push(pos < lines.length && lines[pos].indent > indent ? parseNode(lines[pos].indent, depth + 1) : null);
|
|
340
|
-
}
|
|
341
|
-
else if (findKeyColon(afterDash) >= 0) {
|
|
342
|
-
// Inline map item: "- key: value". Re-interpret the remainder as a
|
|
343
|
-
// mapping that starts at a virtual indent past the dash.
|
|
344
|
-
const virtualIndent = indent + (lines[pos].text.length - afterDash.length);
|
|
345
|
-
lines[pos] = { indent: virtualIndent, text: afterDash };
|
|
346
|
-
arr.push(parseMapping(virtualIndent, depth + 1));
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
arr.push(parseScalar(afterDash));
|
|
350
|
-
pos++;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
return arr;
|
|
354
|
-
}
|
|
355
|
-
const root = parseNode(lines.length ? lines[0].indent : 0, 0);
|
|
382
|
+
const cursor = { lines, pos: 0 };
|
|
383
|
+
const root = parseNode(cursor, lines.length ? lines[0].indent : 0, 0);
|
|
356
384
|
return (root && typeof root === 'object' ? root : {});
|
|
357
385
|
}
|
|
358
386
|
function isSeqItem(text) {
|
|
@@ -579,7 +607,8 @@ async function runMigrate(opts) {
|
|
|
579
607
|
catch (err) {
|
|
580
608
|
throw new Error(`Could not parse ${composeFile}: ${err instanceof Error ? err.message : String(err)}`);
|
|
581
609
|
}
|
|
582
|
-
const
|
|
610
|
+
const hostCaPath = path_1.default.join((0, node_1.nodeCaDir)(), 'ca.crt');
|
|
611
|
+
const result = buildOverride(compose, { caPath, hostCaPath, dockerSocket: opts.dockerSocket });
|
|
583
612
|
console.log(`Marked network: ${(0, utils_1.bold)(result.markedNetwork)}`);
|
|
584
613
|
console.log(`Wired services: ${result.services.length ? result.services.map(utils_1.bold).join(', ') : (0, utils_1.dim)('(none)')}`);
|
|
585
614
|
for (const w of result.warnings)
|
|
@@ -611,9 +640,32 @@ async function runMigrate(opts) {
|
|
|
611
640
|
console.log((0, utils_1.yellow)(`[!] Could not confirm the "${init_1.INTERNAL_NET}" network exists. Run \`huddle init\` first.`));
|
|
612
641
|
console.log();
|
|
613
642
|
}
|
|
614
|
-
|
|
643
|
+
if (!fs_1.default.existsSync(hostCaPath)) {
|
|
644
|
+
console.log((0, utils_1.yellow)(`[!] ${hostCaPath} does not exist yet — the override mounts it. Run \`huddle init\` first.`));
|
|
645
|
+
console.log();
|
|
646
|
+
}
|
|
647
|
+
// Register the socket-mounted container_names with Node NOW, before `docker
|
|
648
|
+
// compose up` ever runs them: the socket has to already exist inside the
|
|
649
|
+
// bind-mounted directory by the time the container starts, or it mounts an
|
|
650
|
+
// empty directory instead (see /api/docker/register-socket, api.ts). This is
|
|
651
|
+
// the only way Node learns about these containers at all — they carry none
|
|
652
|
+
// of the labels a Huddle-created devcontainer does.
|
|
653
|
+
if (result.socketContainers.length > 0) {
|
|
654
|
+
try {
|
|
655
|
+
await (0, api_1.post)('/api/docker/register-socket', { names: result.socketContainers });
|
|
656
|
+
console.log((0, utils_1.green)(`[OK] Registered filtered socket(s) for: ${result.socketContainers.join(', ')}`));
|
|
657
|
+
}
|
|
658
|
+
catch (err) {
|
|
659
|
+
const detail = err instanceof api_1.ApiError ? err.message : String(err);
|
|
660
|
+
console.log((0, utils_1.yellow)(`[!] Could not register the filtered socket with Huddle Node: ${detail}`));
|
|
661
|
+
console.log((0, utils_1.dim)(' Run `huddle init` (or re-run `huddle migrate --docker-socket`) once it is reachable —'));
|
|
662
|
+
console.log((0, utils_1.dim)(' until then the socket mount will not exist and DOCKER_HOST will point at nothing.'));
|
|
663
|
+
}
|
|
664
|
+
console.log();
|
|
665
|
+
}
|
|
666
|
+
printNextSteps(composeFile, outPath, caPath, hostCaPath);
|
|
615
667
|
}
|
|
616
|
-
function printNextSteps(composeFile, outPath, caPath,
|
|
668
|
+
function printNextSteps(composeFile, outPath, caPath, hostCaPath) {
|
|
617
669
|
const composeBase = path_1.default.basename(composeFile);
|
|
618
670
|
const overrideBase = path_1.default.basename(outPath);
|
|
619
671
|
console.log((0, utils_1.bold)('Next steps (this command only GENERATED the override — it did not start anything):'));
|
|
@@ -621,8 +673,8 @@ function printNextSteps(composeFile, outPath, caPath, dockerSocket) {
|
|
|
621
673
|
console.log(' 1. Make sure Huddle is running:');
|
|
622
674
|
console.log((0, utils_1.cyan)(' huddle init'));
|
|
623
675
|
console.log();
|
|
624
|
-
console.log(' 2.
|
|
625
|
-
console.log((0, utils_1.cyan)(`
|
|
676
|
+
console.log(' 2. The Huddle CA is mounted read-only by the override — nothing to fetch:');
|
|
677
|
+
console.log((0, utils_1.cyan)(` ${hostCaPath} -> ${caPath}`));
|
|
626
678
|
console.log((0, utils_1.dim)(` (Adjust ${caPath} to your remoteUser's home if it differs; pass --ca-path to change it.)`));
|
|
627
679
|
console.log();
|
|
628
680
|
console.log(' 3. Reference the override so the IDE merges it. In devcontainer.json:');
|
|
@@ -630,12 +682,5 @@ function printNextSteps(composeFile, outPath, caPath, dockerSocket) {
|
|
|
630
682
|
console.log((0, utils_1.dim)(' Or start it yourself:'));
|
|
631
683
|
console.log((0, utils_1.cyan)(` docker compose -f ${composeBase} -f ${overrideBase} up -d`));
|
|
632
684
|
console.log();
|
|
633
|
-
if (dockerSocket) {
|
|
634
|
-
console.log((0, utils_1.yellow)(' Note (--docker-socket): the socket mount is GENERATED but NOT yet served.'));
|
|
635
|
-
console.log((0, utils_1.dim)(' Huddle does not yet pre-provision the per-container filtered socket for IDE-started\n' +
|
|
636
|
-
' containers (issue #66 follow-up). Until it does, the mount source will not exist and\n' +
|
|
637
|
-
' DOCKER_HOST will point at a missing socket. Only enable this once that lands.'));
|
|
638
|
-
console.log();
|
|
639
|
-
}
|
|
640
685
|
console.log((0, utils_1.dim)('See docs/migrate-devcontainers.md for the full guide and the marked-network convention.'));
|
|
641
686
|
}
|