worktree-compose 1.1.2 → 2.0.0
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/parse.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { parseDocument } from "yaml";
|
|
4
5
|
/** The `host:container` string wtc reads a `ports:` entry as, or null (no published port). */
|
|
@@ -51,14 +52,140 @@ function parseServiceBuild(build) {
|
|
|
51
52
|
}
|
|
52
53
|
return undefined;
|
|
53
54
|
}
|
|
55
|
+
/** `env_file`: a path, or a list of paths and `{ path, required }` entries. */
|
|
54
56
|
function parseEnvFile(envFile) {
|
|
55
57
|
if (typeof envFile === "string")
|
|
56
58
|
return [envFile];
|
|
57
59
|
if (Array.isArray(envFile)) {
|
|
58
|
-
return envFile.
|
|
60
|
+
return envFile.flatMap((e) => {
|
|
61
|
+
if (typeof e === "string")
|
|
62
|
+
return [e];
|
|
63
|
+
const p = e && typeof e === "object" ? e.path : undefined;
|
|
64
|
+
return typeof p === "string" ? [p] : [];
|
|
65
|
+
});
|
|
59
66
|
}
|
|
60
67
|
return undefined;
|
|
61
68
|
}
|
|
69
|
+
/** True when every `env_file` entry is a plain path. */
|
|
70
|
+
function envFileIsSimple(envFile) {
|
|
71
|
+
return typeof envFile === "string" || (Array.isArray(envFile) && envFile.every((e) => typeof e === "string"));
|
|
72
|
+
}
|
|
73
|
+
/** A volume source that names a host path rather than a named volume. */
|
|
74
|
+
function isHostPath(source) {
|
|
75
|
+
return /^(\.{1,2}($|[\\/])|~($|[\\/])|[\\/]|[A-Za-z]:[\\/])/.test(source);
|
|
76
|
+
}
|
|
77
|
+
/** A host path of a compose file, absolute: `~` is the home directory, the rest is relative to `baseDir`. */
|
|
78
|
+
export function resolveHostPath(source, baseDir) {
|
|
79
|
+
if (source === "~" || /^~[\\/]/.test(source))
|
|
80
|
+
return path.join(os.homedir(), source.slice(1));
|
|
81
|
+
return path.resolve(baseDir, source);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A service's volumes, split into bind mounts of host paths and the named
|
|
85
|
+
* volumes it mounts. Sources with `${…}` are left out: their value is only
|
|
86
|
+
* known to compose.
|
|
87
|
+
*/
|
|
88
|
+
function parseVolumes(volumes, baseDir) {
|
|
89
|
+
const binds = [];
|
|
90
|
+
const keys = [];
|
|
91
|
+
const targets = {};
|
|
92
|
+
if (!Array.isArray(volumes))
|
|
93
|
+
return { binds, keys, targets };
|
|
94
|
+
for (const v of volumes) {
|
|
95
|
+
let source;
|
|
96
|
+
let target;
|
|
97
|
+
let readOnly = false;
|
|
98
|
+
let type;
|
|
99
|
+
if (typeof v === "string") {
|
|
100
|
+
// `source:target[:mode]`; a Windows drive letter (`C:\\data`) keeps its colon.
|
|
101
|
+
const parts = v.split(":");
|
|
102
|
+
if (parts.length > 2 && /^[A-Za-z]$/.test(parts[0]) && parts[1].startsWith("\\")) {
|
|
103
|
+
parts.splice(0, 2, `${parts[0]}:${parts[1]}`);
|
|
104
|
+
}
|
|
105
|
+
if (parts.length < 2)
|
|
106
|
+
continue; // an anonymous volume
|
|
107
|
+
[source, target] = parts;
|
|
108
|
+
readOnly = (parts[2] ?? "").split(",").includes("ro");
|
|
109
|
+
}
|
|
110
|
+
else if (v && typeof v === "object") {
|
|
111
|
+
const o = v;
|
|
112
|
+
({ source, target, type } = o);
|
|
113
|
+
readOnly = o.read_only === true;
|
|
114
|
+
}
|
|
115
|
+
if (typeof source !== "string" || !source || source.includes("$"))
|
|
116
|
+
continue;
|
|
117
|
+
if (type === "bind" || (type === undefined && isHostPath(source))) {
|
|
118
|
+
binds.push({
|
|
119
|
+
raw: source,
|
|
120
|
+
source: resolveHostPath(source, baseDir),
|
|
121
|
+
...(typeof target === "string" ? { target } : {}),
|
|
122
|
+
readOnly,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else if (type === "volume" || type === undefined) {
|
|
126
|
+
keys.push(source);
|
|
127
|
+
if (typeof target === "string")
|
|
128
|
+
targets[target] = source;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { binds, keys: [...new Set(keys)], targets };
|
|
132
|
+
}
|
|
133
|
+
/** `depends_on` in its long form: the list form means `condition: service_started`. */
|
|
134
|
+
function parseDependsOn(dependsOn) {
|
|
135
|
+
if (Array.isArray(dependsOn)) {
|
|
136
|
+
const names = dependsOn.filter((d) => typeof d === "string");
|
|
137
|
+
return names.length > 0
|
|
138
|
+
? Object.fromEntries(names.map((n) => [n, { condition: "service_started" }]))
|
|
139
|
+
: undefined;
|
|
140
|
+
}
|
|
141
|
+
if (dependsOn && typeof dependsOn === "object") {
|
|
142
|
+
const out = {};
|
|
143
|
+
for (const [name, def] of Object.entries(dependsOn)) {
|
|
144
|
+
out[name] = def && typeof def === "object" ? def : { condition: "service_started" };
|
|
145
|
+
}
|
|
146
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
/** `environment` as a map: the list form is `KEY=value` (a bare `KEY` passes the host's value through). */
|
|
151
|
+
function parseEnvironment(environment) {
|
|
152
|
+
const out = {};
|
|
153
|
+
if (Array.isArray(environment)) {
|
|
154
|
+
for (const e of environment) {
|
|
155
|
+
if (typeof e !== "string")
|
|
156
|
+
continue;
|
|
157
|
+
const eq = e.indexOf("=");
|
|
158
|
+
if (eq > 0)
|
|
159
|
+
out[e.slice(0, eq)] = e.slice(eq + 1);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else if (environment && typeof environment === "object") {
|
|
163
|
+
for (const [k, v] of Object.entries(environment)) {
|
|
164
|
+
if (v !== null && v !== undefined)
|
|
165
|
+
out[k] = String(v);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
169
|
+
}
|
|
170
|
+
function parseHealthcheck(healthcheck) {
|
|
171
|
+
const test = healthcheck && typeof healthcheck === "object" ? healthcheck.test : undefined;
|
|
172
|
+
if (typeof test === "string")
|
|
173
|
+
return test;
|
|
174
|
+
if (Array.isArray(test))
|
|
175
|
+
return test.filter((t) => typeof t === "string").join(" ");
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
/** Networks on which a service pins its address (`ipv4_address`, `ipv6_address`). */
|
|
179
|
+
export function parseStaticIps(networks) {
|
|
180
|
+
if (!networks || typeof networks !== "object" || Array.isArray(networks))
|
|
181
|
+
return [];
|
|
182
|
+
return Object.entries(networks)
|
|
183
|
+
.filter(([, def]) => {
|
|
184
|
+
const d = def && typeof def === "object" ? def : {};
|
|
185
|
+
return d.ipv4_address != null || d.ipv6_address != null;
|
|
186
|
+
})
|
|
187
|
+
.map(([name]) => name);
|
|
188
|
+
}
|
|
62
189
|
/** Network names a service joins: the keys of the map form, or the list form. */
|
|
63
190
|
function parseServiceNetworks(networks) {
|
|
64
191
|
if (Array.isArray(networks))
|
|
@@ -99,7 +226,7 @@ export function parseContainerRefs(s) {
|
|
|
99
226
|
s.volumes_from.forEach(add);
|
|
100
227
|
return refs;
|
|
101
228
|
}
|
|
102
|
-
function parseServicesObject(doc, sourcePath, tagOf = () => undefined) {
|
|
229
|
+
function parseServicesObject(doc, sourcePath, tagOf = () => undefined, baseDir = path.dirname(sourcePath)) {
|
|
103
230
|
if (!("services" in doc) || !doc.services || typeof doc.services !== "object") {
|
|
104
231
|
return [];
|
|
105
232
|
}
|
|
@@ -111,9 +238,19 @@ function parseServicesObject(doc, sourcePath, tagOf = () => undefined) {
|
|
|
111
238
|
// `!reset` clears the attribute whatever its payload says.
|
|
112
239
|
const portsReset = portsTag === "!reset";
|
|
113
240
|
const nameReset = tagOf(name, "container_name") === "!reset";
|
|
114
|
-
const
|
|
241
|
+
const networksTag = tagOf(name, "networks");
|
|
242
|
+
const networksReset = networksTag === "!reset";
|
|
243
|
+
const networks = networksReset ? undefined : parseServiceNetworks(s.networks);
|
|
115
244
|
const extendsFrom = parseExtends(s.extends);
|
|
116
245
|
const containerRefs = parseContainerRefs(s);
|
|
246
|
+
const staticIps = networksReset ? [] : parseStaticIps(s.networks);
|
|
247
|
+
const volumes = parseVolumes(s.volumes, baseDir);
|
|
248
|
+
const deploy = s.deploy && typeof s.deploy === "object" ? s.deploy : {};
|
|
249
|
+
const noContainer = s.scale === 0 || deploy.replicas === 0 || s.provider != null;
|
|
250
|
+
const dependsOn = parseDependsOn(s.depends_on);
|
|
251
|
+
const environment = parseEnvironment(s.environment);
|
|
252
|
+
const healthcheck = parseHealthcheck(s.healthcheck);
|
|
253
|
+
const profiles = Array.isArray(s.profiles) ? s.profiles.filter((x) => typeof x === "string") : [];
|
|
117
254
|
return {
|
|
118
255
|
name,
|
|
119
256
|
ports: portsReset ? [] : parseServicePorts(s.ports),
|
|
@@ -123,13 +260,25 @@ function parseServicesObject(doc, sourcePath, tagOf = () => undefined) {
|
|
|
123
260
|
...(extendsFrom ? { extendsFrom } : {}),
|
|
124
261
|
...(containerRefs.length > 0 ? { containerRefs } : {}),
|
|
125
262
|
...(networks ? { networks } : {}),
|
|
263
|
+
...(networksTag === "!override" || networksReset ? { networksReplace: true } : {}),
|
|
126
264
|
...(s.network_mode != null ? { networkMode: true } : {}),
|
|
127
265
|
build: parseServiceBuild(s.build),
|
|
128
266
|
envFile: parseEnvFile(s.env_file),
|
|
267
|
+
...(envFileIsSimple(s.env_file) ? { envFileSimple: true } : {}),
|
|
268
|
+
...(noContainer ? { noContainer: true } : {}),
|
|
129
269
|
...(nameReset ? { containerNameReset: true } : {}),
|
|
130
270
|
...(!nameReset && typeof s.container_name === "string" && s.container_name
|
|
131
271
|
? { containerName: s.container_name }
|
|
132
272
|
: {}),
|
|
273
|
+
...(staticIps.length > 0 ? { staticIps } : {}),
|
|
274
|
+
...(volumes.binds.length > 0 ? { binds: volumes.binds } : {}),
|
|
275
|
+
...(volumes.keys.length > 0 ? { volumeKeys: volumes.keys, volumeTargets: volumes.targets } : {}),
|
|
276
|
+
...(dependsOn ? { dependsOn } : {}),
|
|
277
|
+
...(environment ? { environment } : {}),
|
|
278
|
+
...(healthcheck ? { healthcheck } : {}),
|
|
279
|
+
...(s.network_mode === "host" ? { hostNetwork: true } : {}),
|
|
280
|
+
...(typeof s.image === "string" && s.image ? { image: s.image } : {}),
|
|
281
|
+
...(profiles.length > 0 ? { profiles } : {}),
|
|
133
282
|
sourcePath,
|
|
134
283
|
};
|
|
135
284
|
});
|
|
@@ -157,16 +306,31 @@ function parseResources(section) {
|
|
|
157
306
|
: typeof legacyName === "string" && legacyName
|
|
158
307
|
? legacyName
|
|
159
308
|
: undefined;
|
|
160
|
-
|
|
309
|
+
const ipam = def.ipam && typeof def.ipam === "object" ? def.ipam.config : undefined;
|
|
310
|
+
const pinned = Array.isArray(ipam) && ipam.length > 0;
|
|
311
|
+
out.set(key, { ...(name ? { name } : {}), external, ...(pinned ? { pinned } : {}) });
|
|
161
312
|
}
|
|
162
313
|
return out;
|
|
163
314
|
}
|
|
315
|
+
/** Host files that top-level `secrets:` / `configs:` entries read (`file:`). */
|
|
316
|
+
function parseFileSources(section, baseDir) {
|
|
317
|
+
if (!section || typeof section !== "object" || Array.isArray(section))
|
|
318
|
+
return [];
|
|
319
|
+
return Object.values(section).flatMap((def) => {
|
|
320
|
+
const file = def && typeof def === "object" ? def.file : undefined;
|
|
321
|
+
return typeof file === "string" && file && !file.includes("$") ? [resolveHostPath(file, baseDir)] : [];
|
|
322
|
+
});
|
|
323
|
+
}
|
|
164
324
|
/** Later definitions override earlier ones field by field, like services. */
|
|
165
325
|
function mergeResources(into, from) {
|
|
166
326
|
for (const [key, def] of from) {
|
|
167
327
|
const existing = into.get(key);
|
|
168
328
|
into.set(key, existing
|
|
169
|
-
? {
|
|
329
|
+
? {
|
|
330
|
+
name: def.name ?? existing.name,
|
|
331
|
+
external: def.external || existing.external,
|
|
332
|
+
...(def.pinned || existing.pinned ? { pinned: true } : {}),
|
|
333
|
+
}
|
|
170
334
|
: def);
|
|
171
335
|
}
|
|
172
336
|
}
|
|
@@ -244,7 +408,15 @@ function mergeService(base, override) {
|
|
|
244
408
|
const containerName = override.containerNameReset
|
|
245
409
|
? override.containerName
|
|
246
410
|
: (override.containerName ?? base.containerName);
|
|
247
|
-
|
|
411
|
+
// `networks: !override` / `!reset` in the later file replaces the service's networks, fixed addresses included.
|
|
412
|
+
const networks = override.networksReplace
|
|
413
|
+
? [...(override.networks ?? [])]
|
|
414
|
+
: [...new Set([...(base.networks ?? []), ...(override.networks ?? [])])];
|
|
415
|
+
const staticIps = override.networksReplace
|
|
416
|
+
? [...(override.staticIps ?? [])]
|
|
417
|
+
: [...new Set([...(base.staticIps ?? []), ...(override.staticIps ?? [])])];
|
|
418
|
+
const mounts = mergeMounts(base, override);
|
|
419
|
+
const envFileSimple = (!base.envFile || base.envFileSimple === true) && (!override.envFile || override.envFileSimple === true);
|
|
248
420
|
return {
|
|
249
421
|
name: override.name,
|
|
250
422
|
ports,
|
|
@@ -258,12 +430,49 @@ function mergeService(base, override) {
|
|
|
258
430
|
? { containerRefs: [...new Set([...(base.containerRefs ?? []), ...(override.containerRefs ?? [])])] }
|
|
259
431
|
: {}),
|
|
260
432
|
...(base.networks || override.networks ? { networks } : {}),
|
|
433
|
+
...(base.networksReplace || override.networksReplace ? { networksReplace: true } : {}),
|
|
261
434
|
...(base.networkMode || override.networkMode ? { networkMode: true } : {}),
|
|
262
435
|
build: override.build ?? base.build,
|
|
263
|
-
envFile: override.envFile
|
|
436
|
+
envFile: base.envFile || override.envFile ? [...new Set([...(base.envFile ?? []), ...(override.envFile ?? [])])] : undefined,
|
|
437
|
+
...((base.envFile || override.envFile) && envFileSimple ? { envFileSimple: true } : {}),
|
|
438
|
+
...((override.noContainer ?? base.noContainer) ? { noContainer: true } : {}),
|
|
264
439
|
...(containerName ? { containerName } : {}),
|
|
265
440
|
...(override.containerNameReset ? { containerNameReset: true } : {}),
|
|
441
|
+
...(base.staticIps || override.staticIps ? { staticIps } : {}),
|
|
442
|
+
...(base.binds || override.binds ? { binds: mounts.binds } : {}),
|
|
443
|
+
...(base.volumeKeys || override.volumeKeys
|
|
444
|
+
? { volumeKeys: [...new Set(Object.values(mounts.volumeTargets))], volumeTargets: mounts.volumeTargets }
|
|
445
|
+
: {}),
|
|
446
|
+
...(base.dependsOn || override.dependsOn ? { dependsOn: { ...base.dependsOn, ...override.dependsOn } } : {}),
|
|
447
|
+
...(base.environment || override.environment
|
|
448
|
+
? { environment: { ...base.environment, ...override.environment } }
|
|
449
|
+
: {}),
|
|
450
|
+
...((override.healthcheck ?? base.healthcheck) ? { healthcheck: override.healthcheck ?? base.healthcheck } : {}),
|
|
451
|
+
...(base.hostNetwork || override.hostNetwork ? { hostNetwork: true } : {}),
|
|
452
|
+
...((override.image ?? base.image) ? { image: override.image ?? base.image } : {}),
|
|
453
|
+
...((override.profiles ?? base.profiles) ? { profiles: override.profiles ?? base.profiles } : {}),
|
|
266
454
|
sourcePath,
|
|
455
|
+
...((sourcePath === override.sourcePath ? override.baseDir : base.baseDir)
|
|
456
|
+
? { baseDir: sourcePath === override.sourcePath ? override.baseDir : base.baseDir }
|
|
457
|
+
: {}),
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Mounts of both definitions. A later mount at the same mount point
|
|
462
|
+
* replaces the earlier one whatever its kind, as compose merges them: a
|
|
463
|
+
* bind mount there takes a named volume's place, and the other way round.
|
|
464
|
+
*/
|
|
465
|
+
function mergeMounts(base, override) {
|
|
466
|
+
const replaced = new Set([
|
|
467
|
+
...(override.binds ?? []).flatMap((b) => (b.target ? [b.target] : [])),
|
|
468
|
+
...Object.keys(override.volumeTargets ?? {}),
|
|
469
|
+
]);
|
|
470
|
+
return {
|
|
471
|
+
binds: [...(base.binds ?? []).filter((b) => !b.target || !replaced.has(b.target)), ...(override.binds ?? [])],
|
|
472
|
+
volumeTargets: {
|
|
473
|
+
...Object.fromEntries(Object.entries(base.volumeTargets ?? {}).filter(([target]) => !replaced.has(target))),
|
|
474
|
+
...override.volumeTargets,
|
|
475
|
+
},
|
|
267
476
|
};
|
|
268
477
|
}
|
|
269
478
|
/**
|
|
@@ -281,7 +490,7 @@ function foldServices(services) {
|
|
|
281
490
|
}
|
|
282
491
|
return [...byName.values()];
|
|
283
492
|
}
|
|
284
|
-
function parseRecursive(filePath, st) {
|
|
493
|
+
function parseRecursive(filePath, st, projectDir, root = false) {
|
|
285
494
|
if (!fs.existsSync(filePath)) {
|
|
286
495
|
console.warn(`wtc: included compose file not found, skipping: ${filePath}`);
|
|
287
496
|
return [];
|
|
@@ -311,25 +520,63 @@ function parseRecursive(filePath, st) {
|
|
|
311
520
|
}
|
|
312
521
|
}
|
|
313
522
|
const record = doc;
|
|
523
|
+
// The project's own name: a later file given to compose replaces an earlier one's.
|
|
524
|
+
if (root && typeof record.name === "string" && record.name)
|
|
525
|
+
st.name = record.name;
|
|
314
526
|
mergeResources(st.volumes, parseResources(record.volumes));
|
|
315
527
|
mergeResources(st.networks, parseResources(record.networks));
|
|
316
|
-
|
|
528
|
+
// A second `-f` file resolves its relative paths against the project directory, not its own.
|
|
529
|
+
const baseDir = projectDir ?? path.dirname(key);
|
|
530
|
+
st.fileSources.push(...parseFileSources(record.secrets, baseDir), ...parseFileSources(record.configs, baseDir));
|
|
531
|
+
const local = parseServicesObject(record, key, tagOf, baseDir).map((svc) => projectDir && projectDir !== path.dirname(key) ? { ...svc, baseDir: projectDir } : svc);
|
|
317
532
|
return foldServices([...included, ...local]);
|
|
318
533
|
}
|
|
319
534
|
export function parseComposeFile(composePath) {
|
|
320
|
-
|
|
535
|
+
return parseComposeFiles([composePath]);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Parse the compose files compose is given, in order (`-f a -f b`): each
|
|
539
|
+
* later file's services and resources are merged onto the earlier ones, as
|
|
540
|
+
* compose merges them, and relative paths in every file resolve against the
|
|
541
|
+
* first file's directory. One file is the common case.
|
|
542
|
+
*/
|
|
543
|
+
export function parseComposeFiles(composePaths) {
|
|
544
|
+
const [first, ...rest] = composePaths.map((p) => path.resolve(p));
|
|
545
|
+
const abs = first;
|
|
321
546
|
const st = {
|
|
322
547
|
seen: new Set(),
|
|
323
548
|
sourceFiles: [],
|
|
324
549
|
volumes: new Map(),
|
|
325
550
|
networks: new Map(),
|
|
551
|
+
fileSources: [],
|
|
326
552
|
};
|
|
327
|
-
|
|
553
|
+
let services = parseRecursive(abs, st, undefined, true);
|
|
554
|
+
const rootFiles = [st.sourceFiles[0] ?? abs];
|
|
555
|
+
for (const file of rest) {
|
|
556
|
+
const before = st.sourceFiles.length;
|
|
557
|
+
services = foldServices([...services, ...parseRecursive(file, st, path.dirname(abs), true)]);
|
|
558
|
+
if (st.sourceFiles.length > before)
|
|
559
|
+
rootFiles.push(st.sourceFiles[before]);
|
|
560
|
+
}
|
|
561
|
+
const sharedVolumes = sharedOnly(st.volumes);
|
|
562
|
+
const sharedNetworks = sharedOnly(st.networks);
|
|
563
|
+
const sharedNetworkKeys = new Set(sharedNetworks.map((n) => n.key));
|
|
564
|
+
const sharedVolumeKeys = new Set(sharedVolumes.map((v) => v.key));
|
|
565
|
+
const pinnedNetworks = [...st.networks]
|
|
566
|
+
.filter(([key, def]) => def.pinned && !sharedNetworkKeys.has(key))
|
|
567
|
+
.map(([key]) => key);
|
|
568
|
+
const projectVolumes = [...st.volumes.keys()].filter((key) => !sharedVolumeKeys.has(key));
|
|
569
|
+
const fileSources = [...new Set(st.fileSources)];
|
|
328
570
|
return {
|
|
329
571
|
services,
|
|
330
572
|
composePath: abs,
|
|
331
573
|
sourceFiles: st.sourceFiles,
|
|
332
|
-
sharedVolumes
|
|
333
|
-
sharedNetworks
|
|
574
|
+
sharedVolumes,
|
|
575
|
+
sharedNetworks,
|
|
576
|
+
...(rootFiles.length > 1 ? { rootFiles } : {}),
|
|
577
|
+
...(pinnedNetworks.length > 0 ? { pinnedNetworks } : {}),
|
|
578
|
+
...(projectVolumes.length > 0 ? { projectVolumes } : {}),
|
|
579
|
+
...(st.name && !st.name.includes("$") ? { projectName: st.name } : {}),
|
|
580
|
+
...(fileSources.length > 0 ? { fileSources } : {}),
|
|
334
581
|
};
|
|
335
582
|
}
|
package/dist/compose/status.d.ts
CHANGED
|
@@ -36,7 +36,21 @@ export interface PsContainer {
|
|
|
36
36
|
running: boolean;
|
|
37
37
|
/** `compose run` container (one-off), not part of the stack's services. */
|
|
38
38
|
oneoff: boolean;
|
|
39
|
+
/** Compose service the container belongs to, when labelled. */
|
|
40
|
+
service: string | null;
|
|
41
|
+
/** `healthy`, `unhealthy`, `starting`, or null without a healthcheck (or when unknown). */
|
|
42
|
+
health: "healthy" | "unhealthy" | "starting" | null;
|
|
43
|
+
/** Exit code of a container that is not running, when the engine reports it. */
|
|
44
|
+
exitCode: number | null;
|
|
45
|
+
/** Host ports the container publishes. */
|
|
46
|
+
hostPorts: number[];
|
|
39
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Host ports from a `ps` entry's `Ports`: Docker's text
|
|
50
|
+
* (`0.0.0.0:8080->80/tcp, [::]:8080->80/tcp, 9000/tcp`) or Podman's list
|
|
51
|
+
* (`[{ host_port, container_port, range }]`).
|
|
52
|
+
*/
|
|
53
|
+
export declare function parseHostPorts(ports: unknown): number[];
|
|
40
54
|
/**
|
|
41
55
|
* Every container of a `ps -a --format json` listing with what wtc needs per
|
|
42
56
|
* container: compose project, working_dir (to adopt a running stack into
|
package/dist/compose/status.js
CHANGED
|
@@ -78,6 +78,57 @@ export function parseJsonListing(output) {
|
|
|
78
78
|
return e;
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
+
const SERVICE_LABELS = ["com.docker.compose.service", "io.podman.compose.service"];
|
|
82
|
+
/**
|
|
83
|
+
* Host ports from a `ps` entry's `Ports`: Docker's text
|
|
84
|
+
* (`0.0.0.0:8080->80/tcp, [::]:8080->80/tcp, 9000/tcp`) or Podman's list
|
|
85
|
+
* (`[{ host_port, container_port, range }]`).
|
|
86
|
+
*/
|
|
87
|
+
export function parseHostPorts(ports) {
|
|
88
|
+
const out = new Set();
|
|
89
|
+
if (typeof ports === "string") {
|
|
90
|
+
for (const m of ports.matchAll(/:(\d+)(?:-(\d+))?->/g)) {
|
|
91
|
+
const from = Number(m[1]);
|
|
92
|
+
const to = m[2] ? Number(m[2]) : from;
|
|
93
|
+
for (let p = from; p <= to && p - from < 1024; p++)
|
|
94
|
+
out.add(p);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (Array.isArray(ports)) {
|
|
98
|
+
for (const entry of ports) {
|
|
99
|
+
if (!entry || typeof entry !== "object")
|
|
100
|
+
continue;
|
|
101
|
+
const from = Number(field(entry, "host_port"));
|
|
102
|
+
const range = Number(field(entry, "range") ?? 1) || 1;
|
|
103
|
+
if (!Number.isInteger(from) || from <= 0)
|
|
104
|
+
continue;
|
|
105
|
+
for (let p = from; p < from + Math.min(range, 1024); p++)
|
|
106
|
+
out.add(p);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return [...out];
|
|
110
|
+
}
|
|
111
|
+
/** Health from a `ps` entry: Docker's `Status` text (`Up 2 minutes (healthy)`), or Podman's too. */
|
|
112
|
+
function parseHealth(status) {
|
|
113
|
+
const text = String(status ?? "").toLowerCase();
|
|
114
|
+
if (text.includes("(unhealthy)"))
|
|
115
|
+
return "unhealthy";
|
|
116
|
+
if (text.includes("(healthy)"))
|
|
117
|
+
return "healthy";
|
|
118
|
+
if (text.includes("health: starting") || text.includes("(starting)"))
|
|
119
|
+
return "starting";
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
/** Exit code from a `ps` entry: Podman's `ExitCode`, or Docker's `Status` text (`Exited (1) 3 minutes ago`). */
|
|
123
|
+
function parseExitCode(c, running) {
|
|
124
|
+
if (running)
|
|
125
|
+
return null;
|
|
126
|
+
const m = /exited \((\d+)\)/i.exec(String(field(c, "Status") ?? ""));
|
|
127
|
+
if (m)
|
|
128
|
+
return Number(m[1]);
|
|
129
|
+
const code = field(c, "ExitCode");
|
|
130
|
+
return typeof code === "number" && String(field(c, "State") ?? "").toLowerCase() === "exited" ? code : null;
|
|
131
|
+
}
|
|
81
132
|
function firstName(value) {
|
|
82
133
|
if (Array.isArray(value))
|
|
83
134
|
return String(value[0] ?? "");
|
|
@@ -100,14 +151,20 @@ export function parsePsContainers(output) {
|
|
|
100
151
|
const oneoff = (labels[ONEOFF_LABEL] ?? "").toLowerCase() === "true" ||
|
|
101
152
|
(project !== null && /_tmp\d+$/.test(name) && Boolean(labels["io.podman.compose.project"]));
|
|
102
153
|
const state = String(field(c, "State") ?? "").toLowerCase();
|
|
154
|
+
const running = state === "running";
|
|
103
155
|
return {
|
|
104
156
|
id: String(field(c, "ID") ?? ""),
|
|
105
157
|
name,
|
|
106
158
|
project,
|
|
107
159
|
workingDir: labels[WORKING_DIR_LABEL] || null,
|
|
108
160
|
state,
|
|
109
|
-
running
|
|
161
|
+
running,
|
|
110
162
|
oneoff,
|
|
163
|
+
service: SERVICE_LABELS.map((l) => labels[l]).find(Boolean) ?? null,
|
|
164
|
+
health: running ? parseHealth(field(c, "Status")) : null,
|
|
165
|
+
exitCode: parseExitCode(c, running),
|
|
166
|
+
// A paused container still holds its ports.
|
|
167
|
+
hostPorts: running || state === "paused" ? parseHostPorts(field(c, "Ports")) : [],
|
|
111
168
|
};
|
|
112
169
|
});
|
|
113
170
|
}
|
package/dist/compose/types.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface ComposeService {
|
|
|
20
20
|
containerRefs?: string[];
|
|
21
21
|
/** Networks the service joins (absent: only the project's `default`). */
|
|
22
22
|
networks?: string[];
|
|
23
|
+
/** `networks: !override` / `!reset`: the service's networks replace earlier files' instead of adding to them. */
|
|
24
|
+
networksReplace?: boolean;
|
|
23
25
|
/** The service sets `network_mode` (host, none, another container…): no networks of its own. */
|
|
24
26
|
networkMode?: boolean;
|
|
25
27
|
/** `container_name: !reset` in a later file dropped any earlier name. */
|
|
@@ -31,10 +33,47 @@ export interface ComposeService {
|
|
|
31
33
|
inline?: boolean;
|
|
32
34
|
};
|
|
33
35
|
envFile?: string[];
|
|
36
|
+
/** Every `env_file` entry is a plain path (none is a `{ path, required, format }` entry). */
|
|
37
|
+
envFileSimple?: boolean;
|
|
34
38
|
/** Fixed `container_name` — breaks running the same stack twice. */
|
|
35
39
|
containerName?: string;
|
|
40
|
+
/** Networks on which the service asks for a fixed `ipv4_address` / `ipv6_address`. */
|
|
41
|
+
staticIps?: string[];
|
|
42
|
+
/** Bind mounts whose source is a host path (absolute, resolved against the declaring file). */
|
|
43
|
+
binds?: BindMount[];
|
|
44
|
+
/** Top-level volume keys the service mounts. */
|
|
45
|
+
volumeKeys?: string[];
|
|
46
|
+
/** The same mounts by mount point (container path to volume key): a later file's mount there replaces it. */
|
|
47
|
+
volumeTargets?: Record<string, string>;
|
|
48
|
+
/** The service never has a container of its own (`scale: 0`, `deploy.replicas: 0`, a `provider:` service). */
|
|
49
|
+
noContainer?: boolean;
|
|
50
|
+
/** `depends_on`, in its long form (service → condition and friends). */
|
|
51
|
+
dependsOn?: Record<string, Record<string, unknown>>;
|
|
52
|
+
/** `environment`, as written (values not interpolated). */
|
|
53
|
+
environment?: Record<string, string>;
|
|
54
|
+
/** The healthcheck's test command, joined into one string. */
|
|
55
|
+
healthcheck?: string;
|
|
56
|
+
/** `network_mode: host`: the service publishes straight on the host, so nothing can be remapped. */
|
|
57
|
+
hostNetwork?: boolean;
|
|
58
|
+
image?: string;
|
|
59
|
+
profiles?: string[];
|
|
36
60
|
/** Absolute path of the compose file that declared this service. */
|
|
37
61
|
sourcePath: string;
|
|
62
|
+
/**
|
|
63
|
+
* Directory the service's relative paths resolve against when it is not
|
|
64
|
+
* the declaring file's own: the project directory, for a service declared
|
|
65
|
+
* in a second `-f` file.
|
|
66
|
+
*/
|
|
67
|
+
baseDir?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface BindMount {
|
|
70
|
+
/** Host path as written (`./certs`, `~/.config/gcloud`, `/var/run/docker.sock`). */
|
|
71
|
+
raw: string;
|
|
72
|
+
/** Absolute host path; `~` is the home directory. */
|
|
73
|
+
source: string;
|
|
74
|
+
/** Mount point in the container. */
|
|
75
|
+
target?: string;
|
|
76
|
+
readOnly: boolean;
|
|
38
77
|
}
|
|
39
78
|
/**
|
|
40
79
|
* A top-level volume or network that is NOT scoped to the compose project:
|
|
@@ -54,8 +93,25 @@ export interface ComposeFile {
|
|
|
54
93
|
composePath: string;
|
|
55
94
|
/** Absolute paths of the root file plus all transitively-included files, root first. */
|
|
56
95
|
sourceFiles: string[];
|
|
96
|
+
/**
|
|
97
|
+
* The files compose is given, in order, when there are several (`-f a -f
|
|
98
|
+
* b`): `composePath` is the first, and its directory is the project
|
|
99
|
+
* directory every relative path resolves against.
|
|
100
|
+
*/
|
|
101
|
+
rootFiles?: string[];
|
|
57
102
|
/** Top-level volumes with a fixed name or `external`. */
|
|
58
103
|
sharedVolumes: SharedResource[];
|
|
59
104
|
/** Top-level networks with a fixed name or `external`. */
|
|
60
105
|
sharedNetworks: SharedResource[];
|
|
106
|
+
/**
|
|
107
|
+
* Networks of the project that pin their addresses (`ipam.config`): a
|
|
108
|
+
* second stack cannot create the same subnet.
|
|
109
|
+
*/
|
|
110
|
+
pinnedNetworks?: string[];
|
|
111
|
+
/** Top-level volume keys that belong to the project (no fixed name, not external). */
|
|
112
|
+
projectVolumes?: string[];
|
|
113
|
+
/** The top-level `name:` — the project's name where nothing else sets one (absent when it is built from variables). */
|
|
114
|
+
projectName?: string;
|
|
115
|
+
/** Host files that top-level `secrets:` / `configs:` read (`file:`), absolute. */
|
|
116
|
+
fileSources?: string[];
|
|
61
117
|
}
|
package/dist/config.d.ts
CHANGED
|
@@ -32,6 +32,39 @@ export interface WtcConfig {
|
|
|
32
32
|
* or `["docker-compose"]`. `WTC_COMPOSE_COMMAND` takes precedence.
|
|
33
33
|
*/
|
|
34
34
|
composeCommand?: string | string[];
|
|
35
|
+
/**
|
|
36
|
+
* Compose file(s), relative to the repository root, when the project's is
|
|
37
|
+
* not one of the default names at the root: one path, or several that
|
|
38
|
+
* compose merges in order (like `-f a -f b`).
|
|
39
|
+
*/
|
|
40
|
+
composeFile?: string | string[];
|
|
41
|
+
/**
|
|
42
|
+
* Services `start` brings up by default (with whatever they depend on),
|
|
43
|
+
* instead of every service. `--service` replaces it for a run.
|
|
44
|
+
*/
|
|
45
|
+
services?: string[];
|
|
46
|
+
/**
|
|
47
|
+
* Services a worktree stack does not run itself: it reaches the main
|
|
48
|
+
* checkout's instance under the same name. For heavy infrastructure
|
|
49
|
+
* that worktrees can share (search, queues).
|
|
50
|
+
*/
|
|
51
|
+
shared?: string[];
|
|
52
|
+
/**
|
|
53
|
+
* Named volumes copied from the main checkout's stack into a worktree
|
|
54
|
+
* stack the first time it starts: `true` for all of them, or their keys.
|
|
55
|
+
*/
|
|
56
|
+
seedVolumes?: boolean | string[];
|
|
57
|
+
/**
|
|
58
|
+
* Host ports for processes that run outside compose (a dev server
|
|
59
|
+
* started on the host): variable → default port. Each worktree gets its
|
|
60
|
+
* own value, written to its env file.
|
|
61
|
+
*/
|
|
62
|
+
ports?: Record<string, number>;
|
|
63
|
+
/**
|
|
64
|
+
* Rewrite `localhost:<port>` in the env files copied into a worktree to
|
|
65
|
+
* the worktree's own ports. Defaults to true.
|
|
66
|
+
*/
|
|
67
|
+
rewriteEnvPorts?: boolean;
|
|
35
68
|
}
|
|
36
69
|
export interface LoadedConfig {
|
|
37
70
|
config: WtcConfig;
|
package/dist/context.d.ts
CHANGED
|
@@ -52,6 +52,15 @@ export interface WtcContext {
|
|
|
52
52
|
repoName: string;
|
|
53
53
|
cwd: string;
|
|
54
54
|
composeFile: ComposeFile;
|
|
55
|
+
/** The compose files compose is given, in the main checkout (one unless `composeFile` lists several). */
|
|
56
|
+
composeRoots: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Compose would not pick these files by itself from the repository root
|
|
59
|
+
* (a custom name, a subdirectory, several files): every call names them.
|
|
60
|
+
*/
|
|
61
|
+
composeIsCustom: boolean;
|
|
62
|
+
/** Those files relative to the repository root when `composeIsCustom`, else empty. */
|
|
63
|
+
customComposeRoots: string[];
|
|
55
64
|
/** False only with `allowMissingCompose` when no compose file exists. */
|
|
56
65
|
hasComposeFile: boolean;
|
|
57
66
|
portMappings: PortMapping[];
|
|
@@ -80,6 +89,17 @@ export interface WtcContext {
|
|
|
80
89
|
remap: RemapTargets | null;
|
|
81
90
|
/** What runtime remapping does, for `wtc start` (informational). */
|
|
82
91
|
remapNotes: string[];
|
|
92
|
+
/**
|
|
93
|
+
* Whether wtc can remap at runtime in this repository at all (engine
|
|
94
|
+
* support, no `COMPOSE_FILE` of the user's): asked for a worktree whose
|
|
95
|
+
* own compose file differs from the main checkout's. False unless the
|
|
96
|
+
* context resolved remapping (`probeStacks` / `resolveRemap`).
|
|
97
|
+
*/
|
|
98
|
+
canRemap(): boolean;
|
|
99
|
+
/** Mappings for the config's `ports` (host processes outside compose). */
|
|
100
|
+
hostPortMappings: PortMapping[];
|
|
101
|
+
/** Services of the config's `shared` that the compose file declares: worktree stacks do not run them. */
|
|
102
|
+
sharedServices: ReadonlySet<string>;
|
|
83
103
|
/** Stack states (only with `probeStacks`). */
|
|
84
104
|
stacks: StackProbe | null;
|
|
85
105
|
/** Resolve the compose engine (lazily; throws when none is available). */
|
|
@@ -97,6 +117,12 @@ export interface WtcContext {
|
|
|
97
117
|
*/
|
|
98
118
|
export declare function adoptableStacks(containers: PsContainer[], repoName: string, worktrees: WorktreeInfo[]): Map<string, AdoptableStack>;
|
|
99
119
|
export declare function buildContext(cli?: EnvCliOptions, opts?: BuildContextOptions): WtcContext;
|
|
120
|
+
/** The config's `shared` services that exist in the compose file. */
|
|
121
|
+
export declare function sharedServices(config: WtcConfig, composeFile: ComposeFile): Set<string>;
|
|
122
|
+
/** Service name host-process ports are listed under (no compose service has it: parentheses are not allowed). */
|
|
123
|
+
export declare const HOST_PORTS_SERVICE = "(host)";
|
|
124
|
+
/** The config's `ports` as variable mappings, so they are allocated, recorded and injected like compose's. */
|
|
125
|
+
export declare function hostPorts(config: WtcConfig): PortMapping[];
|
|
100
126
|
/** Merge CLI overrides over the loaded config and validate it. */
|
|
101
127
|
export declare function resolveConfig(config: WtcConfig, cli: EnvCliOptions): WtcConfig;
|
|
102
128
|
/**
|