@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/dist/index.js
CHANGED
|
@@ -59,6 +59,7 @@ var AUTO_PORT_SCAN_START = 2e4;
|
|
|
59
59
|
var identifier = z.string().regex(BUILDER_IDENTIFIER_PATTERN);
|
|
60
60
|
var nonblank = z.string().min(1).refine((value) => value.trim().length > 0, "must not be blank");
|
|
61
61
|
var env = z.record(z.string(), z.string());
|
|
62
|
+
var buildArgs = z.record(z.string(), z.string());
|
|
62
63
|
var port = z.number().int().min(1).max(65535);
|
|
63
64
|
var publicPort = z.union([port, z.literal("AUTO")]);
|
|
64
65
|
var requisite = z.enum(["requirement", "dependency", "prerequisite"]);
|
|
@@ -66,10 +67,10 @@ var requisites = z.record(identifier, requisite);
|
|
|
66
67
|
var requisiteOverlay = z.record(identifier, z.union([requisite, z.literal(false)]));
|
|
67
68
|
var mainEndpointSchema = z.object({ port, publicPort: publicPort.optional(), primary: z.boolean().optional(), scheme: z.string().regex(ENDPOINT_SCHEME_PATTERN).optional() }).strict();
|
|
68
69
|
var serviceEndpointSchema = mainEndpointSchema.extend({ service: nonblank }).strict();
|
|
69
|
-
var mainServiceSchema = z.object({ env: env.optional(), endpoints: z.record(identifier, mainEndpointSchema).optional(), requisites: requisites.optional(), "override-compose": nonblank.optional() }).strict();
|
|
70
|
+
var mainServiceSchema = z.object({ env: env.optional(), buildArgs: buildArgs.optional(), endpoints: z.record(identifier, mainEndpointSchema).optional(), requisites: requisites.optional(), "override-compose": nonblank.optional() }).strict();
|
|
70
71
|
var testerServiceSchema = z.object({ compose: nonblank, service: nonblank, env: env.optional() }).strict();
|
|
71
72
|
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");
|
|
72
|
-
var mainOverlaySchema = z.object({ env: env.optional(), endpoints: z.record(identifier, mainEndpointSchema.partial().strict()).optional(), requisites: requisiteOverlay.optional(), "override-compose": nonblank.optional() }).strict();
|
|
73
|
+
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();
|
|
73
74
|
var testerOverlaySchema = testerServiceSchema.partial().strict();
|
|
74
75
|
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();
|
|
75
76
|
var buildServicesSchema = z.record(identifier, z.unknown()).superRefine((value, context) => {
|
|
@@ -80,14 +81,21 @@ var buildServicesSchema = z.record(identifier, z.unknown()).superRefine((value,
|
|
|
80
81
|
if (!parsed.success) for (const issue of parsed.error.issues) context.addIssue({ ...issue, path: [key, ...issue.path] });
|
|
81
82
|
}
|
|
82
83
|
});
|
|
83
|
-
var
|
|
84
|
+
var overlayServices = (allowTester) => z.record(identifier, z.unknown()).superRefine((value, context) => {
|
|
84
85
|
for (const [key, entry] of Object.entries(value)) {
|
|
86
|
+
if (key === "tester" && !allowTester) {
|
|
87
|
+
context.addIssue({ code: "custom", path: [key], message: "tester cannot be configured in on-inframode-isolated" });
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
85
90
|
const schema = key === "main" ? mainOverlaySchema : key === "tester" ? testerOverlaySchema : ordinaryOverlaySchema;
|
|
86
91
|
const parsed = schema.safeParse(entry);
|
|
87
92
|
if (!parsed.success) for (const issue of parsed.error.issues) context.addIssue({ ...issue, path: [key, ...issue.path] });
|
|
88
93
|
}
|
|
89
|
-
})
|
|
90
|
-
var
|
|
94
|
+
});
|
|
95
|
+
var buildStageSchema = z.object({ services: overlayServices(true).optional() }).strict();
|
|
96
|
+
var isolatedInfraOverlaySchema = z.object({ services: overlayServices(false).optional() }).strict();
|
|
97
|
+
var isolatableBuildStageSchema = z.object({ services: overlayServices(true).optional(), "on-inframode-isolated": isolatedInfraOverlaySchema.optional() }).strict();
|
|
98
|
+
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();
|
|
91
99
|
|
|
92
100
|
// src/utils/errorMessage.ts
|
|
93
101
|
function errorMessage(err) {
|
|
@@ -336,6 +344,14 @@ function checkDockerfileContract(build, projectDir) {
|
|
|
336
344
|
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 });
|
|
337
345
|
}
|
|
338
346
|
|
|
347
|
+
// src/core/config/executionProfile.ts
|
|
348
|
+
function executionProfile(stage2, composition, full = false) {
|
|
349
|
+
if (composition === "mesh" && stage2 === "test") throw new Error("Mesh test is a workflow, not a configuration stage");
|
|
350
|
+
if (stage2 === "dev") return { configStage: stage2, envStage: stage2, mainTarget: "dev", execMode: "dev", infraMode: composition === "mesh" || full ? "integrated" : "isolated", attachTester: false };
|
|
351
|
+
if (stage2 === "test") return { configStage: stage2, envStage: stage2, mainTarget: "test", execMode: "test", infraMode: "isolated", attachTester: false };
|
|
352
|
+
return { configStage: stage2, envStage: stage2, mainTarget: "prod", execMode: "prod", infraMode: "integrated", attachTester: stage2 === "e2e" };
|
|
353
|
+
}
|
|
354
|
+
|
|
339
355
|
// src/core/config/endpointProperties.ts
|
|
340
356
|
function resolveEndpointProperty(endpoint, property, context) {
|
|
341
357
|
const reference = context.referencedObject ?? endpoint.logicalPath;
|
|
@@ -403,46 +419,56 @@ function applyServiceOverlay(base, patch) {
|
|
|
403
419
|
}
|
|
404
420
|
|
|
405
421
|
// src/core/config/resolveBuildStage.ts
|
|
406
|
-
var
|
|
422
|
+
var ISOLATED_OVERLAY_KEY = "on-inframode-isolated";
|
|
423
|
+
var originFor = (sourceFile, configPath, layer, isolatedOverlay = false) => ({ sourceFile, configPath, projectDir: path.dirname(sourceFile), scope: "build", layer, ...isolatedOverlay ? { isolatedOverlay: true } : {} });
|
|
407
424
|
var fail = (sourceFile, stage2, configPath, reason, value) => {
|
|
408
425
|
throw new ConfigError({ sourceFile, stage: stage2, composition: "service", configPath, reason, value });
|
|
409
426
|
};
|
|
410
|
-
function resolveBuildStage(build, stage2, sourceFile) {
|
|
427
|
+
function resolveBuildStage(build, stage2, sourceFile, options = {}) {
|
|
411
428
|
const services2 = structuredClone(build.services);
|
|
412
429
|
const origins = /* @__PURE__ */ new Map();
|
|
413
430
|
const envOrigins = /* @__PURE__ */ new Map();
|
|
431
|
+
const buildArgsOrigins = /* @__PURE__ */ new Map();
|
|
414
432
|
const requisiteOrigins = /* @__PURE__ */ new Map();
|
|
415
433
|
const layers = [];
|
|
416
434
|
const deletedRequisiteTargets = [];
|
|
417
|
-
const record = (name, entry, layer) => {
|
|
418
|
-
const where =
|
|
419
|
-
const origin = originFor(sourceFile, where, layer);
|
|
435
|
+
const record = (name, entry, layer, servicesPath, isolatedOverlay = false) => {
|
|
436
|
+
const where = `${servicesPath}.${name}`;
|
|
437
|
+
const origin = originFor(sourceFile, where, layer, isolatedOverlay);
|
|
420
438
|
origins.set(name, origin);
|
|
421
439
|
const env2 = envOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
422
|
-
for (const key of Object.keys(entry.env ?? {})) env2.set(key, originFor(sourceFile, `${where}.env.${key}`, layer));
|
|
440
|
+
for (const key of Object.keys(entry.env ?? {})) env2.set(key, originFor(sourceFile, `${where}.env.${key}`, layer, isolatedOverlay));
|
|
423
441
|
envOrigins.set(name, env2);
|
|
442
|
+
const args = buildArgsOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
443
|
+
for (const key of Object.keys(entry.buildArgs ?? {})) args.set(key, originFor(sourceFile, `${where}.buildArgs.${key}`, layer, isolatedOverlay));
|
|
444
|
+
buildArgsOrigins.set(name, args);
|
|
424
445
|
const edges = requisiteOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
425
446
|
for (const [key, value] of Object.entries(entry.requisites ?? {})) {
|
|
426
447
|
if (value === false) edges.delete(key);
|
|
427
|
-
else edges.set(key, originFor(sourceFile, `${where}.requisites.${key}`, layer));
|
|
448
|
+
else edges.set(key, originFor(sourceFile, `${where}.requisites.${key}`, layer, isolatedOverlay));
|
|
428
449
|
}
|
|
429
450
|
requisiteOrigins.set(name, edges);
|
|
430
451
|
};
|
|
431
|
-
|
|
432
|
-
layers.push({ stage: "base", services: structuredClone(services2), origin: originFor(sourceFile, "services", "base") });
|
|
433
|
-
for (const overlayStage of stageOverlayChain(stage2)) {
|
|
434
|
-
const patches = build[overlayStage]?.services ?? {};
|
|
452
|
+
const applyOverlay = (patches, overlayStage, servicesPath, isolatedOverlay) => {
|
|
435
453
|
for (const [name, patch] of Object.entries(patches).sort(([a], [b]) => a.localeCompare(b))) {
|
|
436
454
|
const current = services2[name];
|
|
437
|
-
const where = `${
|
|
455
|
+
const where = `${servicesPath}.${name}`;
|
|
456
|
+
if (isolatedOverlay && name === "tester") fail(sourceFile, stage2, where, `tester cannot be configured in ${ISOLATED_OVERLAY_KEY}`);
|
|
438
457
|
if (!current && (name === "main" || name === "tester")) fail(sourceFile, stage2, where, "Required special service is missing from base");
|
|
439
458
|
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);
|
|
440
459
|
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");
|
|
441
460
|
services2[name] = current ? applyServiceOverlay(current, patch) : structuredClone(patch);
|
|
442
461
|
for (const [target, kind] of Object.entries(patch.requisites ?? {})) if (kind === false) deletedRequisiteTargets.push({ target, path: `${where}.requisites.${target}` });
|
|
443
|
-
record(name, patch, overlayStage);
|
|
462
|
+
record(name, patch, overlayStage, servicesPath, isolatedOverlay);
|
|
444
463
|
}
|
|
445
|
-
layers.push({ stage: overlayStage, services: structuredClone(patches), origin: originFor(sourceFile,
|
|
464
|
+
layers.push({ stage: overlayStage, services: structuredClone(patches), origin: originFor(sourceFile, servicesPath, overlayStage, isolatedOverlay) });
|
|
465
|
+
};
|
|
466
|
+
for (const [name, value] of Object.entries(services2).sort(([a], [b]) => a.localeCompare(b))) record(name, value, "base", "services");
|
|
467
|
+
layers.push({ stage: "base", services: structuredClone(services2), origin: originFor(sourceFile, "services", "base") });
|
|
468
|
+
for (const overlayStage of stageOverlayChain(stage2)) applyOverlay(build[overlayStage]?.services ?? {}, overlayStage, `${overlayStage}.services`, false);
|
|
469
|
+
if (options.isolated && (stage2 === "dev" || stage2 === "test")) {
|
|
470
|
+
const block = build[stage2]?.[ISOLATED_OVERLAY_KEY];
|
|
471
|
+
if (block) applyOverlay(block.services ?? {}, stage2, `${stage2}.${ISOLATED_OVERLAY_KEY}.services`, true);
|
|
446
472
|
}
|
|
447
473
|
for (const deleted of deletedRequisiteTargets) if (!(deleted.target in services2)) fail(sourceFile, stage2, deleted.path, "Unknown requisite target", deleted.target);
|
|
448
474
|
for (const [name, value] of Object.entries(services2)) {
|
|
@@ -464,11 +490,12 @@ function resolveBuildStage(build, stage2, sourceFile) {
|
|
|
464
490
|
if (primary?.service && value.service !== primary.service) fail(sourceFile, stage2, `${originPath}.service`, "top-level service must equal primary endpoint owner", value.service);
|
|
465
491
|
}
|
|
466
492
|
value.env ??= {};
|
|
493
|
+
if (name === "main") value.buildArgs ??= {};
|
|
467
494
|
value.endpoints ??= {};
|
|
468
495
|
value.requisites ??= {};
|
|
469
496
|
value.kind = name === "main" ? "main" : "ordinary";
|
|
470
497
|
}
|
|
471
|
-
return { name: build.name, services: services2, layers, origins, envOrigins, requisiteOrigins, sourceFile, projectDir: path.dirname(sourceFile) };
|
|
498
|
+
return { name: build.name, services: services2, layers, origins, envOrigins, buildArgsOrigins, requisiteOrigins, sourceFile, projectDir: path.dirname(sourceFile) };
|
|
472
499
|
}
|
|
473
500
|
function normalizeProjectName(name, projectDir) {
|
|
474
501
|
let normalized = name.toLowerCase().replace(/[^a-z0-9_-]/g, "-").replace(/^[-_]+/, "").replace(/[-_]+$/, "");
|
|
@@ -526,14 +553,6 @@ function assertDotenvDoesNotDefineKeys(filePath, keys, context) {
|
|
|
526
553
|
}
|
|
527
554
|
}
|
|
528
555
|
|
|
529
|
-
// src/core/config/executionProfile.ts
|
|
530
|
-
function executionProfile(stage2, composition, full = false) {
|
|
531
|
-
if (composition === "mesh" && stage2 === "test") throw new Error("Mesh test is a workflow, not a configuration stage");
|
|
532
|
-
if (stage2 === "dev") return { configStage: stage2, envStage: stage2, mainTarget: "dev", execMode: "dev", infraMode: composition === "mesh" || full ? "integrated" : "isolated", attachTester: false };
|
|
533
|
-
if (stage2 === "test") return { configStage: stage2, envStage: stage2, mainTarget: "test", execMode: "test", infraMode: "isolated", attachTester: false };
|
|
534
|
-
return { configStage: stage2, envStage: stage2, mainTarget: "prod", execMode: "prod", infraMode: "integrated", attachTester: stage2 === "e2e" };
|
|
535
|
-
}
|
|
536
|
-
|
|
537
556
|
// src/errors/PortConflictError.ts
|
|
538
557
|
var PortConflictError = class extends ConfigError {
|
|
539
558
|
port;
|
|
@@ -730,14 +749,14 @@ function buildDeclaredGraph(input) {
|
|
|
730
749
|
edges.sort((a, b) => `${a.consumer}:${a.target}:${a.kind}`.localeCompare(`${b.consumer}:${b.target}:${b.kind}`));
|
|
731
750
|
return { nodes: input.nodes, roots: [...input.roots].sort(), edges };
|
|
732
751
|
}
|
|
733
|
-
function computeClosure(start, adjacency) {
|
|
752
|
+
function computeClosure(start, adjacency, follow = () => true) {
|
|
734
753
|
const visited = /* @__PURE__ */ new Set();
|
|
735
754
|
const stack = [start];
|
|
736
755
|
while (stack.length) {
|
|
737
756
|
const id = stack.pop();
|
|
738
757
|
if (visited.has(id)) continue;
|
|
739
758
|
visited.add(id);
|
|
740
|
-
for (const edge of adjacency.get(id) ?? []) stack.push(edge.target);
|
|
759
|
+
for (const edge of adjacency.get(id) ?? []) if (follow(edge)) stack.push(edge.target);
|
|
741
760
|
}
|
|
742
761
|
return visited;
|
|
743
762
|
}
|
|
@@ -748,11 +767,12 @@ function selectReachableGraph(declared, profile) {
|
|
|
748
767
|
list.push(edge);
|
|
749
768
|
adjacency.set(edge.consumer, list);
|
|
750
769
|
}
|
|
770
|
+
const rootSet = new Set(declared.roots), isolated = profile.infraMode === "isolated";
|
|
771
|
+
const follow = (edge) => !isolated || !rootSet.has(edge.consumer) || edge.origin.isolatedOverlay === true;
|
|
751
772
|
const active = /* @__PURE__ */ new Set();
|
|
752
|
-
|
|
753
|
-
else for (const root of declared.roots) for (const id of computeClosure(root, adjacency)) active.add(id);
|
|
773
|
+
for (const root of declared.roots) for (const id of computeClosure(root, adjacency, follow)) active.add(id);
|
|
754
774
|
const nodes = new Map([...declared.nodes].filter(([id]) => active.has(id)));
|
|
755
|
-
const edges =
|
|
775
|
+
const edges = declared.edges.filter((edge) => follow(edge) && active.has(edge.consumer) && active.has(edge.target));
|
|
756
776
|
const activeAdjacency = /* @__PURE__ */ new Map();
|
|
757
777
|
for (const edge of edges) {
|
|
758
778
|
const list = activeAdjacency.get(edge.consumer) ?? [];
|
|
@@ -881,6 +901,34 @@ function normalizeComposeEnvironment(value, context) {
|
|
|
881
901
|
}
|
|
882
902
|
return result;
|
|
883
903
|
}
|
|
904
|
+
function normalizeComposeBuildArgs(value, context, sourceFile) {
|
|
905
|
+
const result = {};
|
|
906
|
+
if (value == null) return result;
|
|
907
|
+
const fail4 = (configPath, reason, item) => {
|
|
908
|
+
throw new ConfigError({ ...sourceFile ? { sourceFile } : {}, configPath, value: item, reason });
|
|
909
|
+
};
|
|
910
|
+
if (Array.isArray(value)) {
|
|
911
|
+
for (const item of value) {
|
|
912
|
+
if (typeof item !== "string") fail4(context, "Compose build arg entries must be strings", item);
|
|
913
|
+
const at = item.indexOf("=");
|
|
914
|
+
const key = at < 0 ? item : item.slice(0, at);
|
|
915
|
+
if (!key) fail4(context, "Compose build arg key must not be empty", item);
|
|
916
|
+
result[key] = at < 0 ? "" : item.slice(at + 1);
|
|
917
|
+
}
|
|
918
|
+
return result;
|
|
919
|
+
}
|
|
920
|
+
if (typeof value !== "object") fail4(context, "Compose build args must be a map or list", value);
|
|
921
|
+
for (const [key, val] of Object.entries(value)) {
|
|
922
|
+
if (!key) fail4(context, "Compose build arg key must not be empty", key);
|
|
923
|
+
if (val === null || val === void 0) {
|
|
924
|
+
result[key] = "";
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
if (typeof val === "object") fail4(`${context}.${key}`, "Compose build arg value must be scalar", val);
|
|
928
|
+
result[key] = String(val);
|
|
929
|
+
}
|
|
930
|
+
return result;
|
|
931
|
+
}
|
|
884
932
|
|
|
885
933
|
// src/core/composition/composeNetworks.ts
|
|
886
934
|
function normalizeNetworks(value) {
|
|
@@ -1419,6 +1467,7 @@ function validateAndPrepareMainOverride(document, context) {
|
|
|
1419
1467
|
fail4("services.main.build.context", "override cannot change main build context", build.context);
|
|
1420
1468
|
}
|
|
1421
1469
|
}
|
|
1470
|
+
if (build.args !== void 0) build.args = normalizeComposeBuildArgs(build.args, "services.main.build.args", context.file);
|
|
1422
1471
|
}
|
|
1423
1472
|
const env2 = normalizeComposeEnvironment(main.environment, "services.main.environment");
|
|
1424
1473
|
for (const k of ["EXEC_MODE", "INFRA_MODE"]) if (k in env2) fail4(`services.main.environment.${k}`, "override cannot set Builder-owned environment");
|
|
@@ -1628,7 +1677,7 @@ function makeGraph(input) {
|
|
|
1628
1677
|
for (const [name, declaration] of Object.entries(build.services)) {
|
|
1629
1678
|
if (name === "tester") continue;
|
|
1630
1679
|
const id = nodeId(root, name), origin = copyOrigin(build.origins.get(name), root);
|
|
1631
|
-
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)])) });
|
|
1680
|
+
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)])) });
|
|
1632
1681
|
}
|
|
1633
1682
|
}
|
|
1634
1683
|
input.mesh?.tester ?? input.instances.get("")?.services.tester;
|
|
@@ -1695,6 +1744,22 @@ function resolveJsonEnv(node, graph, endpoints, stage2, composition, shadowed) {
|
|
|
1695
1744
|
function validateJsonEnv(node, graph, endpoints, stage2, composition, shadowed) {
|
|
1696
1745
|
resolveJsonEnv(node, graph, endpoints, stage2, composition, shadowed);
|
|
1697
1746
|
}
|
|
1747
|
+
function resolveJsonBuildArgs(node, graph, endpoints, stage2, composition, shadowed) {
|
|
1748
|
+
const output = {};
|
|
1749
|
+
const main = node.declaration;
|
|
1750
|
+
for (const [key, value] of Object.entries(main.buildArgs)) {
|
|
1751
|
+
if (shadowed.has(key)) continue;
|
|
1752
|
+
const origin = node.buildArgsOrigins.get(key) ?? node.origin;
|
|
1753
|
+
output[key] = interpolateBuilderReferences(value, { graph, endpoints, consumer: node.id, origin, stage: stage2, composition }).replace(/\$/g, "$$$$");
|
|
1754
|
+
}
|
|
1755
|
+
return output;
|
|
1756
|
+
}
|
|
1757
|
+
function assertNoReservedBuildArgs(args, origin, stage2, composition) {
|
|
1758
|
+
for (const key of Object.keys(args)) if (key.startsWith("BUILDER_")) {
|
|
1759
|
+
const where = origin(key);
|
|
1760
|
+
throw new ConfigError({ sourceFile: where.sourceFile, configPath: where.configPath, stage: stage2, composition, reason: "BUILDER_ build arguments are reserved for Builder", value: key });
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1698
1763
|
function validateReserved(node, keys, stage2, composition) {
|
|
1699
1764
|
for (const key of keys) if (key in node.declaration.env) {
|
|
1700
1765
|
const origin = node.envOrigins.get(key) ?? node.origin;
|
|
@@ -1706,6 +1771,7 @@ function compileGraphComposition(input) {
|
|
|
1706
1771
|
const projectName = deriveProjectName(input.name, input.stage, input.projectDir), compose = { name: projectName, services: {}, networks: { builder: { driver: "bridge" } } };
|
|
1707
1772
|
const mainServiceNames = /* @__PURE__ */ new Map(), modules = /* @__PURE__ */ new Map(), runtimeServiceNames = [], deferredHealthChecks = [];
|
|
1708
1773
|
const mainOverrideEnv = /* @__PURE__ */ new Map();
|
|
1774
|
+
const mainOverrideBuildArgs = /* @__PURE__ */ new Map();
|
|
1709
1775
|
for (const [id, node] of [...graph.nodes].sort(([a], [b]) => a.localeCompare(b))) {
|
|
1710
1776
|
if (node.kind === "main") {
|
|
1711
1777
|
resolveApplicationDockerfile(node.projectDir, "Dockerfile", input.stage);
|
|
@@ -1728,11 +1794,11 @@ function compileGraphComposition(input) {
|
|
|
1728
1794
|
validateMaterializedComposeFiles(raw, file, input.stage, { baseDir: selected.origin.projectDir, composition: input.composition });
|
|
1729
1795
|
for (const section of ["volumes", "networks", "configs", "secrets"]) if (prepared.resources[section]) mergeDocument(compose, { services: {}, [section]: prepared.resources[section] }, selected.origin, input.stage);
|
|
1730
1796
|
mainOverrideEnv.set(id, normalizeComposeEnvironment(prepared.main.environment, `${selected.origin.configPath}.services.main.environment`));
|
|
1797
|
+
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));
|
|
1731
1798
|
const overlay = { ...prepared.main };
|
|
1732
1799
|
delete overlay.environment;
|
|
1733
1800
|
delete overlay.build;
|
|
1734
1801
|
Object.assign(service, mergeMainOverride(service, overlay));
|
|
1735
|
-
if (prepared.main.build && typeof prepared.main.build === "object") Object.assign(service.build, { args: prepared.main.build.args });
|
|
1736
1802
|
}
|
|
1737
1803
|
withBuilderNetwork(service);
|
|
1738
1804
|
compose.services[serviceName] = service;
|
|
@@ -1794,6 +1860,13 @@ function compileGraphComposition(input) {
|
|
|
1794
1860
|
const override = mainOverrideEnv.get(id) ?? {};
|
|
1795
1861
|
const shadowed = new Set(node.kind === "main" ? Object.keys(override).filter((key) => node.envOrigins.get(key)?.scope !== "mesh") : []);
|
|
1796
1862
|
validateJsonEnv(node, graph, endpoints, input.stage, input.composition, shadowed);
|
|
1863
|
+
if (node.kind === "main") {
|
|
1864
|
+
const args = node.declaration.buildArgs, overrideArgs = mainOverrideBuildArgs.get(id) ?? {};
|
|
1865
|
+
assertNoReservedBuildArgs(args, (key) => node.buildArgsOrigins.get(key) ?? node.origin, input.stage, input.composition);
|
|
1866
|
+
const overrideFile = selectedOverride(input.instances.get(node.meshRoot ?? ""), "main");
|
|
1867
|
+
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);
|
|
1868
|
+
resolveJsonBuildArgs(node, graph, endpoints, input.stage, input.composition, new Set(Object.keys(overrideArgs).filter((key) => node.buildArgsOrigins.get(key)?.scope !== "mesh")));
|
|
1869
|
+
}
|
|
1797
1870
|
}
|
|
1798
1871
|
const tester = input.mesh?.tester ?? input.instances.get("")?.services.tester;
|
|
1799
1872
|
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" };
|
|
@@ -1826,6 +1899,12 @@ function compileGraphComposition(input) {
|
|
|
1826
1899
|
const sourceEnv = Object.fromEntries(Object.entries(buildEnv).filter(([key]) => node.envOrigins.get(key)?.scope !== "mesh"));
|
|
1827
1900
|
const meshEnv = Object.fromEntries(Object.entries(buildEnv).filter(([key]) => node.envOrigins.get(key)?.scope === "mesh"));
|
|
1828
1901
|
service.environment = { ...sourceEnv, ...override, ...meshEnv, EXEC_MODE: profile.execMode, INFRA_MODE: profile.infraMode, ...primary ? { PORT: String(primary.port) } : {} };
|
|
1902
|
+
const overrideArgs = mainOverrideBuildArgs.get(id) ?? {}, shadowedArgs = new Set(Object.keys(overrideArgs).filter((key) => node.buildArgsOrigins.get(key)?.scope !== "mesh"));
|
|
1903
|
+
const resolvedArgs = resolveJsonBuildArgs(node, graph, endpoints, input.stage, input.composition, shadowedArgs);
|
|
1904
|
+
const sourceArgs = Object.fromEntries(Object.entries(resolvedArgs).filter(([key]) => node.buildArgsOrigins.get(key)?.scope !== "mesh"));
|
|
1905
|
+
const meshArgs = Object.fromEntries(Object.entries(resolvedArgs).filter(([key]) => node.buildArgsOrigins.get(key)?.scope === "mesh"));
|
|
1906
|
+
const effectiveArgs = { ...sourceArgs, ...overrideArgs, ...meshArgs };
|
|
1907
|
+
if (Object.keys(effectiveArgs).length || mainOverrideBuildArgs.has(id)) service.build.args = effectiveArgs;
|
|
1829
1908
|
} else {
|
|
1830
1909
|
const module = modules.get(id);
|
|
1831
1910
|
for (const name of module.serviceNames) {
|
|
@@ -1864,7 +1943,8 @@ function compileGraphComposition(input) {
|
|
|
1864
1943
|
|
|
1865
1944
|
// src/core/composition/compileServiceComposition.ts
|
|
1866
1945
|
function compileServiceComposition(stage2, projectDir, options = {}) {
|
|
1867
|
-
const root = resolveProjectDir(projectDir),
|
|
1946
|
+
const root = resolveProjectDir(projectDir), isolated = executionProfile(stage2, "service", Boolean(options.full)).infraMode === "isolated";
|
|
1947
|
+
const build = resolveBuildStage(getBuildJson(root), stage2, path.join(root, "build.json"), { isolated });
|
|
1868
1948
|
return compileGraphComposition({ stage: stage2, composition: "service", projectDir: root, name: build.name, instances: /* @__PURE__ */ new Map([["", build]]), full: Boolean(options.full), validationMode: Boolean(options.validationMode) });
|
|
1869
1949
|
}
|
|
1870
1950
|
|
|
@@ -2114,6 +2194,9 @@ function applyMeshExtends(mesh, builds, stage2) {
|
|
|
2114
2194
|
const env2 = build.envOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
2115
2195
|
for (const key of Object.keys(patch.env ?? {})) env2.set(key, { ...origin, configPath: `${origin.configPath}.env.${key}` });
|
|
2116
2196
|
build.envOrigins.set(name, env2);
|
|
2197
|
+
const args = build.buildArgsOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
2198
|
+
for (const key of Object.keys(patch.buildArgs ?? {})) args.set(key, { ...origin, configPath: `${origin.configPath}.buildArgs.${key}` });
|
|
2199
|
+
build.buildArgsOrigins.set(name, args);
|
|
2117
2200
|
const edges = build.requisiteOrigins.get(name) ?? /* @__PURE__ */ new Map();
|
|
2118
2201
|
for (const [target, kind] of Object.entries(patch.requisites ?? {})) {
|
|
2119
2202
|
const canonical = target.startsWith("source.") ? target.slice(7) : `@mesh:${target}`;
|
|
@@ -2934,21 +3017,6 @@ var runMeshProd = (options = {}) => {
|
|
|
2934
3017
|
const root = resolveProjectDir(options.projectDir);
|
|
2935
3018
|
return runLongLived("prod", root, options, (validationMode) => compileMeshComposition("prod", root, { validationMode }), "mesh");
|
|
2936
3019
|
};
|
|
2937
|
-
async function runTestUnit(options, adapters = {}) {
|
|
2938
|
-
const compiled = compileServiceComposition("test", options.projectDir, { validationMode: Boolean(options.dryRun) }), yaml = stringify(compiled.compose);
|
|
2939
|
-
const main = compiled.mainServiceNames.get(nodeId(void 0, "main"));
|
|
2940
|
-
if (options.debug) console.log(redactYamlSecrets(yaml));
|
|
2941
|
-
if (options.dryRun) return 0;
|
|
2942
|
-
await (adapters.checkPorts ?? checkHostPortCollisions)(extractHostPorts(yaml));
|
|
2943
|
-
await (adapters.teardown ?? teardownCompose)(yaml, options.projectDir, { removeVolumes: true, silent: true });
|
|
2944
|
-
persistHostPortAllocations(options.projectDir, compiled.allocations);
|
|
2945
|
-
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()] });
|
|
2946
|
-
return runWithCleanup(() => (adapters.compose ?? runCompose)(["up", "--build", "--abort-on-container-exit", "--exit-code-from", main, main], yaml, options.projectDir, { removeVolumes: true }), async () => {
|
|
2947
|
-
await (adapters.teardown ?? teardownCompose)(yaml, options.projectDir, { removeVolumes: true });
|
|
2948
|
-
removeHostPortAllocations(options.projectDir, [...compiled.allocations.keys()]);
|
|
2949
|
-
clearRunState(options.projectDir);
|
|
2950
|
-
});
|
|
2951
|
-
}
|
|
2952
3020
|
function inspectRunnerExit(yaml, projectDir, runner) {
|
|
2953
3021
|
const ps = spawnSync("docker", ["compose", "--project-directory", projectDir, "-f", "-", "ps", "-aq", runner], { cwd: projectDir, encoding: "utf8", input: yaml });
|
|
2954
3022
|
const id = ps.stdout?.trim();
|
|
@@ -2999,7 +3067,43 @@ async function runFiniteTester(compiled, projectDir, adapters = {}) {
|
|
|
2999
3067
|
return status;
|
|
3000
3068
|
}
|
|
3001
3069
|
|
|
3002
|
-
// src/core/runners/
|
|
3070
|
+
// src/core/runners/runTestUnit.ts
|
|
3071
|
+
async function runUnitWithLocalModules(compiled, yaml, main, projectDir, compose, inspectExit) {
|
|
3072
|
+
const started = await compose(["up", "--build", "--detach", ...compiled.runtimeServiceNames], yaml, projectDir, { removeVolumes: true, timeoutMs: 12e4 });
|
|
3073
|
+
if (started !== 0) {
|
|
3074
|
+
try {
|
|
3075
|
+
await compose(["logs", "--no-color"], yaml, projectDir, { removeVolumes: true });
|
|
3076
|
+
} catch (error) {
|
|
3077
|
+
console.warn("Could not collect startup logs", error);
|
|
3078
|
+
}
|
|
3079
|
+
return started;
|
|
3080
|
+
}
|
|
3081
|
+
const waited = await compose(["wait", main], yaml, projectDir, { removeVolumes: true });
|
|
3082
|
+
const status = inspectExit(yaml, projectDir, main) ?? (waited === 0 ? 1 : waited);
|
|
3083
|
+
try {
|
|
3084
|
+
await compose(["logs", "--no-color", main], yaml, projectDir, { removeVolumes: true });
|
|
3085
|
+
} catch (error) {
|
|
3086
|
+
console.warn("Could not collect unit logs", error);
|
|
3087
|
+
}
|
|
3088
|
+
return status;
|
|
3089
|
+
}
|
|
3090
|
+
async function runTestUnit(options, adapters = {}) {
|
|
3091
|
+
const compiled = compileServiceComposition("test", options.projectDir, { validationMode: Boolean(options.dryRun) }), yaml = stringify(compiled.compose);
|
|
3092
|
+
const main = compiled.mainServiceNames.get(nodeId(void 0, "main"));
|
|
3093
|
+
if (options.debug) console.log(redactYamlSecrets(yaml));
|
|
3094
|
+
if (options.dryRun) return 0;
|
|
3095
|
+
await (adapters.checkPorts ?? checkHostPortCollisions)(extractHostPorts(yaml));
|
|
3096
|
+
await (adapters.teardown ?? teardownCompose)(yaml, options.projectDir, { removeVolumes: true, silent: true });
|
|
3097
|
+
persistHostPortAllocations(options.projectDir, compiled.allocations);
|
|
3098
|
+
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()] });
|
|
3099
|
+
const compose = adapters.compose ?? runCompose;
|
|
3100
|
+
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);
|
|
3101
|
+
return runWithCleanup(execute, async () => {
|
|
3102
|
+
await (adapters.teardown ?? teardownCompose)(yaml, options.projectDir, { removeVolumes: true });
|
|
3103
|
+
removeHostPortAllocations(options.projectDir, [...compiled.allocations.keys()]);
|
|
3104
|
+
clearRunState(options.projectDir);
|
|
3105
|
+
});
|
|
3106
|
+
}
|
|
3003
3107
|
async function runTestE2e(options, adapters = {}) {
|
|
3004
3108
|
const compiled = compileServiceComposition("e2e", options.projectDir, { validationMode: Boolean(options.dryRun) }), yaml = stringify(compiled.compose);
|
|
3005
3109
|
if (options.debug) console.log(redactYamlSecrets(yaml));
|