worktree-compose 1.1.2 → 2.0.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/LICENSE +2 -2
- package/README.md +31 -16
- package/SKILL.md +73 -76
- package/dist/cli.js +85 -10
- package/dist/commands/down.d.ts +2 -0
- package/dist/commands/down.js +7 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.js +43 -6
- package/dist/commands/passthrough.d.ts +13 -0
- package/dist/commands/passthrough.js +27 -0
- package/dist/commands/stop.d.ts +3 -1
- package/dist/commands/stop.js +2 -2
- package/dist/compose/detect.d.ts +19 -0
- package/dist/compose/detect.js +56 -0
- package/dist/compose/isolation.d.ts +20 -7
- package/dist/compose/isolation.js +88 -36
- package/dist/compose/override.d.ts +54 -4
- package/dist/compose/override.js +179 -52
- package/dist/compose/parse.d.ts +11 -0
- package/dist/compose/parse.js +260 -13
- package/dist/compose/status.d.ts +14 -0
- package/dist/compose/status.js +58 -1
- package/dist/compose/types.d.ts +56 -0
- package/dist/config.d.ts +33 -0
- package/dist/context.d.ts +26 -0
- package/dist/context.js +140 -29
- package/dist/core/clean.d.ts +3 -1
- package/dist/core/clean.js +8 -3
- package/dist/core/compose.d.ts +87 -13
- package/dist/core/compose.js +282 -57
- package/dist/core/doctor.d.ts +2 -8
- package/dist/core/doctor.js +116 -79
- package/dist/core/down.d.ts +37 -0
- package/dist/core/down.js +54 -0
- package/dist/core/health.d.ts +90 -0
- package/dist/core/health.js +198 -0
- package/dist/core/list.d.ts +53 -6
- package/dist/core/list.js +144 -58
- package/dist/core/passthrough.d.ts +69 -0
- package/dist/core/passthrough.js +216 -0
- package/dist/core/promote.d.ts +4 -2
- package/dist/core/promote.js +5 -3
- package/dist/core/restart.d.ts +3 -3
- package/dist/core/restart.js +6 -5
- package/dist/core/seed.d.ts +50 -0
- package/dist/core/seed.js +245 -0
- package/dist/core/shared.d.ts +63 -0
- package/dist/core/shared.js +194 -0
- package/dist/core/start.d.ts +32 -5
- package/dist/core/start.js +297 -49
- package/dist/core/stop.d.ts +3 -1
- package/dist/core/stop.js +6 -3
- package/dist/core/teardown.d.ts +5 -2
- package/dist/core/teardown.js +33 -8
- package/dist/core/types.d.ts +2 -0
- package/dist/git/promote.d.ts +11 -3
- package/dist/git/promote.js +19 -5
- package/dist/mcp/server.js +154 -28
- package/dist/ports/allocate.d.ts +35 -23
- package/dist/ports/allocate.js +108 -58
- package/dist/ports/probe.d.ts +11 -0
- package/dist/ports/probe.js +40 -0
- package/dist/ports/types.d.ts +5 -0
- package/dist/selectors.d.ts +17 -0
- package/dist/selectors.js +19 -0
- package/dist/state/registry.d.ts +23 -3
- package/dist/state/registry.js +57 -17
- package/dist/sync/env.d.ts +42 -2
- package/dist/sync/env.js +79 -8
- package/dist/sync/envsync.d.ts +91 -0
- package/dist/sync/envsync.js +338 -0
- package/dist/sync/files.d.ts +87 -5
- package/dist/sync/files.js +343 -18
- package/dist/utils/paths.d.ts +2 -0
- package/dist/utils/paths.js +9 -0
- package/package.json +1 -1
- package/wtc.schema.json +155 -13
package/dist/compose/override.js
CHANGED
|
@@ -9,7 +9,7 @@ import { stateDir } from "../state/registry.js";
|
|
|
9
9
|
import { COMPOSE_FILE_VAR } from "../sync/env.js";
|
|
10
10
|
import { COMPOSE_FILENAMES } from "./detect.js";
|
|
11
11
|
import { composeArgs, composeBin } from "./engine.js";
|
|
12
|
-
import { isProjectScopedName, parseContainerRefs, portEntryString } from "./parse.js";
|
|
12
|
+
import { isProjectScopedName, parseContainerRefs, parseStaticIps, portEntryString } from "./parse.js";
|
|
13
13
|
/**
|
|
14
14
|
* Runtime remapping. Two compose settings make every worktree stack collide
|
|
15
15
|
* with the others: a hardcoded host port (`8080:80`) and a fixed
|
|
@@ -35,7 +35,7 @@ export const USER_OVERRIDE_FILENAMES = [
|
|
|
35
35
|
"docker-compose.override.yaml",
|
|
36
36
|
];
|
|
37
37
|
export function remapIsEmpty(t) {
|
|
38
|
-
return t.ports.length === 0 && t.containerNames.length === 0;
|
|
38
|
+
return t.ports.length === 0 && t.containerNames.length === 0 && (t.networks ?? []).length === 0;
|
|
39
39
|
}
|
|
40
40
|
/** Whether a service's port entries use `${…}` interpolation anywhere. */
|
|
41
41
|
function portsUseVariables(svc) {
|
|
@@ -65,7 +65,8 @@ function canMove(port) {
|
|
|
65
65
|
* in for a container identity.
|
|
66
66
|
*/
|
|
67
67
|
export function remapCandidates(composeFile, mappings) {
|
|
68
|
-
|
|
68
|
+
// Files compose is given directly are interpolated with the project's env; only included files have their own.
|
|
69
|
+
const roots = new Set(composeFile.rootFiles ?? composeFile.sourceFiles.slice(0, 1));
|
|
69
70
|
const skipped = [];
|
|
70
71
|
const keep = new Set();
|
|
71
72
|
for (const svc of composeFile.services) {
|
|
@@ -75,7 +76,7 @@ export function remapCandidates(composeFile, mappings) {
|
|
|
75
76
|
keep.add(svc.name);
|
|
76
77
|
skipped.push(`Service "${svc.name}" uses extends, which may bring in ports wtc cannot see, so wtc does not remap its hardcoded ports.`);
|
|
77
78
|
}
|
|
78
|
-
else if (
|
|
79
|
+
else if (roots.size > 0 && !roots.has(svc.sourcePath) && portsUseVariables(svc)) {
|
|
79
80
|
keep.add(svc.name);
|
|
80
81
|
skipped.push(`Service "${svc.name}" comes from an included file (${path.basename(svc.sourcePath)}) whose port variables compose fills in from that file's own env, so wtc does not remap its hardcoded ports.`);
|
|
81
82
|
}
|
|
@@ -108,7 +109,18 @@ export function remapCandidates(composeFile, mappings) {
|
|
|
108
109
|
}
|
|
109
110
|
return [{ service: s.name, name: s.containerName }];
|
|
110
111
|
});
|
|
111
|
-
|
|
112
|
+
const networks = composeFile.pinnedNetworks ?? [];
|
|
113
|
+
const pinned = new Set(networks);
|
|
114
|
+
const staticIps = composeFile.services.flatMap((s) => (s.staticIps ?? []).filter((n) => pinned.has(n)).map((network) => ({ service: s.name, network })));
|
|
115
|
+
return {
|
|
116
|
+
targets: {
|
|
117
|
+
ports,
|
|
118
|
+
containerNames,
|
|
119
|
+
...(networks.length > 0 ? { networks } : {}),
|
|
120
|
+
...(staticIps.length > 0 ? { staticIps } : {}),
|
|
121
|
+
},
|
|
122
|
+
skipped,
|
|
123
|
+
};
|
|
112
124
|
}
|
|
113
125
|
/** The compose override file compose would load from `dir` by itself, or null. */
|
|
114
126
|
export function findUserOverride(dir) {
|
|
@@ -166,11 +178,23 @@ export function withoutUserOverride(targets, dir) {
|
|
|
166
178
|
const defs = serviceDefs(file);
|
|
167
179
|
if (!defs) {
|
|
168
180
|
return {
|
|
169
|
-
|
|
181
|
+
// The subnets are not a service's setting: they are dropped all the same.
|
|
182
|
+
targets: {
|
|
183
|
+
ports: [],
|
|
184
|
+
containerNames: [],
|
|
185
|
+
...(targets.networks ? { networks: targets.networks } : {}),
|
|
186
|
+
...(targets.staticIps ? { staticIps: targets.staticIps } : {}),
|
|
187
|
+
},
|
|
170
188
|
warnings: [`Could not read ${name}, so wtc does not remap hardcoded ports or container_name at runtime.`],
|
|
171
189
|
};
|
|
172
190
|
}
|
|
173
191
|
const sets = (service, key) => defs.get(service)?.[key] !== undefined;
|
|
192
|
+
// A fixed address their override gives a service needs the network's subnet: it stays pinned.
|
|
193
|
+
const addressed = new Set();
|
|
194
|
+
for (const def of defs.values())
|
|
195
|
+
for (const network of parseStaticIps(def.networks))
|
|
196
|
+
addressed.add(network);
|
|
197
|
+
const kept = (targets.networks ?? []).filter((network) => addressed.has(network));
|
|
174
198
|
const joinedBy = new Map();
|
|
175
199
|
for (const [service, def] of defs) {
|
|
176
200
|
for (const ref of parseContainerRefs(def))
|
|
@@ -184,6 +208,9 @@ export function withoutUserOverride(targets, dir) {
|
|
|
184
208
|
for (const service of skippedPorts) {
|
|
185
209
|
warnings.push(`Service "${service}": ${name} also sets its ports, so wtc does not remap its hardcoded ports.`);
|
|
186
210
|
}
|
|
211
|
+
for (const network of kept) {
|
|
212
|
+
warnings.push(`Network "${network}": ${name} gives a service a fixed address on it, so wtc keeps its subnet (two stacks cannot use the same one).`);
|
|
213
|
+
}
|
|
187
214
|
const containerNames = targets.containerNames.flatMap((c) => {
|
|
188
215
|
if (sets(c.service, "container_name")) {
|
|
189
216
|
warnings.push(`Service "${c.service}": ${name} also sets container_name, so wtc does not drop it.`);
|
|
@@ -199,7 +226,13 @@ export function withoutUserOverride(targets, dir) {
|
|
|
199
226
|
: [c];
|
|
200
227
|
});
|
|
201
228
|
return {
|
|
202
|
-
targets: {
|
|
229
|
+
targets: {
|
|
230
|
+
...targets,
|
|
231
|
+
ports: targets.ports.filter((m) => !skippedPorts.has(m.serviceName)),
|
|
232
|
+
containerNames,
|
|
233
|
+
...(targets.networks ? { networks: targets.networks.filter((network) => !kept.includes(network)) } : {}),
|
|
234
|
+
...(targets.staticIps ? { staticIps: targets.staticIps.filter((ip) => !kept.includes(ip.network)) } : {}),
|
|
235
|
+
},
|
|
203
236
|
warnings,
|
|
204
237
|
};
|
|
205
238
|
}
|
|
@@ -255,21 +288,43 @@ export function overridePath(commonDir, project) {
|
|
|
255
288
|
* wtc wrote into a worktree's env file, exported into the shell by a tool
|
|
256
289
|
* that loads `.env` (direnv's `dotenv`, mise, autoenv). That is not a file
|
|
257
290
|
* list of the user's, so it must not switch remapping off. Any other list
|
|
258
|
-
* (a file added, another override picked) is the user's.
|
|
291
|
+
* (a file added, another override picked) is the user's. With a configured
|
|
292
|
+
* `composeFile`, `roots` are those files relative to the repository root:
|
|
293
|
+
* wtc then writes them (in the worktree) in place of the single default file.
|
|
259
294
|
*/
|
|
260
|
-
export function isWtcComposeFile(value, commonDir) {
|
|
295
|
+
export function isWtcComposeFile(value, commonDir, roots = []) {
|
|
261
296
|
const dir = path.dirname(overridePath(commonDir, "_"));
|
|
262
|
-
const files = value.split(composePathSeparator()).map((f) => f.trim()).filter(Boolean);
|
|
263
|
-
if (files.length
|
|
297
|
+
const files = value.split(composePathSeparator()).map((f) => f.trim()).filter(Boolean).map((f) => path.resolve(f));
|
|
298
|
+
if (files.length === 0)
|
|
264
299
|
return false;
|
|
265
|
-
|
|
300
|
+
const withOverride = path.dirname(files[files.length - 1]) === dir;
|
|
301
|
+
const own = withOverride ? files.slice(0, -1) : files;
|
|
302
|
+
if (own.length === 0)
|
|
303
|
+
return false;
|
|
304
|
+
// The default layout: one compose file compose finds by itself, the
|
|
305
|
+
// directory's own compose override if there is one, then wtc's override.
|
|
306
|
+
if (withOverride && own.length <= 2 && COMPOSE_FILENAMES.includes(path.basename(own[0]))) {
|
|
307
|
+
const userOverride = findUserOverride(path.dirname(own[0]));
|
|
308
|
+
if (own.length === 1 ? userOverride === null : userOverride !== null && own[1] === userOverride)
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
// Configured compose files (`composeFile`): the same files in some
|
|
312
|
+
// checkout, in order — with wtc's override, or without when nothing is
|
|
313
|
+
// remapped (compose would not find them by itself).
|
|
314
|
+
if (roots.length === 0)
|
|
266
315
|
return false;
|
|
267
|
-
|
|
316
|
+
const first = path.normalize(roots[0]);
|
|
317
|
+
if (own[0] !== first && !own[0].endsWith(path.sep + first))
|
|
268
318
|
return false;
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
319
|
+
const base = own[0].slice(0, own[0].length - first.length);
|
|
320
|
+
const expected = roots.map((r) => path.resolve(base || path.sep, r));
|
|
321
|
+
if (expected.length === own.length && expected.every((f, i) => f === own[i]))
|
|
322
|
+
return true;
|
|
323
|
+
if (roots.length === 1 && own.length === 2 && own[0] === expected[0]) {
|
|
324
|
+
const userOverride = findUserOverride(path.dirname(expected[0]));
|
|
325
|
+
return userOverride !== null && own[1] === userOverride;
|
|
326
|
+
}
|
|
327
|
+
return false;
|
|
273
328
|
}
|
|
274
329
|
/**
|
|
275
330
|
* Whether the inherited `COMPOSE_FILE` names `file`: a list the shell still
|
|
@@ -280,8 +335,8 @@ export function inheritedComposeFileNames(file) {
|
|
|
280
335
|
return !!value && value.split(composePathSeparator()).some((f) => f.trim() && path.resolve(f.trim()) === file);
|
|
281
336
|
}
|
|
282
337
|
/** A `COMPOSE_FILE` the user set (not one wtc wrote), from a value. */
|
|
283
|
-
export function isUserComposeFile(value, commonDir) {
|
|
284
|
-
return !!value?.trim() && !isWtcComposeFile(value, commonDir);
|
|
338
|
+
export function isUserComposeFile(value, commonDir, roots = []) {
|
|
339
|
+
return !!value?.trim() && !isWtcComposeFile(value, commonDir, roots);
|
|
285
340
|
}
|
|
286
341
|
export function writeOverride(file, content) {
|
|
287
342
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
@@ -348,6 +403,14 @@ function aliasNetworks(composeFile, svc, name) {
|
|
|
348
403
|
const shared = new Set(composeFile.sharedNetworks.map((n) => n.key));
|
|
349
404
|
return (networks.size > 0 ? [...networks] : ["default"]).filter((n) => !shared.has(n));
|
|
350
405
|
}
|
|
406
|
+
/** The profile wtc gives a shared service in a worktree stack: nothing enables it, so the service does not start. */
|
|
407
|
+
export const SHARED_PROFILE = "wtc-shared";
|
|
408
|
+
export function extrasAreEmpty(extra) {
|
|
409
|
+
return ((extra.shared ?? []).length === 0 &&
|
|
410
|
+
Object.keys(extra.dependsOn ?? {}).length === 0 &&
|
|
411
|
+
Object.keys(extra.envFiles ?? {}).length === 0 &&
|
|
412
|
+
Object.keys(extra.envFileLists ?? {}).length === 0);
|
|
413
|
+
}
|
|
351
414
|
/**
|
|
352
415
|
* The override YAML for one stack. A service whose hardcoded ports are
|
|
353
416
|
* remapped gets its whole `ports` list (`!override` replaces it): every
|
|
@@ -356,8 +419,16 @@ function aliasNetworks(composeFile, svc, name) {
|
|
|
356
419
|
* its own networks. Strings are quoted, so YAML 1.1 parsers never read
|
|
357
420
|
* `2222:22` as a base-60 number.
|
|
358
421
|
*/
|
|
359
|
-
export function renderOverride(project, composeFile, targets, allocations) {
|
|
360
|
-
|
|
422
|
+
export function renderOverride(project, composeFile, targets, allocations, extra = {}) {
|
|
423
|
+
// By default port, for the compose mappings only: a hardcoded port's own allocation,
|
|
424
|
+
// or the variable's that publishes the same port (tcp and udp), never a host process's.
|
|
425
|
+
const byDefault = new Map();
|
|
426
|
+
for (const a of allocations) {
|
|
427
|
+
if (a.serviceName.startsWith("("))
|
|
428
|
+
continue;
|
|
429
|
+
if (a.envVar === null || !byDefault.has(a.defaultPort))
|
|
430
|
+
byDefault.set(a.defaultPort, a.port);
|
|
431
|
+
}
|
|
361
432
|
const remapped = new Map();
|
|
362
433
|
for (const m of targets.ports) {
|
|
363
434
|
const port = byDefault.get(m.defaultPort);
|
|
@@ -368,46 +439,89 @@ export function renderOverride(project, composeFile, targets, allocations) {
|
|
|
368
439
|
remapped.set(m.serviceName, forService);
|
|
369
440
|
}
|
|
370
441
|
const reset = new Map(targets.containerNames.map((c) => [c.service, c]));
|
|
442
|
+
const unpinned = new Map();
|
|
443
|
+
for (const ip of targets.staticIps ?? []) {
|
|
444
|
+
unpinned.set(ip.service, [...(unpinned.get(ip.service) ?? []), ip.network]);
|
|
445
|
+
}
|
|
371
446
|
const out = {};
|
|
447
|
+
/** YAML paths of the values that carry compose's `!reset` tag. */
|
|
448
|
+
const resets = [];
|
|
449
|
+
/** YAML paths of the values that carry compose's `!override` tag. */
|
|
450
|
+
const overrides = [];
|
|
372
451
|
for (const svc of composeFile.services) {
|
|
373
452
|
const ports = remapped.get(svc.name);
|
|
374
453
|
const name = reset.get(svc.name);
|
|
375
|
-
|
|
454
|
+
const ips = unpinned.get(svc.name);
|
|
455
|
+
const shared = extra.shared?.includes(svc.name);
|
|
456
|
+
const dependsOn = extra.dependsOn?.[svc.name];
|
|
457
|
+
const envFiles = extra.envFiles?.[svc.name];
|
|
458
|
+
const envFileList = extra.envFileLists?.[svc.name];
|
|
459
|
+
if (!ports && !name && !ips && !shared && !dependsOn && !envFiles && !envFileList)
|
|
376
460
|
continue;
|
|
377
461
|
const entry = {};
|
|
462
|
+
if (shared) {
|
|
463
|
+
// Replacing the list: a profile the service already has (and the user enables) must not start it.
|
|
464
|
+
entry.profiles = [SHARED_PROFILE];
|
|
465
|
+
overrides.push(["services", svc.name, "profiles"]);
|
|
466
|
+
}
|
|
467
|
+
if (dependsOn) {
|
|
468
|
+
entry.depends_on = dependsOn;
|
|
469
|
+
overrides.push(["services", svc.name, "depends_on"]);
|
|
470
|
+
}
|
|
471
|
+
if (envFileList) {
|
|
472
|
+
entry.env_file = envFileList;
|
|
473
|
+
overrides.push(["services", svc.name, "env_file"]);
|
|
474
|
+
}
|
|
475
|
+
else if (envFiles) {
|
|
476
|
+
entry.env_file = envFiles;
|
|
477
|
+
}
|
|
378
478
|
if (ports) {
|
|
379
479
|
entry.ports = (svc.portEntries ?? svc.ports).map((e) => {
|
|
380
480
|
const raw = portEntryString(e);
|
|
381
481
|
const port = raw === null ? undefined : ports.get(raw);
|
|
382
482
|
return port === undefined ? e : withHostPort(e, port);
|
|
383
483
|
});
|
|
484
|
+
overrides.push(["services", svc.name, "ports"]);
|
|
384
485
|
}
|
|
486
|
+
const networks = {};
|
|
385
487
|
if (name) {
|
|
386
488
|
entry.container_name = null;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
489
|
+
resets.push(["services", svc.name, "container_name"]);
|
|
490
|
+
for (const n of name.noAlias ? [] : aliasNetworks(composeFile, svc, name.name)) {
|
|
491
|
+
networks[n] = { aliases: [name.name] };
|
|
390
492
|
}
|
|
391
493
|
}
|
|
494
|
+
for (const n of ips ?? []) {
|
|
495
|
+
networks[n] = { ...networks[n], ipv4_address: null, ipv6_address: null };
|
|
496
|
+
resets.push(["services", svc.name, "networks", n, "ipv4_address"], ["services", svc.name, "networks", n, "ipv6_address"]);
|
|
497
|
+
}
|
|
498
|
+
if (Object.keys(networks).length > 0)
|
|
499
|
+
entry.networks = networks;
|
|
392
500
|
out[svc.name] = entry;
|
|
393
501
|
}
|
|
394
|
-
const
|
|
395
|
-
for (const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
502
|
+
const topNetworks = {};
|
|
503
|
+
for (const n of targets.networks ?? []) {
|
|
504
|
+
topNetworks[n] = { ipam: null };
|
|
505
|
+
resets.push(["networks", n, "ipam"]);
|
|
506
|
+
}
|
|
507
|
+
const doc = new Document({
|
|
508
|
+
...(Object.keys(out).length > 0 ? { services: out } : {}),
|
|
509
|
+
...(Object.keys(topNetworks).length > 0 ? { networks: topNetworks } : {}),
|
|
510
|
+
});
|
|
511
|
+
for (const at of overrides) {
|
|
512
|
+
const node = doc.getIn(at, true);
|
|
513
|
+
if (node)
|
|
514
|
+
node.tag = "!override";
|
|
515
|
+
}
|
|
516
|
+
for (const at of resets) {
|
|
517
|
+
const node = doc.getIn(at, true);
|
|
518
|
+
if (node)
|
|
519
|
+
node.tag = "!reset";
|
|
406
520
|
}
|
|
407
521
|
doc.commentBefore =
|
|
408
522
|
` Generated by wtc for ${project}; rewritten on every start, do not edit.\n` +
|
|
409
|
-
` Remaps hardcoded host ports and drops fixed container names
|
|
410
|
-
` runs next to the others. The compose file itself is not changed.`;
|
|
523
|
+
` Remaps hardcoded host ports and drops fixed container names and subnets so\n` +
|
|
524
|
+
` this stack runs next to the others. The compose file itself is not changed.`;
|
|
411
525
|
return doc.toString({ defaultStringType: "QUOTE_DOUBLE", defaultKeyType: "PLAIN", lineWidth: 0 });
|
|
412
526
|
}
|
|
413
527
|
const PROBE_COMPOSE = [
|
|
@@ -496,23 +610,23 @@ export function engineSupportsRemap(engine) {
|
|
|
496
610
|
probeCache.set(key, { supported, at: Date.now() });
|
|
497
611
|
return supported;
|
|
498
612
|
}
|
|
499
|
-
/**
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
613
|
+
/**
|
|
614
|
+
* Why wtc cannot remap anything in this repository at runtime — a
|
|
615
|
+
* `COMPOSE_FILE` of the user's (wtc's would replace it), a different path
|
|
616
|
+
* separator, or an engine that does not apply `!override` / `!reset` — or
|
|
617
|
+
* null when it can. `engine: false` means no engine was available at all
|
|
618
|
+
* (nothing runs; the engine problem is reported elsewhere).
|
|
619
|
+
*/
|
|
620
|
+
export function remapBlocker(inputs) {
|
|
507
621
|
const cannot = (why) => ({
|
|
508
|
-
...none,
|
|
509
622
|
problem: `wtc cannot remap hardcoded ports or container_name at runtime: ${why}.`,
|
|
623
|
+
engine: true,
|
|
510
624
|
});
|
|
511
|
-
if (isUserComposeFile(process.env[COMPOSE_FILE_VAR], inputs.commonDir)) {
|
|
625
|
+
if (isUserComposeFile(process.env[COMPOSE_FILE_VAR], inputs.commonDir, inputs.composeRoots)) {
|
|
512
626
|
return cannot("COMPOSE_FILE is set in the environment, and wtc would replace it");
|
|
513
627
|
}
|
|
514
628
|
for (const file of new Set(inputs.envFiles)) {
|
|
515
|
-
if (isUserComposeFile(envFileComposeFile(file), inputs.commonDir)) {
|
|
629
|
+
if (isUserComposeFile(envFileComposeFile(file), inputs.commonDir, inputs.composeRoots)) {
|
|
516
630
|
return cannot(`${path.basename(file)} sets COMPOSE_FILE, and wtc would replace it`);
|
|
517
631
|
}
|
|
518
632
|
const conflict = separatorConflict(file);
|
|
@@ -531,12 +645,25 @@ export function decideRemap(inputs) {
|
|
|
531
645
|
engine = inputs.engine();
|
|
532
646
|
}
|
|
533
647
|
catch {
|
|
534
|
-
|
|
535
|
-
return none;
|
|
648
|
+
return { problem: null, engine: false };
|
|
536
649
|
}
|
|
537
650
|
if (!engineSupportsRemap(engine)) {
|
|
538
651
|
return cannot(`${engine.label} does not apply compose's !override / !reset tags (Docker Compose 2.24.4 or newer does)`);
|
|
539
652
|
}
|
|
653
|
+
return { problem: null, engine: true };
|
|
654
|
+
}
|
|
655
|
+
/** Decide what to remap for this repository (see the module comment). */
|
|
656
|
+
export function decideRemap(inputs) {
|
|
657
|
+
const none = { targets: null, problem: null, warnings: [] };
|
|
658
|
+
const { targets: candidates, skipped } = remapCandidates(inputs.composeFile, inputs.mappings);
|
|
659
|
+
if (remapIsEmpty(candidates))
|
|
660
|
+
return { ...none, warnings: skipped };
|
|
661
|
+
const blocker = remapBlocker(inputs);
|
|
662
|
+
if (blocker.problem)
|
|
663
|
+
return { ...none, problem: blocker.problem };
|
|
664
|
+
// No engine: nothing runs, and the engine problem is reported elsewhere.
|
|
665
|
+
if (!blocker.engine)
|
|
666
|
+
return none;
|
|
540
667
|
const { targets, warnings } = withoutUserOverride(candidates, inputs.mainRoot);
|
|
541
668
|
return { targets: remapIsEmpty(targets) ? null : targets, problem: null, warnings: [...skipped, ...warnings] };
|
|
542
669
|
}
|
package/dist/compose/parse.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { ComposeFile } from "./types.js";
|
|
2
2
|
/** The `host:container` string wtc reads a `ports:` entry as, or null (no published port). */
|
|
3
3
|
export declare function portEntryString(p: unknown): string | null;
|
|
4
|
+
/** A host path of a compose file, absolute: `~` is the home directory, the rest is relative to `baseDir`. */
|
|
5
|
+
export declare function resolveHostPath(source: string, baseDir: string): string;
|
|
6
|
+
/** Networks on which a service pins its address (`ipv4_address`, `ipv6_address`). */
|
|
7
|
+
export declare function parseStaticIps(networks: unknown): string[];
|
|
4
8
|
/**
|
|
5
9
|
* Container names a service joins by name: `network_mode`, `ipc` or `pid`
|
|
6
10
|
* set to `container:<name>`, and `volumes_from: [container:<name>[:ro]]`.
|
|
@@ -12,3 +16,10 @@ export declare function parseContainerRefs(s: Record<string, unknown>): string[]
|
|
|
12
16
|
*/
|
|
13
17
|
export declare function isProjectScopedName(name: string): boolean;
|
|
14
18
|
export declare function parseComposeFile(composePath: string): ComposeFile;
|
|
19
|
+
/**
|
|
20
|
+
* Parse the compose files compose is given, in order (`-f a -f b`): each
|
|
21
|
+
* later file's services and resources are merged onto the earlier ones, as
|
|
22
|
+
* compose merges them, and relative paths in every file resolve against the
|
|
23
|
+
* first file's directory. One file is the common case.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseComposeFiles(composePaths: string[]): ComposeFile;
|