@solid-stack/builder 2.0.3 → 2.1.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 +581 -50
- package/dist/bin.js +810 -548
- package/dist/bin.js.map +1 -1
- package/dist/commands/mesh/commands/up/command.d.ts.map +1 -1
- package/dist/commands/mesh/commands/up/handler.d.ts.map +1 -1
- package/dist/commands/service/commands/export/handler.d.ts.map +1 -1
- package/dist/core/composeCleanup.d.ts.map +1 -1
- package/dist/core/composition/assertComposeLifecycleAcyclic.d.ts +7 -0
- package/dist/core/composition/assertComposeLifecycleAcyclic.d.ts.map +1 -0
- package/dist/core/composition/compileServiceComposition.d.ts.map +1 -1
- package/dist/core/composition/mergeAppOverride.d.ts +3 -0
- package/dist/core/composition/mergeAppOverride.d.ts.map +1 -0
- package/dist/core/composition/namespaceDependencyCompose.d.ts.map +1 -1
- package/dist/core/composition/namespaceResourceDefinition.d.ts +3 -0
- package/dist/core/composition/namespaceResourceDefinition.d.ts.map +1 -0
- package/dist/core/composition/selectAppEnvironmentEntries.d.ts +3 -0
- package/dist/core/composition/selectAppEnvironmentEntries.d.ts.map +1 -0
- package/dist/core/composition/types.d.ts +16 -4
- package/dist/core/composition/types.d.ts.map +1 -1
- package/dist/core/composition/validateDependencyCompose.d.ts.map +1 -1
- package/dist/core/composition/validateOverrideCompose.d.ts.map +1 -1
- package/dist/core/config/builderEnvironment.d.ts +12 -0
- package/dist/core/config/builderEnvironment.d.ts.map +1 -0
- package/dist/core/config/endpointProperties.d.ts +5 -2
- package/dist/core/config/endpointProperties.d.ts.map +1 -1
- package/dist/core/config/hostPorts.d.ts +5 -1
- package/dist/core/config/hostPorts.d.ts.map +1 -1
- package/dist/core/config/references.d.ts +9 -3
- package/dist/core/config/references.d.ts.map +1 -1
- package/dist/core/config/resolveBuildStage.d.ts.map +1 -1
- package/dist/core/config/resolveMeshStage.d.ts.map +1 -1
- package/dist/core/config/stageMerge.d.ts +2 -0
- package/dist/core/config/stageMerge.d.ts.map +1 -1
- package/dist/core/config/types.d.ts +7 -2
- package/dist/core/config/types.d.ts.map +1 -1
- package/dist/core/mesh/checkers/checkMesh.d.ts +1 -0
- package/dist/core/mesh/checkers/checkMesh.d.ts.map +1 -1
- package/dist/core/mesh/checkers/checkMeshServices.d.ts +4 -1
- package/dist/core/mesh/checkers/checkMeshServices.d.ts.map +1 -1
- package/dist/core/mesh/meshSchema.d.ts +13 -1
- package/dist/core/mesh/meshSchema.d.ts.map +1 -1
- package/dist/core/mesh/runners/runMeshDev.d.ts.map +1 -1
- package/dist/core/mesh/runners/runMeshProd.d.ts.map +1 -1
- package/dist/core/mesh/runners/runMeshServiceTests.d.ts +3 -0
- package/dist/core/mesh/runners/runMeshServiceTests.d.ts.map +1 -0
- package/dist/core/mesh/runners/runMeshTest.d.ts.map +1 -1
- package/dist/core/mesh/runners/runMeshTestE2e.d.ts.map +1 -1
- package/dist/core/mesh/runners/runMeshTestUnit.d.ts.map +1 -1
- package/dist/core/mesh/v2/compileMeshTester.d.ts.map +1 -1
- package/dist/core/mesh/v2/meshReferences.d.ts +5 -3
- package/dist/core/mesh/v2/meshReferences.d.ts.map +1 -1
- package/dist/core/mesh/v2/resolveMeshAppEnvironment.d.ts +4 -0
- package/dist/core/mesh/v2/resolveMeshAppEnvironment.d.ts.map +1 -0
- package/dist/core/mesh/v2/validateMeshTestStage.d.ts.map +1 -1
- package/dist/core/runWithCleanup.d.ts +3 -0
- package/dist/core/runWithCleanup.d.ts.map +1 -0
- package/dist/core/runners/runDev.d.ts.map +1 -1
- package/dist/core/runners/runProd.d.ts.map +1 -1
- package/dist/core/runners/runTestE2e.d.ts.map +1 -1
- package/dist/core/runners/runTestUnit.d.ts.map +1 -1
- package/dist/core/teardownCompose.d.ts.map +1 -1
- package/dist/errors/PortConflictError.d.ts +1 -1
- package/dist/errors/PortConflictError.d.ts.map +1 -1
- package/dist/index.js +809 -547
- package/dist/index.js.map +1 -1
- package/dist/templates/policy/dockerfile/dockerfile.rego +7 -4
- package/package.json +1 -1
- package/schemas/mesh-schema.json +1 -0
- package/templates/policy/dockerfile/dockerfile.rego +7 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command, Argument } from 'commander';
|
|
2
|
-
import
|
|
2
|
+
import pc14 from 'picocolors';
|
|
3
3
|
import fs, { existsSync, readFileSync, mkdirSync, writeFileSync, renameSync, statSync, realpathSync, lstatSync, readlinkSync, unlinkSync } from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -174,7 +174,7 @@ function runStep(executable, args, projectDir, ctx) {
|
|
|
174
174
|
if (stderr) process.stderr.write(stderr);
|
|
175
175
|
if (result.error || result.status !== 0) {
|
|
176
176
|
console.error("\n" + "=".repeat(60));
|
|
177
|
-
console.error(
|
|
177
|
+
console.error(pc14.red(`\u{1F6A8} INFRASTRUCTURE CHECK FAILED \u{1F6A8}`));
|
|
178
178
|
console.error("=".repeat(60));
|
|
179
179
|
console.error(`Failed Step : ${ctx.stepName}`);
|
|
180
180
|
if (ctx.targetFile) {
|
|
@@ -201,7 +201,7 @@ function checkDockerfile(buildJson, projectDir) {
|
|
|
201
201
|
const dockerfileRel = buildJson.dockerfile || "Dockerfile";
|
|
202
202
|
const dockerfilePath = resolveApplicationDockerfile(projectDir, dockerfileRel);
|
|
203
203
|
const content = readFileSync(dockerfilePath, "utf-8");
|
|
204
|
-
console.log(
|
|
204
|
+
console.log(pc14.cyan(`
|
|
205
205
|
\u{1F50D} Linting Dockerfile (${dockerfileRel})...`));
|
|
206
206
|
runStep(
|
|
207
207
|
"docker",
|
|
@@ -271,7 +271,7 @@ function checkDockerfileContract(build, projectDir) {
|
|
|
271
271
|
const relative = build.dockerfile ?? "Dockerfile";
|
|
272
272
|
resolveApplicationDockerfile(root, relative);
|
|
273
273
|
const policyDir = getDockerfilePolicyDir();
|
|
274
|
-
console.log(
|
|
274
|
+
console.log(pc14.cyan(`
|
|
275
275
|
\u{1F50D} Validating Builder Dockerfile contract (${relative})...`));
|
|
276
276
|
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 });
|
|
277
277
|
}
|
|
@@ -326,7 +326,7 @@ function getDeclaredYamlFiles(build, projectDir) {
|
|
|
326
326
|
function checkYamlFiles(build, projectDir) {
|
|
327
327
|
const root = resolveProjectDir(projectDir);
|
|
328
328
|
const files = getDeclaredYamlFiles(build, root);
|
|
329
|
-
if (files.length) console.log(
|
|
329
|
+
if (files.length) console.log(pc14.cyan(`
|
|
330
330
|
\u{1F50D} Validating ${files.length} declared V2 Compose file(s)...`));
|
|
331
331
|
for (const file of files) {
|
|
332
332
|
const absolutePath = resolveInsideProject(root, file.relativePath, { sourceFile: `${root}/build.json`, configPath: file.source, ...file.stage ? { stage: file.stage } : {} });
|
|
@@ -368,13 +368,24 @@ function normalizeNetworks(value) {
|
|
|
368
368
|
return value && typeof value === "object" ? { ...value } : {};
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
+
// src/core/composition/selectAppEnvironmentEntries.ts
|
|
372
|
+
function selectAppEnvironmentEntries(layers, laterKeys = /* @__PURE__ */ new Set()) {
|
|
373
|
+
const winners = /* @__PURE__ */ new Map();
|
|
374
|
+
for (const layer of layers) {
|
|
375
|
+
for (const key of Object.keys(layer.values)) winners.set(key, layer);
|
|
376
|
+
}
|
|
377
|
+
for (const key of laterKeys) winners.delete(key);
|
|
378
|
+
return winners;
|
|
379
|
+
}
|
|
380
|
+
|
|
371
381
|
// src/core/config/endpointProperties.ts
|
|
372
382
|
function resolveEndpointProperty(endpoint, property, context) {
|
|
383
|
+
const reference = context.referencedObject ?? endpoint.logicalPath;
|
|
373
384
|
const published = () => {
|
|
374
|
-
if (!endpoint.effectivelyPublished || endpoint.publicHost === void 0 || endpoint.publicPort === void 0) throw new ConfigError({ ...context,
|
|
385
|
+
if (!endpoint.effectivelyPublished || endpoint.publicHost === void 0 || endpoint.publicPort === void 0) throw new ConfigError({ ...context, referencedObject: reference, reason: `Endpoint property ${property} requires effective publication` });
|
|
375
386
|
};
|
|
376
387
|
const scheme = () => {
|
|
377
|
-
if (!endpoint.scheme) throw new ConfigError({ ...context, referencedObject:
|
|
388
|
+
if (!endpoint.scheme) throw new ConfigError({ ...context, referencedObject: reference, reason: `Endpoint property ${property} requires an endpoint scheme` });
|
|
378
389
|
return endpoint.scheme;
|
|
379
390
|
};
|
|
380
391
|
switch (property) {
|
|
@@ -429,6 +440,18 @@ function assertAcyclicGraph(graph, context) {
|
|
|
429
440
|
}
|
|
430
441
|
|
|
431
442
|
// src/core/config/stageMerge.ts
|
|
443
|
+
function stageOverlayChain(stage) {
|
|
444
|
+
switch (stage) {
|
|
445
|
+
case "dev":
|
|
446
|
+
return ["dev"];
|
|
447
|
+
case "prod":
|
|
448
|
+
return ["prod"];
|
|
449
|
+
case "test":
|
|
450
|
+
return ["test"];
|
|
451
|
+
case "e2e":
|
|
452
|
+
return ["prod", "e2e"];
|
|
453
|
+
}
|
|
454
|
+
}
|
|
432
455
|
function unionStable(base = [], overlay = []) {
|
|
433
456
|
return [.../* @__PURE__ */ new Set([...base, ...overlay])];
|
|
434
457
|
}
|
|
@@ -438,32 +461,40 @@ function mergeStringMap(base, overlay) {
|
|
|
438
461
|
|
|
439
462
|
// src/core/config/resolveBuildStage.ts
|
|
440
463
|
function resolveBuildStage(build, stage, sourceFile) {
|
|
441
|
-
const
|
|
464
|
+
const context = (configPath, value, reason, referencedObject) => new ConfigError({ sourceFile, configPath, stage, composition: "service", value, ...referencedObject ? { referencedObject } : {}, reason });
|
|
465
|
+
const appEnv = { ...build.app.env ?? {} };
|
|
442
466
|
const appEndpoints = structuredClone(build.app.endpoints ?? {});
|
|
443
|
-
for (const [name, endpoint] of Object.entries(overlay.app?.endpoints ?? {})) appEndpoints[name] = { ...appEndpoints[name] ?? {}, ...endpoint };
|
|
444
467
|
const dependencies = {};
|
|
445
468
|
for (const [name, dep] of Object.entries(build.dependencies ?? {})) dependencies[name] = { ...dep, env: { ...dep.env ?? {} }, endpoints: structuredClone(dep.endpoints ?? {}), dependsOn: [...dep.dependsOn ?? []] };
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
469
|
+
const layers = [{ stage: "base", appEnv: { ...build.app.env ?? {} } }];
|
|
470
|
+
for (const overlayStage of stageOverlayChain(stage)) {
|
|
471
|
+
const overlay = build[overlayStage];
|
|
472
|
+
if (!overlay) continue;
|
|
473
|
+
Object.assign(appEnv, overlay.app?.env ?? {});
|
|
474
|
+
for (const [name, endpoint] of Object.entries(overlay.app?.endpoints ?? {})) appEndpoints[name] = { ...appEndpoints[name] ?? {}, ...endpoint };
|
|
475
|
+
for (const [name, patch] of Object.entries(overlay.dependencies ?? {})) {
|
|
476
|
+
const inherited = dependencies[name];
|
|
477
|
+
if (inherited && patch.compose !== void 0) throw context(`${overlayStage}.dependencies.${name}.compose`, patch.compose, "A stage cannot replace the Compose implementation of an inherited dependency", `dependencies.${name}`);
|
|
478
|
+
const next = inherited ?? { compose: void 0, env: {}, endpoints: {}, dependsOn: [] };
|
|
479
|
+
if (!inherited && patch.compose !== void 0) next.compose = patch.compose;
|
|
480
|
+
next.env = mergeStringMap(next.env, patch.env);
|
|
481
|
+
for (const [endpointName, endpointPatch] of Object.entries(patch.endpoints ?? {})) next.endpoints[endpointName] = { ...next.endpoints[endpointName] ?? {}, ...endpointPatch };
|
|
482
|
+
next.dependsOn = unionStable(next.dependsOn, patch.dependsOn);
|
|
483
|
+
dependencies[name] = next;
|
|
484
|
+
}
|
|
485
|
+
layers.push({ stage: overlayStage, appEnv: { ...overlay.app?.env ?? {} }, ...overlay["override-compose"] ? { overrideCompose: overlay["override-compose"] } : {} });
|
|
486
|
+
}
|
|
487
|
+
const effective = { ...build, app: { env: appEnv, endpoints: appEndpoints }, dependencies, tester: build.tester ? { env: { ...build.tester.env ?? {} } } : void 0, layers };
|
|
455
488
|
delete effective.dev;
|
|
456
489
|
delete effective.prod;
|
|
457
490
|
delete effective.test;
|
|
458
491
|
delete effective.e2e;
|
|
459
|
-
const context = (configPath, value, reason, referencedObject) => new ConfigError({ sourceFile, configPath, stage, composition: "service", value, ...referencedObject ? { referencedObject } : {}, reason });
|
|
460
492
|
for (const [name, ep] of Object.entries(appEndpoints)) if (!Number.isInteger(ep.port) || ep.port < 1 || ep.port > 65535) throw context(`app.endpoints.${name}.port`, ep.port, "Effective endpoint requires a port in 1..65535");
|
|
461
493
|
assertPrimaryEndpointInvariant(appEndpoints, { sourceFile, configPath: "app.endpoints", stage });
|
|
462
494
|
const graph = /* @__PURE__ */ new Map();
|
|
463
495
|
for (const [name, dep] of Object.entries(dependencies)) {
|
|
464
496
|
if (typeof dep.compose !== "string" || !dep.compose.trim()) throw context(`dependencies.${name}.compose`, dep.compose, "Effective dependency requires compose");
|
|
465
|
-
const
|
|
466
|
-
for (const [epName, ep] of endpoints) if (!ep.service || !Number.isInteger(ep.port) || ep.port < 1 || ep.port > 65535) throw context(`dependencies.${name}.endpoints.${epName}`, ep, "Effective dependency endpoint requires service and port");
|
|
497
|
+
for (const [epName, ep] of Object.entries(dep.endpoints)) if (!ep.service || !Number.isInteger(ep.port) || ep.port < 1 || ep.port > 65535) throw context(`dependencies.${name}.endpoints.${epName}`, ep, "Effective dependency endpoint requires service and port");
|
|
467
498
|
assertPrimaryEndpointInvariant(dep.endpoints, { sourceFile, configPath: `dependencies.${name}.endpoints`, stage });
|
|
468
499
|
const node = `dependencies.${name}`;
|
|
469
500
|
graph.set(node, /* @__PURE__ */ new Set());
|
|
@@ -487,29 +518,42 @@ var BUILD_APP = /^app\.endpoints\.([a-z][a-z0-9-]*)\.([a-z_]+)$/;
|
|
|
487
518
|
var BUILD_DEP = /^dependencies\.([a-z][a-z0-9-]*)\.endpoints\.([a-z][a-z0-9-]*)\.([a-z_]+)$/;
|
|
488
519
|
var MESH_APP = /^([a-z][a-z0-9-]*)\.app\.endpoints\.([a-z][a-z0-9-]*)\.([a-z_]+)$/;
|
|
489
520
|
var MESH_DEP = /^([a-z][a-z0-9-]*)\.dependencies\.([a-z][a-z0-9-]*)\.endpoints\.([a-z][a-z0-9-]*)\.([a-z_]+)$/;
|
|
490
|
-
function parse2(raw, scope,
|
|
491
|
-
let
|
|
492
|
-
if (scope === "build" && (
|
|
493
|
-
if (scope === "build" && (
|
|
494
|
-
if (scope === "mesh" && (
|
|
495
|
-
if (scope === "mesh" && (
|
|
496
|
-
throw new ConfigError({
|
|
497
|
-
}
|
|
498
|
-
function valid(ref,
|
|
499
|
-
if (!ENDPOINT_PROPERTIES.includes(ref.property))
|
|
521
|
+
function parse2(raw, scope, context) {
|
|
522
|
+
let match;
|
|
523
|
+
if (scope === "build" && (match = BUILD_APP.exec(raw))) return valid({ raw, scope, target: "app", endpoint: match[1], property: match[2] }, context);
|
|
524
|
+
if (scope === "build" && (match = BUILD_DEP.exec(raw))) return valid({ raw, scope, target: "dependency", dependency: match[1], endpoint: match[2], property: match[3] }, context);
|
|
525
|
+
if (scope === "mesh" && (match = MESH_APP.exec(raw))) return valid({ raw, scope, meshService: match[1], target: "app", endpoint: match[2], property: match[3] }, context);
|
|
526
|
+
if (scope === "mesh" && (match = MESH_DEP.exec(raw))) return valid({ raw, scope, meshService: match[1], target: "dependency", dependency: match[2], endpoint: match[3], property: match[4] }, context);
|
|
527
|
+
throw new ConfigError({ ...context, referencedObject: raw, value: raw, reason: `Invalid ${scope} endpoint reference` });
|
|
528
|
+
}
|
|
529
|
+
function valid(ref, context) {
|
|
530
|
+
if (!ENDPOINT_PROPERTIES.includes(ref.property)) {
|
|
531
|
+
throw new ConfigError({ ...context, referencedObject: ref.raw, value: ref.property, reason: "Unknown endpoint property" });
|
|
532
|
+
}
|
|
500
533
|
return ref;
|
|
501
534
|
}
|
|
502
|
-
function collectBuilderReferences(value, scope,
|
|
503
|
-
const protectedValue = value.replace(/\$\$/g, "\0DOLLAR\0")
|
|
504
|
-
|
|
505
|
-
|
|
535
|
+
function collectBuilderReferences(value, scope, context) {
|
|
536
|
+
const protectedValue = value.replace(/\$\$/g, "\0DOLLAR\0");
|
|
537
|
+
const refs = [];
|
|
538
|
+
for (const match of protectedValue.matchAll(/\$\{([^}]*)\}/g)) refs.push(parse2(match[1], scope, context));
|
|
539
|
+
return refs;
|
|
506
540
|
}
|
|
507
|
-
function interpolateBuilderReferences(value, scope, resolve) {
|
|
541
|
+
function interpolateBuilderReferences(value, scope, resolve, context) {
|
|
508
542
|
const sentinel = "\0DOLLAR\0";
|
|
509
|
-
return value.replace(/\$\$/g, sentinel).replace(/\$\{([^}]*)\}/g, (
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
543
|
+
return value.replace(/\$\$/g, sentinel).replace(/\$\{([^}]*)\}/g, (_whole, body) => {
|
|
544
|
+
const ref = parse2(body, scope, context);
|
|
545
|
+
return resolve(ref, context);
|
|
546
|
+
}).replaceAll(sentinel, "$");
|
|
547
|
+
}
|
|
548
|
+
function assertTesterReferencesArePublic(env, scope, baseContext) {
|
|
549
|
+
for (const [key, value] of Object.entries(env)) {
|
|
550
|
+
const context = { ...baseContext, configPath: `${baseContext.configPath}.${key}` };
|
|
551
|
+
for (const ref of collectBuilderReferences(value, scope, context)) {
|
|
552
|
+
if (!PUBLIC_ENDPOINT_PROPERTIES.has(ref.property)) {
|
|
553
|
+
throw new ConfigError({ ...context, referencedObject: ref.raw, value: ref.raw, reason: "Tester references may use only public endpoint properties" });
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
513
557
|
}
|
|
514
558
|
|
|
515
559
|
// src/errors/PortConflictError.ts
|
|
@@ -517,8 +561,8 @@ var PortConflictError = class extends ConfigError {
|
|
|
517
561
|
port;
|
|
518
562
|
firstOwner;
|
|
519
563
|
secondOwner;
|
|
520
|
-
constructor(port, firstOwner, secondOwner, stage) {
|
|
521
|
-
super({ sourceFile
|
|
564
|
+
constructor(port, firstOwner, secondOwner, stage, sourceFile = "Builder effective composition", composition) {
|
|
565
|
+
super({ sourceFile, configPath: secondOwner, value: port, stage, ...composition ? { composition } : {}, referencedObject: firstOwner, reason: `Host port ${port} is claimed by both ${firstOwner} and ${secondOwner}. Builder does not remap fixed public ports.` });
|
|
522
566
|
this.name = "PortConflictError";
|
|
523
567
|
this.port = port;
|
|
524
568
|
this.firstOwner = firstOwner;
|
|
@@ -532,11 +576,11 @@ function isHostPortAvailableSync(port) {
|
|
|
532
576
|
const result = spawnSync(process.execPath, ["-e", script], { stdio: "ignore", timeout: 3e3 });
|
|
533
577
|
return result.status === 0;
|
|
534
578
|
}
|
|
535
|
-
function allocateHostPorts(projectDir, stage, intentsInDeterministicOrder, validationMode = false) {
|
|
579
|
+
function allocateHostPorts(projectDir, stage, intentsInDeterministicOrder, validationMode = false, context) {
|
|
536
580
|
const reserved = /* @__PURE__ */ new Map(), allocated = /* @__PURE__ */ new Map();
|
|
537
581
|
for (const intent of intentsInDeterministicOrder) if (typeof intent.requested === "number") {
|
|
538
582
|
const owner = reserved.get(intent.requested);
|
|
539
|
-
if (owner) throw new PortConflictError(intent.requested, owner, intent.logicalPath, stage);
|
|
583
|
+
if (owner) throw new PortConflictError(intent.requested, owner, intent.logicalPath, stage, context?.sourceFile, context?.composition);
|
|
540
584
|
reserved.set(intent.requested, intent.logicalPath);
|
|
541
585
|
allocated.set(intent.logicalPath, intent.requested);
|
|
542
586
|
}
|
|
@@ -544,7 +588,7 @@ function allocateHostPorts(projectDir, stage, intentsInDeterministicOrder, valid
|
|
|
544
588
|
let placeholder = 6e4;
|
|
545
589
|
for (const intent of intentsInDeterministicOrder) if (intent.requested === "AUTO") {
|
|
546
590
|
while (reserved.has(placeholder)) placeholder--;
|
|
547
|
-
if (placeholder < 1) throw new ConfigError({ configPath: intent.logicalPath, stage, reason: "No validation placeholder port is available" });
|
|
591
|
+
if (placeholder < 1) throw new ConfigError({ ...context ?? {}, configPath: intent.logicalPath, stage, value: intent.requested, reason: "No validation placeholder port is available" });
|
|
548
592
|
reserved.set(placeholder, intent.logicalPath);
|
|
549
593
|
allocated.set(intent.logicalPath, placeholder--);
|
|
550
594
|
}
|
|
@@ -568,7 +612,7 @@ function allocateHostPorts(projectDir, stage, intentsInDeterministicOrder, valid
|
|
|
568
612
|
const scan = [...Array(65536 - AUTO_PORT_SCAN_START).keys()].map((i) => i + AUTO_PORT_SCAN_START).concat([...Array(19999 - 1024 + 1).keys()].map((i) => i + 1024));
|
|
569
613
|
selected = scan.find((p) => !reserved.has(p) && isHostPortAvailableSync(p));
|
|
570
614
|
}
|
|
571
|
-
if (selected === void 0) throw new ConfigError({ sourceFile: "Builder effective composition", configPath: intent.logicalPath, stage, reason: "No available host port could be allocated" });
|
|
615
|
+
if (selected === void 0) throw new ConfigError({ sourceFile: context?.sourceFile ?? "Builder effective composition", ...context?.composition ? { composition: context.composition } : {}, configPath: intent.logicalPath, stage, value: intent.requested, reason: "No available host port could be allocated" });
|
|
572
616
|
reserved.set(selected, intent.logicalPath);
|
|
573
617
|
allocated.set(intent.logicalPath, selected);
|
|
574
618
|
nextCache[intent.logicalPath] = selected;
|
|
@@ -581,6 +625,26 @@ function allocateHostPorts(projectDir, stage, intentsInDeterministicOrder, valid
|
|
|
581
625
|
}
|
|
582
626
|
return allocated;
|
|
583
627
|
}
|
|
628
|
+
var EXEC_MODE_KEY = "EXEC_MODE";
|
|
629
|
+
var INFRA_MODE_KEY = "INFRA_MODE";
|
|
630
|
+
var PORT_KEY = "PORT";
|
|
631
|
+
function assertNoBuilderOwnedEnvKeys(env, keys, context) {
|
|
632
|
+
for (const key of keys) {
|
|
633
|
+
if (!(key in env)) continue;
|
|
634
|
+
throw new ConfigError({ sourceFile: context.sourceFile, configPath: `${context.configPath}.${key}`, stage: context.stage, composition: context.composition, value: env[key], reason: `User-controlled environment cannot set Builder-owned key "${key}"` });
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
function assertDotenvDoesNotDefineKeys(filePath, keys, context) {
|
|
638
|
+
if (!fs.existsSync(filePath)) return;
|
|
639
|
+
const forbidden = new Set(keys), lines = fs.readFileSync(filePath, "utf8").split(/\r?\n/);
|
|
640
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
641
|
+
const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(lines[index]);
|
|
642
|
+
if (!match) continue;
|
|
643
|
+
const key = match[1];
|
|
644
|
+
if (!forbidden.has(key)) continue;
|
|
645
|
+
throw new ConfigError({ sourceFile: filePath, configPath: `${context.configPath}.${key}`, stage: context.stage, composition: context.composition, value: `line ${index + 1}`, reason: `Environment file cannot set Builder-owned key "${key}"` });
|
|
646
|
+
}
|
|
647
|
+
}
|
|
584
648
|
function normalizeProjectName(name, projectDir) {
|
|
585
649
|
let normalized = name.toLowerCase().replace(/[^a-z0-9_-]/g, "-").replace(/^[-_]+/, "").replace(/[-_]+$/, "");
|
|
586
650
|
if (!normalized || !/^[a-z0-9]/.test(normalized)) {
|
|
@@ -822,6 +886,20 @@ function assertNoServiceBuildContexts(service, configPath, sourceFile) {
|
|
|
822
886
|
}
|
|
823
887
|
}
|
|
824
888
|
|
|
889
|
+
// src/core/composition/namespaceResourceDefinition.ts
|
|
890
|
+
function namespaceResourceDefinition(originalKey, definition) {
|
|
891
|
+
if (definition === null || typeof definition !== "object" || Array.isArray(definition)) {
|
|
892
|
+
return definition;
|
|
893
|
+
}
|
|
894
|
+
const result = structuredClone(definition);
|
|
895
|
+
if (result.external === true) {
|
|
896
|
+
result.name ??= originalKey;
|
|
897
|
+
} else {
|
|
898
|
+
delete result.name;
|
|
899
|
+
}
|
|
900
|
+
return result;
|
|
901
|
+
}
|
|
902
|
+
|
|
825
903
|
// src/core/composition/namespaceDependencyCompose.ts
|
|
826
904
|
var entries = (obj) => obj && typeof obj === "object" && !Array.isArray(obj) ? Object.entries(obj) : [];
|
|
827
905
|
function namespaceDependencyCompose(options) {
|
|
@@ -835,6 +913,7 @@ function namespaceDependencyCompose(options) {
|
|
|
835
913
|
const serviceNameMap = make("service", Object.keys(doc.services ?? {}));
|
|
836
914
|
const volumeNameMap = make("volume", Object.keys(doc.volumes ?? {})), networkNameMap = make("network", Object.keys(doc.networks ?? {})), configNameMap = make("config", Object.keys(doc.configs ?? {})), secretNameMap = make("secret", Object.keys(doc.secrets ?? {}));
|
|
837
915
|
const rewriteKeys = (obj, map) => Object.fromEntries(entries(obj).map(([k, v]) => [map.get(k) ?? k, v]));
|
|
916
|
+
const rewriteResourceDefinitions = (obj, map) => Object.fromEntries(entries(obj).map(([key, definition]) => [map.get(key) ?? key, namespaceResourceDefinition(key, definition)]));
|
|
838
917
|
const addOriginalNetworkAliases = (name, svc) => {
|
|
839
918
|
if (svc.network_mode !== void 0 || svc.networks === void 0) return;
|
|
840
919
|
const attached = Array.isArray(svc.networks) ? Object.fromEntries(svc.networks.filter((network) => typeof network === "string").map((network) => [network, null])) : svc.networks && typeof svc.networks === "object" ? { ...svc.networks } : {};
|
|
@@ -870,16 +949,15 @@ function namespaceDependencyCompose(options) {
|
|
|
870
949
|
};
|
|
871
950
|
for (const [name, svc] of Object.entries(originalServices)) rewriteResourceRefs(svc, name);
|
|
872
951
|
doc.services = rewriteKeys(doc.services, serviceNameMap);
|
|
873
|
-
if (doc.volumes) doc.volumes =
|
|
874
|
-
if (doc.networks) doc.networks =
|
|
875
|
-
if (doc.configs) doc.configs =
|
|
876
|
-
if (doc.secrets) doc.secrets =
|
|
952
|
+
if (doc.volumes) doc.volumes = rewriteResourceDefinitions(doc.volumes, volumeNameMap);
|
|
953
|
+
if (doc.networks) doc.networks = rewriteResourceDefinitions(doc.networks, networkNameMap);
|
|
954
|
+
if (doc.configs) doc.configs = rewriteResourceDefinitions(doc.configs, configNameMap);
|
|
955
|
+
if (doc.secrets) doc.secrets = rewriteResourceDefinitions(doc.secrets, secretNameMap);
|
|
877
956
|
return { document: doc, serviceNameMap, volumeNameMap, networkNameMap, configNameMap, secretNameMap };
|
|
878
957
|
}
|
|
879
958
|
|
|
880
959
|
// src/core/composition/validateComposeResourceReferences.ts
|
|
881
960
|
function validateComposeResourceReferences(document, context, onlyServices) {
|
|
882
|
-
const selected = onlyServices ? new Set(onlyServices) : void 0;
|
|
883
961
|
const fail = (configPath, kind, name) => {
|
|
884
962
|
throw new ConfigError({
|
|
885
963
|
sourceFile: context.sourceFile,
|
|
@@ -894,12 +972,11 @@ function validateComposeResourceReferences(document, context, onlyServices) {
|
|
|
894
972
|
const definitions = document[kind === "volume" ? "volumes" : kind === "network" ? "networks" : kind === "config" ? "configs" : "secrets"];
|
|
895
973
|
return Boolean(definitions && Object.hasOwn(definitions, name));
|
|
896
974
|
};
|
|
897
|
-
const check = (
|
|
975
|
+
const check = (path22, kind, name) => {
|
|
898
976
|
if (kind === "network" && name === "default") return;
|
|
899
|
-
if (!exists(kind, name)) fail(
|
|
977
|
+
if (!exists(kind, name)) fail(path22, kind, name);
|
|
900
978
|
};
|
|
901
979
|
for (const [serviceName, service] of Object.entries(document.services ?? {})) {
|
|
902
|
-
if (selected && !selected.has(serviceName)) continue;
|
|
903
980
|
validateServiceResources(serviceName, service, check);
|
|
904
981
|
}
|
|
905
982
|
}
|
|
@@ -928,6 +1005,21 @@ function validateServiceResources(serviceName, service, check) {
|
|
|
928
1005
|
}
|
|
929
1006
|
}
|
|
930
1007
|
|
|
1008
|
+
// src/core/composition/assertComposeLifecycleAcyclic.ts
|
|
1009
|
+
function assertComposeLifecycleAcyclic(services, context) {
|
|
1010
|
+
const graph = new Map(
|
|
1011
|
+
Object.keys(services).map((name) => [name, /* @__PURE__ */ new Set()])
|
|
1012
|
+
);
|
|
1013
|
+
for (const [name, service] of Object.entries(services)) {
|
|
1014
|
+
const value = service.depends_on;
|
|
1015
|
+
const targets = Array.isArray(value) ? value.filter((item) => typeof item === "string") : value && typeof value === "object" ? Object.keys(value) : [];
|
|
1016
|
+
for (const target of targets) {
|
|
1017
|
+
if (graph.has(target)) graph.get(name).add(target);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
assertAcyclicGraph(graph, context);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
931
1023
|
// src/core/composition/composeHealthcheck.ts
|
|
932
1024
|
function isEnabledValidComposeHealthcheck(value) {
|
|
933
1025
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
@@ -976,6 +1068,11 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
|
|
|
976
1068
|
for (const key of ["ipc", "pid"]) if (typeof svc[key] === "string" && svc[key].startsWith("service:")) internalRefs.push([key, svc[key].slice(8)]);
|
|
977
1069
|
for (const [property, target] of internalRefs) if (!services[target]) fail(`services.${name}.${property}`, `internal service reference "${target}" does not exist in this dependency Compose bundle`, target);
|
|
978
1070
|
}
|
|
1071
|
+
assertComposeLifecycleAcyclic(services, {
|
|
1072
|
+
sourceFile: context.composePath,
|
|
1073
|
+
stage: context.stage,
|
|
1074
|
+
composition: "service"
|
|
1075
|
+
});
|
|
979
1076
|
if (!Object.keys(dependency.endpoints).length) return;
|
|
980
1077
|
if (!Object.keys(services).length) fail("services", "endpoint-bearing dependency Compose must define services");
|
|
981
1078
|
const owners = /* @__PURE__ */ new Set();
|
|
@@ -996,18 +1093,40 @@ function isSameBuildContext(actual, expected, baseDir) {
|
|
|
996
1093
|
return canonicalBuildContext(actual, baseDir) === canonicalBuildContext(expected, baseDir);
|
|
997
1094
|
}
|
|
998
1095
|
function validateAndPrepareAppOverride(document, context) {
|
|
999
|
-
const fail = (
|
|
1000
|
-
throw new ConfigError({ sourceFile: context.file, configPath:
|
|
1096
|
+
const fail = (path22, reason, value) => {
|
|
1097
|
+
throw new ConfigError({ sourceFile: context.file, configPath: path22, stage: context.stage, composition: "service", ...value === void 0 ? {} : { value }, reason });
|
|
1001
1098
|
};
|
|
1002
1099
|
const allowedRootKeys = /* @__PURE__ */ new Set(["services", "volumes", "networks", "configs", "secrets"]);
|
|
1003
1100
|
for (const key of Object.keys(document)) if (!key.startsWith("x-") && !allowedRootKeys.has(key)) fail(key, "unsupported override Compose top-level field");
|
|
1004
1101
|
const keys = Object.keys(document.services ?? {});
|
|
1005
1102
|
if (keys.length !== 1 || keys[0] !== "app") fail("services", "override must define exactly one service named app");
|
|
1103
|
+
validateComposeResourceReferences(document, { sourceFile: context.file, stage: context.stage, composition: "service" });
|
|
1006
1104
|
const app = structuredClone(document.services.app);
|
|
1007
1105
|
for (const k of ["ports", "depends_on", "network_mode", "container_name", "privileged", "profiles", "extends", "env_file"]) if (app[k] !== void 0) fail(`services.app.${k}`, "override cannot own endpoint or lifecycle behavior");
|
|
1008
|
-
if (
|
|
1009
|
-
const
|
|
1010
|
-
|
|
1106
|
+
if (Object.hasOwn(app, "healthcheck")) {
|
|
1107
|
+
const healthcheck = app.healthcheck;
|
|
1108
|
+
if (healthcheck === null || typeof healthcheck !== "object" || Array.isArray(healthcheck)) {
|
|
1109
|
+
fail(
|
|
1110
|
+
"services.app.healthcheck",
|
|
1111
|
+
"override healthcheck must be a mapping of timing fields",
|
|
1112
|
+
healthcheck
|
|
1113
|
+
);
|
|
1114
|
+
}
|
|
1115
|
+
const allowedTiming = /* @__PURE__ */ new Set([
|
|
1116
|
+
"interval",
|
|
1117
|
+
"timeout",
|
|
1118
|
+
"retries",
|
|
1119
|
+
"start_period",
|
|
1120
|
+
"start_interval"
|
|
1121
|
+
]);
|
|
1122
|
+
for (const key of Object.keys(healthcheck)) {
|
|
1123
|
+
if (!allowedTiming.has(key)) {
|
|
1124
|
+
fail(
|
|
1125
|
+
`services.app.healthcheck.${key}`,
|
|
1126
|
+
"override may set only healthcheck timing fields"
|
|
1127
|
+
);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1011
1130
|
}
|
|
1012
1131
|
if (typeof app.build === "string") {
|
|
1013
1132
|
fail("services.app.build", "override cannot replace Builder-owned app build context; use object-form build.args for build arguments", app.build);
|
|
@@ -1035,22 +1154,22 @@ function validateAndPrepareAppOverride(document, context) {
|
|
|
1035
1154
|
const resourceKeys = ["volumes", "networks", "configs", "secrets"];
|
|
1036
1155
|
const resources = {};
|
|
1037
1156
|
for (const kind of resourceKeys) {
|
|
1038
|
-
const defs = document[kind] ?? {},
|
|
1157
|
+
const defs = document[kind] ?? {}, refs = /* @__PURE__ */ new Set(), value = app[kind];
|
|
1039
1158
|
if (Array.isArray(value)) for (const ref of value) {
|
|
1040
1159
|
if (kind === "volumes") {
|
|
1041
1160
|
const volume = parseVolume(ref);
|
|
1042
|
-
if (volume?.type === "volume" && volume.source)
|
|
1043
|
-
} else if (typeof ref === "string")
|
|
1044
|
-
else if (ref && typeof ref === "object" && typeof ref.source === "string")
|
|
1161
|
+
if (volume?.type === "volume" && volume.source) refs.add(volume.source);
|
|
1162
|
+
} else if (typeof ref === "string") refs.add(ref);
|
|
1163
|
+
else if (ref && typeof ref === "object" && typeof ref.source === "string") refs.add(ref.source);
|
|
1045
1164
|
}
|
|
1046
|
-
else if (value && typeof value === "object") for (const name of Object.keys(value))
|
|
1165
|
+
else if (value && typeof value === "object") for (const name of Object.keys(value)) refs.add(name);
|
|
1047
1166
|
const names = /* @__PURE__ */ new Map(), mapped = {};
|
|
1048
1167
|
for (const [name, definition] of Object.entries(defs)) {
|
|
1049
|
-
if (!
|
|
1168
|
+
if (!refs.has(name)) fail(`${kind}.${name}`, "override resource must be consumed by app");
|
|
1050
1169
|
const prefix = context.resourceNamespace && context.resourceNamespace !== "app" ? `svc--${context.resourceNamespace}--app-override` : "app-override";
|
|
1051
1170
|
const target = allocator.allocate(JSON.stringify(["service", context.resourceNamespace ?? "app", "override", context.stage, kind, name]), `${prefix}--${context.stage}--${kind.slice(0, -1)}--${name}`);
|
|
1052
1171
|
names.set(name, target);
|
|
1053
|
-
mapped[target] = definition;
|
|
1172
|
+
mapped[target] = namespaceResourceDefinition(name, definition);
|
|
1054
1173
|
}
|
|
1055
1174
|
if (names.size) resources[kind] = mapped;
|
|
1056
1175
|
if (Array.isArray(value)) app[kind] = value.map((ref) => kind === "volumes" ? namespaceVolume(ref, names) : typeof ref === "string" ? names.get(ref) ?? ref : ref && typeof ref === "object" && typeof ref.source === "string" ? { ...ref, source: names.get(ref.source) ?? ref.source } : ref);
|
|
@@ -1059,6 +1178,26 @@ function validateAndPrepareAppOverride(document, context) {
|
|
|
1059
1178
|
return { app, resources };
|
|
1060
1179
|
}
|
|
1061
1180
|
|
|
1181
|
+
// src/core/composition/mergeAppOverride.ts
|
|
1182
|
+
function isMap(value) {
|
|
1183
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1184
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1185
|
+
return prototype === Object.prototype || prototype === null;
|
|
1186
|
+
}
|
|
1187
|
+
function mergeValue(inherited, overlay) {
|
|
1188
|
+
if (overlay === void 0) return structuredClone(inherited);
|
|
1189
|
+
if (!isMap(inherited) || !isMap(overlay)) return structuredClone(overlay);
|
|
1190
|
+
return Object.fromEntries(
|
|
1191
|
+
[.../* @__PURE__ */ new Set([...Object.keys(inherited), ...Object.keys(overlay)])].map((key) => [
|
|
1192
|
+
key,
|
|
1193
|
+
Object.hasOwn(overlay, key) ? mergeValue(inherited[key], overlay[key]) : structuredClone(inherited[key])
|
|
1194
|
+
])
|
|
1195
|
+
);
|
|
1196
|
+
}
|
|
1197
|
+
function mergeAppOverride(inherited, overlay) {
|
|
1198
|
+
return mergeValue(inherited, overlay);
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1062
1201
|
// src/core/composition/dependencyLifecycle.ts
|
|
1063
1202
|
function asMap(value) {
|
|
1064
1203
|
if (Array.isArray(value)) return Object.fromEntries(value.filter((v) => typeof v === "string").map((v) => [v, {}]));
|
|
@@ -1113,13 +1252,13 @@ function buildStandaloneDependencyEndpoints(key, build, serviceNames, materializ
|
|
|
1113
1252
|
function getExecutionProfile(stage, full) {
|
|
1114
1253
|
switch (stage) {
|
|
1115
1254
|
case "dev":
|
|
1116
|
-
return { configStage: "dev", appTarget: "dev",
|
|
1255
|
+
return { configStage: "dev", envStage: "dev", appTarget: "dev", execMode: "dev", infraMode: full ? "integrated" : "isolated", attachTester: false };
|
|
1117
1256
|
case "prod":
|
|
1118
|
-
return { configStage: "prod", appTarget: "prod",
|
|
1257
|
+
return { configStage: "prod", envStage: "prod", appTarget: "prod", execMode: "prod", infraMode: "integrated", attachTester: false };
|
|
1119
1258
|
case "test":
|
|
1120
|
-
return { configStage: "test", appTarget: "test",
|
|
1259
|
+
return { configStage: "test", envStage: "test", appTarget: "test", execMode: "test", infraMode: "isolated", attachTester: false };
|
|
1121
1260
|
case "e2e":
|
|
1122
|
-
return { configStage: "e2e", appTarget: "prod",
|
|
1261
|
+
return { configStage: "e2e", envStage: "e2e", appTarget: "prod", execMode: "prod", infraMode: "integrated", attachTester: true, testerTarget: "test-e2e" };
|
|
1123
1262
|
}
|
|
1124
1263
|
}
|
|
1125
1264
|
function mergeDocument(target, source, context) {
|
|
@@ -1128,7 +1267,7 @@ function mergeDocument(target, source, context) {
|
|
|
1128
1267
|
if (!src) continue;
|
|
1129
1268
|
const dst = target[section] ??= {};
|
|
1130
1269
|
for (const [key, value] of Object.entries(src)) {
|
|
1131
|
-
if (key in dst) throw new ConfigError({ configPath: `${section}.${key}`,
|
|
1270
|
+
if (key in dst) throw new ConfigError({ ...context, configPath: `${context.configPath}.${section}.${key}`, value: key, reason: "Internal Compose namespace collision" });
|
|
1132
1271
|
dst[key] = value;
|
|
1133
1272
|
}
|
|
1134
1273
|
}
|
|
@@ -1142,24 +1281,22 @@ function getTemplateSeed(stage, meshMode) {
|
|
|
1142
1281
|
if (meshMode) delete merged.services.tester;
|
|
1143
1282
|
return merged;
|
|
1144
1283
|
}
|
|
1145
|
-
function
|
|
1146
|
-
const env = { ...build.app.env };
|
|
1147
|
-
const reserved = ["EXEC_MODE", "INFRA_MODE", ...getPrimaryEndpoint(build.app.endpoints) ? ["PORT"] : []];
|
|
1148
|
-
for (const key of reserved) if (key in env) throw new ConfigError({ sourceFile: "build.json", configPath: "app.env", stage, composition: "service", value: key, reason: "Application env cannot set a Builder-owned key" });
|
|
1149
|
-
return env;
|
|
1150
|
-
}
|
|
1151
|
-
function resolveEnv(input, registry, source) {
|
|
1284
|
+
function resolveEnv(input, registry, baseContext) {
|
|
1152
1285
|
const out = {};
|
|
1153
1286
|
for (const [key, value] of Object.entries(input)) {
|
|
1154
|
-
|
|
1155
|
-
|
|
1287
|
+
if (value === null) {
|
|
1288
|
+
out[key] = null;
|
|
1289
|
+
continue;
|
|
1290
|
+
}
|
|
1291
|
+
const context = { ...baseContext, configPath: `${baseContext.configPath}.${key}` };
|
|
1292
|
+
out[key] = interpolateBuilderReferences(value, "build", registry, context).replace(/\$/g, "$$$$");
|
|
1156
1293
|
}
|
|
1157
1294
|
return out;
|
|
1158
1295
|
}
|
|
1159
|
-
function addPorts(service, endpointPairs) {
|
|
1296
|
+
function addPorts(service, endpointPairs, sourceFile, stage) {
|
|
1160
1297
|
for (const [ep, hostPort] of endpointPairs) {
|
|
1161
1298
|
const ports = Array.isArray(service.ports) ? service.ports : [];
|
|
1162
|
-
if (ports.some((p) => p && typeof p === "object" && p.published === hostPort)) throw new ConfigError({ configPath: ep.logicalPath, stage: "service", value: hostPort, reason: "Duplicate host port publication" });
|
|
1299
|
+
if (ports.some((p) => p && typeof p === "object" && p.published === hostPort)) throw new ConfigError({ sourceFile, configPath: ep.logicalPath, stage, composition: "service", referencedObject: ep.logicalPath, value: hostPort, reason: "Duplicate host port publication" });
|
|
1163
1300
|
ports.push({ target: ep.networkPort, published: hostPort, host_ip: PUBLIC_HOST, protocol: "tcp" });
|
|
1164
1301
|
service.ports = ports;
|
|
1165
1302
|
}
|
|
@@ -1184,11 +1321,11 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
1184
1321
|
const materialized = {};
|
|
1185
1322
|
const compose = { ...seed, ...options.meshMode ? {} : { name: projectName }, services: { ...seed.services } };
|
|
1186
1323
|
let app = compose.services.app ?? (compose.services.app = { build: { context: "." } });
|
|
1187
|
-
if (profile.integrated) for (const [key, entry] of Object.entries(namespaced)) {
|
|
1324
|
+
if (profile.infraMode === "integrated") for (const [key, entry] of Object.entries(namespaced)) {
|
|
1188
1325
|
if (options.suppressDependencies?.has(key)) continue;
|
|
1189
1326
|
const dep = effective.dependencies[key];
|
|
1190
1327
|
const item = structuredClone(entry.doc);
|
|
1191
|
-
mergeDocument(compose, item, `
|
|
1328
|
+
mergeDocument(compose, item, { sourceFile: entry.source, configPath: `dependencies.${key}.compose`, stage, composition: "service" });
|
|
1192
1329
|
const endpointOwnerMap = /* @__PURE__ */ new Map();
|
|
1193
1330
|
for (const [epName, ep] of Object.entries(dep.endpoints)) endpointOwnerMap.set(epName, entry.map.get(ep.service));
|
|
1194
1331
|
const endpointOwners = new Set(endpointOwnerMap.values());
|
|
@@ -1216,7 +1353,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
1216
1353
|
for (const [name, e] of Object.entries(dep.endpoints).sort(([a], [b]) => a.localeCompare(b))) if (e.publicPort !== void 0) intents.push({ logicalPath: `dependencies.${key}.endpoints.${name}`, requested: e.publicPort });
|
|
1217
1354
|
}
|
|
1218
1355
|
}
|
|
1219
|
-
const allocation = allocateHostPorts(root, stage, intents, Boolean(options.validationMode));
|
|
1356
|
+
const allocation = allocateHostPorts(root, stage, intents, Boolean(options.validationMode), { sourceFile: buildPath, composition: "service" });
|
|
1220
1357
|
for (const [name, ep] of Object.entries(appEndpoints)) if (allocation.has(ep.logicalPath)) {
|
|
1221
1358
|
ep.publicHost = PUBLIC_HOST;
|
|
1222
1359
|
ep.publicPort = allocation.get(ep.logicalPath);
|
|
@@ -1227,32 +1364,49 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
1227
1364
|
ep.publicPort = allocation.get(ep.logicalPath);
|
|
1228
1365
|
ep.effectivelyPublished = true;
|
|
1229
1366
|
}
|
|
1230
|
-
const registry = (ref) => {
|
|
1367
|
+
const registry = (ref, context) => {
|
|
1231
1368
|
if (ref.target === "app") {
|
|
1232
1369
|
const ep2 = appEndpoints[ref.endpoint];
|
|
1233
|
-
if (!ep2) throw new ConfigError({
|
|
1234
|
-
return resolveEndpointProperty(ep2, ref.property, {
|
|
1370
|
+
if (!ep2) throw new ConfigError({ ...context, referencedObject: ref.raw, reason: "Unknown app endpoint reference" });
|
|
1371
|
+
return resolveEndpointProperty(ep2, ref.property, { ...context, referencedObject: ref.raw });
|
|
1235
1372
|
}
|
|
1236
1373
|
const ep = depEndpoints[ref.dependency]?.[ref.endpoint];
|
|
1237
|
-
if (!ep) throw new ConfigError({
|
|
1238
|
-
return resolveEndpointProperty(ep, ref.property, {
|
|
1374
|
+
if (!ep) throw new ConfigError({ ...context, referencedObject: ref.raw, reason: "Unknown dependency endpoint reference" });
|
|
1375
|
+
return resolveEndpointProperty(ep, ref.property, { ...context, referencedObject: ref.raw });
|
|
1239
1376
|
};
|
|
1240
1377
|
for (const [key, dep] of Object.entries(effective.dependencies)) {
|
|
1241
|
-
const depEnv = options.deferReferenceResolution ? dep.env : resolveEnv(dep.env, registry, `dependencies.${key}.env
|
|
1378
|
+
const depEnv = options.deferReferenceResolution ? dep.env : resolveEnv(dep.env, registry, { sourceFile: buildPath, configPath: `dependencies.${key}.env`, stage, composition: "service" });
|
|
1242
1379
|
for (const svc of Object.values(materialized[key]?.compose.services ?? {})) mergeComposeEnvironment(svc, depEnv);
|
|
1243
1380
|
}
|
|
1244
|
-
const
|
|
1245
|
-
const
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1381
|
+
const appEnvironmentLayers = [];
|
|
1382
|
+
for (const layer of effective.layers) {
|
|
1383
|
+
if (Object.keys(layer.appEnv).length) {
|
|
1384
|
+
const configPath = layer.stage === "base" ? "app.env" : `${layer.stage}.app.env`;
|
|
1385
|
+
assertNoBuilderOwnedEnvKeys(layer.appEnv, [EXEC_MODE_KEY, INFRA_MODE_KEY, ...getPrimaryEndpoint(effective.app.endpoints) ? [PORT_KEY] : []], { sourceFile: buildPath, configPath, stage, composition: "service" });
|
|
1386
|
+
appEnvironmentLayers.push({ kind: "build-json", stage: layer.stage, configPath, values: { ...layer.appEnv } });
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
const resolveAppLayers = () => {
|
|
1390
|
+
const result = {};
|
|
1391
|
+
const laterKeys = new Set(Object.keys(options.externalAppEnv ?? {}));
|
|
1392
|
+
for (const [key, layer] of selectAppEnvironmentEntries(appEnvironmentLayers, laterKeys)) {
|
|
1393
|
+
if (layer.kind === "build-json") {
|
|
1394
|
+
const context = {
|
|
1395
|
+
sourceFile: buildPath,
|
|
1396
|
+
configPath: layer.configPath,
|
|
1397
|
+
stage,
|
|
1398
|
+
composition: "service"
|
|
1399
|
+
};
|
|
1400
|
+
result[key] = resolveEnv({ [key]: layer.values[key] }, registry, context)[key];
|
|
1401
|
+
} else {
|
|
1402
|
+
result[key] = layer.values[key];
|
|
1403
|
+
}
|
|
1253
1404
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1405
|
+
return result;
|
|
1406
|
+
};
|
|
1407
|
+
const runtimeDotenv = path.join(root, `.env.${profile.envStage}`);
|
|
1408
|
+
assertDotenvDoesNotDefineKeys(runtimeDotenv, [EXEC_MODE_KEY, INFRA_MODE_KEY, ...getPrimaryEndpoint(effective.app.endpoints) ? [PORT_KEY] : []], { configPath: `.env.${profile.envStage}`, stage, composition: "service" });
|
|
1409
|
+
const internal = { EXEC_MODE: profile.execMode, INFRA_MODE: profile.infraMode, ...getPrimaryEndpoint(effective.app.endpoints) ? { PORT: String(getPrimaryEndpoint(effective.app.endpoints)[1].port) } : {} };
|
|
1256
1410
|
const appBuild = app.build && typeof app.build === "object" ? app.build : { context: "." };
|
|
1257
1411
|
const outputDir = options.composeOutputDir ? path.resolve(options.composeOutputDir) : root;
|
|
1258
1412
|
const serviceContext = path.relative(outputDir, root).replace(/\\/g, "/") || ".";
|
|
@@ -1261,14 +1415,14 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
1261
1415
|
else delete appBuild.dockerfile;
|
|
1262
1416
|
appBuild.target = profile.appTarget;
|
|
1263
1417
|
app.build = appBuild;
|
|
1264
|
-
app.env_file = [{ path: options.meshMode ? path.posix.join(serviceContext, `.env.${profile.
|
|
1265
|
-
app.environment = { ...
|
|
1418
|
+
app.env_file = [{ path: options.meshMode ? path.posix.join(serviceContext, `.env.${profile.envStage}`) : `.env.${profile.envStage}`, required: false }];
|
|
1419
|
+
app.environment = { ...options.externalAppEnv ? Object.fromEntries(Object.entries(options.externalAppEnv).map(([k, v]) => [k, v.replace(/\$/g, "$$$$")])) : {}, ...internal };
|
|
1266
1420
|
if (stage === "dev") app.volumes = [`${options.meshMode && serviceContext !== "." ? `./${serviceContext}` : "."}:/app`, "/app/node_modules"];
|
|
1267
|
-
for (const [name, ep] of Object.entries(appEndpoints)) if (!options.meshMode && ep.effectivelyPublished) addPorts(app, [[ep, ep.publicPort]]);
|
|
1421
|
+
for (const [name, ep] of Object.entries(appEndpoints)) if (!options.meshMode && ep.effectivelyPublished) addPorts(app, [[ep, ep.publicPort]], buildPath, stage);
|
|
1268
1422
|
for (const [key, dependency] of Object.entries(materialized)) {
|
|
1269
1423
|
for (const [epName, owner] of dependency.endpointOwnerMap.entries()) {
|
|
1270
1424
|
const endpoint = depEndpoints[key][epName];
|
|
1271
|
-
if (!options.meshMode && endpoint.effectivelyPublished) addPorts(compose.services[owner], [[endpoint, endpoint.publicPort]]);
|
|
1425
|
+
if (!options.meshMode && endpoint.effectivelyPublished) addPorts(compose.services[owner], [[endpoint, endpoint.publicPort]], dependency.composePath, stage);
|
|
1272
1426
|
}
|
|
1273
1427
|
for (const owner of dependency.endpointOwners) {
|
|
1274
1428
|
const svc = compose.services[owner];
|
|
@@ -1281,36 +1435,47 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
1281
1435
|
}
|
|
1282
1436
|
for (const [epName, ep] of Object.entries(depEndpoints[key])) dependency.endpoints[epName] = ep;
|
|
1283
1437
|
}
|
|
1284
|
-
|
|
1285
|
-
|
|
1438
|
+
for (const layer of effective.layers) {
|
|
1439
|
+
if (!layer.overrideCompose) continue;
|
|
1440
|
+
const overridePath = resolveInsideProject(root, layer.overrideCompose, {
|
|
1286
1441
|
sourceFile: buildPath,
|
|
1287
|
-
configPath:
|
|
1442
|
+
configPath: `${layer.stage}.override-compose`,
|
|
1288
1443
|
stage
|
|
1289
1444
|
});
|
|
1290
1445
|
const loadedOverride = loadComposeDocument(overridePath, {
|
|
1291
1446
|
sourceFile: buildPath,
|
|
1292
|
-
configPath:
|
|
1447
|
+
configPath: `${layer.stage}.override-compose`,
|
|
1293
1448
|
stage,
|
|
1294
1449
|
composition: "service"
|
|
1295
1450
|
});
|
|
1296
1451
|
const overrideDocument = rebaseAppOverridePaths(loadedOverride, root, outputDir);
|
|
1297
1452
|
const prepared = validateAndPrepareAppOverride(overrideDocument, {
|
|
1298
1453
|
file: overridePath,
|
|
1299
|
-
stage,
|
|
1454
|
+
stage: layer.stage === "base" ? stage : layer.stage,
|
|
1300
1455
|
expectedBuildContext: String(appBuild.context),
|
|
1301
1456
|
buildContextBaseDir: outputDir,
|
|
1302
1457
|
allocator: nameAllocator,
|
|
1303
1458
|
resourceNamespace: options.meshMode ? options.appServiceName ?? "app" : "app"
|
|
1304
1459
|
});
|
|
1305
|
-
for (const section of ["volumes", "networks", "configs", "secrets"]) if (prepared.resources[section]) mergeDocument(compose, { services: {}, [section]: prepared.resources[section] },
|
|
1306
|
-
const rawOverrideEnv = normalizeComposeEnvironment(prepared.app.environment,
|
|
1460
|
+
for (const section of ["volumes", "networks", "configs", "secrets"]) if (prepared.resources[section]) mergeDocument(compose, { services: {}, [section]: prepared.resources[section] }, { sourceFile: overridePath, configPath: `${layer.stage}.override-compose`, stage, composition: "service" });
|
|
1461
|
+
const rawOverrideEnv = normalizeComposeEnvironment(prepared.app.environment, `${layer.stage}.override-compose.services.app.environment`);
|
|
1307
1462
|
const overrideEnv = rawOverrideEnv;
|
|
1308
1463
|
if (getPrimaryEndpoint(effective.app.endpoints) && "PORT" in overrideEnv) throw new ConfigError({ sourceFile: overridePath, configPath: "services.app.environment.PORT", stage, composition: "service", reason: "Override cannot set Builder-owned PORT" });
|
|
1309
|
-
|
|
1310
|
-
const
|
|
1311
|
-
|
|
1464
|
+
const overrideStage = layer.stage === "base" ? stage : layer.stage;
|
|
1465
|
+
const stageOrder = { base: 0, dev: 1, prod: 1, test: 1, e2e: 2 };
|
|
1466
|
+
let insertAt = appEnvironmentLayers.findIndex((item) => (stageOrder[item.stage] ?? 0) > (stageOrder[overrideStage] ?? 0));
|
|
1467
|
+
if (insertAt < 0) insertAt = appEnvironmentLayers.length;
|
|
1468
|
+
appEnvironmentLayers.splice(insertAt, 0, { kind: "override-compose", stage: overrideStage, sourceFile: overridePath, configPath: `${layer.stage}.override-compose.services.app.environment`, values: overrideEnv });
|
|
1469
|
+
const preparedApp = { ...prepared.app };
|
|
1470
|
+
delete preparedApp.environment;
|
|
1471
|
+
delete preparedApp.build;
|
|
1472
|
+
const merged = mergeAppOverride(app, preparedApp);
|
|
1473
|
+
merged.environment = { ...app.environment, ...options.externalAppEnv ? Object.fromEntries(Object.entries(options.externalAppEnv).map(([k, v]) => [k, v.replace(/\$/g, "$$$$")])) : {}, ...internal };
|
|
1312
1474
|
const overrideBuild = prepared.app.build && typeof prepared.app.build === "object" ? prepared.app.build : {};
|
|
1313
|
-
if (overrideBuild.args !== void 0)
|
|
1475
|
+
if (overrideBuild.args !== void 0) {
|
|
1476
|
+
const current = appBuild.args, incoming = overrideBuild.args;
|
|
1477
|
+
appBuild.args = current && incoming && typeof current === "object" && typeof incoming === "object" && !Array.isArray(current) && !Array.isArray(incoming) ? { ...current, ...incoming } : incoming;
|
|
1478
|
+
}
|
|
1314
1479
|
merged.build = appBuild;
|
|
1315
1480
|
merged.env_file = app.env_file;
|
|
1316
1481
|
merged.depends_on = app.depends_on;
|
|
@@ -1318,19 +1483,27 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
1318
1483
|
compose.services.app = merged;
|
|
1319
1484
|
app = merged;
|
|
1320
1485
|
}
|
|
1486
|
+
if (!options.deferReferenceResolution) {
|
|
1487
|
+
const finalEnv = resolveAppLayers();
|
|
1488
|
+
app.environment = { ...finalEnv, ...options.externalAppEnv ? Object.fromEntries(Object.entries(options.externalAppEnv).map(([k, v]) => [k, v.replace(/\$/g, "$$$$")])) : {}, ...internal };
|
|
1489
|
+
}
|
|
1321
1490
|
if (options.meshMode && options.appServiceName && options.appServiceName !== "app") {
|
|
1322
1491
|
delete compose.services.app;
|
|
1323
1492
|
compose.services[options.appServiceName] = app;
|
|
1324
1493
|
}
|
|
1325
|
-
if (profile.integrated) applyDependencyLifecycle(app, materialized, effective);
|
|
1494
|
+
if (profile.infraMode === "integrated") applyDependencyLifecycle(app, materialized, effective);
|
|
1326
1495
|
if (profile.attachTester && !options.meshMode) {
|
|
1496
|
+
const testerDotenvPath = path.join(root, ".env.e2e-tester"), testerBuilderKeys = [EXEC_MODE_KEY, INFRA_MODE_KEY];
|
|
1497
|
+
assertDotenvDoesNotDefineKeys(testerDotenvPath, testerBuilderKeys, { configPath: ".env.e2e-tester", stage: "e2e", composition: "service" });
|
|
1327
1498
|
const testerEnvRaw = effective.tester?.env ?? {};
|
|
1328
|
-
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1499
|
+
assertNoBuilderOwnedEnvKeys(testerEnvRaw, testerBuilderKeys, { sourceFile: buildPath, configPath: "tester.env", stage: "e2e", composition: "service" });
|
|
1500
|
+
const testerContext = { sourceFile: buildPath, configPath: "tester.env", stage: "e2e", composition: "service" };
|
|
1501
|
+
assertTesterReferencesArePublic(testerEnvRaw, "build", testerContext);
|
|
1502
|
+
const testerEnv = options.deferReferenceResolution ? testerEnvRaw : resolveEnv(testerEnvRaw, registry, testerContext);
|
|
1503
|
+
compose.services.tester = { build: { context: ".", ...raw.dockerfile ? { dockerfile: raw.dockerfile } : {}, target: profile.testerTarget ?? "test-e2e" }, network_mode: "host", env_file: [{ path: ".env.e2e-tester", required: false }], environment: { ...testerEnv, EXEC_MODE: "e2e" }, depends_on: { app: { condition: "service_healthy" } } };
|
|
1331
1504
|
}
|
|
1332
1505
|
nameAllocator.assertUnique();
|
|
1333
|
-
return { compose, effectiveBuild: effective, endpoints: { app: appEndpoints, dependencies: depEndpoints }, projectName, ...profile.attachTester && !options.meshMode ? { testerServiceName: "tester" } : {},
|
|
1506
|
+
return { compose, effectiveBuild: effective, endpoints: { app: appEndpoints, dependencies: depEndpoints }, projectName, ...profile.attachTester && !options.meshMode ? { testerServiceName: "tester" } : {}, appEnvironmentLayers, builderInternalEnvironment: { ...internal }, externalAppEnvironment: { ...options.externalAppEnv ?? {} }, dependencyServiceNames: Object.fromEntries(Object.entries(materialized).map(([key, dep]) => [key, [...dep.serviceNames]])), dependencyEnvironments: Object.fromEntries(Object.entries(effective.dependencies).map(([key, dep]) => [key, dep.env])) };
|
|
1334
1507
|
}
|
|
1335
1508
|
|
|
1336
1509
|
// src/core/checkers/checkEffectiveServiceStages.ts
|
|
@@ -1350,7 +1523,7 @@ function checkInfra(projectDir = process.cwd()) {
|
|
|
1350
1523
|
checkDockerfileContract(buildJson, absProjectDir);
|
|
1351
1524
|
checkYamlFiles(buildJson, absProjectDir);
|
|
1352
1525
|
checkAllEffectiveServiceStages(absProjectDir);
|
|
1353
|
-
console.log(
|
|
1526
|
+
console.log(pc14.green("\n\u2705 All V2 service infrastructure and contract checks passed.\n"));
|
|
1354
1527
|
}
|
|
1355
1528
|
function checkComposeAvailability() {
|
|
1356
1529
|
const composeCheck = spawnSync(
|
|
@@ -1395,7 +1568,7 @@ function checkDependencies() {
|
|
|
1395
1568
|
const count = (networkCheck.stdout || "").trim().split("\n").filter(Boolean).length;
|
|
1396
1569
|
if (count > 25) {
|
|
1397
1570
|
console.warn(
|
|
1398
|
-
|
|
1571
|
+
pc14.yellow(
|
|
1399
1572
|
`
|
|
1400
1573
|
\u26A0\uFE0F High Docker Network Count Warning: Detected ${count} networks. Docker's default address pool can become exhausted, resulting in "could not find an available, non-overlapping IPv4 address pool" errors.
|
|
1401
1574
|
To resolve, run "builder prune" or "docker network prune -f", or configure default-address-pools in /etc/docker/daemon.json.
|
|
@@ -1440,7 +1613,8 @@ var envSchema2 = z.record(z.string(), z.string());
|
|
|
1440
1613
|
var meshServiceSchema = z.object({ path: z.string().min(1), env: envSchema2.optional(), dependencies: z.record(identifierSchema2, serviceNameSchema).optional(), dependsOn: z.array(serviceNameSchema).optional(), publish: z.array(z.string()).optional() }).strict();
|
|
1441
1614
|
var meshServiceStageOverlaySchema = z.object({ path: z.string().min(1).optional(), env: envSchema2.optional(), dependencies: z.record(identifierSchema2, serviceNameSchema).optional(), dependsOn: z.array(serviceNameSchema).optional(), publish: z.array(z.string()).optional() }).strict();
|
|
1442
1615
|
var meshStageSchema = z.object({ services: z.record(serviceNameSchema, meshServiceStageOverlaySchema).optional() }).strict();
|
|
1443
|
-
var
|
|
1616
|
+
var rootServicesSchema = z.record(serviceNameSchema, meshServiceSchema).refine((services) => Object.keys(services).length >= 1, { message: "must contain at least one root service" });
|
|
1617
|
+
var meshSchema = z.object({ $schema: z.string().optional(), name: z.string().optional(), tester: z.object({ compose: z.string().min(1), service: z.string().min(1), env: envSchema2.optional() }).strict().optional(), services: rootServicesSchema, dev: meshStageSchema.optional(), prod: meshStageSchema.optional(), test: meshStageSchema.optional(), e2e: meshStageSchema.optional() }).strict();
|
|
1444
1618
|
|
|
1445
1619
|
// src/core/mesh/getMeshJson.ts
|
|
1446
1620
|
function getMeshJson(projectDir = process.cwd()) {
|
|
@@ -1468,14 +1642,15 @@ function getMeshJson(projectDir = process.cwd()) {
|
|
|
1468
1642
|
|
|
1469
1643
|
// src/core/config/resolveMeshStage.ts
|
|
1470
1644
|
function resolveMeshStage(mesh, stage, sourceFile) {
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
services[name] =
|
|
1645
|
+
if (Object.keys(mesh.services).length === 0) throw new ConfigError({ sourceFile, configPath: "services", stage, composition: "mesh", reason: "mesh.json must declare at least one root service" });
|
|
1646
|
+
const services = {};
|
|
1647
|
+
for (const [name, service] of Object.entries(mesh.services)) services[name] = { path: service.path, env: { ...service.env ?? {} }, dependencies: { ...service.dependencies ?? {} }, dependsOn: [...service.dependsOn ?? []], publish: [...service.publish ?? []] };
|
|
1648
|
+
for (const overlayStage of stageOverlayChain(stage)) for (const [name, patch] of Object.entries(mesh[overlayStage]?.services ?? {})) {
|
|
1649
|
+
const prior = services[name] ?? { path: void 0, env: {}, dependencies: {}, dependsOn: [], publish: [] };
|
|
1650
|
+
services[name] = { path: patch.path ?? prior.path, env: mergeStringMap(prior.env, patch.env), dependencies: { ...prior.dependencies, ...patch.dependencies ?? {} }, dependsOn: unionStable(prior.dependsOn, patch.dependsOn), publish: unionStable(prior.publish, patch.publish) };
|
|
1477
1651
|
}
|
|
1478
1652
|
if (!Object.keys(services).length) throw new ConfigError({ sourceFile, configPath: "services", stage, composition: "mesh", reason: "At least one effective mesh service is required" });
|
|
1653
|
+
for (const [name, service] of Object.entries(services)) if (!service.path) throw new ConfigError({ sourceFile, configPath: `services.${name}.path`, stage, composition: "mesh", reason: "Effective mesh service requires path" });
|
|
1479
1654
|
const graph = /* @__PURE__ */ new Map();
|
|
1480
1655
|
for (const [name, service] of Object.entries(services)) {
|
|
1481
1656
|
if (!BUILDER_IDENTIFIER_PATTERN.test(name) || RESERVED_MESH_SERVICE_NAMES.has(name)) throw new ConfigError({ sourceFile, configPath: `services.${name}`, stage, composition: "mesh", value: name, reason: "Invalid or reserved mesh service name" });
|
|
@@ -1553,40 +1728,56 @@ function resolveMeshPublication(services, bindings, stage, meshJsonPath) {
|
|
|
1553
1728
|
}
|
|
1554
1729
|
|
|
1555
1730
|
// src/core/mesh/v2/meshReferences.ts
|
|
1556
|
-
function resolveMesh(ref, ctx,
|
|
1731
|
+
function resolveMesh(ref, ctx, context) {
|
|
1557
1732
|
const name = ref.meshService;
|
|
1558
|
-
if (!ctx.services[name]) throw new ConfigError({
|
|
1733
|
+
if (!ctx.services[name]) throw new ConfigError({ ...context, referencedObject: ref.raw, reason: `Unknown mesh service reference "${name}"` });
|
|
1559
1734
|
const provider = ref.target === "dependency" ? ctx.bindings.get(bindingKey(name, ref.dependency)) : void 0;
|
|
1560
|
-
const
|
|
1561
|
-
if (!
|
|
1562
|
-
return resolveEndpointProperty(
|
|
1735
|
+
const endpoint = ref.target === "app" ? ctx.endpoints.app[name]?.[ref.endpoint] : provider ? ctx.endpoints.app[provider]?.[ref.endpoint] : ctx.endpoints.dependencies[name]?.[ref.dependency]?.[ref.endpoint];
|
|
1736
|
+
if (!endpoint) throw new ConfigError({ ...context, referencedObject: ref.raw, reason: "Referenced endpoint does not exist" });
|
|
1737
|
+
return resolveEndpointProperty(endpoint, ref.property, { ...context, referencedObject: ref.raw });
|
|
1563
1738
|
}
|
|
1564
|
-
function resolveBuild(ref, consumer, ctx,
|
|
1739
|
+
function resolveBuild(ref, consumer, ctx, context) {
|
|
1565
1740
|
const provider = ref.target === "dependency" ? ctx.bindings.get(bindingKey(consumer, ref.dependency)) : void 0;
|
|
1566
|
-
const
|
|
1567
|
-
if (!
|
|
1741
|
+
const endpoint = ref.target === "app" ? ctx.endpoints.app[consumer]?.[ref.endpoint] : provider ? ctx.endpoints.app[provider]?.[ref.endpoint] : ctx.endpoints.dependencies[consumer]?.[ref.dependency]?.[ref.endpoint];
|
|
1742
|
+
if (!endpoint) {
|
|
1743
|
+
const reason = provider ? `Provider "${provider}" does not expose endpoint "${ref.endpoint}"` : "Referenced endpoint does not exist";
|
|
1744
|
+
throw new ConfigError({ ...context, referencedObject: ref.raw, reason });
|
|
1745
|
+
}
|
|
1568
1746
|
try {
|
|
1569
|
-
return resolveEndpointProperty(
|
|
1747
|
+
return resolveEndpointProperty(endpoint, ref.property, { ...context, referencedObject: ref.raw });
|
|
1570
1748
|
} catch (error) {
|
|
1571
|
-
if (provider && error instanceof ConfigError)
|
|
1749
|
+
if (provider && error instanceof ConfigError) {
|
|
1750
|
+
throw new ConfigError({
|
|
1751
|
+
...context,
|
|
1752
|
+
referencedObject: `${consumer}.dependencies.${ref.dependency}.endpoints.${ref.endpoint}.${ref.property} -> ${provider}.app.endpoints.${ref.endpoint}.${ref.property}`,
|
|
1753
|
+
reason: error.message
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1572
1756
|
throw error;
|
|
1573
1757
|
}
|
|
1574
1758
|
}
|
|
1575
|
-
function interpolate(value, scope,
|
|
1576
|
-
const
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1759
|
+
function interpolate(value, scope, ctx, configPath, consumer) {
|
|
1760
|
+
const context = {
|
|
1761
|
+
sourceFile: scope === "mesh" ? ctx.meshJsonPath : ctx.services[consumer]?.buildJsonPath ?? ctx.meshJsonPath,
|
|
1762
|
+
configPath,
|
|
1763
|
+
stage: ctx.stage,
|
|
1764
|
+
composition: scope === "mesh" ? "mesh" : "service"
|
|
1765
|
+
};
|
|
1766
|
+
return interpolateBuilderReferences(value, scope, (ref, refContext) => scope === "mesh" ? resolveMesh(ref, ctx, refContext) : resolveBuild(ref, consumer, ctx, refContext), context).replace(/\$/g, "$$$$");
|
|
1581
1767
|
}
|
|
1582
1768
|
function resolveMeshEnvMap(env, ctx, sourcePrefix) {
|
|
1583
|
-
return Object.fromEntries(Object.entries(env).map(([key, value]) => [key, interpolate(value, "mesh",
|
|
1769
|
+
return Object.fromEntries(Object.entries(env).map(([key, value]) => [key, interpolate(value, "mesh", ctx, `${sourcePrefix}.${key}`)]));
|
|
1584
1770
|
}
|
|
1585
1771
|
function resolveServiceBuildEnvThroughMesh(consumer, env, ctx, sourcePrefix) {
|
|
1586
|
-
return Object.fromEntries(Object.entries(env).map(([key, value]) => [key, interpolate(value, "build",
|
|
1587
|
-
}
|
|
1588
|
-
function assertMeshTesterEnvPublic(env,
|
|
1589
|
-
assertTesterReferencesArePublic(env, "mesh",
|
|
1772
|
+
return Object.fromEntries(Object.entries(env).map(([key, value]) => [key, interpolate(value, "build", ctx, `${sourcePrefix}.${key}`, consumer)]));
|
|
1773
|
+
}
|
|
1774
|
+
function assertMeshTesterEnvPublic(env, ctx, configPath = "tester.env") {
|
|
1775
|
+
assertTesterReferencesArePublic(env, "mesh", {
|
|
1776
|
+
sourceFile: ctx.meshJsonPath,
|
|
1777
|
+
configPath,
|
|
1778
|
+
stage: ctx.stage,
|
|
1779
|
+
composition: "mesh"
|
|
1780
|
+
});
|
|
1590
1781
|
}
|
|
1591
1782
|
|
|
1592
1783
|
// src/core/mesh/v2/lifecycle.ts
|
|
@@ -1625,88 +1816,97 @@ function normalizeComposeDependsOn(value) {
|
|
|
1625
1816
|
}
|
|
1626
1817
|
|
|
1627
1818
|
// src/core/mesh/v2/compileMeshTester.ts
|
|
1628
|
-
function
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
for (const
|
|
1638
|
-
const
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
const
|
|
1648
|
-
if (
|
|
1649
|
-
} else if (v && typeof v === "object" && v.type === "volume" && doc.volumes?.[v.source]) sets.volumes.add(v.source);
|
|
1650
|
-
}
|
|
1651
|
-
const nets = svc.networks;
|
|
1652
|
-
if (Array.isArray(nets)) nets.forEach((n) => {
|
|
1653
|
-
if (typeof n === "string" && doc.networks?.[n]) sets.networks.add(n);
|
|
1654
|
-
});
|
|
1655
|
-
else if (nets && typeof nets === "object") Object.keys(nets).forEach((n) => {
|
|
1656
|
-
if (doc.networks?.[n]) sets.networks.add(n);
|
|
1657
|
-
});
|
|
1658
|
-
for (const kind of ["configs", "secrets"]) {
|
|
1659
|
-
const v = svc[kind];
|
|
1660
|
-
if (Array.isArray(v)) for (const x of v) {
|
|
1661
|
-
const n = typeof x === "string" ? x : x?.source;
|
|
1662
|
-
if (typeof n === "string" && doc[kind]?.[n]) sets[kind].add(n);
|
|
1819
|
+
function appendEnvFile(existing, next) {
|
|
1820
|
+
if (existing === void 0) return [next];
|
|
1821
|
+
return Array.isArray(existing) ? [...existing, next] : [existing, next];
|
|
1822
|
+
}
|
|
1823
|
+
function envFilePaths(value) {
|
|
1824
|
+
const entries2 = Array.isArray(value) ? value : [value];
|
|
1825
|
+
return entries2.flatMap((entry) => typeof entry === "string" ? [entry] : entry && typeof entry === "object" && typeof entry.path === "string" ? [entry.path] : []);
|
|
1826
|
+
}
|
|
1827
|
+
function validateServiceReferences(document, sourceFile, stage) {
|
|
1828
|
+
for (const [name, service] of Object.entries(document.services)) {
|
|
1829
|
+
const refs = [];
|
|
1830
|
+
const add = (value) => {
|
|
1831
|
+
if (typeof value === "string" && value) refs.push(value);
|
|
1832
|
+
};
|
|
1833
|
+
if (Array.isArray(service.depends_on)) service.depends_on.forEach(add);
|
|
1834
|
+
else if (service.depends_on && typeof service.depends_on === "object") Object.keys(service.depends_on).forEach(add);
|
|
1835
|
+
if (Array.isArray(service.links)) service.links.forEach((value) => add(typeof value === "string" ? value.split(":")[0] : void 0));
|
|
1836
|
+
if (Array.isArray(service.volumes_from)) service.volumes_from.forEach((value) => add(typeof value === "string" ? value.split(":")[0] : void 0));
|
|
1837
|
+
for (const key of ["network_mode", "ipc", "pid"]) {
|
|
1838
|
+
const value = service[key];
|
|
1839
|
+
if (typeof value === "string" && value.startsWith("service:")) add(value.slice("service:".length));
|
|
1663
1840
|
}
|
|
1841
|
+
for (const ref of refs) if (!document.services[ref]) throw new ConfigError({ sourceFile, configPath: `services.${name}`, stage, composition: "mesh", referencedObject: ref, reason: "Tester Compose service reference does not exist" });
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
function applyTesterBuildTarget(service) {
|
|
1845
|
+
if (service.build === void 0) return;
|
|
1846
|
+
if (typeof service.build === "string") {
|
|
1847
|
+
service.build = { context: service.build, target: "test-e2e" };
|
|
1848
|
+
return;
|
|
1664
1849
|
}
|
|
1665
|
-
|
|
1666
|
-
return sets;
|
|
1850
|
+
if (service.build && typeof service.build === "object" && !Array.isArray(service.build)) service.build = { ...service.build, target: "test-e2e" };
|
|
1667
1851
|
}
|
|
1668
1852
|
function compileMeshTester(meshDir, tester, endpointRegistry, effectiveTopLevelApps, stage, referenceContext, nameAllocator = new GeneratedComposeNameAllocator(effectiveTopLevelApps)) {
|
|
1669
|
-
const meshPath =
|
|
1853
|
+
const meshPath = path.join(meshDir, "mesh.json"), file = resolveInsideProject(meshDir, tester.compose, { sourceFile: meshPath, configPath: "tester.compose", stage }), raw = rebaseComposePaths(loadComposeDocument(file, { sourceFile: meshPath, configPath: "tester.compose", stage, composition: "mesh" }), file, meshDir);
|
|
1670
1854
|
if (!raw.services || !raw.services[tester.service]) throw new ConfigError({ sourceFile: meshPath, configPath: "tester.service", stage, composition: "mesh", value: tester.service, reason: "Selected tester service does not exist in tester Compose" });
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
for (const
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
const ns = namespaceDependencyCompose({ dependencyKey: "mesh-tester", namespacePrefix: "mesh-tester", document:
|
|
1855
|
+
validateComposeResourceReferences(raw, { sourceFile: file, stage, composition: "mesh" });
|
|
1856
|
+
validateServiceReferences(raw, file, stage);
|
|
1857
|
+
assertComposeLifecycleAcyclic(raw.services, {
|
|
1858
|
+
sourceFile: file,
|
|
1859
|
+
stage,
|
|
1860
|
+
composition: "mesh"
|
|
1861
|
+
});
|
|
1862
|
+
for (const [serviceName, service] of Object.entries(raw.services)) {
|
|
1863
|
+
if (service.extends !== void 0) throw new ConfigError({ sourceFile: file, configPath: `services.${serviceName}.extends`, stage, composition: "mesh", reason: "Tester Compose extends is unsupported until effective Compose inheritance can be validated safely" });
|
|
1864
|
+
assertNoServiceBuildContexts(service, `services.${serviceName}`, file);
|
|
1865
|
+
}
|
|
1866
|
+
const selectedRaw = raw.services[tester.service];
|
|
1867
|
+
if (selectedRaw.network_mode !== void 0 && selectedRaw.network_mode !== "host") throw new ConfigError({ sourceFile: file, configPath: `services.${tester.service}.network_mode`, stage, composition: "mesh", reason: "Selected tester runner must be compatible with host networking" });
|
|
1868
|
+
if (selectedRaw.networks !== void 0) throw new ConfigError({ sourceFile: file, configPath: `services.${tester.service}.networks`, stage, composition: "mesh", reason: "Selected host-network tester runner cannot declare Compose networks" });
|
|
1869
|
+
if (selectedRaw.ports !== void 0) throw new ConfigError({ sourceFile: file, configPath: `services.${tester.service}.ports`, stage, composition: "mesh", reason: "Selected host-network tester runner cannot define ports" });
|
|
1870
|
+
const meshCtx = referenceContext ?? { services: {}, bindings: /* @__PURE__ */ new Map(), endpoints: endpointRegistry, stage, meshJsonPath: meshPath };
|
|
1871
|
+
const testerBuilderKeys = [EXEC_MODE_KEY, INFRA_MODE_KEY], rawRunnerEnvironment = normalizeComposeEnvironment(selectedRaw.environment, "tester runner environment");
|
|
1872
|
+
assertNoBuilderOwnedEnvKeys(rawRunnerEnvironment, testerBuilderKeys, { sourceFile: file, configPath: `services.${tester.service}.environment`, stage, composition: "mesh" });
|
|
1873
|
+
for (const envFile of envFilePaths(selectedRaw.env_file)) assertDotenvDoesNotDefineKeys(path.resolve(meshDir, envFile), testerBuilderKeys, { configPath: `services.${tester.service}.env_file`, stage, composition: "mesh" });
|
|
1874
|
+
const meshTesterDotenv = path.join(meshDir, ".env.e2e-tester");
|
|
1875
|
+
assertDotenvDoesNotDefineKeys(meshTesterDotenv, testerBuilderKeys, { configPath: ".env.e2e-tester", stage, composition: "mesh" });
|
|
1876
|
+
const testerEnv = tester.env ?? {};
|
|
1877
|
+
assertNoBuilderOwnedEnvKeys(testerEnv, testerBuilderKeys, { sourceFile: meshPath, configPath: "tester.env", stage, composition: "mesh" });
|
|
1878
|
+
assertMeshTesterEnvPublic(testerEnv, meshCtx);
|
|
1879
|
+
const ns = namespaceDependencyCompose({ dependencyKey: "mesh-tester", namespacePrefix: "mesh-tester", document: raw, allocator: nameAllocator, identityPrefix: JSON.stringify(["mesh-tester"]) });
|
|
1696
1880
|
const runner = ns.serviceNameMap.get(tester.service);
|
|
1697
1881
|
const runnerSvc = ns.document.services[runner];
|
|
1698
|
-
|
|
1882
|
+
applyTesterBuildTarget(runnerSvc);
|
|
1699
1883
|
runnerSvc.network_mode = "host";
|
|
1700
1884
|
delete runnerSvc.networks;
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
assertMeshTesterEnvPublic(env, "tester.env");
|
|
1704
|
-
runnerSvc.environment = { ...normalizeComposeEnvironment(runnerSvc.environment, "tester runner environment"), ...resolveMeshEnvMap(env, meshCtx, "tester.env") };
|
|
1885
|
+
runnerSvc.env_file = appendEnvFile(runnerSvc.env_file, { path: ".env.e2e-tester", required: false });
|
|
1886
|
+
runnerSvc.environment = { ...normalizeComposeEnvironment(runnerSvc.environment, "tester runner environment"), ...resolveMeshEnvMap(testerEnv, meshCtx, "tester.env"), EXEC_MODE: "e2e" };
|
|
1705
1887
|
const depends = normalizeComposeDependsOn(runnerSvc.depends_on);
|
|
1706
1888
|
for (const app of effectiveTopLevelApps) depends[app] = { condition: "service_healthy" };
|
|
1707
1889
|
runnerSvc.depends_on = depends;
|
|
1708
1890
|
return { services: ns.document.services, ...ns.document.volumes ? { volumes: ns.document.volumes } : {}, ...ns.document.networks ? { networks: ns.document.networks } : {}, ...ns.document.configs ? { configs: ns.document.configs } : {}, ...ns.document.secrets ? { secrets: ns.document.secrets } : {}, runnerServiceName: runner };
|
|
1709
1891
|
}
|
|
1892
|
+
|
|
1893
|
+
// src/core/mesh/v2/resolveMeshAppEnvironment.ts
|
|
1894
|
+
function resolveMeshAppEnvironmentLayers(serviceName, layers, context, laterKeys = /* @__PURE__ */ new Set()) {
|
|
1895
|
+
const result = {};
|
|
1896
|
+
for (const [key, layer] of selectAppEnvironmentEntries(layers, laterKeys)) {
|
|
1897
|
+
if (layer.kind === "build-json") {
|
|
1898
|
+
result[key] = resolveServiceBuildEnvThroughMesh(
|
|
1899
|
+
serviceName,
|
|
1900
|
+
{ [key]: layer.values[key] },
|
|
1901
|
+
context,
|
|
1902
|
+
`services.${serviceName}.${layer.configPath}`
|
|
1903
|
+
)[key];
|
|
1904
|
+
} else {
|
|
1905
|
+
result[key] = layer.values[key];
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
return result;
|
|
1909
|
+
}
|
|
1710
1910
|
function validPort(value) {
|
|
1711
1911
|
if (!/^\d+$/.test(value)) return void 0;
|
|
1712
1912
|
const port = Number(value);
|
|
@@ -1830,7 +2030,10 @@ function compileMeshComposition(stage, meshDir, options = {}) {
|
|
|
1830
2030
|
for (const ep of Object.values(fragment.endpoints.dependencies[dep] ?? {})) {
|
|
1831
2031
|
const owner = ep.networkHost;
|
|
1832
2032
|
const ownerService = compose.services[owner];
|
|
1833
|
-
if (ownerService)
|
|
2033
|
+
if (ownerService) {
|
|
2034
|
+
attachNetworkIfCompatible(ownerService, privateName);
|
|
2035
|
+
attachNetworkIfCompatible(ownerService, "mesh");
|
|
2036
|
+
}
|
|
1834
2037
|
}
|
|
1835
2038
|
for (const generated of fragment.dependencyServiceNames?.[dep] ?? []) {
|
|
1836
2039
|
const ownerService = compose.services[generated];
|
|
@@ -1840,7 +2043,7 @@ function compileMeshComposition(stage, meshDir, options = {}) {
|
|
|
1840
2043
|
}
|
|
1841
2044
|
app.networks = { ...normalizeNetworks(app.networks), ...networks };
|
|
1842
2045
|
}
|
|
1843
|
-
const publication = resolveMeshPublication(services, bindingMap, stage, meshPath), intents = buildMeshPortIntents(services, publication), ports = allocateHostPorts(meshDir, stage, intents, Boolean(options.validationMode));
|
|
2046
|
+
const publication = resolveMeshPublication(services, bindingMap, stage, meshPath), intents = buildMeshPortIntents(services, publication), ports = allocateHostPorts(meshDir, stage, intents, Boolean(options.validationMode), { sourceFile: meshPath, composition: "mesh" });
|
|
1844
2047
|
const endpoints = { app: {}, dependencies: {} };
|
|
1845
2048
|
for (const [name, svc] of Object.entries(services)) {
|
|
1846
2049
|
endpoints.app[name] = {};
|
|
@@ -1877,9 +2080,9 @@ function compileMeshComposition(stage, meshDir, options = {}) {
|
|
|
1877
2080
|
const refContext = { services, bindings: bindingMap, endpoints, stage, meshJsonPath: meshPath };
|
|
1878
2081
|
for (const [name, fragment] of Object.entries(fragments)) {
|
|
1879
2082
|
const app = compose.services[name];
|
|
1880
|
-
const buildEnv = resolveServiceBuildEnvThroughMesh(name, fragment.buildJsonAppEnvironment ?? {}, refContext, `services.${name}.app.env`);
|
|
1881
2083
|
const meshEnv = resolveMeshEnvMap(fragment.externalAppEnvironment ?? {}, refContext, `services.${name}.env`);
|
|
1882
|
-
|
|
2084
|
+
const serviceEnv = resolveMeshAppEnvironmentLayers(name, fragment.appEnvironmentLayers, refContext, new Set(Object.keys(meshEnv)));
|
|
2085
|
+
app.environment = { ...serviceEnv, ...meshEnv, ...fragment.builderInternalEnvironment ?? {} };
|
|
1883
2086
|
for (const [depName, depEnv] of Object.entries(fragment.dependencyEnvironments ?? {})) {
|
|
1884
2087
|
const logicalBinding = bindingMap.get(bindingKey(name, depName));
|
|
1885
2088
|
if (logicalBinding) continue;
|
|
@@ -1968,16 +2171,21 @@ function validateMeshTestStage(services, meshDir, meshPath, validationMode = fal
|
|
|
1968
2171
|
requested: endpoint.publicPort
|
|
1969
2172
|
};
|
|
1970
2173
|
});
|
|
1971
|
-
const
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2174
|
+
const allocatedPorts = /* @__PURE__ */ new Map();
|
|
2175
|
+
for (const name of Object.keys(services).sort((a, b) => a.localeCompare(b))) {
|
|
2176
|
+
const intents = appPublications.filter((pub) => pub.meshService === name).map((pub) => ({
|
|
2177
|
+
logicalPath: pub.logicalPath,
|
|
2178
|
+
requested: pub.requested
|
|
2179
|
+
}));
|
|
2180
|
+
const ownPorts = allocateHostPorts(
|
|
2181
|
+
meshDir,
|
|
2182
|
+
"test",
|
|
2183
|
+
intents,
|
|
2184
|
+
validationMode,
|
|
2185
|
+
{ sourceFile: meshPath, composition: "mesh" }
|
|
2186
|
+
);
|
|
2187
|
+
for (const [logicalPath, port] of ownPorts) allocatedPorts.set(logicalPath, port);
|
|
2188
|
+
}
|
|
1981
2189
|
return { bindings, appPublications, allocatedPorts };
|
|
1982
2190
|
}
|
|
1983
2191
|
function applyTestAppPublications(validated, meshService, app, endpointRegistry) {
|
|
@@ -2002,28 +2210,30 @@ function applyTestAppPublications(validated, meshService, app, endpointRegistry)
|
|
|
2002
2210
|
}
|
|
2003
2211
|
|
|
2004
2212
|
// src/core/mesh/checkers/checkMeshServices.ts
|
|
2005
|
-
function checkMeshServices(mesh, meshDir) {
|
|
2213
|
+
function checkMeshServices(mesh, meshDir, options = {}) {
|
|
2006
2214
|
const root = resolveProjectDir(meshDir), meshPath = path.join(root, "mesh.json");
|
|
2007
2215
|
const checked = /* @__PURE__ */ new Set();
|
|
2008
|
-
|
|
2216
|
+
const stages = options.includeTestStage ? ["dev", "prod", "test", "e2e"] : ["dev", "prod", "e2e"];
|
|
2217
|
+
for (const stage of stages) {
|
|
2009
2218
|
const effective = resolveMeshStage(mesh, stage, meshPath);
|
|
2010
2219
|
const services = loadEffectiveMeshServices(root, effective, stage);
|
|
2011
|
-
|
|
2220
|
+
const testValidation = stage === "test" ? validateMeshTestStage(services, root, meshPath, true) : void 0;
|
|
2012
2221
|
for (const [name, svc] of Object.entries(services)) {
|
|
2013
2222
|
if (!checked.has(svc.absolutePath)) {
|
|
2014
|
-
console.log(
|
|
2223
|
+
console.log(pc14.cyan(`
|
|
2015
2224
|
\u{1F50D} Checking mesh service ${name}...`));
|
|
2016
2225
|
checkInfra(svc.absolutePath);
|
|
2017
2226
|
checked.add(svc.absolutePath);
|
|
2018
2227
|
}
|
|
2019
2228
|
if (stage === "test") {
|
|
2020
2229
|
const fragment = compileServiceComposition("test", svc.absolutePath, { validationMode: true, meshMode: true, deferReferenceResolution: true });
|
|
2230
|
+
applyTestAppPublications(testValidation, name, fragment.compose.services.app, fragment.endpoints.app);
|
|
2021
2231
|
const endpoints = { app: { [name]: fragment.endpoints.app }, dependencies: { [name]: fragment.endpoints.dependencies } };
|
|
2022
2232
|
const ctx = { services: { [name]: svc }, bindings: /* @__PURE__ */ new Map(), endpoints, stage: "test", meshJsonPath: meshPath };
|
|
2023
2233
|
for (const key of ["EXEC_MODE", "INFRA_MODE", ...Object.values(svc.effectiveBuild.app.endpoints).some((ep) => ep.primary) ? ["PORT"] : []]) {
|
|
2024
2234
|
if (key in svc.meshEnv) throw new ConfigError({ sourceFile: meshPath, configPath: `services.${name}.env.${key}`, stage: "test", composition: "mesh", reason: "Mesh service env cannot set Builder-owned environment" });
|
|
2025
2235
|
}
|
|
2026
|
-
|
|
2236
|
+
resolveMeshAppEnvironmentLayers(name, fragment.appEnvironmentLayers, ctx, new Set(Object.keys(svc.meshEnv)));
|
|
2027
2237
|
for (const [depName, depEnv] of Object.entries(fragment.dependencyEnvironments ?? {})) resolveServiceBuildEnvThroughMesh(name, depEnv, ctx, `services.${name}.dependencies.${depName}.env`);
|
|
2028
2238
|
resolveMeshEnvMap(svc.meshEnv, ctx, `services.${name}.env`);
|
|
2029
2239
|
}
|
|
@@ -2046,11 +2256,13 @@ function checkMeshTester(mesh, meshDir, options = {}) {
|
|
|
2046
2256
|
function checkMesh(meshDir = process.cwd(), options = {}) {
|
|
2047
2257
|
const absMeshDir = resolveProjectDir(meshDir);
|
|
2048
2258
|
const mesh = getMeshJson(absMeshDir);
|
|
2049
|
-
checkMeshServices(mesh, absMeshDir
|
|
2259
|
+
checkMeshServices(mesh, absMeshDir, {
|
|
2260
|
+
includeTestStage: Boolean(options.includeTestStage)
|
|
2261
|
+
});
|
|
2050
2262
|
checkMeshTester(mesh, absMeshDir, { required: Boolean(options.requireTester) });
|
|
2051
2263
|
console.log(
|
|
2052
|
-
|
|
2053
|
-
|
|
2264
|
+
pc14.bold(
|
|
2265
|
+
pc14.green("\n\u{1F389} All V2 mesh infrastructure, services, and contract checks passed!\n")
|
|
2054
2266
|
)
|
|
2055
2267
|
);
|
|
2056
2268
|
}
|
|
@@ -2170,18 +2382,19 @@ function ensureSignalHandlers() {
|
|
|
2170
2382
|
}
|
|
2171
2383
|
if (isShuttingDown) return;
|
|
2172
2384
|
isShuttingDown = true;
|
|
2173
|
-
for (const item of activeComposeSet) {
|
|
2174
|
-
try {
|
|
2175
|
-
teardownCompose(item.yamlConfig, item.projectDir, {
|
|
2176
|
-
removeVolumes: item.removeVolumes ?? false
|
|
2177
|
-
}).catch(() => {
|
|
2178
|
-
});
|
|
2179
|
-
} catch {
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
|
-
activeComposeSet.clear();
|
|
2183
2385
|
const signalNumber = os.constants.signals[signal] ?? 0;
|
|
2184
|
-
|
|
2386
|
+
void (async () => {
|
|
2387
|
+
for (const item of activeComposeSet) {
|
|
2388
|
+
try {
|
|
2389
|
+
await teardownCompose(item.yamlConfig, item.projectDir, {
|
|
2390
|
+
removeVolumes: item.removeVolumes ?? false
|
|
2391
|
+
});
|
|
2392
|
+
activeComposeSet.delete(item);
|
|
2393
|
+
} catch (error) {
|
|
2394
|
+
console.error("Compose cleanup failed during signal shutdown:", error);
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
})().finally(() => process.exit(128 + signalNumber));
|
|
2185
2398
|
};
|
|
2186
2399
|
const SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
2187
2400
|
for (const sig of SIGNALS) {
|
|
@@ -2277,17 +2490,11 @@ async function teardownCompose(yamlConfig, projectDir, options = {}) {
|
|
|
2277
2490
|
6e4
|
|
2278
2491
|
);
|
|
2279
2492
|
}
|
|
2280
|
-
if (result.error) {
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
}
|
|
2286
|
-
} else if (result.status !== 0 && !silent) {
|
|
2287
|
-
console.error(
|
|
2288
|
-
pc22.red(
|
|
2289
|
-
`Docker compose down exited with non-zero status code: ${result.status}`
|
|
2290
|
-
)
|
|
2493
|
+
if (result.error || result.status !== 0) {
|
|
2494
|
+
const detail = result.error?.message ?? `exit code ${result.status ?? "unknown"}`;
|
|
2495
|
+
throw new ScriptError(
|
|
2496
|
+
`Failed to tear down Compose project in ${absProjectDir} after two attempts: ${detail}`,
|
|
2497
|
+
result.error ? { cause: result.error } : void 0
|
|
2291
2498
|
);
|
|
2292
2499
|
}
|
|
2293
2500
|
} finally {
|
|
@@ -2419,7 +2626,7 @@ async function handleMeshDown(rawStage = "dev", options = {}) {
|
|
|
2419
2626
|
);
|
|
2420
2627
|
}
|
|
2421
2628
|
console.log(
|
|
2422
|
-
|
|
2629
|
+
pc14.cyan(`
|
|
2423
2630
|
\u{1F9F9} Stopping and tearing down global mesh environment [${stage}]...`)
|
|
2424
2631
|
);
|
|
2425
2632
|
if (options.debug) {
|
|
@@ -2427,7 +2634,7 @@ async function handleMeshDown(rawStage = "dev", options = {}) {
|
|
|
2427
2634
|
const mode = stage === "dev" ? "dev" : stage === "test-e2e" ? "e2e" : "prod";
|
|
2428
2635
|
const { yaml } = compileMeshEnvironment(mode, meshDir, { validateWithDocker: false });
|
|
2429
2636
|
console.log(
|
|
2430
|
-
|
|
2637
|
+
pc14.yellow("\nFinal merged Mesh YAML configuration:\n"),
|
|
2431
2638
|
redactYamlSecrets(yaml)
|
|
2432
2639
|
);
|
|
2433
2640
|
} catch {
|
|
@@ -2448,7 +2655,7 @@ async function handleMeshDown(rawStage = "dev", options = {}) {
|
|
|
2448
2655
|
}
|
|
2449
2656
|
clearRunState(meshDir);
|
|
2450
2657
|
console.log(
|
|
2451
|
-
|
|
2658
|
+
pc14.green(`\u2705 Global mesh environment [${stage}] stopped and removed.
|
|
2452
2659
|
`)
|
|
2453
2660
|
);
|
|
2454
2661
|
return 0;
|
|
@@ -2485,6 +2692,36 @@ Examples:
|
|
|
2485
2692
|
}
|
|
2486
2693
|
);
|
|
2487
2694
|
};
|
|
2695
|
+
|
|
2696
|
+
// src/core/runWithCleanup.ts
|
|
2697
|
+
async function runWithCleanup(run, cleanup) {
|
|
2698
|
+
let executionFailed = false;
|
|
2699
|
+
let executionError;
|
|
2700
|
+
try {
|
|
2701
|
+
const status = await run();
|
|
2702
|
+
if (status !== 0) {
|
|
2703
|
+
executionFailed = true;
|
|
2704
|
+
executionError = new ScriptError(`Compose execution exited with code ${status}`, { exitCode: status });
|
|
2705
|
+
}
|
|
2706
|
+
return status;
|
|
2707
|
+
} catch (error) {
|
|
2708
|
+
executionFailed = true;
|
|
2709
|
+
executionError = error;
|
|
2710
|
+
throw error;
|
|
2711
|
+
} finally {
|
|
2712
|
+
try {
|
|
2713
|
+
await cleanup();
|
|
2714
|
+
} catch (cleanupError) {
|
|
2715
|
+
if (executionFailed) {
|
|
2716
|
+
throw new AggregateError(
|
|
2717
|
+
[executionError, cleanupError],
|
|
2718
|
+
`Compose execution failed (${errorMessage(executionError)}); cleanup also failed (${errorMessage(cleanupError)}). Saved run state was retained`
|
|
2719
|
+
);
|
|
2720
|
+
}
|
|
2721
|
+
throw cleanupError;
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2488
2725
|
function extractHostPorts(yamlConfig) {
|
|
2489
2726
|
const ports = [];
|
|
2490
2727
|
try {
|
|
@@ -2585,19 +2822,19 @@ async function runCompose(args, yamlConfig, projectDir, options = {}) {
|
|
|
2585
2822
|
// src/core/mesh/runners/runMeshDev.ts
|
|
2586
2823
|
async function runMeshDev(options = {}) {
|
|
2587
2824
|
const meshDir = resolveProjectDir(options.projectDir);
|
|
2588
|
-
console.log(
|
|
2825
|
+
console.log(pc14.cyan(`
|
|
2589
2826
|
\u{1F680} Starting Global DEV Mesh Environment...`));
|
|
2590
2827
|
const { yaml } = compileMeshEnvironment("dev", meshDir);
|
|
2591
2828
|
const parsed = parse(yaml);
|
|
2592
2829
|
const projectName = parsed?.name || "mesh-dev";
|
|
2593
2830
|
if (options.debug) {
|
|
2594
2831
|
console.log(
|
|
2595
|
-
|
|
2832
|
+
pc14.yellow("\nFinal merged Mesh Dev YAML configuration:\n"),
|
|
2596
2833
|
redactYamlSecrets(yaml)
|
|
2597
2834
|
);
|
|
2598
2835
|
}
|
|
2599
2836
|
if (options.dryRun) {
|
|
2600
|
-
console.log(
|
|
2837
|
+
console.log(pc14.green("Dry run complete. Compose was not started."));
|
|
2601
2838
|
return 0;
|
|
2602
2839
|
}
|
|
2603
2840
|
const hostPorts = extractHostPorts(yaml);
|
|
@@ -2612,34 +2849,34 @@ async function runMeshDev(options = {}) {
|
|
|
2612
2849
|
if (options.detach) {
|
|
2613
2850
|
upArgs.push("-d");
|
|
2614
2851
|
}
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
status = await runCompose(upArgs, yaml, meshDir, {
|
|
2852
|
+
const status = await runWithCleanup(
|
|
2853
|
+
() => runCompose(upArgs, yaml, meshDir, {
|
|
2618
2854
|
removeVolumes: false
|
|
2619
|
-
})
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2855
|
+
}),
|
|
2856
|
+
async () => {
|
|
2857
|
+
if (!options.detach) {
|
|
2858
|
+
await teardownCompose(yaml, meshDir, { removeVolumes: false });
|
|
2859
|
+
clearRunState(meshDir);
|
|
2860
|
+
}
|
|
2624
2861
|
}
|
|
2625
|
-
|
|
2862
|
+
);
|
|
2626
2863
|
return status;
|
|
2627
2864
|
}
|
|
2628
2865
|
async function runMeshProd(options = {}) {
|
|
2629
2866
|
const meshDir = resolveProjectDir(options.projectDir);
|
|
2630
|
-
console.log(
|
|
2867
|
+
console.log(pc14.cyan(`
|
|
2631
2868
|
\u{1F3ED} Starting Global PROD Mesh Environment...`));
|
|
2632
2869
|
const { yaml } = compileMeshEnvironment("prod", meshDir);
|
|
2633
2870
|
const parsed = parse(yaml);
|
|
2634
2871
|
const projectName = parsed?.name || "mesh-prod";
|
|
2635
2872
|
if (options.debug) {
|
|
2636
2873
|
console.log(
|
|
2637
|
-
|
|
2874
|
+
pc14.yellow("\nFinal merged Mesh Prod YAML configuration:\n"),
|
|
2638
2875
|
redactYamlSecrets(yaml)
|
|
2639
2876
|
);
|
|
2640
2877
|
}
|
|
2641
2878
|
if (options.dryRun) {
|
|
2642
|
-
console.log(
|
|
2879
|
+
console.log(pc14.green("Dry run complete. Compose was not started."));
|
|
2643
2880
|
return 0;
|
|
2644
2881
|
}
|
|
2645
2882
|
const hostPorts = extractHostPorts(yaml);
|
|
@@ -2654,52 +2891,199 @@ async function runMeshProd(options = {}) {
|
|
|
2654
2891
|
if (options.detach) {
|
|
2655
2892
|
upArgs.push("-d");
|
|
2656
2893
|
}
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
status = await runCompose(upArgs, yaml, meshDir, {
|
|
2894
|
+
const status = await runWithCleanup(
|
|
2895
|
+
() => runCompose(upArgs, yaml, meshDir, {
|
|
2660
2896
|
removeVolumes: false
|
|
2661
|
-
})
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2897
|
+
}),
|
|
2898
|
+
async () => {
|
|
2899
|
+
if (!options.detach) {
|
|
2900
|
+
await teardownCompose(yaml, meshDir, { removeVolumes: false });
|
|
2901
|
+
clearRunState(meshDir);
|
|
2902
|
+
}
|
|
2666
2903
|
}
|
|
2667
|
-
|
|
2904
|
+
);
|
|
2668
2905
|
return status;
|
|
2669
2906
|
}
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2907
|
+
var compileEnvironment = (stage, projectDir = process.cwd(), options = {}) => stringify(compileServiceComposition(stage, projectDir, { full: Boolean(options.full), silenceWarnings: options.silenceWarnings }).compose);
|
|
2908
|
+
|
|
2909
|
+
// src/core/runners/runTestUnit.ts
|
|
2910
|
+
var runTestUnit = async (options) => {
|
|
2911
|
+
if (!options.skipBanner) {
|
|
2912
|
+
console.log(pc14.bold(pc14.blue(`
|
|
2913
|
+
========================================`)));
|
|
2914
|
+
console.log(pc14.bold(pc14.blue(`\u{1F9EA} STAGE: UNIT & ISOLATED TESTS`)));
|
|
2915
|
+
console.log(pc14.bold(pc14.blue(`========================================
|
|
2916
|
+
`)));
|
|
2917
|
+
}
|
|
2918
|
+
const finalYamlConfig = compileEnvironment("test", options.projectDir, {
|
|
2919
|
+
silenceWarnings: options.silenceWarnings
|
|
2920
|
+
});
|
|
2921
|
+
const parsed = parse(finalYamlConfig);
|
|
2922
|
+
const projectName = parsed?.name || "test";
|
|
2923
|
+
if (options.debug) {
|
|
2924
|
+
console.log(
|
|
2925
|
+
pc14.yellow("Final merged YAML configuration:\n"),
|
|
2926
|
+
redactYamlSecrets(finalYamlConfig)
|
|
2927
|
+
);
|
|
2928
|
+
}
|
|
2929
|
+
if (options.dryRun) {
|
|
2930
|
+
console.log(pc14.green("[DRY-RUN] Unit tests simulated. Compose was not started."));
|
|
2931
|
+
return 0;
|
|
2932
|
+
}
|
|
2933
|
+
await checkHostPortCollisions(extractHostPorts(finalYamlConfig));
|
|
2934
|
+
await teardownCompose(finalYamlConfig, options.projectDir, {
|
|
2935
|
+
removeVolumes: true,
|
|
2936
|
+
silent: true
|
|
2937
|
+
});
|
|
2938
|
+
writeRunState(options.projectDir, {
|
|
2939
|
+
projectName,
|
|
2940
|
+
stage: "test-unit",
|
|
2941
|
+
projectDir: options.projectDir
|
|
2942
|
+
});
|
|
2943
|
+
const status = await runWithCleanup(
|
|
2944
|
+
() => runCompose(
|
|
2945
|
+
["up", "--build", "--abort-on-container-exit", "--exit-code-from", "app"],
|
|
2946
|
+
finalYamlConfig,
|
|
2947
|
+
options.projectDir,
|
|
2948
|
+
{ removeVolumes: true }
|
|
2949
|
+
),
|
|
2950
|
+
async () => {
|
|
2951
|
+
await teardownCompose(finalYamlConfig, options.projectDir, { removeVolumes: true });
|
|
2952
|
+
clearRunState(options.projectDir);
|
|
2693
2953
|
}
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2954
|
+
);
|
|
2955
|
+
if (status === 0) {
|
|
2956
|
+
console.log(pc14.bold(pc14.green(`
|
|
2957
|
+
\u2705 Unit tests passed successfully.
|
|
2958
|
+
`)));
|
|
2959
|
+
} else {
|
|
2960
|
+
console.error(pc14.red(`
|
|
2961
|
+
\u274C Unit tests failed with exit code ${status}.
|
|
2962
|
+
`));
|
|
2963
|
+
}
|
|
2964
|
+
return status;
|
|
2965
|
+
};
|
|
2966
|
+
var runTestE2e = async (options) => {
|
|
2967
|
+
if (!options.skipBanner) {
|
|
2968
|
+
console.log(pc14.bold(pc14.blue(`
|
|
2969
|
+
========================================`)));
|
|
2970
|
+
console.log(pc14.bold(pc14.blue(`\u{1F6A6} STAGE: INTEGRATED E2E TESTS`)));
|
|
2971
|
+
console.log(pc14.bold(pc14.blue(`========================================
|
|
2972
|
+
`)));
|
|
2973
|
+
}
|
|
2974
|
+
const finalYamlConfig = compileEnvironment("e2e", options.projectDir, {
|
|
2975
|
+
silenceWarnings: options.silenceWarnings
|
|
2976
|
+
});
|
|
2977
|
+
const parsed = parse(finalYamlConfig);
|
|
2978
|
+
const projectName = parsed?.name || "e2e";
|
|
2979
|
+
if (options.debug) {
|
|
2980
|
+
console.log(
|
|
2981
|
+
pc14.yellow("Final merged YAML configuration:\n"),
|
|
2982
|
+
redactYamlSecrets(finalYamlConfig)
|
|
2983
|
+
);
|
|
2984
|
+
}
|
|
2985
|
+
if (options.dryRun) {
|
|
2986
|
+
console.log(pc14.green("[DRY-RUN] E2E tests simulated. Compose was not started."));
|
|
2987
|
+
return 0;
|
|
2988
|
+
}
|
|
2989
|
+
await checkHostPortCollisions(extractHostPorts(finalYamlConfig));
|
|
2990
|
+
await teardownCompose(finalYamlConfig, options.projectDir, {
|
|
2991
|
+
removeVolumes: true,
|
|
2992
|
+
silent: true
|
|
2993
|
+
});
|
|
2994
|
+
writeRunState(options.projectDir, {
|
|
2995
|
+
projectName,
|
|
2996
|
+
stage: "test-e2e",
|
|
2997
|
+
projectDir: options.projectDir
|
|
2998
|
+
});
|
|
2999
|
+
const status = await runWithCleanup(
|
|
3000
|
+
() => runCompose(
|
|
3001
|
+
[
|
|
3002
|
+
"up",
|
|
3003
|
+
"--build",
|
|
3004
|
+
"--abort-on-container-exit",
|
|
3005
|
+
"--exit-code-from",
|
|
3006
|
+
"tester"
|
|
3007
|
+
],
|
|
3008
|
+
finalYamlConfig,
|
|
3009
|
+
options.projectDir,
|
|
3010
|
+
{ removeVolumes: true }
|
|
3011
|
+
),
|
|
3012
|
+
async () => {
|
|
3013
|
+
await teardownCompose(finalYamlConfig, options.projectDir, { removeVolumes: true });
|
|
3014
|
+
clearRunState(options.projectDir);
|
|
2702
3015
|
}
|
|
3016
|
+
);
|
|
3017
|
+
if (status === 0) {
|
|
3018
|
+
console.log(pc14.bold(pc14.green(`
|
|
3019
|
+
\u2705 E2E tests passed successfully.
|
|
3020
|
+
`)));
|
|
3021
|
+
} else {
|
|
3022
|
+
console.error(pc14.red(`
|
|
3023
|
+
\u274C E2E tests failed with exit code ${status}.
|
|
3024
|
+
`));
|
|
3025
|
+
}
|
|
3026
|
+
return status;
|
|
3027
|
+
};
|
|
3028
|
+
|
|
3029
|
+
// src/core/runners/runTest.ts
|
|
3030
|
+
var runTest = async (options) => {
|
|
3031
|
+
console.log(pc14.bold(pc14.blue(`
|
|
3032
|
+
========================================`)));
|
|
3033
|
+
console.log(pc14.bold(pc14.blue(`\u{1F9EA} [1/2] STAGE: UNIT & ISOLATED TESTS`)));
|
|
3034
|
+
console.log(pc14.bold(pc14.blue(`========================================
|
|
3035
|
+
`)));
|
|
3036
|
+
const unitStatus = await runTestUnit({ ...options, skipBanner: true });
|
|
3037
|
+
if (unitStatus !== 0) {
|
|
3038
|
+
console.error(
|
|
3039
|
+
pc14.red(
|
|
3040
|
+
`
|
|
3041
|
+
\u274C [1/2] Unit tests failed with exit code ${unitStatus}. Aborting E2E tests.
|
|
3042
|
+
`
|
|
3043
|
+
)
|
|
3044
|
+
);
|
|
3045
|
+
return unitStatus;
|
|
3046
|
+
}
|
|
3047
|
+
console.log(
|
|
3048
|
+
pc14.bold(pc14.green(`
|
|
3049
|
+
\u2705 [1/2] Unit tests passed successfully.
|
|
3050
|
+
`))
|
|
3051
|
+
);
|
|
3052
|
+
console.log(pc14.bold(pc14.blue(`========================================`)));
|
|
3053
|
+
console.log(pc14.bold(pc14.blue(`\u{1F6A6} [2/2] STAGE: INTEGRATED E2E TESTS`)));
|
|
3054
|
+
console.log(pc14.bold(pc14.blue(`========================================
|
|
3055
|
+
`)));
|
|
3056
|
+
const e2eStatus = await runTestE2e({ ...options, skipBanner: true });
|
|
3057
|
+
if (e2eStatus !== 0) {
|
|
3058
|
+
console.error(
|
|
3059
|
+
pc14.red(`
|
|
3060
|
+
\u274C [2/2] E2E tests failed with exit code ${e2eStatus}.
|
|
3061
|
+
`)
|
|
3062
|
+
);
|
|
3063
|
+
return e2eStatus;
|
|
3064
|
+
}
|
|
3065
|
+
console.log(pc14.bold(pc14.green(`
|
|
3066
|
+
\u2705 [2/2] E2E tests passed successfully.
|
|
3067
|
+
`)));
|
|
3068
|
+
console.log(
|
|
3069
|
+
pc14.bold(
|
|
3070
|
+
pc14.green(`\u{1F389} All test stages (unit + e2e) completed successfully!
|
|
3071
|
+
`)
|
|
3072
|
+
)
|
|
3073
|
+
);
|
|
3074
|
+
return 0;
|
|
3075
|
+
};
|
|
3076
|
+
|
|
3077
|
+
// src/core/mesh/runners/runMeshServiceTests.ts
|
|
3078
|
+
async function runMeshServiceTests(options = {}) {
|
|
3079
|
+
const meshDir = resolveProjectDir(options.projectDir), meshPath = path.join(meshDir, "mesh.json"), mesh = getMeshJson(meshDir);
|
|
3080
|
+
const rootServices = Object.entries(mesh.services).sort(([left], [right]) => left.localeCompare(right));
|
|
3081
|
+
for (const [serviceName, service] of rootServices) {
|
|
3082
|
+
const serviceDir = resolveInsideProject(meshDir, service.path, { sourceFile: meshPath, configPath: `services.${serviceName}.path`, stage: "test" });
|
|
3083
|
+
console.log(pc14.bold(pc14.cyan(`
|
|
3084
|
+
-> Running full standalone test lifecycle for [${serviceName}]
|
|
3085
|
+
`)));
|
|
3086
|
+
const status = await runTest({ projectDir: serviceDir, debug: Boolean(options.debug), detach: false, skipBanner: true, silenceWarnings: false, ...options.dryRun !== void 0 ? { dryRun: options.dryRun } : {} });
|
|
2703
3087
|
if (status !== 0) return status;
|
|
2704
3088
|
}
|
|
2705
3089
|
return 0;
|
|
@@ -2709,34 +3093,65 @@ async function runMeshTestE2e(options = {}) {
|
|
|
2709
3093
|
if (!mesh.tester) throw new ScriptError("Global mesh E2E requires root mesh.json.tester { compose, service, env? }");
|
|
2710
3094
|
const { yaml, testerServiceName } = compileMeshEnvironment("e2e", meshDir);
|
|
2711
3095
|
if (!testerServiceName) throw new ScriptError("Global mesh E2E tester runner could not be compiled.");
|
|
2712
|
-
if (options.debug) console.log(
|
|
3096
|
+
if (options.debug) console.log(pc14.yellow("\nFinal global mesh E2E YAML configuration:\n"), redactYamlSecrets(yaml));
|
|
2713
3097
|
if (options.dryRun) {
|
|
2714
|
-
console.log(
|
|
3098
|
+
console.log(pc14.green("[DRY-RUN] Global mesh E2E compiled; Compose was not started."));
|
|
2715
3099
|
return 0;
|
|
2716
3100
|
}
|
|
2717
3101
|
await checkHostPortCollisions(extractHostPorts(yaml));
|
|
2718
3102
|
const projectName = parse(yaml)?.name || "mesh-e2e";
|
|
2719
3103
|
await teardownCompose(yaml, meshDir, { removeVolumes: true, silent: true });
|
|
2720
3104
|
writeRunState(meshDir, { projectName, stage: "test-e2e", projectDir: meshDir });
|
|
2721
|
-
|
|
2722
|
-
try {
|
|
2723
|
-
status = await runCompose(["up", "--build", "--abort-on-container-exit", "--exit-code-from", testerServiceName], yaml, meshDir, { removeVolumes: true });
|
|
2724
|
-
} finally {
|
|
3105
|
+
const status = await runWithCleanup(() => runCompose(["up", "--build", "--abort-on-container-exit", "--exit-code-from", testerServiceName], yaml, meshDir, { removeVolumes: true }), async () => {
|
|
2725
3106
|
await teardownCompose(yaml, meshDir, { removeVolumes: true });
|
|
2726
3107
|
clearRunState(meshDir);
|
|
2727
|
-
}
|
|
3108
|
+
});
|
|
2728
3109
|
return status;
|
|
2729
3110
|
}
|
|
2730
3111
|
|
|
2731
3112
|
// src/core/mesh/runners/runMeshTest.ts
|
|
2732
3113
|
async function runMeshTest(options = {}) {
|
|
2733
|
-
console.log(
|
|
2734
|
-
console.log(
|
|
2735
|
-
const
|
|
2736
|
-
if (
|
|
2737
|
-
console.log(
|
|
3114
|
+
console.log(pc14.bold(pc14.blue("\n========================================\nMESH TEST PIPELINE\n========================================\n")));
|
|
3115
|
+
console.log(pc14.bold(pc14.blue("[1/2] ROOT SERVICE TEST LIFECYCLES")));
|
|
3116
|
+
const serviceStatus = await runMeshServiceTests(options);
|
|
3117
|
+
if (serviceStatus !== 0) return serviceStatus;
|
|
3118
|
+
console.log(pc14.bold(pc14.blue("[2/2] GLOBAL MESH E2E")));
|
|
2738
3119
|
return runMeshTestE2e(options);
|
|
2739
3120
|
}
|
|
3121
|
+
async function runMeshTestUnit(options = {}) {
|
|
3122
|
+
const meshDir = resolveProjectDir(options.projectDir), meshPath = path.join(meshDir, "mesh.json"), raw = getMeshJson(meshDir), effective = resolveMeshStage(raw, "test", meshPath), services = loadEffectiveMeshServices(meshDir, effective, "test"), validated = validateMeshTestStage(services, meshDir, meshPath, Boolean(options.dryRun));
|
|
3123
|
+
console.log(pc14.bold(pc14.blue("\nEXPLICIT MESH TEST-STAGE (UNIT/ISOLATED)\n")));
|
|
3124
|
+
for (const [name, svc] of Object.entries(services).sort(([a], [b]) => a.localeCompare(b))) {
|
|
3125
|
+
console.log(pc14.cyan(`-> Running isolated unit tests for [${name}]`));
|
|
3126
|
+
const compiled = compileServiceComposition("test", svc.absolutePath, { meshMode: true, full: false, externalAppEnv: {}, deferReferenceResolution: true, appServiceName: "app" });
|
|
3127
|
+
const app = compiled.compose.services.app;
|
|
3128
|
+
applyTestAppPublications(validated, name, app, compiled.endpoints.app);
|
|
3129
|
+
const endpoints = { app: { [name]: compiled.endpoints.app }, dependencies: { [name]: compiled.endpoints.dependencies } };
|
|
3130
|
+
const refCtx = { services: { [name]: svc }, bindings: /* @__PURE__ */ new Map(), endpoints, stage: "test", meshJsonPath: meshPath };
|
|
3131
|
+
const env = svc.meshEnv;
|
|
3132
|
+
for (const key of ["EXEC_MODE", "INFRA_MODE", ...Object.keys(svc.effectiveBuild.app.endpoints).some((k) => svc.effectiveBuild.app.endpoints[k]?.primary) ? ["PORT"] : []]) if (key in env) throw new ConfigError({ sourceFile: meshPath, configPath: `services.${name}.env.${key}`, stage: "test", composition: "mesh", reason: "Mesh service env cannot set Builder-owned environment" });
|
|
3133
|
+
const resolvedBuild = resolveMeshAppEnvironmentLayers(name, compiled.appEnvironmentLayers, refCtx, new Set(Object.keys(svc.meshEnv)));
|
|
3134
|
+
for (const [depName, depEnv] of Object.entries(compiled.dependencyEnvironments ?? {})) resolveServiceBuildEnvThroughMesh(name, depEnv, refCtx, `services.${name}.dependencies.${depName}.env`);
|
|
3135
|
+
const resolved = resolveMeshEnvMap(env, refCtx, `services.${name}.env`);
|
|
3136
|
+
app.environment = { ...resolvedBuild, ...resolved, ...compiled.builderInternalEnvironment ?? {} };
|
|
3137
|
+
const projectName = `${deriveProjectName(raw.name ?? path.basename(meshDir), "dev")}-${name}-test`;
|
|
3138
|
+
compiled.compose.name = projectName;
|
|
3139
|
+
const yaml = stringify(compiled.compose);
|
|
3140
|
+
if (options.debug) console.log(redactYamlSecrets(yaml));
|
|
3141
|
+
if (options.dryRun) {
|
|
3142
|
+
console.log(pc14.green(`[DRY-RUN] Unit tests for ${name} compiled.`));
|
|
3143
|
+
continue;
|
|
3144
|
+
}
|
|
3145
|
+
await teardownCompose(yaml, svc.absolutePath, { removeVolumes: true, silent: true });
|
|
3146
|
+
writeRunState(svc.absolutePath, { projectName, stage: "test-unit", projectDir: svc.absolutePath });
|
|
3147
|
+
const status = await runWithCleanup(() => runCompose(["up", "--build", "--abort-on-container-exit", "--exit-code-from", "app"], yaml, svc.absolutePath, { removeVolumes: true }), async () => {
|
|
3148
|
+
await teardownCompose(yaml, svc.absolutePath, { removeVolumes: true });
|
|
3149
|
+
clearRunState(svc.absolutePath);
|
|
3150
|
+
});
|
|
3151
|
+
if (status !== 0) return status;
|
|
3152
|
+
}
|
|
3153
|
+
return 0;
|
|
3154
|
+
}
|
|
2740
3155
|
|
|
2741
3156
|
// src/commands/mesh/commands/up/handler.ts
|
|
2742
3157
|
async function handleMeshUp(rawStage = "dev", options = {}) {
|
|
@@ -2747,7 +3162,10 @@ async function handleMeshUp(rawStage = "dev", options = {}) {
|
|
|
2747
3162
|
projectDir
|
|
2748
3163
|
};
|
|
2749
3164
|
if (["dev", "prod", "test-unit", "test-e2e", "test"].includes(stage) && !options.skipChecks) {
|
|
2750
|
-
checkMesh(projectDir, {
|
|
3165
|
+
checkMesh(projectDir, {
|
|
3166
|
+
requireTester: stage === "test-e2e" || stage === "test",
|
|
3167
|
+
includeTestStage: stage === "test-unit"
|
|
3168
|
+
});
|
|
2751
3169
|
}
|
|
2752
3170
|
switch (stage) {
|
|
2753
3171
|
case "dev":
|
|
@@ -2794,7 +3212,8 @@ Examples:
|
|
|
2794
3212
|
$ builder mesh up test-e2e
|
|
2795
3213
|
|
|
2796
3214
|
JSON overlays: test-unit uses mesh/build test; test-e2e uses mesh/build e2e.
|
|
2797
|
-
The test command runs
|
|
3215
|
+
The test command runs each root service test lifecycle (unit, then service E2E) before global E2E.
|
|
3216
|
+
The explicit test-unit stage exercises mesh.json.test overlays only.`
|
|
2798
3217
|
).action(
|
|
2799
3218
|
async (stage = "dev", options = {}) => {
|
|
2800
3219
|
const exitCode = await handleMeshUp(stage, {
|
|
@@ -2822,7 +3241,7 @@ var registerMeshCommand = (program) => {
|
|
|
2822
3241
|
registerMeshCheckCommand(meshCmd);
|
|
2823
3242
|
};
|
|
2824
3243
|
async function handlePrune(options = {}) {
|
|
2825
|
-
console.log(
|
|
3244
|
+
console.log(pc14.cyan("\n\u{1F9F9} Pruning stopped Compose containers and unused networks..."));
|
|
2826
3245
|
const rmContainers = spawnSync("docker", ["container", "prune", "-f"], {
|
|
2827
3246
|
stdio: "inherit",
|
|
2828
3247
|
encoding: "utf-8"
|
|
@@ -2842,13 +3261,13 @@ async function handlePrune(options = {}) {
|
|
|
2842
3261
|
});
|
|
2843
3262
|
}
|
|
2844
3263
|
if (options.volumes) {
|
|
2845
|
-
console.log(
|
|
3264
|
+
console.log(pc14.cyan("\u{1F9F9} Pruning dangling volumes..."));
|
|
2846
3265
|
spawnSync("docker", ["volume", "prune", "-f"], {
|
|
2847
3266
|
stdio: "inherit",
|
|
2848
3267
|
encoding: "utf-8"
|
|
2849
3268
|
});
|
|
2850
3269
|
}
|
|
2851
|
-
console.log(
|
|
3270
|
+
console.log(pc14.green("\u2705 Docker environment pruned successfully.\n"));
|
|
2852
3271
|
return 0;
|
|
2853
3272
|
}
|
|
2854
3273
|
|
|
@@ -2863,9 +3282,6 @@ var registerPruneCommand = (cmd) => {
|
|
|
2863
3282
|
}
|
|
2864
3283
|
});
|
|
2865
3284
|
};
|
|
2866
|
-
var compileEnvironment = (stage, projectDir = process.cwd(), options = {}) => stringify(compileServiceComposition(stage, projectDir, { full: Boolean(options.full), silenceWarnings: options.silenceWarnings }).compose);
|
|
2867
|
-
|
|
2868
|
-
// src/commands/service/commands/down/handler.ts
|
|
2869
3285
|
async function handleServiceDown(rawStage = "dev", options = {}) {
|
|
2870
3286
|
const projectDir = resolveProjectDir(options.projectDir);
|
|
2871
3287
|
const stage = (rawStage || "dev").toLowerCase();
|
|
@@ -2876,7 +3292,7 @@ async function handleServiceDown(rawStage = "dev", options = {}) {
|
|
|
2876
3292
|
);
|
|
2877
3293
|
}
|
|
2878
3294
|
console.log(
|
|
2879
|
-
|
|
3295
|
+
pc14.cyan(`
|
|
2880
3296
|
\u{1F9F9} Stopping and tearing down service environment [${stage}]...`)
|
|
2881
3297
|
);
|
|
2882
3298
|
if (options.debug) {
|
|
@@ -2887,7 +3303,7 @@ async function handleServiceDown(rawStage = "dev", options = {}) {
|
|
|
2887
3303
|
else if (stage === "test-e2e") env = "e2e";
|
|
2888
3304
|
const finalYamlConfig = compileEnvironment(env, projectDir);
|
|
2889
3305
|
console.log(
|
|
2890
|
-
|
|
3306
|
+
pc14.yellow("Final merged YAML configuration:\n"),
|
|
2891
3307
|
redactYamlSecrets(finalYamlConfig)
|
|
2892
3308
|
);
|
|
2893
3309
|
} catch {
|
|
@@ -2908,7 +3324,7 @@ async function handleServiceDown(rawStage = "dev", options = {}) {
|
|
|
2908
3324
|
}
|
|
2909
3325
|
clearRunState(projectDir);
|
|
2910
3326
|
console.log(
|
|
2911
|
-
|
|
3327
|
+
pc14.green(`\u2705 Service environment [${stage}] stopped and removed.
|
|
2912
3328
|
`)
|
|
2913
3329
|
);
|
|
2914
3330
|
return 0;
|
|
@@ -2947,7 +3363,7 @@ Examples:
|
|
|
2947
3363
|
};
|
|
2948
3364
|
var runDev = async (options) => {
|
|
2949
3365
|
console.log(
|
|
2950
|
-
|
|
3366
|
+
pc14.cyan(
|
|
2951
3367
|
options.full ? `\u{1F680} Starting DEV environment (full / integrated)...` : `\u{1F680} Starting DEV environment...`
|
|
2952
3368
|
)
|
|
2953
3369
|
);
|
|
@@ -2959,12 +3375,12 @@ var runDev = async (options) => {
|
|
|
2959
3375
|
const projectName = parsed?.name || "dev";
|
|
2960
3376
|
if (options.debug) {
|
|
2961
3377
|
console.log(
|
|
2962
|
-
|
|
3378
|
+
pc14.yellow("Final merged YAML configuration:\n"),
|
|
2963
3379
|
redactYamlSecrets(finalYamlConfig)
|
|
2964
3380
|
);
|
|
2965
3381
|
}
|
|
2966
3382
|
if (options.dryRun) {
|
|
2967
|
-
console.log(
|
|
3383
|
+
console.log(pc14.green("Dry run complete. Compose was not started."));
|
|
2968
3384
|
return 0;
|
|
2969
3385
|
}
|
|
2970
3386
|
const hostPorts = extractHostPorts(finalYamlConfig);
|
|
@@ -2979,23 +3395,23 @@ var runDev = async (options) => {
|
|
|
2979
3395
|
if (options.detach) {
|
|
2980
3396
|
upArgs.push("-d");
|
|
2981
3397
|
}
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
status = await runCompose(upArgs, finalYamlConfig, options.projectDir, {
|
|
3398
|
+
const status = await runWithCleanup(
|
|
3399
|
+
() => runCompose(upArgs, finalYamlConfig, options.projectDir, {
|
|
2985
3400
|
removeVolumes: false
|
|
2986
|
-
})
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
3401
|
+
}),
|
|
3402
|
+
async () => {
|
|
3403
|
+
if (!options.detach) {
|
|
3404
|
+
await teardownCompose(finalYamlConfig, options.projectDir, {
|
|
3405
|
+
removeVolumes: false
|
|
3406
|
+
});
|
|
3407
|
+
clearRunState(options.projectDir);
|
|
3408
|
+
}
|
|
2993
3409
|
}
|
|
2994
|
-
|
|
3410
|
+
);
|
|
2995
3411
|
return status;
|
|
2996
3412
|
};
|
|
2997
3413
|
var runProd = async (options) => {
|
|
2998
|
-
console.log(
|
|
3414
|
+
console.log(pc14.cyan(`\u{1F3ED} Starting PROD environment...`));
|
|
2999
3415
|
const finalYamlConfig = compileEnvironment("prod", options.projectDir, {
|
|
3000
3416
|
silenceWarnings: options.silenceWarnings
|
|
3001
3417
|
});
|
|
@@ -3003,12 +3419,12 @@ var runProd = async (options) => {
|
|
|
3003
3419
|
const projectName = parsed?.name || "prod";
|
|
3004
3420
|
if (options.debug) {
|
|
3005
3421
|
console.log(
|
|
3006
|
-
|
|
3422
|
+
pc14.yellow("Final merged YAML configuration:\n"),
|
|
3007
3423
|
redactYamlSecrets(finalYamlConfig)
|
|
3008
3424
|
);
|
|
3009
3425
|
}
|
|
3010
3426
|
if (options.dryRun) {
|
|
3011
|
-
console.log(
|
|
3427
|
+
console.log(pc14.green("Dry run complete. Compose was not started."));
|
|
3012
3428
|
return 0;
|
|
3013
3429
|
}
|
|
3014
3430
|
const hostPorts = extractHostPorts(finalYamlConfig);
|
|
@@ -3023,186 +3439,20 @@ var runProd = async (options) => {
|
|
|
3023
3439
|
if (options.detach) {
|
|
3024
3440
|
upArgs.push("-d");
|
|
3025
3441
|
}
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
status = await runCompose(upArgs, finalYamlConfig, options.projectDir, {
|
|
3442
|
+
const status = await runWithCleanup(
|
|
3443
|
+
() => runCompose(upArgs, finalYamlConfig, options.projectDir, {
|
|
3029
3444
|
removeVolumes: false
|
|
3030
|
-
})
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3445
|
+
}),
|
|
3446
|
+
async () => {
|
|
3447
|
+
if (!options.detach) {
|
|
3448
|
+
await teardownCompose(finalYamlConfig, options.projectDir, {
|
|
3449
|
+
removeVolumes: false
|
|
3450
|
+
});
|
|
3451
|
+
clearRunState(options.projectDir);
|
|
3452
|
+
}
|
|
3037
3453
|
}
|
|
3038
|
-
}
|
|
3039
|
-
return status;
|
|
3040
|
-
};
|
|
3041
|
-
var runTestUnit = async (options) => {
|
|
3042
|
-
if (!options.skipBanner) {
|
|
3043
|
-
console.log(pc22.bold(pc22.blue(`
|
|
3044
|
-
========================================`)));
|
|
3045
|
-
console.log(pc22.bold(pc22.blue(`\u{1F9EA} STAGE: UNIT & ISOLATED TESTS`)));
|
|
3046
|
-
console.log(pc22.bold(pc22.blue(`========================================
|
|
3047
|
-
`)));
|
|
3048
|
-
}
|
|
3049
|
-
const finalYamlConfig = compileEnvironment("test", options.projectDir, {
|
|
3050
|
-
silenceWarnings: options.silenceWarnings
|
|
3051
|
-
});
|
|
3052
|
-
const parsed = parse(finalYamlConfig);
|
|
3053
|
-
const projectName = parsed?.name || "test";
|
|
3054
|
-
if (options.debug) {
|
|
3055
|
-
console.log(
|
|
3056
|
-
pc22.yellow("Final merged YAML configuration:\n"),
|
|
3057
|
-
redactYamlSecrets(finalYamlConfig)
|
|
3058
|
-
);
|
|
3059
|
-
}
|
|
3060
|
-
if (options.dryRun) {
|
|
3061
|
-
console.log(pc22.green("[DRY-RUN] Unit tests simulated. Compose was not started."));
|
|
3062
|
-
return 0;
|
|
3063
|
-
}
|
|
3064
|
-
await checkHostPortCollisions(extractHostPorts(finalYamlConfig));
|
|
3065
|
-
await teardownCompose(finalYamlConfig, options.projectDir, {
|
|
3066
|
-
removeVolumes: true,
|
|
3067
|
-
silent: true
|
|
3068
|
-
});
|
|
3069
|
-
writeRunState(options.projectDir, {
|
|
3070
|
-
projectName,
|
|
3071
|
-
stage: "test-unit",
|
|
3072
|
-
projectDir: options.projectDir
|
|
3073
|
-
});
|
|
3074
|
-
let status = 0;
|
|
3075
|
-
try {
|
|
3076
|
-
status = await runCompose(
|
|
3077
|
-
["up", "--build", "--abort-on-container-exit", "--exit-code-from", "app"],
|
|
3078
|
-
finalYamlConfig,
|
|
3079
|
-
options.projectDir,
|
|
3080
|
-
{ removeVolumes: true }
|
|
3081
|
-
);
|
|
3082
|
-
} finally {
|
|
3083
|
-
await teardownCompose(finalYamlConfig, options.projectDir, { removeVolumes: true });
|
|
3084
|
-
clearRunState(options.projectDir);
|
|
3085
|
-
}
|
|
3086
|
-
if (status === 0) {
|
|
3087
|
-
console.log(pc22.bold(pc22.green(`
|
|
3088
|
-
\u2705 Unit tests passed successfully.
|
|
3089
|
-
`)));
|
|
3090
|
-
} else {
|
|
3091
|
-
console.error(pc22.red(`
|
|
3092
|
-
\u274C Unit tests failed with exit code ${status}.
|
|
3093
|
-
`));
|
|
3094
|
-
}
|
|
3095
|
-
return status;
|
|
3096
|
-
};
|
|
3097
|
-
var runTestE2e = async (options) => {
|
|
3098
|
-
if (!options.skipBanner) {
|
|
3099
|
-
console.log(pc22.bold(pc22.blue(`
|
|
3100
|
-
========================================`)));
|
|
3101
|
-
console.log(pc22.bold(pc22.blue(`\u{1F6A6} STAGE: INTEGRATED E2E TESTS`)));
|
|
3102
|
-
console.log(pc22.bold(pc22.blue(`========================================
|
|
3103
|
-
`)));
|
|
3104
|
-
}
|
|
3105
|
-
const finalYamlConfig = compileEnvironment("e2e", options.projectDir, {
|
|
3106
|
-
silenceWarnings: options.silenceWarnings
|
|
3107
|
-
});
|
|
3108
|
-
const parsed = parse(finalYamlConfig);
|
|
3109
|
-
const projectName = parsed?.name || "e2e";
|
|
3110
|
-
if (options.debug) {
|
|
3111
|
-
console.log(
|
|
3112
|
-
pc22.yellow("Final merged YAML configuration:\n"),
|
|
3113
|
-
redactYamlSecrets(finalYamlConfig)
|
|
3114
|
-
);
|
|
3115
|
-
}
|
|
3116
|
-
if (options.dryRun) {
|
|
3117
|
-
console.log(pc22.green("[DRY-RUN] E2E tests simulated. Compose was not started."));
|
|
3118
|
-
return 0;
|
|
3119
|
-
}
|
|
3120
|
-
await checkHostPortCollisions(extractHostPorts(finalYamlConfig));
|
|
3121
|
-
await teardownCompose(finalYamlConfig, options.projectDir, {
|
|
3122
|
-
removeVolumes: true,
|
|
3123
|
-
silent: true
|
|
3124
|
-
});
|
|
3125
|
-
writeRunState(options.projectDir, {
|
|
3126
|
-
projectName,
|
|
3127
|
-
stage: "test-e2e",
|
|
3128
|
-
projectDir: options.projectDir
|
|
3129
|
-
});
|
|
3130
|
-
let status = 0;
|
|
3131
|
-
try {
|
|
3132
|
-
status = await runCompose(
|
|
3133
|
-
[
|
|
3134
|
-
"up",
|
|
3135
|
-
"--build",
|
|
3136
|
-
"--abort-on-container-exit",
|
|
3137
|
-
"--exit-code-from",
|
|
3138
|
-
"tester"
|
|
3139
|
-
],
|
|
3140
|
-
finalYamlConfig,
|
|
3141
|
-
options.projectDir,
|
|
3142
|
-
{ removeVolumes: true }
|
|
3143
|
-
);
|
|
3144
|
-
} finally {
|
|
3145
|
-
await teardownCompose(finalYamlConfig, options.projectDir, { removeVolumes: true });
|
|
3146
|
-
clearRunState(options.projectDir);
|
|
3147
|
-
}
|
|
3148
|
-
if (status === 0) {
|
|
3149
|
-
console.log(pc22.bold(pc22.green(`
|
|
3150
|
-
\u2705 E2E tests passed successfully.
|
|
3151
|
-
`)));
|
|
3152
|
-
} else {
|
|
3153
|
-
console.error(pc22.red(`
|
|
3154
|
-
\u274C E2E tests failed with exit code ${status}.
|
|
3155
|
-
`));
|
|
3156
|
-
}
|
|
3157
|
-
return status;
|
|
3158
|
-
};
|
|
3159
|
-
|
|
3160
|
-
// src/core/runners/runTest.ts
|
|
3161
|
-
var runTest = async (options) => {
|
|
3162
|
-
console.log(pc22.bold(pc22.blue(`
|
|
3163
|
-
========================================`)));
|
|
3164
|
-
console.log(pc22.bold(pc22.blue(`\u{1F9EA} [1/2] STAGE: UNIT & ISOLATED TESTS`)));
|
|
3165
|
-
console.log(pc22.bold(pc22.blue(`========================================
|
|
3166
|
-
`)));
|
|
3167
|
-
const unitStatus = await runTestUnit({ ...options, skipBanner: true });
|
|
3168
|
-
if (unitStatus !== 0) {
|
|
3169
|
-
console.error(
|
|
3170
|
-
pc22.red(
|
|
3171
|
-
`
|
|
3172
|
-
\u274C [1/2] Unit tests failed with exit code ${unitStatus}. Aborting E2E tests.
|
|
3173
|
-
`
|
|
3174
|
-
)
|
|
3175
|
-
);
|
|
3176
|
-
return unitStatus;
|
|
3177
|
-
}
|
|
3178
|
-
console.log(
|
|
3179
|
-
pc22.bold(pc22.green(`
|
|
3180
|
-
\u2705 [1/2] Unit tests passed successfully.
|
|
3181
|
-
`))
|
|
3182
3454
|
);
|
|
3183
|
-
|
|
3184
|
-
console.log(pc22.bold(pc22.blue(`\u{1F6A6} [2/2] STAGE: INTEGRATED E2E TESTS`)));
|
|
3185
|
-
console.log(pc22.bold(pc22.blue(`========================================
|
|
3186
|
-
`)));
|
|
3187
|
-
const e2eStatus = await runTestE2e({ ...options, skipBanner: true });
|
|
3188
|
-
if (e2eStatus !== 0) {
|
|
3189
|
-
console.error(
|
|
3190
|
-
pc22.red(`
|
|
3191
|
-
\u274C [2/2] E2E tests failed with exit code ${e2eStatus}.
|
|
3192
|
-
`)
|
|
3193
|
-
);
|
|
3194
|
-
return e2eStatus;
|
|
3195
|
-
}
|
|
3196
|
-
console.log(pc22.bold(pc22.green(`
|
|
3197
|
-
\u2705 [2/2] E2E tests passed successfully.
|
|
3198
|
-
`)));
|
|
3199
|
-
console.log(
|
|
3200
|
-
pc22.bold(
|
|
3201
|
-
pc22.green(`\u{1F389} All test stages (unit + e2e) completed successfully!
|
|
3202
|
-
`)
|
|
3203
|
-
)
|
|
3204
|
-
);
|
|
3205
|
-
return 0;
|
|
3455
|
+
return status;
|
|
3206
3456
|
};
|
|
3207
3457
|
|
|
3208
3458
|
// src/commands/service/commands/up/handler.ts
|
|
@@ -3335,6 +3585,16 @@ async function handleExportEnv(rawStage, options = {}) {
|
|
|
3335
3585
|
throw new ScriptError(`Unknown environment stage: "${rawStage}". Supported stages: ${STAGES.join(", ")}`);
|
|
3336
3586
|
}
|
|
3337
3587
|
const projectDir = resolveProjectDir(options.projectDir);
|
|
3588
|
+
const runtimeInputs = new Set(
|
|
3589
|
+
STAGES.map((s) => canonicalPath(path.join(projectDir, `.env.${s}`)))
|
|
3590
|
+
);
|
|
3591
|
+
const assertSafeDestination = (candidate) => {
|
|
3592
|
+
if (runtimeInputs.has(canonicalPath(candidate))) {
|
|
3593
|
+
throw new ScriptError(
|
|
3594
|
+
`Resolved env export cannot overwrite a runtime .env.<stage> input: ${candidate}`
|
|
3595
|
+
);
|
|
3596
|
+
}
|
|
3597
|
+
};
|
|
3338
3598
|
const stages = stage === void 0 ? STAGES : [stage];
|
|
3339
3599
|
const snapshots = stages.map((stage2) => ({
|
|
3340
3600
|
stage: stage2,
|
|
@@ -3352,7 +3612,7 @@ async function handleExportEnv(rawStage, options = {}) {
|
|
|
3352
3612
|
const files = [];
|
|
3353
3613
|
try {
|
|
3354
3614
|
for (const snapshot of snapshots) {
|
|
3355
|
-
let filename = path.join(projectDir, `.env.${snapshot.stage}`);
|
|
3615
|
+
let filename = path.join(projectDir, `.env.${snapshot.stage}.resolved`);
|
|
3356
3616
|
while (true) {
|
|
3357
3617
|
let overwrite = false;
|
|
3358
3618
|
if (existsSync(filename)) {
|
|
@@ -3362,9 +3622,11 @@ async function handleExportEnv(rawStage, options = {}) {
|
|
|
3362
3622
|
const name = (await ask(`New filename for ${snapshot.stage} (relative to the service directory): `)).trim();
|
|
3363
3623
|
if (!name) continue;
|
|
3364
3624
|
filename = path.resolve(projectDir, name);
|
|
3625
|
+
assertSafeDestination(filename);
|
|
3365
3626
|
continue;
|
|
3366
3627
|
}
|
|
3367
3628
|
}
|
|
3629
|
+
assertSafeDestination(filename);
|
|
3368
3630
|
mkdirSync(path.dirname(filename), { recursive: true });
|
|
3369
3631
|
try {
|
|
3370
3632
|
writeFileSync(filename, snapshot.content, { encoding: "utf-8", flag: overwrite ? "w" : "wx", mode: 384 });
|
|
@@ -3373,7 +3635,7 @@ async function handleExportEnv(rawStage, options = {}) {
|
|
|
3373
3635
|
throw error;
|
|
3374
3636
|
}
|
|
3375
3637
|
files.push(filename);
|
|
3376
|
-
console.log(
|
|
3638
|
+
console.log(pc14.green(`Exported ${snapshot.stage} application environment to ${filename}`));
|
|
3377
3639
|
break;
|
|
3378
3640
|
}
|
|
3379
3641
|
}
|
|
@@ -3449,10 +3711,10 @@ async function runCli(argv = process.argv) {
|
|
|
3449
3711
|
(arg) => arg === "-h" || arg === "--help" || arg === "-V" || arg === "--version"
|
|
3450
3712
|
);
|
|
3451
3713
|
if (!isHelpOrVersion && argv.length > 2) {
|
|
3452
|
-
console.log(
|
|
3714
|
+
console.log(pc14.dim(`builder v${version}`));
|
|
3453
3715
|
}
|
|
3454
3716
|
if (argv.length <= 2) {
|
|
3455
|
-
console.log(
|
|
3717
|
+
console.log(pc14.dim(`builder v${version}
|
|
3456
3718
|
`));
|
|
3457
3719
|
cli.outputHelp();
|
|
3458
3720
|
return;
|
|
@@ -3475,20 +3737,20 @@ async function runCli(argv = process.argv) {
|
|
|
3475
3737
|
if (err instanceof ScriptError) {
|
|
3476
3738
|
exitCode = err.exitCode;
|
|
3477
3739
|
const formatted = err.message.startsWith("\u274C") ? err.message : `\u274C ${err.message}`;
|
|
3478
|
-
console.error(
|
|
3740
|
+
console.error(pc14.red(`
|
|
3479
3741
|
${formatted}
|
|
3480
3742
|
`));
|
|
3481
3743
|
if (isVerbose && err.stack) {
|
|
3482
|
-
console.error(
|
|
3744
|
+
console.error(pc14.dim(err.stack));
|
|
3483
3745
|
}
|
|
3484
3746
|
} else {
|
|
3485
3747
|
const message = errorMessage(err);
|
|
3486
3748
|
const formatted = message.startsWith("\u274C") ? message : `\u274C Error: ${message}`;
|
|
3487
|
-
console.error(
|
|
3749
|
+
console.error(pc14.red(`
|
|
3488
3750
|
${formatted}
|
|
3489
3751
|
`));
|
|
3490
3752
|
if (isVerbose && err instanceof Error && err.stack) {
|
|
3491
|
-
console.error(
|
|
3753
|
+
console.error(pc14.dim(err.stack));
|
|
3492
3754
|
}
|
|
3493
3755
|
}
|
|
3494
3756
|
if (process.env.VITEST) {
|