@solid-stack/builder 2.0.1 → 2.0.3
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/dist/bin.js +467 -100
- package/dist/bin.js.map +1 -1
- package/dist/core/composition/compileServiceComposition.d.ts +2 -0
- package/dist/core/composition/compileServiceComposition.d.ts.map +1 -1
- package/dist/core/composition/composeBuildResources.d.ts +6 -0
- package/dist/core/composition/composeBuildResources.d.ts.map +1 -0
- package/dist/core/composition/composeDependsOn.d.ts +3 -0
- package/dist/core/composition/composeDependsOn.d.ts.map +1 -0
- package/dist/core/composition/composeEnvironment.d.ts +2 -2
- package/dist/core/composition/composeEnvironment.d.ts.map +1 -1
- package/dist/core/composition/composeHealthcheck.d.ts +3 -0
- package/dist/core/composition/composeHealthcheck.d.ts.map +1 -0
- package/dist/core/composition/composePaths.d.ts +2 -0
- package/dist/core/composition/composePaths.d.ts.map +1 -1
- package/dist/core/composition/generatedNames.d.ts +9 -0
- package/dist/core/composition/generatedNames.d.ts.map +1 -0
- package/dist/core/composition/namespaceDependencyCompose.d.ts +3 -0
- package/dist/core/composition/namespaceDependencyCompose.d.ts.map +1 -1
- package/dist/core/composition/types.d.ts +8 -3
- package/dist/core/composition/types.d.ts.map +1 -1
- package/dist/core/composition/validateComposeResourceReferences.d.ts +7 -0
- package/dist/core/composition/validateComposeResourceReferences.d.ts.map +1 -0
- package/dist/core/composition/validateDependencyCompose.d.ts.map +1 -1
- package/dist/core/composition/validateOverrideCompose.d.ts +10 -3
- package/dist/core/composition/validateOverrideCompose.d.ts.map +1 -1
- package/dist/core/config/pathSafety.d.ts.map +1 -1
- package/dist/core/mesh/checkers/checkMeshServices.d.ts.map +1 -1
- package/dist/core/mesh/runners/runMeshTestUnit.d.ts.map +1 -1
- package/dist/core/mesh/v2/compileMeshComposition.d.ts.map +1 -1
- package/dist/core/mesh/v2/compileMeshTester.d.ts +2 -1
- package/dist/core/mesh/v2/compileMeshTester.d.ts.map +1 -1
- package/dist/core/mesh/v2/validateMeshTestStage.d.ts +22 -0
- package/dist/core/mesh/v2/validateMeshTestStage.d.ts.map +1 -0
- package/dist/index.js +467 -100
- package/dist/index.js.map +1 -1
- package/dist/templates/policy/dockerfile/dockerfile.rego +6 -9
- package/dist/utils/assertUniqueHostPortMappings.d.ts.map +1 -1
- package/dist/utils/checkPortCollision.d.ts.map +1 -1
- package/dist/utils/composePublishedPort.d.ts +3 -0
- package/dist/utils/composePublishedPort.d.ts.map +1 -0
- package/package.json +1 -1
- package/schemas/mesh-schema.json +310 -20
- package/templates/policy/dockerfile/dockerfile.rego +6 -9
package/dist/bin.js
CHANGED
|
@@ -7,9 +7,9 @@ import { z } from 'zod';
|
|
|
7
7
|
import { spawnSync, spawn } from 'child_process';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
9
|
import { parseAllDocuments, parse, stringify } from 'yaml';
|
|
10
|
-
import crypto from 'crypto';
|
|
10
|
+
import crypto, { createHash } from 'crypto';
|
|
11
|
+
import net, { isIP } from 'net';
|
|
11
12
|
import os from 'os';
|
|
12
|
-
import net from 'net';
|
|
13
13
|
import { createInterface } from 'readline/promises';
|
|
14
14
|
import { createRequire } from 'module';
|
|
15
15
|
|
|
@@ -137,8 +137,12 @@ var getBuildJson = (projectDir = process.cwd()) => {
|
|
|
137
137
|
}
|
|
138
138
|
return result.data;
|
|
139
139
|
};
|
|
140
|
+
function isAbsoluteManagedPath(value) {
|
|
141
|
+
return path.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || /^\\\\/.test(value) || /^\/\//.test(value);
|
|
142
|
+
}
|
|
140
143
|
function resolveInsideProject(projectDir, relativePath, context) {
|
|
141
144
|
if (!relativePath.trim()) throw new ConfigError({ ...context, value: relativePath, reason: "Path must not be empty" });
|
|
145
|
+
if (isAbsoluteManagedPath(relativePath)) throw new ConfigError({ ...context, value: relativePath, reason: "Builder-managed path must be relative to its project root" });
|
|
142
146
|
const resolved = path.resolve(projectDir, relativePath);
|
|
143
147
|
if (!isPathInside(projectDir, relativePath)) throw new ConfigError({ ...context, value: relativePath, reason: "Path escapes the project directory" });
|
|
144
148
|
return resolved;
|
|
@@ -327,6 +331,34 @@ function checkYamlFiles(build, projectDir) {
|
|
|
327
331
|
loadComposeDocument(absolutePath, { sourceFile: `${root}/build.json`, configPath: file.source, stage: file.stage ?? "base", composition: "service" });
|
|
328
332
|
}
|
|
329
333
|
}
|
|
334
|
+
var GeneratedComposeNameAllocator = class {
|
|
335
|
+
occupied;
|
|
336
|
+
allocated = /* @__PURE__ */ new Map();
|
|
337
|
+
constructor(initialNames = []) {
|
|
338
|
+
this.occupied = new Set(initialNames);
|
|
339
|
+
}
|
|
340
|
+
allocate(identity, hint) {
|
|
341
|
+
const existing = this.allocated.get(identity);
|
|
342
|
+
if (existing) return existing;
|
|
343
|
+
const hash = createHash("sha256").update(identity).digest("hex");
|
|
344
|
+
const safeHint = hint.replace(/[^a-zA-Z0-9_-]/g, "-") || "item";
|
|
345
|
+
for (const candidate of [
|
|
346
|
+
safeHint,
|
|
347
|
+
...[12, 16, 24, 32, 64].map((length) => `${safeHint}-${hash.slice(0, length)}`)
|
|
348
|
+
]) {
|
|
349
|
+
if (this.occupied.has(candidate)) continue;
|
|
350
|
+
this.occupied.add(candidate);
|
|
351
|
+
this.allocated.set(identity, candidate);
|
|
352
|
+
return candidate;
|
|
353
|
+
}
|
|
354
|
+
throw new Error(`Unable to allocate unique Compose name for ${identity}`);
|
|
355
|
+
}
|
|
356
|
+
assertUnique() {
|
|
357
|
+
if (new Set(this.allocated.values()).size !== this.allocated.size) {
|
|
358
|
+
throw new Error("Internal generated Compose name collision");
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
};
|
|
330
362
|
|
|
331
363
|
// src/core/composition/composeNetworks.ts
|
|
332
364
|
function normalizeNetworks(value) {
|
|
@@ -640,14 +672,33 @@ function volumeShort(v, base, out) {
|
|
|
640
672
|
if (mount?.type !== "bind" || !mount.source || /^(?:[\\/]|~|[a-z]:)/i.test(mount.source)) return v;
|
|
641
673
|
return rewriteVolumeSource(v, rebase(mount.source, base, out));
|
|
642
674
|
}
|
|
675
|
+
function isRemoteBuildContext(value) {
|
|
676
|
+
return /^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(value) || /^[^/@\s]+@[^:\s]+:.+/.test(value);
|
|
677
|
+
}
|
|
678
|
+
function rebaseAdditionalContext(value, base, out) {
|
|
679
|
+
if (value.startsWith("service:") || isRemoteBuildContext(value)) return value;
|
|
680
|
+
return rebase(value, base, out);
|
|
681
|
+
}
|
|
682
|
+
function rebaseAdditionalContexts(value, base, out) {
|
|
683
|
+
if (Array.isArray(value)) return value.map((entry) => {
|
|
684
|
+
if (typeof entry !== "string") return entry;
|
|
685
|
+
const separator = entry.indexOf("=");
|
|
686
|
+
if (separator < 0) return entry;
|
|
687
|
+
return `${entry.slice(0, separator)}=${rebaseAdditionalContext(entry.slice(separator + 1), base, out)}`;
|
|
688
|
+
});
|
|
689
|
+
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([name, context]) => [name, typeof context === "string" ? rebaseAdditionalContext(context, base, out) : context]));
|
|
690
|
+
return value;
|
|
691
|
+
}
|
|
643
692
|
function rebaseComposePaths(document, composeFilePath, outputProjectDir) {
|
|
644
693
|
const doc = structuredClone(document), base = path.dirname(composeFilePath), out = path.resolve(outputProjectDir);
|
|
645
694
|
for (const svc of Object.values(doc.services ?? {})) {
|
|
646
|
-
if (typeof svc.build === "string")
|
|
647
|
-
|
|
695
|
+
if (typeof svc.build === "string") {
|
|
696
|
+
if (!isRemoteBuildContext(svc.build)) svc.build = rebase(svc.build, base, out);
|
|
697
|
+
} else if (svc.build && typeof svc.build === "object") {
|
|
648
698
|
const b = svc.build;
|
|
649
699
|
const context = typeof b.context === "string" ? b.context : ".";
|
|
650
|
-
b.context = rebase(context, base, out);
|
|
700
|
+
if (!isRemoteBuildContext(context)) b.context = rebase(context, base, out);
|
|
701
|
+
if (b.additional_contexts !== void 0) b.additional_contexts = rebaseAdditionalContexts(b.additional_contexts, base, out);
|
|
651
702
|
}
|
|
652
703
|
if (typeof svc.env_file === "string") svc.env_file = rebase(svc.env_file, base, out);
|
|
653
704
|
else if (Array.isArray(svc.env_file)) svc.env_file = svc.env_file.map((v) => typeof v === "string" ? rebase(v, base, out) : v && typeof v === "object" && typeof v.path === "string" ? { ...v, path: rebase(v.path, base, out) } : v);
|
|
@@ -656,6 +707,52 @@ function rebaseComposePaths(document, composeFilePath, outputProjectDir) {
|
|
|
656
707
|
for (const kind of ["configs", "secrets"]) for (const def of Object.values(doc[kind] ?? {})) if (def && typeof def === "object" && typeof def.file === "string") def.file = rebase(def.file, base, out);
|
|
657
708
|
return doc;
|
|
658
709
|
}
|
|
710
|
+
function rebaseAppOverridePaths(document, serviceProjectDir, outputProjectDir) {
|
|
711
|
+
const doc = structuredClone(document);
|
|
712
|
+
const base = path.resolve(serviceProjectDir);
|
|
713
|
+
const out = path.resolve(outputProjectDir);
|
|
714
|
+
for (const svc of Object.values(doc.services ?? {})) {
|
|
715
|
+
if (svc.build && typeof svc.build === "object" && !Array.isArray(svc.build)) {
|
|
716
|
+
const build = svc.build;
|
|
717
|
+
if (typeof build.context === "string") {
|
|
718
|
+
build.context = rebase(build.context, base, out);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (typeof svc.env_file === "string") {
|
|
722
|
+
svc.env_file = rebase(svc.env_file, base, out);
|
|
723
|
+
} else if (Array.isArray(svc.env_file)) {
|
|
724
|
+
svc.env_file = svc.env_file.map((entry) => {
|
|
725
|
+
if (typeof entry === "string") return rebase(entry, base, out);
|
|
726
|
+
if (entry && typeof entry === "object") {
|
|
727
|
+
const value = entry;
|
|
728
|
+
if (typeof value.path === "string") return { ...value, path: rebase(value.path, base, out) };
|
|
729
|
+
}
|
|
730
|
+
return entry;
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
if (Array.isArray(svc.volumes)) {
|
|
734
|
+
svc.volumes = svc.volumes.map((volume) => {
|
|
735
|
+
if (typeof volume === "string") return volumeShort(volume, base, out);
|
|
736
|
+
if (volume && typeof volume === "object") {
|
|
737
|
+
const value = volume;
|
|
738
|
+
if (value.type === "bind" && typeof value.source === "string") {
|
|
739
|
+
return { ...value, source: rebase(value.source, base, out) };
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
return volume;
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
for (const kind of ["configs", "secrets"]) {
|
|
747
|
+
for (const definition of Object.values(doc[kind] ?? {})) {
|
|
748
|
+
if (definition && typeof definition === "object") {
|
|
749
|
+
const value = definition;
|
|
750
|
+
if (typeof value.file === "string") value.file = rebase(value.file, base, out);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return doc;
|
|
755
|
+
}
|
|
659
756
|
|
|
660
757
|
// src/core/composition/composeEnvironment.ts
|
|
661
758
|
function normalizeComposeEnvironment(value, context) {
|
|
@@ -666,7 +763,7 @@ function normalizeComposeEnvironment(value, context) {
|
|
|
666
763
|
if (typeof item !== "string") throw new ConfigError({ configPath: context, value: item, reason: "Compose environment entries must be strings" });
|
|
667
764
|
const at = item.indexOf("=");
|
|
668
765
|
if (at < 0) {
|
|
669
|
-
result[item] =
|
|
766
|
+
result[item] = null;
|
|
670
767
|
continue;
|
|
671
768
|
}
|
|
672
769
|
result[item.slice(0, at)] = item.slice(at + 1);
|
|
@@ -675,7 +772,10 @@ function normalizeComposeEnvironment(value, context) {
|
|
|
675
772
|
}
|
|
676
773
|
if (typeof value !== "object") throw new ConfigError({ configPath: context, value, reason: "Compose environment must be a map or list" });
|
|
677
774
|
for (const [key, val] of Object.entries(value)) {
|
|
678
|
-
if (val === null || val === void 0)
|
|
775
|
+
if (val === null || val === void 0) {
|
|
776
|
+
result[key] = null;
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
679
779
|
if (typeof val === "object") throw new ConfigError({ configPath: `${context}.${key}`, value: val, reason: "Compose environment value must be scalar" });
|
|
680
780
|
result[key] = String(val);
|
|
681
781
|
}
|
|
@@ -685,16 +785,66 @@ function mergeComposeEnvironment(service, overlay) {
|
|
|
685
785
|
service.environment = { ...normalizeComposeEnvironment(service.environment, "service.environment"), ...overlay };
|
|
686
786
|
}
|
|
687
787
|
|
|
788
|
+
// src/core/composition/composeBuildResources.ts
|
|
789
|
+
function buildObject(service) {
|
|
790
|
+
return service.build && typeof service.build === "object" && !Array.isArray(service.build) ? service.build : void 0;
|
|
791
|
+
}
|
|
792
|
+
function rewriteBuildSecretReferences(service, names) {
|
|
793
|
+
const build = buildObject(service);
|
|
794
|
+
if (!build || !Array.isArray(build.secrets)) return;
|
|
795
|
+
build.secrets = build.secrets.map((entry) => {
|
|
796
|
+
if (typeof entry === "string") return names.get(entry) ?? entry;
|
|
797
|
+
if (entry && typeof entry === "object" && typeof entry.source === "string") {
|
|
798
|
+
return { ...entry, source: names.get(entry.source) ?? entry.source };
|
|
799
|
+
}
|
|
800
|
+
return entry;
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
function collectBuildSecretReferences(service) {
|
|
804
|
+
const build = buildObject(service);
|
|
805
|
+
if (!build || !Array.isArray(build.secrets)) return [];
|
|
806
|
+
return build.secrets.flatMap((entry) => {
|
|
807
|
+
if (typeof entry === "string") return [entry];
|
|
808
|
+
return entry && typeof entry === "object" && typeof entry.source === "string" ? [entry.source] : [];
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
function assertNoServiceBuildContexts(service, configPath, sourceFile) {
|
|
812
|
+
const contexts = buildObject(service)?.additional_contexts;
|
|
813
|
+
const values = Array.isArray(contexts) ? contexts.map((entry) => typeof entry === "string" ? entry.slice(entry.indexOf("=") + 1) : entry) : contexts && typeof contexts === "object" ? Object.values(contexts) : [];
|
|
814
|
+
if (values.some((value) => typeof value === "string" && value.startsWith("service:"))) {
|
|
815
|
+
throw new ConfigError({
|
|
816
|
+
sourceFile,
|
|
817
|
+
configPath: `${configPath}.build.additional_contexts`,
|
|
818
|
+
reason: "Compose service-reference additional_contexts are unsupported"
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
688
823
|
// src/core/composition/namespaceDependencyCompose.ts
|
|
689
824
|
var entries = (obj) => obj && typeof obj === "object" && !Array.isArray(obj) ? Object.entries(obj) : [];
|
|
690
825
|
function namespaceDependencyCompose(options) {
|
|
691
826
|
const { document, namespacePrefix: prefix } = options, doc = structuredClone(document);
|
|
692
|
-
const
|
|
693
|
-
const
|
|
694
|
-
|
|
827
|
+
const originalServices = doc.services ?? {};
|
|
828
|
+
const usesImplicitDefault = Object.values(originalServices).some((service) => service.network_mode === void 0 && service.networks === void 0);
|
|
829
|
+
if (usesImplicitDefault && !Object.hasOwn(doc.networks ?? {}, "default")) doc.networks = { ...doc.networks ?? {}, default: {} };
|
|
830
|
+
const allocator = options.allocator ?? new GeneratedComposeNameAllocator();
|
|
831
|
+
const identityPrefix = options.identityPrefix ?? JSON.stringify(["dependency", options.dependencyKey, prefix]);
|
|
832
|
+
const make = (kind, keys) => new Map(keys.sort().map((k) => [k, allocator.allocate(JSON.stringify([identityPrefix, kind, k]), kind === "service" ? `${prefix}--${k}` : `${prefix}--${kind}--${k}`)]));
|
|
833
|
+
const serviceNameMap = make("service", Object.keys(doc.services ?? {}));
|
|
695
834
|
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 ?? {}));
|
|
696
835
|
const rewriteKeys = (obj, map) => Object.fromEntries(entries(obj).map(([k, v]) => [map.get(k) ?? k, v]));
|
|
697
|
-
const
|
|
836
|
+
const addOriginalNetworkAliases = (name, svc) => {
|
|
837
|
+
if (svc.network_mode !== void 0 || svc.networks === void 0) return;
|
|
838
|
+
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 } : {};
|
|
839
|
+
for (const [network, rawOptions] of Object.entries(attached)) {
|
|
840
|
+
const options2 = rawOptions && typeof rawOptions === "object" && !Array.isArray(rawOptions) ? rawOptions : {};
|
|
841
|
+
const aliases = Array.isArray(options2.aliases) ? options2.aliases.filter((alias) => typeof alias === "string") : [];
|
|
842
|
+
attached[network] = { ...options2, aliases: [.../* @__PURE__ */ new Set([...aliases, name])] };
|
|
843
|
+
}
|
|
844
|
+
svc.networks = attached;
|
|
845
|
+
};
|
|
846
|
+
const rewriteResourceRefs = (svc, originalName) => {
|
|
847
|
+
rewriteBuildSecretReferences(svc, secretNameMap);
|
|
698
848
|
if (Array.isArray(svc.depends_on)) {
|
|
699
849
|
svc.depends_on = svc.depends_on.map((v) => typeof v === "string" ? serviceNameMap.get(v) ?? v : v);
|
|
700
850
|
} else if (svc.depends_on && typeof svc.depends_on === "object") svc.depends_on = rewriteKeys(svc.depends_on, serviceNameMap);
|
|
@@ -709,17 +859,14 @@ function namespaceDependencyCompose(options) {
|
|
|
709
859
|
}
|
|
710
860
|
if (Array.isArray(svc.volumes_from)) svc.volumes_from = svc.volumes_from.map((v) => typeof v === "string" ? v.replace(/^([^:]+)(.*)$/, (all, n, rest) => `${serviceNameMap.get(n) ?? n}${rest}`) : v);
|
|
711
861
|
if (Array.isArray(svc.volumes)) svc.volumes = svc.volumes.map((v) => namespaceVolume(v, volumeNameMap));
|
|
712
|
-
if (svc.networks === void 0 && svc.network_mode === void 0 &&
|
|
862
|
+
if (svc.networks === void 0 && svc.network_mode === void 0 && networkNameMap.has("default")) svc.networks = { default: null };
|
|
713
863
|
for (const key of ["ipc", "pid"]) if (typeof svc[key] === "string" && svc[key].startsWith("service:")) svc[key] = `service:${serviceNameMap.get(svc[key].slice(8)) ?? svc[key].slice(8)}`;
|
|
714
|
-
if (svc.extends && typeof svc.extends === "object" && !svc.extends.file) {
|
|
715
|
-
const ref = svc.extends;
|
|
716
|
-
if (typeof ref.service === "string") ref.service = serviceNameMap.get(ref.service) ?? ref.service;
|
|
717
|
-
}
|
|
718
864
|
if (Array.isArray(svc.networks)) svc.networks = svc.networks.map((v) => typeof v === "string" ? networkNameMap.get(v) ?? v : v);
|
|
719
865
|
else if (svc.networks && typeof svc.networks === "object") svc.networks = rewriteKeys(svc.networks, networkNameMap);
|
|
720
866
|
for (const key of ["configs", "secrets"]) if (Array.isArray(svc[key])) svc[key] = svc[key].map((v) => typeof v === "string" ? (key === "configs" ? configNameMap : secretNameMap).get(v) ?? v : v && typeof v === "object" ? { ...v, source: (key === "configs" ? configNameMap : secretNameMap).get(v.source) ?? v.source } : v);
|
|
867
|
+
addOriginalNetworkAliases(originalName, svc);
|
|
721
868
|
};
|
|
722
|
-
for (const svc of Object.
|
|
869
|
+
for (const [name, svc] of Object.entries(originalServices)) rewriteResourceRefs(svc, name);
|
|
723
870
|
doc.services = rewriteKeys(doc.services, serviceNameMap);
|
|
724
871
|
if (doc.volumes) doc.volumes = rewriteKeys(doc.volumes, volumeNameMap);
|
|
725
872
|
if (doc.networks) doc.networks = rewriteKeys(doc.networks, networkNameMap);
|
|
@@ -728,14 +875,81 @@ function namespaceDependencyCompose(options) {
|
|
|
728
875
|
return { document: doc, serviceNameMap, volumeNameMap, networkNameMap, configNameMap, secretNameMap };
|
|
729
876
|
}
|
|
730
877
|
|
|
878
|
+
// src/core/composition/validateComposeResourceReferences.ts
|
|
879
|
+
function validateComposeResourceReferences(document, context, onlyServices) {
|
|
880
|
+
const selected = onlyServices ? new Set(onlyServices) : void 0;
|
|
881
|
+
const fail = (configPath, kind, name) => {
|
|
882
|
+
throw new ConfigError({
|
|
883
|
+
sourceFile: context.sourceFile,
|
|
884
|
+
configPath,
|
|
885
|
+
...context.stage ? { stage: context.stage } : {},
|
|
886
|
+
composition: context.composition,
|
|
887
|
+
referencedObject: name,
|
|
888
|
+
reason: `Compose ${kind} reference "${name}" has no top-level definition`
|
|
889
|
+
});
|
|
890
|
+
};
|
|
891
|
+
const exists = (kind, name) => {
|
|
892
|
+
const definitions = document[kind === "volume" ? "volumes" : kind === "network" ? "networks" : kind === "config" ? "configs" : "secrets"];
|
|
893
|
+
return Boolean(definitions && Object.hasOwn(definitions, name));
|
|
894
|
+
};
|
|
895
|
+
const check = (path20, kind, name) => {
|
|
896
|
+
if (kind === "network" && name === "default") return;
|
|
897
|
+
if (!exists(kind, name)) fail(path20, kind, name);
|
|
898
|
+
};
|
|
899
|
+
for (const [serviceName, service] of Object.entries(document.services ?? {})) {
|
|
900
|
+
if (selected && !selected.has(serviceName)) continue;
|
|
901
|
+
validateServiceResources(serviceName, service, check);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
function validateServiceResources(serviceName, service, check) {
|
|
905
|
+
for (const mount of Array.isArray(service.volumes) ? service.volumes : []) {
|
|
906
|
+
const parsed = parseVolume(mount);
|
|
907
|
+
if (parsed?.type === "volume" && parsed.source) {
|
|
908
|
+
check(`services.${serviceName}.volumes`, "volume", parsed.source);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
const networks = service.networks;
|
|
912
|
+
const networkNames = Array.isArray(networks) ? networks.filter((name) => typeof name === "string") : networks && typeof networks === "object" ? Object.keys(networks) : [];
|
|
913
|
+
for (const name of networkNames) {
|
|
914
|
+
check(`services.${serviceName}.networks`, "network", name);
|
|
915
|
+
}
|
|
916
|
+
for (const kind of ["configs", "secrets"]) {
|
|
917
|
+
const entries2 = service[kind];
|
|
918
|
+
if (!Array.isArray(entries2)) continue;
|
|
919
|
+
for (const entry of entries2) {
|
|
920
|
+
const name = typeof entry === "string" ? entry : entry && typeof entry === "object" && typeof entry.source === "string" ? entry.source : void 0;
|
|
921
|
+
if (name) check(`services.${serviceName}.${kind}`, kind === "configs" ? "config" : "secret", name);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
for (const name of collectBuildSecretReferences(service)) {
|
|
925
|
+
check(`services.${serviceName}.build.secrets`, "secret", name);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// src/core/composition/composeHealthcheck.ts
|
|
930
|
+
function isEnabledValidComposeHealthcheck(value) {
|
|
931
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
932
|
+
const health = value;
|
|
933
|
+
if (health.disable === true) return false;
|
|
934
|
+
const test = health.test;
|
|
935
|
+
if (typeof test === "string") return test.trim().length > 0;
|
|
936
|
+
if (!Array.isArray(test) || !test.every((item) => typeof item === "string")) return false;
|
|
937
|
+
if (test[0] !== "CMD" && test[0] !== "CMD-SHELL") return false;
|
|
938
|
+
return test.length >= 2 && test.slice(1).some((item) => item.trim().length > 0);
|
|
939
|
+
}
|
|
940
|
+
|
|
731
941
|
// src/core/composition/validateDependencyCompose.ts
|
|
732
942
|
function validateDependencyCompose(dependencyKey, dependency, document, context) {
|
|
733
943
|
const fail = (configPath, reason, value) => {
|
|
734
944
|
throw new ConfigError({ sourceFile: context.composePath, configPath, stage: context.stage, composition: "service", ...value === void 0 ? {} : { value }, reason: `Dependency "${dependencyKey}": ${reason}` });
|
|
735
945
|
};
|
|
736
946
|
if (document.include !== void 0) fail("include", "Compose include is unsupported for atomic dependency implementations");
|
|
947
|
+
validateComposeResourceReferences(document, { sourceFile: context.composePath, stage: context.stage, composition: "service" });
|
|
737
948
|
const services = document.services ?? {};
|
|
738
949
|
for (const [name, svc] of Object.entries(services)) {
|
|
950
|
+
assertNoServiceBuildContexts(svc, `services.${name}`, context.composePath);
|
|
951
|
+
if (svc.profiles !== void 0) fail(`services.${name}.profiles`, "dependency Compose profiles are unsupported because a materialized dependency is atomic");
|
|
952
|
+
if (svc.extends !== void 0) fail(`services.${name}.extends`, "dependency Compose extends is unsupported until effective endpoint-owner networking and health can be validated");
|
|
739
953
|
if (svc.ports !== void 0) fail(`services.${name}.ports`, "raw dependency ports are forbidden");
|
|
740
954
|
if (svc.network_mode === "host") fail(`services.${name}.network_mode`, "host network mode is forbidden");
|
|
741
955
|
if (svc.privileged === true) fail(`services.${name}.privileged`, `privileged services are forbidden`);
|
|
@@ -758,11 +972,6 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
|
|
|
758
972
|
for (const ref of svc.volumes_from) if (typeof ref === "string") internalRefs.push(["volumes_from", ref.split(":")[0]]);
|
|
759
973
|
}
|
|
760
974
|
for (const key of ["ipc", "pid"]) if (typeof svc[key] === "string" && svc[key].startsWith("service:")) internalRefs.push([key, svc[key].slice(8)]);
|
|
761
|
-
if (svc.extends && typeof svc.extends === "object") {
|
|
762
|
-
const ref = svc.extends;
|
|
763
|
-
if (ref.file !== void 0) fail(`services.${name}.extends.file`, "external extends is unsupported for atomic dependency implementations");
|
|
764
|
-
if (typeof ref.service === "string") internalRefs.push(["extends.service", ref.service]);
|
|
765
|
-
}
|
|
766
975
|
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);
|
|
767
976
|
}
|
|
768
977
|
if (!Object.keys(dependency.endpoints).length) return;
|
|
@@ -775,32 +984,52 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
|
|
|
775
984
|
}
|
|
776
985
|
for (const owner of owners) {
|
|
777
986
|
if (services[owner].network_mode !== void 0) fail(`services.${owner}.network_mode`, `endpoint owner cannot use network_mode`);
|
|
778
|
-
|
|
779
|
-
if (!health || health.disable === true || !health.test || typeof health.test === "string" && !health.test.trim() || Array.isArray(health.test) && (!health.test.length || health.test[0] === "NONE" || health.test.every((v) => typeof v === "string" && !v.trim()))) fail(`services.${owner}.healthcheck`, `endpoint owner requires an enabled, non-empty healthcheck`);
|
|
987
|
+
if (!isEnabledValidComposeHealthcheck(services[owner].healthcheck)) fail(`services.${owner}.healthcheck`, "endpoint owner requires a valid enabled Compose healthcheck");
|
|
780
988
|
}
|
|
781
989
|
}
|
|
782
|
-
|
|
783
|
-
|
|
990
|
+
function canonicalBuildContext(value, baseDir) {
|
|
991
|
+
return canonicalPath(path.resolve(baseDir, value));
|
|
992
|
+
}
|
|
993
|
+
function isSameBuildContext(actual, expected, baseDir) {
|
|
994
|
+
return canonicalBuildContext(actual, baseDir) === canonicalBuildContext(expected, baseDir);
|
|
995
|
+
}
|
|
784
996
|
function validateAndPrepareAppOverride(document, context) {
|
|
785
|
-
const fail = (
|
|
786
|
-
throw new ConfigError({ sourceFile: context.file, configPath:
|
|
997
|
+
const fail = (path20, reason, value) => {
|
|
998
|
+
throw new ConfigError({ sourceFile: context.file, configPath: path20, stage: context.stage, composition: "service", ...value === void 0 ? {} : { value }, reason });
|
|
787
999
|
};
|
|
1000
|
+
const allowedRootKeys = /* @__PURE__ */ new Set(["services", "volumes", "networks", "configs", "secrets"]);
|
|
1001
|
+
for (const key of Object.keys(document)) if (!key.startsWith("x-") && !allowedRootKeys.has(key)) fail(key, "unsupported override Compose top-level field");
|
|
788
1002
|
const keys = Object.keys(document.services ?? {});
|
|
789
1003
|
if (keys.length !== 1 || keys[0] !== "app") fail("services", "override must define exactly one service named app");
|
|
790
1004
|
const app = structuredClone(document.services.app);
|
|
791
|
-
for (const k of ["ports", "depends_on", "network_mode", "container_name", "privileged"]) if (app[k] !== void 0) fail(`services.app.${k}`, "override cannot own endpoint or lifecycle behavior");
|
|
1005
|
+
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");
|
|
792
1006
|
if (app.healthcheck && typeof app.healthcheck === "object") {
|
|
793
1007
|
const health = app.healthcheck;
|
|
794
1008
|
for (const key of Object.keys(health)) if (!["interval", "timeout", "retries", "start_period", "start_interval"].includes(key)) fail(`services.app.healthcheck.${key}`, "override may set only healthcheck timing fields");
|
|
795
1009
|
}
|
|
1010
|
+
if (typeof app.build === "string") {
|
|
1011
|
+
fail("services.app.build", "override cannot replace Builder-owned app build context; use object-form build.args for build arguments", app.build);
|
|
1012
|
+
}
|
|
796
1013
|
if (app.build && typeof app.build === "object") {
|
|
797
|
-
const
|
|
798
|
-
for (const
|
|
799
|
-
|
|
1014
|
+
const build = app.build;
|
|
1015
|
+
for (const key of Object.keys(build)) {
|
|
1016
|
+
if (!["args", "context"].includes(key)) {
|
|
1017
|
+
fail(`services.app.build.${key}`, "override cannot change Builder-owned build configuration");
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
if (build.context !== void 0) {
|
|
1021
|
+
if (typeof build.context !== "string") {
|
|
1022
|
+
fail("services.app.build.context", "override app build context must be a string", build.context);
|
|
1023
|
+
}
|
|
1024
|
+
if (!isSameBuildContext(build.context, context.expectedBuildContext, context.buildContextBaseDir)) {
|
|
1025
|
+
fail("services.app.build.context", "override cannot change app build context", build.context);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
800
1028
|
}
|
|
801
1029
|
const env = normalizeComposeEnvironment(app.environment, "services.app.environment");
|
|
802
1030
|
for (const k of ["EXEC_MODE", "INFRA_MODE"]) if (k in env) fail(`services.app.environment.${k}`, "override cannot set Builder-owned environment");
|
|
803
1031
|
app.environment = env;
|
|
1032
|
+
const allocator = context.allocator ?? new GeneratedComposeNameAllocator();
|
|
804
1033
|
const resourceKeys = ["volumes", "networks", "configs", "secrets"];
|
|
805
1034
|
const resources = {};
|
|
806
1035
|
for (const kind of resourceKeys) {
|
|
@@ -816,7 +1045,8 @@ function validateAndPrepareAppOverride(document, context) {
|
|
|
816
1045
|
const names = /* @__PURE__ */ new Map(), mapped = {};
|
|
817
1046
|
for (const [name, definition] of Object.entries(defs)) {
|
|
818
1047
|
if (!refs2.has(name)) fail(`${kind}.${name}`, "override resource must be consumed by app");
|
|
819
|
-
const
|
|
1048
|
+
const prefix = context.resourceNamespace && context.resourceNamespace !== "app" ? `svc--${context.resourceNamespace}--app-override` : "app-override";
|
|
1049
|
+
const target = allocator.allocate(JSON.stringify(["service", context.resourceNamespace ?? "app", "override", context.stage, kind, name]), `${prefix}--${context.stage}--${kind.slice(0, -1)}--${name}`);
|
|
820
1050
|
names.set(name, target);
|
|
821
1051
|
mapped[target] = definition;
|
|
822
1052
|
}
|
|
@@ -938,13 +1168,14 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
938
1168
|
const seed = getTemplateSeed(stage, Boolean(options.meshMode));
|
|
939
1169
|
const rawName = options.projectNameOverride ?? raw.name ?? path.basename(root);
|
|
940
1170
|
const projectName = deriveProjectName(rawName, stage);
|
|
1171
|
+
const nameAllocator = options.nameAllocator ?? new GeneratedComposeNameAllocator(["app", "tester", "default", options.appServiceName ?? "app"]);
|
|
941
1172
|
const namespaced = {};
|
|
942
1173
|
for (const [key, dep] of Object.entries(effective.dependencies).sort(([a], [b]) => a.localeCompare(b))) {
|
|
943
1174
|
const sourcePath = resolveInsideProject(root, dep.compose, { sourceFile: buildPath, configPath: `dependencies.${key}.compose`, stage });
|
|
944
1175
|
const document = rebaseComposePaths(loadComposeDocument(sourcePath, { sourceFile: buildPath, configPath: `dependencies.${key}.compose`, stage, composition: "service" }), sourcePath, options.composeOutputDir ?? root);
|
|
945
1176
|
validateDependencyCompose(key, dep, document, { composePath: sourcePath, stage });
|
|
946
1177
|
if (Object.keys(dep.endpoints).length) {
|
|
947
|
-
const ns = namespaceDependencyCompose({ namespacePrefix: options.namespacePrefix ? `${options.namespacePrefix}${key}` : `dep--${key}`, document });
|
|
1178
|
+
const ns = namespaceDependencyCompose({ dependencyKey: key, namespacePrefix: options.namespacePrefix ? `${options.namespacePrefix}${key}` : `dep--${key}`, document, allocator: nameAllocator, identityPrefix: JSON.stringify(["service", options.appServiceName ?? "app", "dependency", key]) });
|
|
948
1179
|
namespaced[key] = { doc: ns.document, map: ns.serviceNameMap, source: sourcePath };
|
|
949
1180
|
}
|
|
950
1181
|
}
|
|
@@ -959,7 +1190,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
959
1190
|
const endpointOwnerMap = /* @__PURE__ */ new Map();
|
|
960
1191
|
for (const [epName, ep] of Object.entries(dep.endpoints)) endpointOwnerMap.set(epName, entry.map.get(ep.service));
|
|
961
1192
|
const endpointOwners = new Set(endpointOwnerMap.values());
|
|
962
|
-
materialized[key] = { key, composePath: entry.source, compose: item, serviceNameMap: entry.map, endpointOwnerMap, endpoints: {}, endpointOwners };
|
|
1193
|
+
materialized[key] = { key, composePath: entry.source, compose: item, serviceNameMap: entry.map, endpointOwnerMap, endpoints: {}, endpointOwners, serviceNames: new Set(Object.keys(item.services)) };
|
|
963
1194
|
}
|
|
964
1195
|
const appEndpoints = buildStandaloneAppEndpoints(effective, stage, options.appServiceName ?? "app");
|
|
965
1196
|
const depEndpoints = {};
|
|
@@ -1008,8 +1239,9 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
1008
1239
|
const depEnv = options.deferReferenceResolution ? dep.env : resolveEnv(dep.env, registry, `dependencies.${key}.env`);
|
|
1009
1240
|
for (const svc of Object.values(materialized[key]?.compose.services ?? {})) mergeComposeEnvironment(svc, depEnv);
|
|
1010
1241
|
}
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1242
|
+
const buildJsonAppEnvironment = ownEnv(effective, stage);
|
|
1243
|
+
const appEnv = options.deferReferenceResolution ? buildJsonAppEnvironment : resolveEnv(buildJsonAppEnvironment, registry, "app.env");
|
|
1244
|
+
let overrideComposeAppEnvironment = {};
|
|
1013
1245
|
const runtimeDotenv = path.join(root, `.env.${profile.runtimeStage}`);
|
|
1014
1246
|
if (fs.existsSync(runtimeDotenv)) {
|
|
1015
1247
|
const text = fs.readFileSync(runtimeDotenv, "utf8");
|
|
@@ -1048,14 +1280,31 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
1048
1280
|
for (const [epName, ep] of Object.entries(depEndpoints[key])) dependency.endpoints[epName] = ep;
|
|
1049
1281
|
}
|
|
1050
1282
|
if (effective.overrideCompose) {
|
|
1051
|
-
const overridePath = resolveInsideProject(root, effective.overrideCompose, {
|
|
1052
|
-
|
|
1053
|
-
|
|
1283
|
+
const overridePath = resolveInsideProject(root, effective.overrideCompose, {
|
|
1284
|
+
sourceFile: buildPath,
|
|
1285
|
+
configPath: "override-compose",
|
|
1286
|
+
stage
|
|
1287
|
+
});
|
|
1288
|
+
const loadedOverride = loadComposeDocument(overridePath, {
|
|
1289
|
+
sourceFile: buildPath,
|
|
1290
|
+
configPath: "override-compose",
|
|
1291
|
+
stage,
|
|
1292
|
+
composition: "service"
|
|
1293
|
+
});
|
|
1294
|
+
const overrideDocument = rebaseAppOverridePaths(loadedOverride, root, outputDir);
|
|
1295
|
+
const prepared = validateAndPrepareAppOverride(overrideDocument, {
|
|
1296
|
+
file: overridePath,
|
|
1297
|
+
stage,
|
|
1298
|
+
expectedBuildContext: String(appBuild.context),
|
|
1299
|
+
buildContextBaseDir: outputDir,
|
|
1300
|
+
allocator: nameAllocator,
|
|
1301
|
+
resourceNamespace: options.meshMode ? options.appServiceName ?? "app" : "app"
|
|
1302
|
+
});
|
|
1054
1303
|
for (const section of ["volumes", "networks", "configs", "secrets"]) if (prepared.resources[section]) mergeDocument(compose, { services: {}, [section]: prepared.resources[section] }, "app override");
|
|
1055
1304
|
const rawOverrideEnv = normalizeComposeEnvironment(prepared.app.environment, "override-compose.services.app.environment");
|
|
1056
|
-
const overrideEnv =
|
|
1305
|
+
const overrideEnv = rawOverrideEnv;
|
|
1057
1306
|
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" });
|
|
1058
|
-
|
|
1307
|
+
overrideComposeAppEnvironment = { ...overrideEnv };
|
|
1059
1308
|
const merged = { ...app, ...prepared.app };
|
|
1060
1309
|
merged.environment = { ...appEnv, ...overrideEnv, ...options.externalAppEnv ? Object.fromEntries(Object.entries(options.externalAppEnv).map(([k, v]) => [k, v.replace(/\$/g, "$$$$")])) : {}, ...internal };
|
|
1061
1310
|
const overrideBuild = prepared.app.build && typeof prepared.app.build === "object" ? prepared.app.build : {};
|
|
@@ -1078,8 +1327,8 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
1078
1327
|
const testerEnv = options.deferReferenceResolution ? testerEnvRaw : resolveEnv(testerEnvRaw, registry, "tester.env");
|
|
1079
1328
|
compose.services.tester = { build: { context: ".", ...raw.dockerfile ? { dockerfile: raw.dockerfile } : {}, target: "test-e2e" }, network_mode: "host", environment: testerEnv, depends_on: { app: { condition: "service_healthy" } } };
|
|
1080
1329
|
}
|
|
1081
|
-
|
|
1082
|
-
return { compose, effectiveBuild: effective, endpoints: { app: appEndpoints, dependencies: depEndpoints }, projectName, ...profile.attachTester && !options.meshMode ? { testerServiceName: "tester" } : {},
|
|
1330
|
+
nameAllocator.assertUnique();
|
|
1331
|
+
return { compose, effectiveBuild: effective, endpoints: { app: appEndpoints, dependencies: depEndpoints }, projectName, ...profile.attachTester && !options.meshMode ? { testerServiceName: "tester" } : {}, buildJsonAppEnvironment, overrideComposeAppEnvironment, 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])) };
|
|
1083
1332
|
}
|
|
1084
1333
|
|
|
1085
1334
|
// src/core/checkers/checkEffectiveServiceStages.ts
|
|
@@ -1365,18 +1614,29 @@ function applyMeshLifecycleEdges(services, edges) {
|
|
|
1365
1614
|
}
|
|
1366
1615
|
}
|
|
1367
1616
|
|
|
1617
|
+
// src/core/composition/composeDependsOn.ts
|
|
1618
|
+
function normalizeComposeDependsOn(value) {
|
|
1619
|
+
if (Array.isArray(value)) {
|
|
1620
|
+
return Object.fromEntries(value.filter((item) => typeof item === "string").map((name) => [name, {}]));
|
|
1621
|
+
}
|
|
1622
|
+
return value && typeof value === "object" ? { ...value } : {};
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1368
1625
|
// src/core/mesh/v2/compileMeshTester.ts
|
|
1369
1626
|
function refs(svc) {
|
|
1370
|
-
const out =
|
|
1627
|
+
const out = /* @__PURE__ */ new Set();
|
|
1371
1628
|
const add = (v) => {
|
|
1372
|
-
if (typeof v === "string") out.
|
|
1629
|
+
if (typeof v === "string" && v) out.add(v);
|
|
1373
1630
|
};
|
|
1374
1631
|
if (Array.isArray(svc.depends_on)) svc.depends_on.forEach(add);
|
|
1375
1632
|
else if (svc.depends_on && typeof svc.depends_on === "object") Object.keys(svc.depends_on).forEach(add);
|
|
1376
1633
|
if (Array.isArray(svc.links)) svc.links.forEach((v) => add(typeof v === "string" ? v.split(":")[0] : v));
|
|
1377
1634
|
if (Array.isArray(svc.volumes_from)) svc.volumes_from.forEach((v) => add(typeof v === "string" ? v.split(":")[0] : v));
|
|
1378
|
-
|
|
1379
|
-
|
|
1635
|
+
for (const property of ["network_mode", "ipc", "pid"]) {
|
|
1636
|
+
const value = svc[property];
|
|
1637
|
+
if (typeof value === "string" && value.startsWith("service:")) add(value.slice("service:".length));
|
|
1638
|
+
}
|
|
1639
|
+
return [...out];
|
|
1380
1640
|
}
|
|
1381
1641
|
function referencedResources(svc, doc) {
|
|
1382
1642
|
const sets = { volumes: /* @__PURE__ */ new Set(), networks: /* @__PURE__ */ new Set(), configs: /* @__PURE__ */ new Set(), secrets: /* @__PURE__ */ new Set() };
|
|
@@ -1400,20 +1660,25 @@ function referencedResources(svc, doc) {
|
|
|
1400
1660
|
if (typeof n === "string" && doc[kind]?.[n]) sets[kind].add(n);
|
|
1401
1661
|
}
|
|
1402
1662
|
}
|
|
1663
|
+
for (const name of collectBuildSecretReferences(svc)) if (doc.secrets && name in doc.secrets) sets.secrets.add(name);
|
|
1403
1664
|
return sets;
|
|
1404
1665
|
}
|
|
1405
|
-
function compileMeshTester(meshDir, tester, endpointRegistry, effectiveTopLevelApps, stage, referenceContext) {
|
|
1666
|
+
function compileMeshTester(meshDir, tester, endpointRegistry, effectiveTopLevelApps, stage, referenceContext, nameAllocator = new GeneratedComposeNameAllocator(effectiveTopLevelApps)) {
|
|
1406
1667
|
const meshPath = `${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);
|
|
1407
1668
|
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" });
|
|
1408
1669
|
const included = /* @__PURE__ */ new Set(), visit = (name) => {
|
|
1409
1670
|
if (included.has(name)) return;
|
|
1410
|
-
|
|
1671
|
+
const service = raw.services[name];
|
|
1672
|
+
if (!service) throw new ConfigError({ sourceFile: file, configPath: `services.${name}`, stage, composition: "mesh", reason: "Tester service dependency does not exist" });
|
|
1673
|
+
if (service.extends !== void 0) throw new ConfigError({ sourceFile: file, configPath: `services.${name}.extends`, stage, composition: "mesh", reason: "Tester Compose extends is unsupported until effective Compose inheritance can be validated before host-network rewriting" });
|
|
1411
1674
|
included.add(name);
|
|
1412
|
-
for (const ref of refs(
|
|
1675
|
+
for (const ref of refs(service)) visit(ref);
|
|
1413
1676
|
};
|
|
1414
1677
|
visit(tester.service);
|
|
1678
|
+
validateComposeResourceReferences(raw, { sourceFile: file, stage, composition: "mesh" }, included);
|
|
1415
1679
|
for (const name of included) {
|
|
1416
1680
|
const svc = raw.services[name];
|
|
1681
|
+
assertNoServiceBuildContexts(svc, `services.${name}`, file);
|
|
1417
1682
|
if (name !== tester.service && svc.network_mode === "host") throw new ConfigError({ sourceFile: file, configPath: `services.${name}.network_mode`, stage, composition: "mesh", reason: "Only the selected tester runner may use host networking" });
|
|
1418
1683
|
if (name === tester.service && svc.network_mode !== void 0 && svc.network_mode !== "host") throw new ConfigError({ sourceFile: file, configPath: `services.${name}.network_mode`, stage, composition: "mesh", reason: "Selected tester runner must be compatible with host networking" });
|
|
1419
1684
|
if (name === tester.service && svc.networks !== void 0) throw new ConfigError({ sourceFile: file, configPath: `services.${name}.networks`, stage, composition: "mesh", reason: "Selected host-network tester runner cannot declare networks" });
|
|
@@ -1425,7 +1690,7 @@ function compileMeshTester(meshDir, tester, endpointRegistry, effectiveTopLevelA
|
|
|
1425
1690
|
}
|
|
1426
1691
|
const selected = { services: Object.fromEntries([...included].map((k) => [k, raw.services[k]])) };
|
|
1427
1692
|
for (const k of Object.keys(res)) if (res[k].size) selected[k] = Object.fromEntries([...res[k]].map((n) => [n, raw[k]?.[n]]));
|
|
1428
|
-
const ns = namespaceDependencyCompose({ namespacePrefix: "mesh-tester", document: selected });
|
|
1693
|
+
const ns = namespaceDependencyCompose({ dependencyKey: "mesh-tester", namespacePrefix: "mesh-tester", document: selected, allocator: nameAllocator, identityPrefix: JSON.stringify(["mesh-tester"]) });
|
|
1429
1694
|
const runner = ns.serviceNameMap.get(tester.service);
|
|
1430
1695
|
const runnerSvc = ns.document.services[runner];
|
|
1431
1696
|
if (runnerSvc.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" });
|
|
@@ -1435,25 +1700,52 @@ function compileMeshTester(meshDir, tester, endpointRegistry, effectiveTopLevelA
|
|
|
1435
1700
|
const env = tester.env ?? {};
|
|
1436
1701
|
assertMeshTesterEnvPublic(env, "tester.env");
|
|
1437
1702
|
runnerSvc.environment = { ...normalizeComposeEnvironment(runnerSvc.environment, "tester runner environment"), ...resolveMeshEnvMap(env, meshCtx, "tester.env") };
|
|
1438
|
-
const depends =
|
|
1703
|
+
const depends = normalizeComposeDependsOn(runnerSvc.depends_on);
|
|
1439
1704
|
for (const app of effectiveTopLevelApps) depends[app] = { condition: "service_healthy" };
|
|
1440
1705
|
runnerSvc.depends_on = depends;
|
|
1441
1706
|
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 };
|
|
1442
1707
|
}
|
|
1708
|
+
function validPort(value) {
|
|
1709
|
+
if (!/^\d+$/.test(value)) return void 0;
|
|
1710
|
+
const port = Number(value);
|
|
1711
|
+
return Number.isInteger(port) && port >= 1 && port <= 65535 ? port : void 0;
|
|
1712
|
+
}
|
|
1713
|
+
function parsePublishedHostPort(value) {
|
|
1714
|
+
if (value && typeof value === "object") {
|
|
1715
|
+
const published = value.published;
|
|
1716
|
+
if (typeof published === "number" && Number.isInteger(published)) {
|
|
1717
|
+
return published >= 1 && published <= 65535 ? published : void 0;
|
|
1718
|
+
}
|
|
1719
|
+
if (typeof published === "string") return validPort(published);
|
|
1720
|
+
return void 0;
|
|
1721
|
+
}
|
|
1722
|
+
if (typeof value !== "string") return void 0;
|
|
1723
|
+
const mapping = value.replace(/\/(?:tcp|udp|sctp)$/i, "");
|
|
1724
|
+
if (/^\d+(?:-\d+)?$/.test(mapping)) return void 0;
|
|
1725
|
+
if (mapping.startsWith("[")) {
|
|
1726
|
+
const close = mapping.indexOf("]");
|
|
1727
|
+
if (close < 0 || isIP(mapping.slice(1, close)) !== 6) return void 0;
|
|
1728
|
+
const suffix = mapping.slice(close + 1);
|
|
1729
|
+
const match = suffix.match(/^:(\d+)(?:-\d+)?:\d+(?:-\d+)?$/);
|
|
1730
|
+
return match ? validPort(match[1]) : void 0;
|
|
1731
|
+
}
|
|
1732
|
+
const parts = mapping.split(":");
|
|
1733
|
+
if (parts.length === 2) return validPort(parts[0]);
|
|
1734
|
+
if (parts.length >= 3) {
|
|
1735
|
+
const hostIp = parts.slice(0, -2).join(":");
|
|
1736
|
+
if (isIP(hostIp) === 4) return validPort(parts[parts.length - 2]);
|
|
1737
|
+
}
|
|
1738
|
+
return void 0;
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
// src/utils/assertUniqueHostPortMappings.ts
|
|
1443
1742
|
function assertUniqueHostPortMappings(yamlConfig) {
|
|
1444
1743
|
const parsed = parse(yamlConfig);
|
|
1445
1744
|
const owners = /* @__PURE__ */ new Map();
|
|
1446
1745
|
for (const [serviceName, service] of Object.entries(parsed?.services ?? {})) {
|
|
1447
1746
|
for (const port of service?.ports ?? []) {
|
|
1448
|
-
|
|
1449
|
-
if (
|
|
1450
|
-
const parts = port.split(":");
|
|
1451
|
-
if (parts.length === 2) hostPort = Number(parts[0]);
|
|
1452
|
-
if (parts.length === 3) hostPort = Number(parts[1]);
|
|
1453
|
-
} else if (port && typeof port === "object" && "published" in port) {
|
|
1454
|
-
hostPort = Number(port.published);
|
|
1455
|
-
}
|
|
1456
|
-
if (!hostPort || !Number.isInteger(hostPort)) continue;
|
|
1747
|
+
const hostPort = parsePublishedHostPort(port);
|
|
1748
|
+
if (hostPort === void 0) continue;
|
|
1457
1749
|
const existing = owners.get(hostPort);
|
|
1458
1750
|
if (existing) {
|
|
1459
1751
|
throw new ScriptError(
|
|
@@ -1482,6 +1774,26 @@ function appendPort(service, target, published) {
|
|
|
1482
1774
|
ports.push({ target, published, host_ip: PUBLIC_HOST, protocol: "tcp" });
|
|
1483
1775
|
service.ports = ports;
|
|
1484
1776
|
}
|
|
1777
|
+
function buildMeshPortIntents(services, publication) {
|
|
1778
|
+
const intents = [];
|
|
1779
|
+
for (const name of Object.keys(services).sort((a, b) => a.localeCompare(b))) {
|
|
1780
|
+
const service = services[name];
|
|
1781
|
+
const appPublications = publication.filter((pub) => pub.ownerMeshService === name && pub.target === "app").sort((a, b) => a.endpoint.localeCompare(b.endpoint));
|
|
1782
|
+
for (const pub of appPublications) {
|
|
1783
|
+
const endpoint = service.effectiveBuild.app.endpoints[pub.endpoint];
|
|
1784
|
+
intents.push({ logicalPath: pub.logicalPath, requested: endpoint.publicPort });
|
|
1785
|
+
}
|
|
1786
|
+
const dependencyNames = [...new Set(publication.filter((pub) => pub.ownerMeshService === name && pub.target === "dependency").map((pub) => pub.dependency))].sort((a, b) => a.localeCompare(b));
|
|
1787
|
+
for (const dependency of dependencyNames) {
|
|
1788
|
+
const dependencyPublications = publication.filter((pub) => pub.ownerMeshService === name && pub.target === "dependency" && pub.dependency === dependency).sort((a, b) => a.endpoint.localeCompare(b.endpoint));
|
|
1789
|
+
for (const pub of dependencyPublications) {
|
|
1790
|
+
const endpoint = service.effectiveBuild.dependencies[dependency].endpoints[pub.endpoint];
|
|
1791
|
+
intents.push({ logicalPath: pub.logicalPath, requested: endpoint.publicPort });
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
return intents;
|
|
1796
|
+
}
|
|
1485
1797
|
function ownerFor(pub, fragment) {
|
|
1486
1798
|
return pub.target === "app" ? pub.ownerMeshService : fragment.endpoints.dependencies[pub.dependency]?.[pub.endpoint]?.networkHost ?? "";
|
|
1487
1799
|
}
|
|
@@ -1489,15 +1801,20 @@ function setEnv(service, env) {
|
|
|
1489
1801
|
const current = service.environment && typeof service.environment === "object" && !Array.isArray(service.environment) ? service.environment : {};
|
|
1490
1802
|
service.environment = { ...current, ...env };
|
|
1491
1803
|
}
|
|
1804
|
+
function attachNetworkIfCompatible(service, networkName) {
|
|
1805
|
+
if (service.network_mode !== void 0) return;
|
|
1806
|
+
service.networks = { ...normalizeNetworks(service.networks), [networkName]: null };
|
|
1807
|
+
}
|
|
1492
1808
|
function compileMeshComposition(stage, meshDir, options = {}) {
|
|
1493
1809
|
const meshPath = path.join(meshDir, "mesh.json"), raw = getMeshJson(meshDir), effective = resolveMeshStage(raw, stage, meshPath), services = loadEffectiveMeshServices(meshDir, effective, stage), bindings = buildDependencyBindings(services, stage, meshPath), bindingMap = bindingsMap(bindings);
|
|
1494
1810
|
const rawName = raw.name ?? path.basename(meshDir), projectName = deriveProjectName(rawName, stage, meshDir);
|
|
1811
|
+
const nameAllocator = new GeneratedComposeNameAllocator(["mesh", "default", ...Object.keys(services), ...Object.keys(services).map((name) => `mesh--${name}`)]);
|
|
1495
1812
|
const fragments = {};
|
|
1496
1813
|
const compose = { name: projectName, services: {}, networks: { mesh: { driver: "bridge" } } };
|
|
1497
1814
|
for (const [name, svc] of Object.entries(services).sort(([a], [b]) => a.localeCompare(b))) {
|
|
1498
1815
|
for (const key of ["EXEC_MODE", "INFRA_MODE", ...Object.keys(svc.effectiveBuild.app.endpoints).some((ep) => svc.effectiveBuild.app.endpoints[ep]?.primary) ? ["PORT"] : []]) if (key in svc.meshEnv) throw new ConfigError({ sourceFile: meshPath, configPath: `services.${name}.env.${key}`, stage, composition: "mesh", reason: "Mesh service env cannot set Builder-owned environment" });
|
|
1499
1816
|
const suppress = new Set(Object.keys(svc.dependencyBindings));
|
|
1500
|
-
const fragment = compileServiceComposition(stage, svc.absolutePath, { full: true, meshMode: true, projectNameOverride: projectName, namespacePrefix: `svc--${name}--dep--`, suppressDependencies: suppress, externalAppEnv: svc.meshEnv, deferReferenceResolution: true, appServiceName: name, composeOutputDir: meshDir, validationMode: options.validationMode });
|
|
1817
|
+
const fragment = compileServiceComposition(stage, svc.absolutePath, { nameAllocator, full: true, meshMode: true, projectNameOverride: projectName, namespacePrefix: `svc--${name}--dep--`, suppressDependencies: suppress, externalAppEnv: svc.meshEnv, deferReferenceResolution: true, appServiceName: name, composeOutputDir: meshDir, validationMode: options.validationMode });
|
|
1501
1818
|
fragments[name] = fragment;
|
|
1502
1819
|
mergeFragment(compose, fragment.compose, name);
|
|
1503
1820
|
const app = compose.services[name];
|
|
@@ -1511,32 +1828,17 @@ function compileMeshComposition(stage, meshDir, options = {}) {
|
|
|
1511
1828
|
for (const ep of Object.values(fragment.endpoints.dependencies[dep] ?? {})) {
|
|
1512
1829
|
const owner = ep.networkHost;
|
|
1513
1830
|
const ownerService = compose.services[owner];
|
|
1514
|
-
if (ownerService)
|
|
1515
|
-
const old = normalizeNetworks(ownerService.networks);
|
|
1516
|
-
old[privateName] = null;
|
|
1517
|
-
ownerService.networks = old;
|
|
1518
|
-
}
|
|
1831
|
+
if (ownerService) attachNetworkIfCompatible(ownerService, privateName);
|
|
1519
1832
|
}
|
|
1520
|
-
for (const generated of
|
|
1833
|
+
for (const generated of fragment.dependencyServiceNames?.[dep] ?? []) {
|
|
1521
1834
|
const ownerService = compose.services[generated];
|
|
1522
|
-
|
|
1523
|
-
old[privateName] = null;
|
|
1524
|
-
ownerService.networks = old;
|
|
1835
|
+
attachNetworkIfCompatible(ownerService, privateName);
|
|
1525
1836
|
}
|
|
1526
1837
|
}
|
|
1527
1838
|
}
|
|
1528
1839
|
app.networks = { ...normalizeNetworks(app.networks), ...networks };
|
|
1529
1840
|
}
|
|
1530
|
-
const publication = resolveMeshPublication(services, bindingMap, stage, meshPath), intents =
|
|
1531
|
-
for (const name of Object.keys(services).sort()) for (const pub of publication.filter((p) => p.ownerMeshService === name && p.target === "app").sort((a, b) => a.endpoint.localeCompare(b.endpoint))) {
|
|
1532
|
-
const ep = services[name].effectiveBuild.app.endpoints[pub.endpoint];
|
|
1533
|
-
intents.push({ logicalPath: pub.logicalPath, requested: ep.publicPort });
|
|
1534
|
-
}
|
|
1535
|
-
for (const name of Object.keys(services).sort()) for (const pub of publication.filter((p) => p.ownerMeshService === name && p.target === "dependency").sort((a, b) => `${a.dependency}.${a.endpoint}`.localeCompare(`${b.dependency}.${b.endpoint}`))) {
|
|
1536
|
-
const ep = services[name].effectiveBuild.dependencies[pub.dependency].endpoints[pub.endpoint];
|
|
1537
|
-
intents.push({ logicalPath: pub.logicalPath, requested: ep.publicPort });
|
|
1538
|
-
}
|
|
1539
|
-
const ports = allocateHostPorts(meshDir, stage, intents, Boolean(options.validationMode));
|
|
1841
|
+
const publication = resolveMeshPublication(services, bindingMap, stage, meshPath), intents = buildMeshPortIntents(services, publication), ports = allocateHostPorts(meshDir, stage, intents, Boolean(options.validationMode));
|
|
1540
1842
|
const endpoints = { app: {}, dependencies: {} };
|
|
1541
1843
|
for (const [name, svc] of Object.entries(services)) {
|
|
1542
1844
|
endpoints.app[name] = {};
|
|
@@ -1573,15 +1875,17 @@ function compileMeshComposition(stage, meshDir, options = {}) {
|
|
|
1573
1875
|
const refContext = { services, bindings: bindingMap, endpoints, stage, meshJsonPath: meshPath };
|
|
1574
1876
|
for (const [name, fragment] of Object.entries(fragments)) {
|
|
1575
1877
|
const app = compose.services[name];
|
|
1576
|
-
const buildEnv = resolveServiceBuildEnvThroughMesh(name, fragment.
|
|
1878
|
+
const buildEnv = resolveServiceBuildEnvThroughMesh(name, fragment.buildJsonAppEnvironment ?? {}, refContext, `services.${name}.app.env`);
|
|
1577
1879
|
const meshEnv = resolveMeshEnvMap(fragment.externalAppEnvironment ?? {}, refContext, `services.${name}.env`);
|
|
1578
|
-
|
|
1880
|
+
app.environment = { ...buildEnv, ...fragment.overrideComposeAppEnvironment ?? {}, ...meshEnv, ...fragment.builderInternalEnvironment ?? {} };
|
|
1579
1881
|
for (const [depName, depEnv] of Object.entries(fragment.dependencyEnvironments ?? {})) {
|
|
1580
1882
|
const logicalBinding = bindingMap.get(bindingKey(name, depName));
|
|
1581
1883
|
if (logicalBinding) continue;
|
|
1582
1884
|
const resolvedDep = resolveServiceBuildEnvThroughMesh(name, depEnv, refContext, `services.${name}.dependencies.${depName}.env`);
|
|
1583
|
-
const
|
|
1584
|
-
|
|
1885
|
+
for (const serviceName of fragment.dependencyServiceNames?.[depName] ?? []) {
|
|
1886
|
+
const service = compose.services[serviceName];
|
|
1887
|
+
if (service) setEnv(service, resolvedDep);
|
|
1888
|
+
}
|
|
1585
1889
|
}
|
|
1586
1890
|
}
|
|
1587
1891
|
const edges = buildMeshLifecycleEdges(services, bindingMap, stage, meshPath);
|
|
@@ -1616,18 +1920,85 @@ function compileMeshComposition(stage, meshDir, options = {}) {
|
|
|
1616
1920
|
let testerServiceName;
|
|
1617
1921
|
if (stage === "e2e") {
|
|
1618
1922
|
if (!raw.tester && !options.allowMissingTester) throw new ConfigError({ sourceFile: meshPath, configPath: "tester", stage, composition: "mesh", reason: "Global mesh E2E requires root mesh.json.tester { compose, service, env? }" });
|
|
1619
|
-
const built = raw.tester ? compileMeshTester(meshDir, raw.tester, endpoints, Object.keys(services).sort(), "e2e", refContext) : void 0;
|
|
1923
|
+
const built = raw.tester ? compileMeshTester(meshDir, raw.tester, endpoints, Object.keys(services).sort(), "e2e", refContext, nameAllocator) : void 0;
|
|
1620
1924
|
if (built) {
|
|
1621
1925
|
const fragment = { services: built.services, ...built.volumes ? { volumes: built.volumes } : {}, ...built.networks ? { networks: built.networks } : {}, ...built.configs ? { configs: built.configs } : {}, ...built.secrets ? { secrets: built.secrets } : {} };
|
|
1622
1926
|
mergeFragment(compose, fragment, "mesh tester");
|
|
1623
1927
|
testerServiceName = built.runnerServiceName;
|
|
1624
1928
|
}
|
|
1625
1929
|
}
|
|
1930
|
+
nameAllocator.assertUnique();
|
|
1626
1931
|
const yaml = stringify(compose);
|
|
1627
1932
|
assertUniqueHostPortMappings(yaml);
|
|
1628
1933
|
return { compose, effectiveMesh: effective, loadedServices: services, endpoints, projectName, ...testerServiceName ? { testerServiceName } : {} };
|
|
1629
1934
|
}
|
|
1630
1935
|
|
|
1936
|
+
// src/core/mesh/v2/validateMeshTestStage.ts
|
|
1937
|
+
function validateMeshTestStage(services, meshDir, meshPath, validationMode = false) {
|
|
1938
|
+
const bindings = bindingsMap(buildDependencyBindings(services, "test", meshPath));
|
|
1939
|
+
const publication = resolveMeshPublication(
|
|
1940
|
+
services,
|
|
1941
|
+
bindings,
|
|
1942
|
+
"test",
|
|
1943
|
+
meshPath
|
|
1944
|
+
);
|
|
1945
|
+
for (const pub of publication) {
|
|
1946
|
+
if (pub.target === "dependency") {
|
|
1947
|
+
throw new ConfigError({
|
|
1948
|
+
sourceFile: meshPath,
|
|
1949
|
+
configPath: `services.${pub.ownerMeshService}.publish`,
|
|
1950
|
+
stage: "test",
|
|
1951
|
+
composition: "mesh",
|
|
1952
|
+
value: pub.logicalPath,
|
|
1953
|
+
reason: "mesh.test is isolated; dependency endpoints are not materialized and cannot be published"
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
const appPublications = publication.filter((pub) => pub.target === "app").sort(
|
|
1958
|
+
(a, b) => a.ownerMeshService.localeCompare(b.ownerMeshService) || a.endpoint.localeCompare(b.endpoint)
|
|
1959
|
+
).map((pub) => {
|
|
1960
|
+
const endpoint = services[pub.ownerMeshService].effectiveBuild.app.endpoints[pub.endpoint];
|
|
1961
|
+
return {
|
|
1962
|
+
meshService: pub.ownerMeshService,
|
|
1963
|
+
endpoint: pub.endpoint,
|
|
1964
|
+
logicalPath: pub.logicalPath,
|
|
1965
|
+
containerPort: endpoint.port,
|
|
1966
|
+
requested: endpoint.publicPort
|
|
1967
|
+
};
|
|
1968
|
+
});
|
|
1969
|
+
const intents = appPublications.map((pub) => ({
|
|
1970
|
+
logicalPath: pub.logicalPath,
|
|
1971
|
+
requested: pub.requested
|
|
1972
|
+
}));
|
|
1973
|
+
const allocatedPorts = allocateHostPorts(
|
|
1974
|
+
meshDir,
|
|
1975
|
+
"test",
|
|
1976
|
+
intents,
|
|
1977
|
+
validationMode
|
|
1978
|
+
);
|
|
1979
|
+
return { bindings, appPublications, allocatedPorts };
|
|
1980
|
+
}
|
|
1981
|
+
function applyTestAppPublications(validated, meshService, app, endpointRegistry) {
|
|
1982
|
+
for (const publication of validated.appPublications) {
|
|
1983
|
+
if (publication.meshService !== meshService) continue;
|
|
1984
|
+
const published = validated.allocatedPorts.get(publication.logicalPath);
|
|
1985
|
+
const ports = Array.isArray(app.ports) ? app.ports : [];
|
|
1986
|
+
ports.push({
|
|
1987
|
+
target: publication.containerPort,
|
|
1988
|
+
published,
|
|
1989
|
+
host_ip: PUBLIC_HOST,
|
|
1990
|
+
protocol: "tcp"
|
|
1991
|
+
});
|
|
1992
|
+
app.ports = ports;
|
|
1993
|
+
const endpoint = endpointRegistry[publication.endpoint];
|
|
1994
|
+
if (endpoint) {
|
|
1995
|
+
endpoint.publicHost = PUBLIC_HOST;
|
|
1996
|
+
endpoint.publicPort = published;
|
|
1997
|
+
endpoint.effectivelyPublished = true;
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
|
|
1631
2002
|
// src/core/mesh/checkers/checkMeshServices.ts
|
|
1632
2003
|
function checkMeshServices(mesh, meshDir) {
|
|
1633
2004
|
const root = resolveProjectDir(meshDir), meshPath = path.join(root, "mesh.json");
|
|
@@ -1635,6 +2006,7 @@ function checkMeshServices(mesh, meshDir) {
|
|
|
1635
2006
|
for (const stage of ["dev", "prod", "test", "e2e"]) {
|
|
1636
2007
|
const effective = resolveMeshStage(mesh, stage, meshPath);
|
|
1637
2008
|
const services = loadEffectiveMeshServices(root, effective, stage);
|
|
2009
|
+
if (stage === "test") validateMeshTestStage(services, root, meshPath, true);
|
|
1638
2010
|
for (const [name, svc] of Object.entries(services)) {
|
|
1639
2011
|
if (!checked.has(svc.absolutePath)) {
|
|
1640
2012
|
console.log(pc22.cyan(`
|
|
@@ -1649,7 +2021,7 @@ function checkMeshServices(mesh, meshDir) {
|
|
|
1649
2021
|
for (const key of ["EXEC_MODE", "INFRA_MODE", ...Object.values(svc.effectiveBuild.app.endpoints).some((ep) => ep.primary) ? ["PORT"] : []]) {
|
|
1650
2022
|
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" });
|
|
1651
2023
|
}
|
|
1652
|
-
resolveServiceBuildEnvThroughMesh(name, fragment.
|
|
2024
|
+
resolveServiceBuildEnvThroughMesh(name, fragment.buildJsonAppEnvironment ?? {}, ctx, `services.${name}.app.env`);
|
|
1653
2025
|
for (const [depName, depEnv] of Object.entries(fragment.dependencyEnvironments ?? {})) resolveServiceBuildEnvThroughMesh(name, depEnv, ctx, `services.${name}.dependencies.${depName}.env`);
|
|
1654
2026
|
resolveMeshEnvMap(svc.meshEnv, ctx, `services.${name}.env`);
|
|
1655
2027
|
}
|
|
@@ -2118,15 +2490,9 @@ function extractHostPorts(yamlConfig) {
|
|
|
2118
2490
|
if (parsed?.services && typeof parsed.services === "object") {
|
|
2119
2491
|
for (const svc of Object.values(parsed.services)) {
|
|
2120
2492
|
if (Array.isArray(svc?.ports)) {
|
|
2121
|
-
for (const
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
const hostPort = parts.length > 1 ? parseInt(parts[0], 10) : parseInt(p, 10);
|
|
2125
|
-
if (!isNaN(hostPort)) ports.push(hostPort);
|
|
2126
|
-
} else if (typeof p === "object" && p.published) {
|
|
2127
|
-
const hostPort = parseInt(p.published, 10);
|
|
2128
|
-
if (!isNaN(hostPort)) ports.push(hostPort);
|
|
2129
|
-
}
|
|
2493
|
+
for (const mapping of svc.ports) {
|
|
2494
|
+
const hostPort = parsePublishedHostPort(mapping);
|
|
2495
|
+
if (hostPort !== void 0) ports.push(hostPort);
|
|
2130
2496
|
}
|
|
2131
2497
|
}
|
|
2132
2498
|
}
|
|
@@ -2300,7 +2666,7 @@ async function runMeshProd(options = {}) {
|
|
|
2300
2666
|
return status;
|
|
2301
2667
|
}
|
|
2302
2668
|
async function runMeshTestUnit(options = {}) {
|
|
2303
|
-
const meshDir = resolveProjectDir(options.projectDir), meshPath = path.join(meshDir, "mesh.json"), raw = getMeshJson(meshDir), effective = resolveMeshStage(raw, "test", meshPath), services = loadEffectiveMeshServices(meshDir, effective, "test");
|
|
2669
|
+
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));
|
|
2304
2670
|
console.log(pc22.bold(pc22.blue("\n[1/2] MESH SERVICE UNIT/ISOLATED TESTS\n")));
|
|
2305
2671
|
for (const [name, svc] of Object.entries(services).sort(([a], [b]) => a.localeCompare(b))) {
|
|
2306
2672
|
console.log(pc22.cyan(`-> Running isolated unit tests for [${name}]`));
|
|
@@ -2309,11 +2675,12 @@ async function runMeshTestUnit(options = {}) {
|
|
|
2309
2675
|
const refCtx = { services: { [name]: svc }, bindings: /* @__PURE__ */ new Map(), endpoints, stage: "test", meshJsonPath: meshPath };
|
|
2310
2676
|
const env = svc.meshEnv;
|
|
2311
2677
|
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" });
|
|
2312
|
-
const resolvedBuild = resolveServiceBuildEnvThroughMesh(name, compiled.
|
|
2678
|
+
const resolvedBuild = resolveServiceBuildEnvThroughMesh(name, compiled.buildJsonAppEnvironment ?? {}, refCtx, `services.${name}.app.env`);
|
|
2313
2679
|
for (const [depName, depEnv] of Object.entries(compiled.dependencyEnvironments ?? {})) resolveServiceBuildEnvThroughMesh(name, depEnv, refCtx, `services.${name}.dependencies.${depName}.env`);
|
|
2314
2680
|
const resolved = resolveMeshEnvMap(env, refCtx, `services.${name}.env`);
|
|
2315
2681
|
const app = compiled.compose.services.app;
|
|
2316
|
-
app.environment = { ...
|
|
2682
|
+
app.environment = { ...resolvedBuild, ...compiled.overrideComposeAppEnvironment ?? {}, ...resolved, ...compiled.builderInternalEnvironment ?? {} };
|
|
2683
|
+
applyTestAppPublications(validated, name, app, compiled.endpoints.app);
|
|
2317
2684
|
const projectName = `${deriveProjectName(raw.name ?? path.basename(meshDir), "dev")}-${name}-test`;
|
|
2318
2685
|
compiled.compose.name = projectName;
|
|
2319
2686
|
const yaml = stringify(compiled.compose);
|