@solid-stack/builder 3.0.0 → 3.2.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/README.md +7 -3
- package/dist/bin.js +156 -52
- package/dist/bin.js.map +1 -1
- package/dist/core/buildSchema.d.ts +71 -0
- package/dist/core/buildSchema.d.ts.map +1 -1
- package/dist/core/composition/compileGraphComposition.d.ts.map +1 -1
- package/dist/core/composition/compileServiceComposition.d.ts.map +1 -1
- package/dist/core/composition/composeEnvironment.d.ts +1 -0
- package/dist/core/composition/composeEnvironment.d.ts.map +1 -1
- package/dist/core/composition/validateOverrideCompose.d.ts.map +1 -1
- package/dist/core/config/resolveBuildStage.d.ts +5 -1
- package/dist/core/config/resolveBuildStage.d.ts.map +1 -1
- package/dist/core/config/serviceGraph.d.ts +1 -1
- package/dist/core/config/serviceGraph.d.ts.map +1 -1
- package/dist/core/config/types.d.ts +4 -0
- package/dist/core/config/types.d.ts.map +1 -1
- package/dist/core/mesh/applyMeshExtends.d.ts.map +1 -1
- package/dist/core/runners/runFiniteTester.d.ts +1 -0
- package/dist/core/runners/runFiniteTester.d.ts.map +1 -1
- package/dist/core/runners/runTestUnit.d.ts +2 -0
- package/dist/core/runners/runTestUnit.d.ts.map +1 -1
- package/dist/index.js +156 -52
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +12 -2
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/schemas/build-schema.json +394 -0
- package/schemas/mesh-schema.json +24 -0
package/README.md
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
# Solid Stack Builder V3
|
|
2
2
|
|
|
3
|
-
Builder 3.
|
|
3
|
+
Builder 3.2.0 compiles a service's `build.json` or a system's `mesh.json` into Docker Compose. Services declare possible runtime modules; explicit **requisites** select which modules run and how they wait. Mesh sources stay independently runnable, with explicit `extends` rewrites when a real service replaces a local mock. Main services can declare stage-aware Docker `buildArgs`, and isolated runs can start local helper modules through `on-inframode-isolated`.
|
|
4
4
|
|
|
5
|
-
The source package declares version 3.
|
|
5
|
+
The source package declares version 3.2.0. This checkout does not imply that version has been published to a package registry. For a local checkout, run `pnpm install`, `pnpm build`, and `node dist/bin.js --version`. The package exposes both `builder` and `solid-builder` when installed. Node.js 20 or newer and Docker Engine with Compose are required for runtime commands.
|
|
6
6
|
|
|
7
7
|
[Builder V3 documentation](docs/README.md)
|
|
8
8
|
|
|
9
9
|
[Upgrade from Builder 2.2.0](docs/migration/v2.2-to-v3.0.md)
|
|
10
10
|
|
|
11
|
+
[Upgrade from Builder 3.0.0](docs/migration/v3.0-to-v3.1.md)
|
|
12
|
+
|
|
13
|
+
[Upgrade from Builder 3.1.0](docs/migration/v3.1-to-v3.2.md)
|
|
14
|
+
|
|
11
15
|
## Tests
|
|
12
16
|
|
|
13
17
|
Run `pnpm test` for the complete V3 verification suite. It runs non-Docker tests, typechecking, build and API checks first, then the three Docker acceptance tests. Docker tests require a prepared local fixture image; run `pnpm test:v3:prepare` once when the fixture is missing or stale. For a quick run without Docker, use `pnpm test:v3:fast`.
|
|
@@ -39,7 +43,7 @@ services:
|
|
|
39
43
|
command: ["sh", "-c", "exit 0"]
|
|
40
44
|
```
|
|
41
45
|
|
|
42
|
-
The [service quickstart](docs/getting-started/service-quickstart.md) gives a runnable tree. Run `builder check`, then `builder service up dev`; `builder service up dev --full` includes the effective requisite closure. `builder service up prod` uses the `prod` target and integrated graph. `builder service up test` runs isolated unit tests, cleans up, then runs service E2E with a production main and full graph.
|
|
46
|
+
The [service quickstart](docs/getting-started/service-quickstart.md) gives a runnable tree. Run `builder check`, then `builder service up dev`; `builder service up dev --full` includes the effective requisite closure; `dev.on-inframode-isolated` can add local helpers to plain isolated dev. `builder service up prod` uses the `prod` target and integrated graph. `builder service up test` runs isolated unit tests, cleans up, then runs service E2E with a production main and full graph.
|
|
43
47
|
|
|
44
48
|
| Workflow | Main target | Main execution mode | Infrastructure mode |
|
|
45
49
|
|---|---|---|---|
|
package/dist/bin.js
CHANGED
|
@@ -55,6 +55,7 @@ var AUTO_PORT_SCAN_START = 2e4;
|
|
|
55
55
|
var identifier = z.string().regex(BUILDER_IDENTIFIER_PATTERN);
|
|
56
56
|
var nonblank = z.string().min(1).refine((value) => value.trim().length > 0, "must not be blank");
|
|
57
57
|
var env = z.record(z.string(), z.string());
|
|
58
|
+
var buildArgs = z.record(z.string(), z.string());
|
|
58
59
|
var port = z.number().int().min(1).max(65535);
|
|
59
60
|
var publicPort = z.union([port, z.literal("AUTO")]);
|
|
60
61
|
var requisite = z.enum(["requirement", "dependency", "prerequisite"]);
|
|
@@ -62,10 +63,10 @@ var requisites = z.record(identifier, requisite);
|
|
|
62
63
|
var requisiteOverlay = z.record(identifier, z.union([requisite, z.literal(false)]));
|
|
63
64
|
var mainEndpointSchema = z.object({ port, publicPort: publicPort.optional(), primary: z.boolean().optional(), scheme: z.string().regex(ENDPOINT_SCHEME_PATTERN).optional() }).strict();
|
|
64
65
|
var serviceEndpointSchema = mainEndpointSchema.extend({ service: nonblank }).strict();
|
|
65
|
-
var mainServiceSchema = z.object({ env: env.optional(), endpoints: z.record(identifier, mainEndpointSchema).optional(), requisites: requisites.optional(), "override-compose": nonblank.optional() }).strict();
|
|
66
|
+
var mainServiceSchema = z.object({ env: env.optional(), buildArgs: buildArgs.optional(), endpoints: z.record(identifier, mainEndpointSchema).optional(), requisites: requisites.optional(), "override-compose": nonblank.optional() }).strict();
|
|
66
67
|
var testerServiceSchema = z.object({ compose: nonblank, service: nonblank, env: env.optional() }).strict();
|
|
67
68
|
var ordinaryServiceSchema = z.object({ compose: nonblank, service: nonblank.optional(), env: env.optional(), endpoints: z.record(identifier, serviceEndpointSchema).optional(), requisites: requisites.optional() }).strict().refine((value) => Boolean(value.service) || Boolean(value.endpoints && Object.keys(value.endpoints).length), "endpoint-less service requires service");
|
|
68
|
-
var mainOverlaySchema = z.object({ env: env.optional(), endpoints: z.record(identifier, mainEndpointSchema.partial().strict()).optional(), requisites: requisiteOverlay.optional(), "override-compose": nonblank.optional() }).strict();
|
|
69
|
+
var mainOverlaySchema = z.object({ env: env.optional(), buildArgs: buildArgs.optional(), endpoints: z.record(identifier, mainEndpointSchema.partial().strict()).optional(), requisites: requisiteOverlay.optional(), "override-compose": nonblank.optional() }).strict();
|
|
69
70
|
var testerOverlaySchema = testerServiceSchema.partial().strict();
|
|
70
71
|
var ordinaryOverlaySchema = z.object({ compose: nonblank.optional(), service: nonblank.optional(), env: env.optional(), endpoints: z.record(identifier, serviceEndpointSchema.partial().strict()).optional(), requisites: requisiteOverlay.optional() }).strict();
|
|
71
72
|
var buildServicesSchema = z.record(identifier, z.unknown()).superRefine((value, context) => {
|
|
@@ -76,14 +77,21 @@ var buildServicesSchema = z.record(identifier, z.unknown()).superRefine((value,
|
|
|
76
77
|
if (!parsed.success) for (const issue of parsed.error.issues) context.addIssue({ ...issue, path: [key, ...issue.path] });
|
|
77
78
|
}
|
|
78
79
|
});
|
|
79
|
-
var
|
|
80
|
+
var overlayServices = (allowTester) => z.record(identifier, z.unknown()).superRefine((value, context) => {
|
|
80
81
|
for (const [key, entry] of Object.entries(value)) {
|
|
82
|
+
if (key === "tester" && !allowTester) {
|
|
83
|
+
context.addIssue({ code: "custom", path: [key], message: "tester cannot be configured in on-inframode-isolated" });
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
81
86
|
const schema = key === "main" ? mainOverlaySchema : key === "tester" ? testerOverlaySchema : ordinaryOverlaySchema;
|
|
82
87
|
const parsed = schema.safeParse(entry);
|
|
83
88
|
if (!parsed.success) for (const issue of parsed.error.issues) context.addIssue({ ...issue, path: [key, ...issue.path] });
|
|
84
89
|
}
|
|
85
|
-
})
|
|
86
|
-
var
|
|
90
|
+
});
|
|
91
|
+
var buildStageSchema = z.object({ services: overlayServices(true).optional() }).strict();
|
|
92
|
+
var isolatedInfraOverlaySchema = z.object({ services: overlayServices(false).optional() }).strict();
|
|
93
|
+
var isolatableBuildStageSchema = z.object({ services: overlayServices(true).optional(), "on-inframode-isolated": isolatedInfraOverlaySchema.optional() }).strict();
|
|
94
|
+
var buildJsonSchema = z.object({ $schema: z.string().optional(), name: nonblank, services: buildServicesSchema, dev: isolatableBuildStageSchema.optional(), prod: buildStageSchema.optional(), test: isolatableBuildStageSchema.optional(), e2e: buildStageSchema.optional() }).strict();
|
|
87
95
|
|
|
88
96
|
// src/utils/errorMessage.ts
|
|
89
97
|
function errorMessage(err) {
|
|
@@ -332,6 +340,14 @@ function checkDockerfileContract(build, projectDir) {
|
|
|
332
340
|
runStep("docker", ["run", "--rm", "--network", "none", "--mount", `type=bind,src=${root},dst=/project,readonly`, "--mount", `type=bind,src=${policyDir},dst=/builder-policy,readonly`, "-w", "/project", CONFTEST_IMAGE, "test", relative, "-p", "/builder-policy"], root, { stepName: "Dockerfile Contract", targetFile: relative });
|
|
333
341
|
}
|
|
334
342
|
|
|
343
|
+
// src/core/config/executionProfile.ts
|
|
344
|
+
function executionProfile(stage2, composition, full = false) {
|
|
345
|
+
if (composition === "mesh" && stage2 === "test") throw new Error("Mesh test is a workflow, not a configuration stage");
|
|
346
|
+
if (stage2 === "dev") return { configStage: stage2, envStage: stage2, mainTarget: "dev", execMode: "dev", infraMode: composition === "mesh" || full ? "integrated" : "isolated", attachTester: false };
|
|
347
|
+
if (stage2 === "test") return { configStage: stage2, envStage: stage2, mainTarget: "test", execMode: "test", infraMode: "isolated", attachTester: false };
|
|
348
|
+
return { configStage: stage2, envStage: stage2, mainTarget: "prod", execMode: "prod", infraMode: "integrated", attachTester: stage2 === "e2e" };
|
|
349
|
+
}
|
|
350
|
+
|
|
335
351
|
// src/core/config/endpointProperties.ts
|
|
336
352
|
function resolveEndpointProperty(endpoint, property, context) {
|
|
337
353
|
const reference = context.referencedObject ?? endpoint.logicalPath;
|
|
@@ -399,46 +415,56 @@ function applyServiceOverlay(base, patch) {
|
|
|
399
415
|
}
|
|
400
416
|
|
|
401
417
|
// src/core/config/resolveBuildStage.ts
|
|
402
|
-
var
|
|
418
|
+
var ISOLATED_OVERLAY_KEY = "on-inframode-isolated";
|
|
419
|
+
var originFor = (sourceFile, configPath, layer, isolatedOverlay = false) => ({ sourceFile, configPath, projectDir: path.dirname(sourceFile), scope: "build", layer, ...isolatedOverlay ? { isolatedOverlay: true } : {} });
|
|
403
420
|
var fail = (sourceFile, stage2, configPath, reason, value) => {
|
|
404
421
|
throw new ConfigError({ sourceFile, stage: stage2, composition: "service", configPath, reason, value });
|
|
405
422
|
};
|
|
406
|
-
function resolveBuildStage(build, stage2, sourceFile) {
|
|
423
|
+
function resolveBuildStage(build, stage2, sourceFile, options = {}) {
|
|
407
424
|
const services2 = structuredClone(build.services);
|
|
408
425
|
const origins = /* @__PURE__ */ new Map();
|
|
409
426
|
const envOrigins = /* @__PURE__ */ new Map();
|
|
427
|
+
const buildArgsOrigins = /* @__PURE__ */ new Map();
|
|
410
428
|
const requisiteOrigins = /* @__PURE__ */ new Map();
|
|
411
429
|
const layers = [];
|
|
412
430
|
const deletedRequisiteTargets = [];
|
|
413
|
-
const record = (name, entry, layer) => {
|
|
414
|
-
const where =
|
|
415
|
-
const origin = originFor(sourceFile, where, layer);
|
|
431
|
+
const record = (name, entry, layer, servicesPath, isolatedOverlay = false) => {
|
|
432
|
+
const where = `${servicesPath}.${name}`;
|
|
433
|
+
const origin = originFor(sourceFile, where, layer, isolatedOverlay);
|
|
416
434
|
origins.set(name, origin);
|
|
417
435
|
const env2 = envOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
418
|
-
for (const key of Object.keys(entry.env ?? {})) env2.set(key, originFor(sourceFile, `${where}.env.${key}`, layer));
|
|
436
|
+
for (const key of Object.keys(entry.env ?? {})) env2.set(key, originFor(sourceFile, `${where}.env.${key}`, layer, isolatedOverlay));
|
|
419
437
|
envOrigins.set(name, env2);
|
|
438
|
+
const args = buildArgsOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
439
|
+
for (const key of Object.keys(entry.buildArgs ?? {})) args.set(key, originFor(sourceFile, `${where}.buildArgs.${key}`, layer, isolatedOverlay));
|
|
440
|
+
buildArgsOrigins.set(name, args);
|
|
420
441
|
const edges = requisiteOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
421
442
|
for (const [key, value] of Object.entries(entry.requisites ?? {})) {
|
|
422
443
|
if (value === false) edges.delete(key);
|
|
423
|
-
else edges.set(key, originFor(sourceFile, `${where}.requisites.${key}`, layer));
|
|
444
|
+
else edges.set(key, originFor(sourceFile, `${where}.requisites.${key}`, layer, isolatedOverlay));
|
|
424
445
|
}
|
|
425
446
|
requisiteOrigins.set(name, edges);
|
|
426
447
|
};
|
|
427
|
-
|
|
428
|
-
layers.push({ stage: "base", services: structuredClone(services2), origin: originFor(sourceFile, "services", "base") });
|
|
429
|
-
for (const overlayStage of stageOverlayChain(stage2)) {
|
|
430
|
-
const patches = build[overlayStage]?.services ?? {};
|
|
448
|
+
const applyOverlay = (patches, overlayStage, servicesPath, isolatedOverlay) => {
|
|
431
449
|
for (const [name, patch] of Object.entries(patches).sort(([a], [b]) => a.localeCompare(b))) {
|
|
432
450
|
const current = services2[name];
|
|
433
|
-
const where = `${
|
|
451
|
+
const where = `${servicesPath}.${name}`;
|
|
452
|
+
if (isolatedOverlay && name === "tester") fail(sourceFile, stage2, where, `tester cannot be configured in ${ISOLATED_OVERLAY_KEY}`);
|
|
434
453
|
if (!current && (name === "main" || name === "tester")) fail(sourceFile, stage2, where, "Required special service is missing from base");
|
|
435
454
|
if (current && patch.compose !== void 0 && patch.compose !== current.compose) fail(sourceFile, stage2, `${where}.compose`, `compose is immutable; previous declaration ${origins.get(name)?.configPath}.compose, attempted ${where}.compose`, patch.compose);
|
|
436
455
|
if (!current && name !== "main" && name !== "tester" && (typeof patch.compose !== "string" || !patch.compose.trim())) fail(sourceFile, stage2, `${where}.compose`, "Stage-introduced service requires a complete compose declaration");
|
|
437
456
|
services2[name] = current ? applyServiceOverlay(current, patch) : structuredClone(patch);
|
|
438
457
|
for (const [target, kind] of Object.entries(patch.requisites ?? {})) if (kind === false) deletedRequisiteTargets.push({ target, path: `${where}.requisites.${target}` });
|
|
439
|
-
record(name, patch, overlayStage);
|
|
458
|
+
record(name, patch, overlayStage, servicesPath, isolatedOverlay);
|
|
440
459
|
}
|
|
441
|
-
layers.push({ stage: overlayStage, services: structuredClone(patches), origin: originFor(sourceFile,
|
|
460
|
+
layers.push({ stage: overlayStage, services: structuredClone(patches), origin: originFor(sourceFile, servicesPath, overlayStage, isolatedOverlay) });
|
|
461
|
+
};
|
|
462
|
+
for (const [name, value] of Object.entries(services2).sort(([a], [b]) => a.localeCompare(b))) record(name, value, "base", "services");
|
|
463
|
+
layers.push({ stage: "base", services: structuredClone(services2), origin: originFor(sourceFile, "services", "base") });
|
|
464
|
+
for (const overlayStage of stageOverlayChain(stage2)) applyOverlay(build[overlayStage]?.services ?? {}, overlayStage, `${overlayStage}.services`, false);
|
|
465
|
+
if (options.isolated && (stage2 === "dev" || stage2 === "test")) {
|
|
466
|
+
const block = build[stage2]?.[ISOLATED_OVERLAY_KEY];
|
|
467
|
+
if (block) applyOverlay(block.services ?? {}, stage2, `${stage2}.${ISOLATED_OVERLAY_KEY}.services`, true);
|
|
442
468
|
}
|
|
443
469
|
for (const deleted of deletedRequisiteTargets) if (!(deleted.target in services2)) fail(sourceFile, stage2, deleted.path, "Unknown requisite target", deleted.target);
|
|
444
470
|
for (const [name, value] of Object.entries(services2)) {
|
|
@@ -460,11 +486,12 @@ function resolveBuildStage(build, stage2, sourceFile) {
|
|
|
460
486
|
if (primary?.service && value.service !== primary.service) fail(sourceFile, stage2, `${originPath}.service`, "top-level service must equal primary endpoint owner", value.service);
|
|
461
487
|
}
|
|
462
488
|
value.env ??= {};
|
|
489
|
+
if (name === "main") value.buildArgs ??= {};
|
|
463
490
|
value.endpoints ??= {};
|
|
464
491
|
value.requisites ??= {};
|
|
465
492
|
value.kind = name === "main" ? "main" : "ordinary";
|
|
466
493
|
}
|
|
467
|
-
return { name: build.name, services: services2, layers, origins, envOrigins, requisiteOrigins, sourceFile, projectDir: path.dirname(sourceFile) };
|
|
494
|
+
return { name: build.name, services: services2, layers, origins, envOrigins, buildArgsOrigins, requisiteOrigins, sourceFile, projectDir: path.dirname(sourceFile) };
|
|
468
495
|
}
|
|
469
496
|
function normalizeProjectName(name, projectDir) {
|
|
470
497
|
let normalized = name.toLowerCase().replace(/[^a-z0-9_-]/g, "-").replace(/^[-_]+/, "").replace(/[-_]+$/, "");
|
|
@@ -522,14 +549,6 @@ function assertDotenvDoesNotDefineKeys(filePath, keys, context) {
|
|
|
522
549
|
}
|
|
523
550
|
}
|
|
524
551
|
|
|
525
|
-
// src/core/config/executionProfile.ts
|
|
526
|
-
function executionProfile(stage2, composition, full = false) {
|
|
527
|
-
if (composition === "mesh" && stage2 === "test") throw new Error("Mesh test is a workflow, not a configuration stage");
|
|
528
|
-
if (stage2 === "dev") return { configStage: stage2, envStage: stage2, mainTarget: "dev", execMode: "dev", infraMode: composition === "mesh" || full ? "integrated" : "isolated", attachTester: false };
|
|
529
|
-
if (stage2 === "test") return { configStage: stage2, envStage: stage2, mainTarget: "test", execMode: "test", infraMode: "isolated", attachTester: false };
|
|
530
|
-
return { configStage: stage2, envStage: stage2, mainTarget: "prod", execMode: "prod", infraMode: "integrated", attachTester: stage2 === "e2e" };
|
|
531
|
-
}
|
|
532
|
-
|
|
533
552
|
// src/errors/PortConflictError.ts
|
|
534
553
|
var PortConflictError = class extends ConfigError {
|
|
535
554
|
port;
|
|
@@ -726,14 +745,14 @@ function buildDeclaredGraph(input) {
|
|
|
726
745
|
edges.sort((a, b) => `${a.consumer}:${a.target}:${a.kind}`.localeCompare(`${b.consumer}:${b.target}:${b.kind}`));
|
|
727
746
|
return { nodes: input.nodes, roots: [...input.roots].sort(), edges };
|
|
728
747
|
}
|
|
729
|
-
function computeClosure(start, adjacency) {
|
|
748
|
+
function computeClosure(start, adjacency, follow = () => true) {
|
|
730
749
|
const visited = /* @__PURE__ */ new Set();
|
|
731
750
|
const stack = [start];
|
|
732
751
|
while (stack.length) {
|
|
733
752
|
const id = stack.pop();
|
|
734
753
|
if (visited.has(id)) continue;
|
|
735
754
|
visited.add(id);
|
|
736
|
-
for (const edge of adjacency.get(id) ?? []) stack.push(edge.target);
|
|
755
|
+
for (const edge of adjacency.get(id) ?? []) if (follow(edge)) stack.push(edge.target);
|
|
737
756
|
}
|
|
738
757
|
return visited;
|
|
739
758
|
}
|
|
@@ -744,11 +763,12 @@ function selectReachableGraph(declared, profile) {
|
|
|
744
763
|
list.push(edge);
|
|
745
764
|
adjacency.set(edge.consumer, list);
|
|
746
765
|
}
|
|
766
|
+
const rootSet = new Set(declared.roots), isolated = profile.infraMode === "isolated";
|
|
767
|
+
const follow = (edge) => !isolated || !rootSet.has(edge.consumer) || edge.origin.isolatedOverlay === true;
|
|
747
768
|
const active = /* @__PURE__ */ new Set();
|
|
748
|
-
|
|
749
|
-
else for (const root of declared.roots) for (const id of computeClosure(root, adjacency)) active.add(id);
|
|
769
|
+
for (const root of declared.roots) for (const id of computeClosure(root, adjacency, follow)) active.add(id);
|
|
750
770
|
const nodes = new Map([...declared.nodes].filter(([id]) => active.has(id)));
|
|
751
|
-
const edges =
|
|
771
|
+
const edges = declared.edges.filter((edge) => follow(edge) && active.has(edge.consumer) && active.has(edge.target));
|
|
752
772
|
const activeAdjacency = /* @__PURE__ */ new Map();
|
|
753
773
|
for (const edge of edges) {
|
|
754
774
|
const list = activeAdjacency.get(edge.consumer) ?? [];
|
|
@@ -877,6 +897,34 @@ function normalizeComposeEnvironment(value, context) {
|
|
|
877
897
|
}
|
|
878
898
|
return result;
|
|
879
899
|
}
|
|
900
|
+
function normalizeComposeBuildArgs(value, context, sourceFile) {
|
|
901
|
+
const result = {};
|
|
902
|
+
if (value == null) return result;
|
|
903
|
+
const fail4 = (configPath, reason, item) => {
|
|
904
|
+
throw new ConfigError({ ...sourceFile ? { sourceFile } : {}, configPath, value: item, reason });
|
|
905
|
+
};
|
|
906
|
+
if (Array.isArray(value)) {
|
|
907
|
+
for (const item of value) {
|
|
908
|
+
if (typeof item !== "string") fail4(context, "Compose build arg entries must be strings", item);
|
|
909
|
+
const at = item.indexOf("=");
|
|
910
|
+
const key = at < 0 ? item : item.slice(0, at);
|
|
911
|
+
if (!key) fail4(context, "Compose build arg key must not be empty", item);
|
|
912
|
+
result[key] = at < 0 ? "" : item.slice(at + 1);
|
|
913
|
+
}
|
|
914
|
+
return result;
|
|
915
|
+
}
|
|
916
|
+
if (typeof value !== "object") fail4(context, "Compose build args must be a map or list", value);
|
|
917
|
+
for (const [key, val] of Object.entries(value)) {
|
|
918
|
+
if (!key) fail4(context, "Compose build arg key must not be empty", key);
|
|
919
|
+
if (val === null || val === void 0) {
|
|
920
|
+
result[key] = "";
|
|
921
|
+
continue;
|
|
922
|
+
}
|
|
923
|
+
if (typeof val === "object") fail4(`${context}.${key}`, "Compose build arg value must be scalar", val);
|
|
924
|
+
result[key] = String(val);
|
|
925
|
+
}
|
|
926
|
+
return result;
|
|
927
|
+
}
|
|
880
928
|
|
|
881
929
|
// src/core/composition/composeNetworks.ts
|
|
882
930
|
function normalizeNetworks(value) {
|
|
@@ -1415,6 +1463,7 @@ function validateAndPrepareMainOverride(document, context) {
|
|
|
1415
1463
|
fail4("services.main.build.context", "override cannot change main build context", build.context);
|
|
1416
1464
|
}
|
|
1417
1465
|
}
|
|
1466
|
+
if (build.args !== void 0) build.args = normalizeComposeBuildArgs(build.args, "services.main.build.args", context.file);
|
|
1418
1467
|
}
|
|
1419
1468
|
const env2 = normalizeComposeEnvironment(main.environment, "services.main.environment");
|
|
1420
1469
|
for (const k of ["EXEC_MODE", "INFRA_MODE"]) if (k in env2) fail4(`services.main.environment.${k}`, "override cannot set Builder-owned environment");
|
|
@@ -1624,7 +1673,7 @@ function makeGraph(input) {
|
|
|
1624
1673
|
for (const [name, declaration] of Object.entries(build.services)) {
|
|
1625
1674
|
if (name === "tester") continue;
|
|
1626
1675
|
const id = nodeId(root, name), origin = copyOrigin(build.origins.get(name), root);
|
|
1627
|
-
nodes.set(id, { id, kind: name === "main" ? "main" : "ordinary", projectDir: build.projectDir, sourceService: name, ...root ? { meshRoot: root } : {}, declaration, envLayers: [], origin, envOrigins: new Map([...build.envOrigins.get(name) ?? []].map(([key, value]) => [key, copyOrigin(value, root)])), requisiteOrigins: new Map([...build.requisiteOrigins.get(name) ?? []].map(([key, value]) => [key, copyOrigin(value, root)])) });
|
|
1676
|
+
nodes.set(id, { id, kind: name === "main" ? "main" : "ordinary", projectDir: build.projectDir, sourceService: name, ...root ? { meshRoot: root } : {}, declaration, envLayers: [], origin, envOrigins: new Map([...build.envOrigins.get(name) ?? []].map(([key, value]) => [key, copyOrigin(value, root)])), buildArgsOrigins: new Map([...build.buildArgsOrigins.get(name) ?? []].map(([key, value]) => [key, copyOrigin(value, root)])), requisiteOrigins: new Map([...build.requisiteOrigins.get(name) ?? []].map(([key, value]) => [key, copyOrigin(value, root)])) });
|
|
1628
1677
|
}
|
|
1629
1678
|
}
|
|
1630
1679
|
input.mesh?.tester ?? input.instances.get("")?.services.tester;
|
|
@@ -1691,6 +1740,22 @@ function resolveJsonEnv(node, graph, endpoints, stage2, composition, shadowed) {
|
|
|
1691
1740
|
function validateJsonEnv(node, graph, endpoints, stage2, composition, shadowed) {
|
|
1692
1741
|
resolveJsonEnv(node, graph, endpoints, stage2, composition, shadowed);
|
|
1693
1742
|
}
|
|
1743
|
+
function resolveJsonBuildArgs(node, graph, endpoints, stage2, composition, shadowed) {
|
|
1744
|
+
const output = {};
|
|
1745
|
+
const main = node.declaration;
|
|
1746
|
+
for (const [key, value] of Object.entries(main.buildArgs)) {
|
|
1747
|
+
if (shadowed.has(key)) continue;
|
|
1748
|
+
const origin = node.buildArgsOrigins.get(key) ?? node.origin;
|
|
1749
|
+
output[key] = interpolateBuilderReferences(value, { graph, endpoints, consumer: node.id, origin, stage: stage2, composition }).replace(/\$/g, "$$$$");
|
|
1750
|
+
}
|
|
1751
|
+
return output;
|
|
1752
|
+
}
|
|
1753
|
+
function assertNoReservedBuildArgs(args, origin, stage2, composition) {
|
|
1754
|
+
for (const key of Object.keys(args)) if (key.startsWith("BUILDER_")) {
|
|
1755
|
+
const where = origin(key);
|
|
1756
|
+
throw new ConfigError({ sourceFile: where.sourceFile, configPath: where.configPath, stage: stage2, composition, reason: "BUILDER_ build arguments are reserved for Builder", value: key });
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1694
1759
|
function validateReserved(node, keys, stage2, composition) {
|
|
1695
1760
|
for (const key of keys) if (key in node.declaration.env) {
|
|
1696
1761
|
const origin = node.envOrigins.get(key) ?? node.origin;
|
|
@@ -1702,6 +1767,7 @@ function compileGraphComposition(input) {
|
|
|
1702
1767
|
const projectName = deriveProjectName(input.name, input.stage, input.projectDir), compose = { name: projectName, services: {}, networks: { builder: { driver: "bridge" } } };
|
|
1703
1768
|
const mainServiceNames = /* @__PURE__ */ new Map(), modules = /* @__PURE__ */ new Map(), runtimeServiceNames = [], deferredHealthChecks = [];
|
|
1704
1769
|
const mainOverrideEnv = /* @__PURE__ */ new Map();
|
|
1770
|
+
const mainOverrideBuildArgs = /* @__PURE__ */ new Map();
|
|
1705
1771
|
for (const [id, node] of [...graph.nodes].sort(([a], [b]) => a.localeCompare(b))) {
|
|
1706
1772
|
if (node.kind === "main") {
|
|
1707
1773
|
resolveApplicationDockerfile(node.projectDir, "Dockerfile", input.stage);
|
|
@@ -1724,11 +1790,11 @@ function compileGraphComposition(input) {
|
|
|
1724
1790
|
validateMaterializedComposeFiles(raw, file, input.stage, { baseDir: selected.origin.projectDir, composition: input.composition });
|
|
1725
1791
|
for (const section of ["volumes", "networks", "configs", "secrets"]) if (prepared.resources[section]) mergeDocument(compose, { services: {}, [section]: prepared.resources[section] }, selected.origin, input.stage);
|
|
1726
1792
|
mainOverrideEnv.set(id, normalizeComposeEnvironment(prepared.main.environment, `${selected.origin.configPath}.services.main.environment`));
|
|
1793
|
+
if (prepared.main.build && typeof prepared.main.build === "object" && Object.hasOwn(prepared.main.build, "args")) mainOverrideBuildArgs.set(id, normalizeComposeBuildArgs(prepared.main.build.args, "services.main.build.args", file));
|
|
1727
1794
|
const overlay = { ...prepared.main };
|
|
1728
1795
|
delete overlay.environment;
|
|
1729
1796
|
delete overlay.build;
|
|
1730
1797
|
Object.assign(service, mergeMainOverride(service, overlay));
|
|
1731
|
-
if (prepared.main.build && typeof prepared.main.build === "object") Object.assign(service.build, { args: prepared.main.build.args });
|
|
1732
1798
|
}
|
|
1733
1799
|
withBuilderNetwork(service);
|
|
1734
1800
|
compose.services[serviceName] = service;
|
|
@@ -1790,6 +1856,13 @@ function compileGraphComposition(input) {
|
|
|
1790
1856
|
const override = mainOverrideEnv.get(id) ?? {};
|
|
1791
1857
|
const shadowed = new Set(node.kind === "main" ? Object.keys(override).filter((key) => node.envOrigins.get(key)?.scope !== "mesh") : []);
|
|
1792
1858
|
validateJsonEnv(node, graph, endpoints, input.stage, input.composition, shadowed);
|
|
1859
|
+
if (node.kind === "main") {
|
|
1860
|
+
const args = node.declaration.buildArgs, overrideArgs = mainOverrideBuildArgs.get(id) ?? {};
|
|
1861
|
+
assertNoReservedBuildArgs(args, (key) => node.buildArgsOrigins.get(key) ?? node.origin, input.stage, input.composition);
|
|
1862
|
+
const overrideFile = selectedOverride(input.instances.get(node.meshRoot ?? ""), "main");
|
|
1863
|
+
assertNoReservedBuildArgs(overrideArgs, (key) => ({ sourceFile: overrideFile?.origin.sourceFile ?? node.origin.sourceFile, configPath: `services.main.build.args.${key}`, projectDir: node.projectDir, scope: node.origin.scope, layer: node.origin.layer }), input.stage, input.composition);
|
|
1864
|
+
resolveJsonBuildArgs(node, graph, endpoints, input.stage, input.composition, new Set(Object.keys(overrideArgs).filter((key) => node.buildArgsOrigins.get(key)?.scope !== "mesh")));
|
|
1865
|
+
}
|
|
1793
1866
|
}
|
|
1794
1867
|
const tester = input.mesh?.tester ?? input.instances.get("")?.services.tester;
|
|
1795
1868
|
const testerOrigin = input.mesh ? { sourceFile: input.mesh.sourceFile, configPath: "services.tester", projectDir: input.projectDir, scope: "mesh", layer: "base" } : { sourceFile: input.instances.get("").sourceFile, configPath: "services.tester", projectDir: input.projectDir, scope: "build", layer: "base" };
|
|
@@ -1822,6 +1895,12 @@ function compileGraphComposition(input) {
|
|
|
1822
1895
|
const sourceEnv = Object.fromEntries(Object.entries(buildEnv).filter(([key]) => node.envOrigins.get(key)?.scope !== "mesh"));
|
|
1823
1896
|
const meshEnv = Object.fromEntries(Object.entries(buildEnv).filter(([key]) => node.envOrigins.get(key)?.scope === "mesh"));
|
|
1824
1897
|
service.environment = { ...sourceEnv, ...override, ...meshEnv, EXEC_MODE: profile.execMode, INFRA_MODE: profile.infraMode, ...primary ? { PORT: String(primary.port) } : {} };
|
|
1898
|
+
const overrideArgs = mainOverrideBuildArgs.get(id) ?? {}, shadowedArgs = new Set(Object.keys(overrideArgs).filter((key) => node.buildArgsOrigins.get(key)?.scope !== "mesh"));
|
|
1899
|
+
const resolvedArgs = resolveJsonBuildArgs(node, graph, endpoints, input.stage, input.composition, shadowedArgs);
|
|
1900
|
+
const sourceArgs = Object.fromEntries(Object.entries(resolvedArgs).filter(([key]) => node.buildArgsOrigins.get(key)?.scope !== "mesh"));
|
|
1901
|
+
const meshArgs = Object.fromEntries(Object.entries(resolvedArgs).filter(([key]) => node.buildArgsOrigins.get(key)?.scope === "mesh"));
|
|
1902
|
+
const effectiveArgs = { ...sourceArgs, ...overrideArgs, ...meshArgs };
|
|
1903
|
+
if (Object.keys(effectiveArgs).length || mainOverrideBuildArgs.has(id)) service.build.args = effectiveArgs;
|
|
1825
1904
|
} else {
|
|
1826
1905
|
const module = modules.get(id);
|
|
1827
1906
|
for (const name of module.serviceNames) {
|
|
@@ -1860,7 +1939,8 @@ function compileGraphComposition(input) {
|
|
|
1860
1939
|
|
|
1861
1940
|
// src/core/composition/compileServiceComposition.ts
|
|
1862
1941
|
function compileServiceComposition(stage2, projectDir, options = {}) {
|
|
1863
|
-
const root = resolveProjectDir(projectDir),
|
|
1942
|
+
const root = resolveProjectDir(projectDir), isolated = executionProfile(stage2, "service", Boolean(options.full)).infraMode === "isolated";
|
|
1943
|
+
const build = resolveBuildStage(getBuildJson(root), stage2, path.join(root, "build.json"), { isolated });
|
|
1864
1944
|
return compileGraphComposition({ stage: stage2, composition: "service", projectDir: root, name: build.name, instances: /* @__PURE__ */ new Map([["", build]]), full: Boolean(options.full), validationMode: Boolean(options.validationMode) });
|
|
1865
1945
|
}
|
|
1866
1946
|
|
|
@@ -2110,6 +2190,9 @@ function applyMeshExtends(mesh, builds, stage2) {
|
|
|
2110
2190
|
const env2 = build.envOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
2111
2191
|
for (const key of Object.keys(patch.env ?? {})) env2.set(key, { ...origin, configPath: `${origin.configPath}.env.${key}` });
|
|
2112
2192
|
build.envOrigins.set(name, env2);
|
|
2193
|
+
const args = build.buildArgsOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
2194
|
+
for (const key of Object.keys(patch.buildArgs ?? {})) args.set(key, { ...origin, configPath: `${origin.configPath}.buildArgs.${key}` });
|
|
2195
|
+
build.buildArgsOrigins.set(name, args);
|
|
2113
2196
|
const edges = build.requisiteOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
2114
2197
|
for (const [target, kind] of Object.entries(patch.requisites ?? {})) {
|
|
2115
2198
|
const canonical = target.startsWith("source.") ? target.slice(7) : `@mesh:${target}`;
|
|
@@ -2930,21 +3013,6 @@ var runMeshProd = (options = {}) => {
|
|
|
2930
3013
|
const root = resolveProjectDir(options.projectDir);
|
|
2931
3014
|
return runLongLived("prod", root, options, (validationMode) => compileMeshComposition("prod", root, { validationMode }), "mesh");
|
|
2932
3015
|
};
|
|
2933
|
-
async function runTestUnit(options, adapters = {}) {
|
|
2934
|
-
const compiled = compileServiceComposition("test", options.projectDir, { validationMode: Boolean(options.dryRun) }), yaml = stringify(compiled.compose);
|
|
2935
|
-
const main = compiled.mainServiceNames.get(nodeId(void 0, "main"));
|
|
2936
|
-
if (options.debug) console.log(redactYamlSecrets(yaml));
|
|
2937
|
-
if (options.dryRun) return 0;
|
|
2938
|
-
await (adapters.checkPorts ?? checkHostPortCollisions)(extractHostPorts(yaml));
|
|
2939
|
-
await (adapters.teardown ?? teardownCompose)(yaml, options.projectDir, { removeVolumes: true, silent: true });
|
|
2940
|
-
persistHostPortAllocations(options.projectDir, compiled.allocations);
|
|
2941
|
-
writeRunState(options.projectDir, { projectName: compiled.projectName, stage: "test-unit", configStage: "test", workflow: "test", composition: "service", projectDir: options.projectDir, runtimeServiceNames: [main], testerServiceNames: [], allocatedEndpointKeys: [...compiled.allocations.keys()] });
|
|
2942
|
-
return runWithCleanup(() => (adapters.compose ?? runCompose)(["up", "--build", "--abort-on-container-exit", "--exit-code-from", main, main], yaml, options.projectDir, { removeVolumes: true }), async () => {
|
|
2943
|
-
await (adapters.teardown ?? teardownCompose)(yaml, options.projectDir, { removeVolumes: true });
|
|
2944
|
-
removeHostPortAllocations(options.projectDir, [...compiled.allocations.keys()]);
|
|
2945
|
-
clearRunState(options.projectDir);
|
|
2946
|
-
});
|
|
2947
|
-
}
|
|
2948
3016
|
function inspectRunnerExit(yaml, projectDir, runner) {
|
|
2949
3017
|
const ps = spawnSync("docker", ["compose", "--project-directory", projectDir, "-f", "-", "ps", "-aq", runner], { cwd: projectDir, encoding: "utf8", input: yaml });
|
|
2950
3018
|
const id = ps.stdout?.trim();
|
|
@@ -2995,7 +3063,43 @@ async function runFiniteTester(compiled, projectDir, adapters = {}) {
|
|
|
2995
3063
|
return status;
|
|
2996
3064
|
}
|
|
2997
3065
|
|
|
2998
|
-
// src/core/runners/
|
|
3066
|
+
// src/core/runners/runTestUnit.ts
|
|
3067
|
+
async function runUnitWithLocalModules(compiled, yaml, main, projectDir, compose, inspectExit) {
|
|
3068
|
+
const started = await compose(["up", "--build", "--detach", ...compiled.runtimeServiceNames], yaml, projectDir, { removeVolumes: true, timeoutMs: 12e4 });
|
|
3069
|
+
if (started !== 0) {
|
|
3070
|
+
try {
|
|
3071
|
+
await compose(["logs", "--no-color"], yaml, projectDir, { removeVolumes: true });
|
|
3072
|
+
} catch (error) {
|
|
3073
|
+
console.warn("Could not collect startup logs", error);
|
|
3074
|
+
}
|
|
3075
|
+
return started;
|
|
3076
|
+
}
|
|
3077
|
+
const waited = await compose(["wait", main], yaml, projectDir, { removeVolumes: true });
|
|
3078
|
+
const status = inspectExit(yaml, projectDir, main) ?? (waited === 0 ? 1 : waited);
|
|
3079
|
+
try {
|
|
3080
|
+
await compose(["logs", "--no-color", main], yaml, projectDir, { removeVolumes: true });
|
|
3081
|
+
} catch (error) {
|
|
3082
|
+
console.warn("Could not collect unit logs", error);
|
|
3083
|
+
}
|
|
3084
|
+
return status;
|
|
3085
|
+
}
|
|
3086
|
+
async function runTestUnit(options, adapters = {}) {
|
|
3087
|
+
const compiled = compileServiceComposition("test", options.projectDir, { validationMode: Boolean(options.dryRun) }), yaml = stringify(compiled.compose);
|
|
3088
|
+
const main = compiled.mainServiceNames.get(nodeId(void 0, "main"));
|
|
3089
|
+
if (options.debug) console.log(redactYamlSecrets(yaml));
|
|
3090
|
+
if (options.dryRun) return 0;
|
|
3091
|
+
await (adapters.checkPorts ?? checkHostPortCollisions)(extractHostPorts(yaml));
|
|
3092
|
+
await (adapters.teardown ?? teardownCompose)(yaml, options.projectDir, { removeVolumes: true, silent: true });
|
|
3093
|
+
persistHostPortAllocations(options.projectDir, compiled.allocations);
|
|
3094
|
+
writeRunState(options.projectDir, { projectName: compiled.projectName, stage: "test-unit", configStage: "test", workflow: "test", composition: "service", projectDir: options.projectDir, runtimeServiceNames: compiled.runtimeServiceNames, testerServiceNames: [], allocatedEndpointKeys: [...compiled.allocations.keys()] });
|
|
3095
|
+
const compose = adapters.compose ?? runCompose;
|
|
3096
|
+
const execute = compiled.runtimeServiceNames.length === 1 ? () => compose(["up", "--build", "--abort-on-container-exit", "--exit-code-from", main, main], yaml, options.projectDir, { removeVolumes: true }) : () => runUnitWithLocalModules(compiled, yaml, main, options.projectDir, compose, adapters.inspectExit ?? inspectRunnerExit);
|
|
3097
|
+
return runWithCleanup(execute, async () => {
|
|
3098
|
+
await (adapters.teardown ?? teardownCompose)(yaml, options.projectDir, { removeVolumes: true });
|
|
3099
|
+
removeHostPortAllocations(options.projectDir, [...compiled.allocations.keys()]);
|
|
3100
|
+
clearRunState(options.projectDir);
|
|
3101
|
+
});
|
|
3102
|
+
}
|
|
2999
3103
|
async function runTestE2e(options, adapters = {}) {
|
|
3000
3104
|
const compiled = compileServiceComposition("e2e", options.projectDir, { validationMode: Boolean(options.dryRun) }), yaml = stringify(compiled.compose);
|
|
3001
3105
|
if (options.debug) console.log(redactYamlSecrets(yaml));
|