@infosupport/huddle-cli 0.0.0-experiment-136.72.1 → 0.0.0-experiment-98.73.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 +53 -1
- package/dist/config.js +145 -6
- package/dist/experiment.js +12 -7
- package/dist/firewall.js +184 -3
- package/dist/images.js +13 -9
- package/dist/index.js +119 -8
- package/dist/indexfolder.js +167 -0
- package/dist/init.js +49 -26
- package/dist/migrate.js +67 -58
- package/dist/start.js +49 -42
- package/package.json +1 -1
- package/dist/vscode.js +0 -144
package/dist/index.js
CHANGED
|
@@ -11,16 +11,18 @@ const start_1 = require("./start");
|
|
|
11
11
|
const firewall_1 = require("./firewall");
|
|
12
12
|
const init_1 = require("./init");
|
|
13
13
|
const migrate_1 = require("./migrate");
|
|
14
|
+
const indexfolder_1 = require("./indexfolder");
|
|
14
15
|
const images_1 = require("./images");
|
|
15
16
|
const self_update_1 = require("./self-update");
|
|
16
17
|
const utils_1 = require("./utils");
|
|
17
18
|
const experiment_1 = require("./experiment");
|
|
18
|
-
const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output']);
|
|
19
|
-
const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force', '
|
|
20
|
-
const COMMANDS = new Set(['start', 'firewall', 'fw', 'init', 'experiment', 'migrate', 'help', 'version']);
|
|
19
|
+
const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output', 'out', 'workspace-root', 'depth']);
|
|
20
|
+
const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force', 'replace', 'all', 'list', 'clear']);
|
|
21
|
+
const COMMANDS = new Set(['start', 'firewall', 'fw', 'init', 'restart', 'experiment', 'migrate', 'indexfolder', 'indexfolders', 'help', 'version']);
|
|
21
22
|
function parseArgs(argv) {
|
|
22
23
|
const positional = [];
|
|
23
24
|
const flags = {};
|
|
25
|
+
const mounts = [];
|
|
24
26
|
for (let i = 0; i < argv.length; i++) {
|
|
25
27
|
const arg = argv[i];
|
|
26
28
|
if (arg === '--') {
|
|
@@ -33,6 +35,23 @@ function parseArgs(argv) {
|
|
|
33
35
|
const name = eq >= 0 ? raw.slice(0, eq) : raw;
|
|
34
36
|
if (!name)
|
|
35
37
|
throw new Error(`Invalid option: ${arg}`);
|
|
38
|
+
// Repeatable, unlike every other value flag (one `--mount host=container` per folder).
|
|
39
|
+
if (name === 'mount') {
|
|
40
|
+
let value;
|
|
41
|
+
if (eq >= 0) {
|
|
42
|
+
value = raw.slice(eq + 1);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const next = argv[i + 1];
|
|
46
|
+
if (next === undefined || next.startsWith('-')) {
|
|
47
|
+
throw new Error('Option --mount expects a value (host=container)');
|
|
48
|
+
}
|
|
49
|
+
value = next;
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
mounts.push(value);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
36
55
|
if (eq >= 0) {
|
|
37
56
|
flags[name] = raw.slice(eq + 1);
|
|
38
57
|
}
|
|
@@ -70,7 +89,13 @@ function parseArgs(argv) {
|
|
|
70
89
|
}
|
|
71
90
|
positional.push(arg);
|
|
72
91
|
}
|
|
73
|
-
return { positional, flags };
|
|
92
|
+
return { positional, flags, mounts };
|
|
93
|
+
}
|
|
94
|
+
function parseMountFlag(raw) {
|
|
95
|
+
const eq = raw.indexOf('=');
|
|
96
|
+
if (eq <= 0)
|
|
97
|
+
throw new Error(`Invalid --mount value "${raw}", expected host=container`);
|
|
98
|
+
return { hostPath: raw.slice(0, eq), containerPath: raw.slice(eq + 1) };
|
|
74
99
|
}
|
|
75
100
|
function readVersion() {
|
|
76
101
|
// npm always includes package.json in the published tarball, and it holds the
|
|
@@ -94,14 +119,29 @@ Usage:
|
|
|
94
119
|
huddle start [options] [folder] Explicitly start a devcontainer
|
|
95
120
|
huddle init [options] Pull the Huddle + devcontainer base images and
|
|
96
121
|
start them via Docker or Podman
|
|
122
|
+
huddle restart Recreate the gateway (e.g. to mount a changed
|
|
123
|
+
team firewall-rules folder)
|
|
97
124
|
huddle migrate [folder] Wire an existing docker-compose devcontainer
|
|
98
125
|
behind Huddle by generating an override file
|
|
126
|
+
huddle indexfolder [folder] Index the folders under this one so the portal
|
|
127
|
+
can offer them where a host path is needed
|
|
128
|
+
(the portal runs in a container and cannot
|
|
129
|
+
browse your host)
|
|
99
130
|
huddle firewall list [options] Show firewall requests
|
|
100
131
|
huddle fw list [options] Alias for firewall list
|
|
101
132
|
huddle firewall add <domain> Add a custom firewall rule (wildcards
|
|
102
133
|
supported: *.example.com and /path/*)
|
|
103
134
|
huddle firewall delete <id> Delete a firewall rule by id (or domain;
|
|
104
135
|
narrow with --container)
|
|
136
|
+
huddle firewall export [options] Export firewall rules as JSON
|
|
137
|
+
huddle firewall import <file> Import firewall rules from a JSON file
|
|
138
|
+
huddle firewall group list List firewall groups (#69)
|
|
139
|
+
huddle firewall group export <name> Export a group as JSON (--out <file>)
|
|
140
|
+
huddle firewall group import <file> Import a group (--replace to mirror)
|
|
141
|
+
huddle firewall group apply <name> Apply a group (--container <id> or global)
|
|
142
|
+
huddle firewall folder set <path> Set the team-managed rules folder
|
|
143
|
+
huddle firewall folder reload Re-read the team-managed rules folder
|
|
144
|
+
huddle firewall folder sync Write the portal's groups back to the folder
|
|
105
145
|
huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
|
|
106
146
|
and run init
|
|
107
147
|
huddle experiment reset Back to the stable release
|
|
@@ -116,11 +156,14 @@ Init options:
|
|
|
116
156
|
Start options:
|
|
117
157
|
--ide <intellij|rider|vscode> IDE (default: intellij)
|
|
118
158
|
--workspace <path> Workspace directory (default: current directory)
|
|
159
|
+
--mount <host>=<container> Mount a host folder at an absolute container path, e.g.
|
|
160
|
+
C:/projects/my-repo/backend=/workspace/backend
|
|
161
|
+
(repeatable; cannot combine with --workspace/--empty)
|
|
162
|
+
--workspace-root <path> Container path the IDE opens as project root when using
|
|
163
|
+
--mount (default: common parent of the mount targets)
|
|
119
164
|
--name <name> Container name (default: devcontainer-<foldername>)
|
|
120
165
|
--image <image> Use a specific image
|
|
121
166
|
--empty Empty container without a workspace
|
|
122
|
-
--no-vscode-config Do not write the per-container attach config
|
|
123
|
-
that makes VS Code open the workspace folder
|
|
124
167
|
|
|
125
168
|
Migrate options:
|
|
126
169
|
--ca-path <path> Where the Huddle CA lands in the container
|
|
@@ -131,9 +174,21 @@ Migrate options:
|
|
|
131
174
|
(default: docker-compose.huddle.yml next to the source)
|
|
132
175
|
--force Overwrite an existing override file
|
|
133
176
|
|
|
177
|
+
Indexfolder options:
|
|
178
|
+
--depth <n> How deep to walk (default: 2, max 8)
|
|
179
|
+
--all Also index build folders (node_modules, dist,
|
|
180
|
+
target, ...); hidden folders stay skipped
|
|
181
|
+
--replace Drop the earlier entries under this folder
|
|
182
|
+
first, instead of merging
|
|
183
|
+
--list Show the current index and exit
|
|
184
|
+
--clear Empty the index (or, with a folder, only the
|
|
185
|
+
entries under it)
|
|
186
|
+
|
|
134
187
|
Firewall options:
|
|
135
188
|
-i, --interactive Interactively approve/deny (list)
|
|
136
189
|
--container <name> Filter by (list) / scope to (add) a container
|
|
190
|
+
(or __global__). On import: remap all rules
|
|
191
|
+
to this scope
|
|
137
192
|
--status <requested|allow|deny> Filter by status (default: requested)
|
|
138
193
|
|
|
139
194
|
Firewall add options:
|
|
@@ -142,6 +197,11 @@ Firewall add options:
|
|
|
142
197
|
(e.g. /_packaging/*/nuget/v3/*)
|
|
143
198
|
--deny Create a block rule (default: allow)
|
|
144
199
|
|
|
200
|
+
Firewall export/import options:
|
|
201
|
+
--out <file> Write export to a file (default: stdout)
|
|
202
|
+
--replace Import in replace mode: wipe the target
|
|
203
|
+
scope first (default: merge/upsert)
|
|
204
|
+
|
|
145
205
|
Global options:
|
|
146
206
|
--url <url> Huddle URL (default: http://localhost:3000)
|
|
147
207
|
Or via the HUDDLE_URL env var
|
|
@@ -160,7 +220,7 @@ async function main() {
|
|
|
160
220
|
console.error('Run "huddle --help" for help.');
|
|
161
221
|
process.exit(1);
|
|
162
222
|
}
|
|
163
|
-
const { positional, flags } = parsed;
|
|
223
|
+
const { positional, flags, mounts } = parsed;
|
|
164
224
|
const [cmd, sub] = positional;
|
|
165
225
|
if (flagBool(flags, 'version', 'v') || cmd === 'version') {
|
|
166
226
|
console.log(readVersion());
|
|
@@ -181,10 +241,11 @@ async function main() {
|
|
|
181
241
|
await (0, start_1.runStart)({
|
|
182
242
|
ide: flagString(flags, 'ide') ?? 'intellij',
|
|
183
243
|
workspace: flagString(flags, 'workspace') ?? startArgs[0],
|
|
244
|
+
mounts: mounts.length ? mounts.map(parseMountFlag) : undefined,
|
|
245
|
+
workspaceRoot: flagString(flags, 'workspace-root'),
|
|
184
246
|
name: flagString(flags, 'name'),
|
|
185
247
|
image: flagString(flags, 'image'),
|
|
186
248
|
empty: flagBool(flags, 'empty'),
|
|
187
|
-
vscodeConfig: !flagBool(flags, 'no-vscode-config'),
|
|
188
249
|
});
|
|
189
250
|
return;
|
|
190
251
|
}
|
|
@@ -205,6 +266,15 @@ async function main() {
|
|
|
205
266
|
await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
|
|
206
267
|
return;
|
|
207
268
|
}
|
|
269
|
+
if (cmd === 'restart') {
|
|
270
|
+
// Stop + recreate the gateway (runInit does `rm -f` first) so changed team
|
|
271
|
+
// folders get mounted. The portal writes the paths straight into the mounted
|
|
272
|
+
// ~/.huddle/config.json, so runInit already reads the latest values here.
|
|
273
|
+
const initOpts = { runtime: flagString(flags, 'runtime') };
|
|
274
|
+
(0, experiment_1.ensureCliForChannel)(process.argv.slice(2));
|
|
275
|
+
await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
208
278
|
if (cmd === 'experiment') {
|
|
209
279
|
const subCmd = sub ?? 'status';
|
|
210
280
|
if (subCmd === 'use') {
|
|
@@ -246,12 +316,53 @@ async function main() {
|
|
|
246
316
|
container: flagString(flags, 'container'),
|
|
247
317
|
});
|
|
248
318
|
}
|
|
319
|
+
else if (subCmd === 'export') {
|
|
320
|
+
await (0, firewall_1.runFirewallExport)({
|
|
321
|
+
container: flagString(flags, 'container'),
|
|
322
|
+
out: flagString(flags, 'out'),
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
else if (subCmd === 'import') {
|
|
326
|
+
const file = positional[2];
|
|
327
|
+
if (!file) {
|
|
328
|
+
console.error('Usage: huddle firewall import <file> [--replace] [--container <id>]');
|
|
329
|
+
process.exit(1);
|
|
330
|
+
}
|
|
331
|
+
await (0, firewall_1.runFirewallImport)({
|
|
332
|
+
file,
|
|
333
|
+
replace: flagBool(flags, 'replace'),
|
|
334
|
+
container: flagString(flags, 'container'),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
else if (subCmd === 'group' || subCmd === 'groups') {
|
|
338
|
+
await (0, firewall_1.runFirewallGroup)({
|
|
339
|
+
action: positional[2],
|
|
340
|
+
arg: positional[3],
|
|
341
|
+
out: flagString(flags, 'out'),
|
|
342
|
+
replace: flagBool(flags, 'replace'),
|
|
343
|
+
container: flagString(flags, 'container'),
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
else if (subCmd === 'folder') {
|
|
347
|
+
await (0, firewall_1.runFirewallFolder)({ action: positional[2], path: positional[3] });
|
|
348
|
+
}
|
|
249
349
|
else {
|
|
250
350
|
console.error(`Unknown firewall subcommand: ${subCmd}`);
|
|
251
351
|
process.exit(1);
|
|
252
352
|
}
|
|
253
353
|
return;
|
|
254
354
|
}
|
|
355
|
+
if (cmd === 'indexfolder' || cmd === 'indexfolders') {
|
|
356
|
+
await (0, indexfolder_1.runIndexFolder)({
|
|
357
|
+
path: positional[1],
|
|
358
|
+
depth: flagString(flags, 'depth'),
|
|
359
|
+
all: flagBool(flags, 'all'),
|
|
360
|
+
replace: flagBool(flags, 'replace'),
|
|
361
|
+
clear: flagBool(flags, 'clear'),
|
|
362
|
+
list: flagBool(flags, 'list'),
|
|
363
|
+
});
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
255
366
|
if (cmd === 'migrate') {
|
|
256
367
|
await (0, migrate_1.runMigrate)({
|
|
257
368
|
path: positional[1],
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runIndexFolder = runIndexFolder;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const api_1 = require("./api");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
// `huddle indexfolder` — make host folders selectable in the portal.
|
|
12
|
+
//
|
|
13
|
+
// The portal runs inside a container: it cannot open a file dialog on the host,
|
|
14
|
+
// so every host path had to be typed from memory. This command walks the host
|
|
15
|
+
// filesystem where the operator already is (their projects folder) and posts the
|
|
16
|
+
// folders it finds to the gateway, which stores them as an index. The portal then
|
|
17
|
+
// offers that index wherever a host path is needed.
|
|
18
|
+
//
|
|
19
|
+
// Deliberately a snapshot, not a live view: the gateway has no way to read the
|
|
20
|
+
// host filesystem, and re-running the command is cheap.
|
|
21
|
+
// Folders that are never a workspace choice but do contain thousands of
|
|
22
|
+
// subfolders. Skipping them is what keeps a scan of a projects folder in the
|
|
23
|
+
// hundreds rather than the tens of thousands. `--all` turns this off; hidden
|
|
24
|
+
// (dot) folders stay skipped either way.
|
|
25
|
+
const NOISE = new Set([
|
|
26
|
+
'node_modules', 'dist', 'build', 'out', 'bin', 'obj', 'target', 'vendor',
|
|
27
|
+
'venv', '__pycache__', 'coverage', 'packages', 'AppData', 'Library',
|
|
28
|
+
'$RECYCLE.BIN', 'System Volume Information', 'Windows', 'Program Files',
|
|
29
|
+
'Program Files (x86)', 'ProgramData',
|
|
30
|
+
]);
|
|
31
|
+
// Hard stop on discovery, well under the gateway's own cap. Pointing the command
|
|
32
|
+
// at a drive root should end in a clear warning, not a ten-minute walk.
|
|
33
|
+
const MAX_FOLDERS = 1500;
|
|
34
|
+
// Host paths travel to the gateway with forward slashes: `path.resolve` hands
|
|
35
|
+
// back `T:\projects\app` on Windows, and the whole stack (the portal, the index,
|
|
36
|
+
// the Docker mount translation) speaks the forward-slash form. The gateway
|
|
37
|
+
// normalizes again on ingest — this is only so what we PRINT matches what gets
|
|
38
|
+
// stored.
|
|
39
|
+
function toPosix(p) {
|
|
40
|
+
return p.replace(/\\/g, '/').replace(/^([a-z]):/, (_m, d) => `${d.toUpperCase()}:`);
|
|
41
|
+
}
|
|
42
|
+
function parseDepth(raw) {
|
|
43
|
+
if (raw === undefined)
|
|
44
|
+
return 2;
|
|
45
|
+
const n = Number(raw);
|
|
46
|
+
if (!Number.isInteger(n) || n < 0 || n > 8) {
|
|
47
|
+
throw new Error(`Invalid --depth "${raw}": use a whole number between 0 and 8.`);
|
|
48
|
+
}
|
|
49
|
+
return n;
|
|
50
|
+
}
|
|
51
|
+
// The folder to walk comes from argv, or from wherever the operator's shell is.
|
|
52
|
+
// Resolving it here — once, before anything touches the filesystem — is what lets
|
|
53
|
+
// the rest of the command treat "the root" as one absolute, `..`-free path: the
|
|
54
|
+
// walk below, the containment check, and the paths posted to the gateway all
|
|
55
|
+
// derive from this value.
|
|
56
|
+
function resolveScanRoot(raw) {
|
|
57
|
+
const input = raw ?? process.cwd();
|
|
58
|
+
// A null byte makes every fs call throw ERR_INVALID_ARG_VALUE with a stack
|
|
59
|
+
// trace; say what is wrong instead.
|
|
60
|
+
if (input.includes('\0'))
|
|
61
|
+
throw new Error('Invalid folder: the path contains a null byte.');
|
|
62
|
+
return path_1.default.resolve(input);
|
|
63
|
+
}
|
|
64
|
+
// Whether `candidate` is the root or sits underneath it.
|
|
65
|
+
function contains(root, candidate) {
|
|
66
|
+
const rel = path_1.default.relative(root, candidate);
|
|
67
|
+
return rel === '' || (!rel.startsWith('..') && !path_1.default.isAbsolute(rel));
|
|
68
|
+
}
|
|
69
|
+
// Breadth-first so a depth cut-off keeps the folders nearest the root — those are
|
|
70
|
+
// the ones an operator actually mounts. Symlinks are not followed: `isDirectory()`
|
|
71
|
+
// is false for a symlink entry, which also rules out a link loop.
|
|
72
|
+
function scan(root, depth, all) {
|
|
73
|
+
const folders = [root];
|
|
74
|
+
let level = [root];
|
|
75
|
+
for (let d = 0; d < depth; d++) {
|
|
76
|
+
const next = [];
|
|
77
|
+
for (const dir of level) {
|
|
78
|
+
let entries;
|
|
79
|
+
try {
|
|
80
|
+
entries = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
continue; // unreadable folder (permissions, a vanished dir) — skip it
|
|
84
|
+
}
|
|
85
|
+
for (const e of entries) {
|
|
86
|
+
if (!e.isDirectory())
|
|
87
|
+
continue;
|
|
88
|
+
if (e.name.startsWith('.'))
|
|
89
|
+
continue;
|
|
90
|
+
if (!all && NOISE.has(e.name))
|
|
91
|
+
continue;
|
|
92
|
+
const full = path_1.default.join(dir, e.name);
|
|
93
|
+
// Nothing outside the folder the operator named ever enters the index or
|
|
94
|
+
// gets opened by the next round of readdirSync. Entries come from
|
|
95
|
+
// readdirSync and symlinks are already skipped, so this should never
|
|
96
|
+
// fire — it is here so a scan can never walk out of its root by accident.
|
|
97
|
+
if (!contains(root, full))
|
|
98
|
+
continue;
|
|
99
|
+
folders.push(full);
|
|
100
|
+
next.push(full);
|
|
101
|
+
if (folders.length >= MAX_FOLDERS)
|
|
102
|
+
return { folders, truncated: true };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
level = next;
|
|
106
|
+
if (level.length === 0)
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
return { folders, truncated: false };
|
|
110
|
+
}
|
|
111
|
+
async function runIndexFolder(opts) {
|
|
112
|
+
if (opts.list) {
|
|
113
|
+
const res = await (0, api_1.get)('/api/indexed-folders');
|
|
114
|
+
if (res.folders.length === 0) {
|
|
115
|
+
console.log((0, utils_1.dim)('No folders indexed yet. Run `huddle indexfolder` in your projects folder.'));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
(0, utils_1.printTable)(['ID', 'PATH', 'SOURCE'], res.folders.map((f) => [String(f.id), f.path, f.source]));
|
|
119
|
+
console.log((0, utils_1.dim)(`\n${res.folders.length} folder(s) indexed (max ${res.max}).`));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (opts.clear) {
|
|
123
|
+
// Scoped when a folder is given, so clearing one project's entries does not
|
|
124
|
+
// throw away everything else that was indexed.
|
|
125
|
+
const root = opts.path ? toPosix(resolveScanRoot(opts.path)) : undefined;
|
|
126
|
+
const query = root ? `?root=${encodeURIComponent(root)}` : '';
|
|
127
|
+
const res = await (0, api_1.del)(`/api/indexed-folders${query}`);
|
|
128
|
+
console.log((0, utils_1.green)(`[OK] Removed ${res.removed} folder(s) from the index${root ? ` under ${(0, utils_1.cyan)(root)}` : ''}.`));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const depth = parseDepth(opts.depth);
|
|
132
|
+
const root = resolveScanRoot(opts.path);
|
|
133
|
+
let stat;
|
|
134
|
+
try {
|
|
135
|
+
stat = fs_1.default.statSync(root);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
throw new Error(`Folder does not exist: ${root}`);
|
|
139
|
+
}
|
|
140
|
+
if (!stat.isDirectory())
|
|
141
|
+
throw new Error(`Not a folder: ${root}`);
|
|
142
|
+
const posixRoot = toPosix(root);
|
|
143
|
+
console.log(`Indexing ${(0, utils_1.bold)(posixRoot)} ${(0, utils_1.dim)(`(depth ${depth}${opts.all ? ', including build folders' : ''})`)}`);
|
|
144
|
+
const { folders, truncated } = scan(root, depth, opts.all === true);
|
|
145
|
+
if (truncated) {
|
|
146
|
+
console.log((0, utils_1.yellow)(`[!] Stopped at ${MAX_FOLDERS} folders. Index a more specific folder, or lower --depth.`));
|
|
147
|
+
}
|
|
148
|
+
const res = await (0, api_1.post)('/api/indexed-folders', {
|
|
149
|
+
paths: folders.map(toPosix),
|
|
150
|
+
root: posixRoot,
|
|
151
|
+
replace: opts.replace === true,
|
|
152
|
+
});
|
|
153
|
+
if (res.removed)
|
|
154
|
+
console.log((0, utils_1.dim)(` Replaced: removed ${res.removed} earlier entr(y|ies) under this folder.`));
|
|
155
|
+
console.log((0, utils_1.green)(`[OK] ${res.added} added, ${res.updated} already known — ${res.total} folder(s) in the index.`));
|
|
156
|
+
if (res.skipped) {
|
|
157
|
+
console.log((0, utils_1.yellow)(`[!] ${res.skipped} folder(s) skipped (index limit ${res.max} reached, or a duplicate spelling).`));
|
|
158
|
+
}
|
|
159
|
+
for (const bad of res.invalid.slice(0, 5)) {
|
|
160
|
+
console.log((0, utils_1.yellow)(`[!] Refused ${bad.path}: ${bad.error}`));
|
|
161
|
+
}
|
|
162
|
+
if (res.invalid.length > 5)
|
|
163
|
+
console.log((0, utils_1.yellow)(`[!] ...and ${res.invalid.length - 5} more refused.`));
|
|
164
|
+
console.log();
|
|
165
|
+
console.log('Pick these folders in the portal when starting a devcontainer,');
|
|
166
|
+
console.log(`or manage the index under ${(0, utils_1.cyan)('Settings > Indexed folders')}.`);
|
|
167
|
+
}
|
package/dist/init.js
CHANGED
|
@@ -29,12 +29,16 @@ exports.INTERNAL_NET = 'devcontainer-net';
|
|
|
29
29
|
*/
|
|
30
30
|
exports.HOST_SOCKET_DIR = '/tmp/dc-sockets';
|
|
31
31
|
const HOST_PORT = process.env.HUDDLE_PORT ?? '3000';
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// Run a binary with an argv array — NO shell. Values that originate from config
|
|
33
|
+
// (team-folder paths, which are writable via `huddle firewall folder set` and the
|
|
34
|
+
// authenticated settings API) must never be interpolated into a shell string, or
|
|
35
|
+
// a path containing `$()`/quotes would execute on the host. Used for `docker run`.
|
|
36
|
+
function runArgs(file, args) {
|
|
37
|
+
(0, child_process_1.execFileSync)(file, args, { stdio: 'inherit' });
|
|
34
38
|
}
|
|
35
|
-
function
|
|
39
|
+
function runArgsSilent(file, args) {
|
|
36
40
|
try {
|
|
37
|
-
(0, child_process_1.
|
|
41
|
+
(0, child_process_1.execFileSync)(file, args, { stdio: 'ignore' });
|
|
38
42
|
return true;
|
|
39
43
|
}
|
|
40
44
|
catch {
|
|
@@ -52,7 +56,7 @@ function pullBaseImages(rt, images) {
|
|
|
52
56
|
for (const image of images) {
|
|
53
57
|
console.log((0, utils_1.dim)(` Pulling ${image}`));
|
|
54
58
|
try {
|
|
55
|
-
|
|
59
|
+
runArgs(rt, ['pull', image]);
|
|
56
60
|
}
|
|
57
61
|
catch {
|
|
58
62
|
failed.push(image);
|
|
@@ -82,15 +86,15 @@ async function runInit(opts, images) {
|
|
|
82
86
|
}
|
|
83
87
|
else {
|
|
84
88
|
console.log((0, utils_1.dim)(`Pulling ${IMAGE}`));
|
|
85
|
-
|
|
89
|
+
runArgs(rt, ['pull', IMAGE]);
|
|
86
90
|
pullBaseImages(rt, images.baseImages.map((b) => b.image));
|
|
87
91
|
}
|
|
88
92
|
console.log((0, utils_1.dim)(`Volume: ${VOLUME}`));
|
|
89
|
-
|
|
93
|
+
runArgsSilent(rt, ['volume', 'inspect', VOLUME]) || runArgs(rt, ['volume', 'create', VOLUME]);
|
|
90
94
|
console.log((0, utils_1.dim)(`Network: ${exports.INTERNAL_NET}`));
|
|
91
|
-
|
|
95
|
+
runArgsSilent(rt, ['network', 'inspect', exports.INTERNAL_NET]) || runArgs(rt, ['network', 'create', '--internal', exports.INTERNAL_NET]);
|
|
92
96
|
console.log((0, utils_1.dim)(`Removing old container if it exists`));
|
|
93
|
-
|
|
97
|
+
runArgsSilent(rt, ['rm', '-f', CONTAINER]);
|
|
94
98
|
console.log((0, utils_1.dim)(`Socket directory: /tmp/dc-sockets`));
|
|
95
99
|
// The mount SOURCE must be the path on the Docker ENGINE host (on Windows:
|
|
96
100
|
// the WSL2/Linux VM), even when the CLI itself runs on Windows. The gateway
|
|
@@ -105,7 +109,7 @@ async function runInit(opts, images) {
|
|
|
105
109
|
// Desktop) and fails with "statfs: no such file or directory". So create
|
|
106
110
|
// the directory explicitly in the machine VM; the socket lives there too.
|
|
107
111
|
console.log((0, utils_1.dim)(` (Podman: creating ${hostTmpSockets} in the machine VM)`));
|
|
108
|
-
if (!
|
|
112
|
+
if (!runArgsSilent('podman', ['machine', 'ssh', `mkdir -p ${hostTmpSockets}`])) {
|
|
109
113
|
console.log((0, utils_1.yellow)(`[!] Could not create ${hostTmpSockets} in the Podman VM.`));
|
|
110
114
|
}
|
|
111
115
|
}
|
|
@@ -126,8 +130,7 @@ async function runInit(opts, images) {
|
|
|
126
130
|
// The gateway is engine-agnostic (talks the Docker-compatible API on the
|
|
127
131
|
// mounted socket), but does need to know it's Podman: it then sets
|
|
128
132
|
// `--security-opt label=disable` on every devcontainer so it can reach the
|
|
129
|
-
// SELinux-labeled proxy socket.
|
|
130
|
-
const securityOptFlags = runtime.securityOpts.map((opt) => ` --security-opt ${opt}`).join('');
|
|
133
|
+
// SELinux-labeled proxy socket. (Applied as argv below via runtime.securityOpts.)
|
|
131
134
|
// Operator token for control-plane auth. Reuse the token from the config (so an
|
|
132
135
|
// existing browser session/CLI keeps working across re-inits), otherwise
|
|
133
136
|
// generate one. We pass it to the gateway via env AND store it locally so that
|
|
@@ -137,7 +140,7 @@ async function runInit(opts, images) {
|
|
|
137
140
|
(cfg.operatorToken && cfg.operatorToken.trim()) ||
|
|
138
141
|
crypto_1.default.randomBytes(32).toString('base64url');
|
|
139
142
|
if (cfg.operatorToken !== operatorToken) {
|
|
140
|
-
(0, config_1.
|
|
143
|
+
(0, config_1.updateConfig)({ operatorToken });
|
|
141
144
|
}
|
|
142
145
|
// The container is created on the engine's default network first (with -p),
|
|
143
146
|
// then joins devcontainer-net (--internal) afterwards: Docker skips the host
|
|
@@ -145,23 +148,43 @@ async function runInit(opts, images) {
|
|
|
145
148
|
// network (moby/moby#36174). Which source IP the gateway sees for forwarded
|
|
146
149
|
// traffic no longer matters — the control plane authenticates with the
|
|
147
150
|
// operator token instead of source-IP filtering.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
` -
|
|
158
|
-
|
|
159
|
-
` ${
|
|
151
|
+
// Team-managed folders (#69). Bind the CLI config dir (~/.huddle) read-write so
|
|
152
|
+
// the gateway/portal read and write the folder paths there (config.json is the
|
|
153
|
+
// single source of truth), then bind each configured team folder to a FIXED
|
|
154
|
+
// path so the gateway reads it without knowing the host path. The firewall-rules
|
|
155
|
+
// folder is bound read-write so the portal's "Sync to folder" can write the
|
|
156
|
+
// groups back out; extensions stay read-only (loaded, never written).
|
|
157
|
+
const fwFolder = cfg.firewallRulesFolder?.trim();
|
|
158
|
+
const extFolder = cfg.extensionsFolder?.trim();
|
|
159
|
+
if (fwFolder)
|
|
160
|
+
console.log((0, utils_1.dim)(` Mounting firewall-rules folder: ${fwFolder} -> /firewall-rules`));
|
|
161
|
+
if (extFolder)
|
|
162
|
+
console.log((0, utils_1.dim)(` Mounting extensions folder: ${extFolder} -> /extensions`));
|
|
163
|
+
// Build the container command as an argv array (runArgs → execFileSync, no
|
|
164
|
+
// shell). The folder paths below come from config and are operator-writable via
|
|
165
|
+
// the settings API, so they must never reach a shell as a string.
|
|
166
|
+
const dockerArgs = ['run', '-d', '--name', CONTAINER, '--network', runtime.defaultNetwork];
|
|
167
|
+
for (const opt of runtime.securityOpts)
|
|
168
|
+
dockerArgs.push('--security-opt', opt);
|
|
169
|
+
dockerArgs.push('-e', `HUDDLE_RUNTIME=${runtime.name}`);
|
|
170
|
+
dockerArgs.push('-e', `HUDDLE_OPERATOR_TOKEN=${operatorToken}`);
|
|
171
|
+
dockerArgs.push('-p', `${HOST_PORT}:3000`);
|
|
172
|
+
dockerArgs.push('-v', `${VOLUME}:/data`);
|
|
173
|
+
dockerArgs.push('-v', `${runtime.socketPath}:/var/run/docker.sock`);
|
|
174
|
+
dockerArgs.push('-v', `${hostTmpSockets}:/tmp/dc-sockets`);
|
|
175
|
+
dockerArgs.push('-v', `${config_1.CONFIG_DIR}:/huddle-home:rw`, '-e', 'HUDDLE_HOME_DIR=/huddle-home');
|
|
176
|
+
if (fwFolder)
|
|
177
|
+
dockerArgs.push('-v', `${fwFolder}:/firewall-rules:rw`);
|
|
178
|
+
if (extFolder)
|
|
179
|
+
dockerArgs.push('-v', `${extFolder}:/extensions:ro`);
|
|
180
|
+
dockerArgs.push(...(0, images_1.gatewayEnvArgs)(images));
|
|
181
|
+
dockerArgs.push(IMAGE);
|
|
182
|
+
runArgs(rt, dockerArgs);
|
|
160
183
|
// Attaching devcontainer-net after the container has started pollutes
|
|
161
184
|
// resolv.conf on Podman with that network's internal aardvark-DNS; the
|
|
162
185
|
// gateway cleans that up itself (see dns-egress.ts / the startup sanitize in
|
|
163
186
|
// index.ts).
|
|
164
|
-
|
|
187
|
+
runArgsSilent(rt, ['network', 'connect', exports.INTERNAL_NET, CONTAINER]);
|
|
165
188
|
console.log();
|
|
166
189
|
console.log((0, utils_1.green)(`[OK] Huddle is running at http://localhost:${HOST_PORT}`));
|
|
167
190
|
console.log();
|