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