@solid-stack/builder 2.0.0 → 2.0.2
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 +10 -0
- package/dist/bin.js +287 -125
- package/dist/bin.js.map +1 -1
- package/dist/commands/mesh/commands/down/handler.d.ts.map +1 -1
- package/dist/commands/mesh/commands/up/handler.d.ts.map +1 -1
- package/dist/commands/service/commands/down/handler.d.ts.map +1 -1
- package/dist/core/checkers/checkDockerfile.d.ts.map +1 -1
- package/dist/core/checkers/checkDockerfileContract.d.ts.map +1 -1
- package/dist/core/composition/compileServiceComposition.d.ts.map +1 -1
- package/dist/core/composition/composeNetworks.d.ts +2 -0
- package/dist/core/composition/composeNetworks.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/composeVolumes.d.ts +15 -0
- package/dist/core/composition/composeVolumes.d.ts.map +1 -0
- package/dist/core/composition/namespaceDependencyCompose.d.ts.map +1 -1
- package/dist/core/composition/validateDependencyCompose.d.ts.map +1 -1
- package/dist/core/composition/validateOverrideCompose.d.ts +7 -3
- package/dist/core/composition/validateOverrideCompose.d.ts.map +1 -1
- package/dist/core/config/pathSafety.d.ts +1 -0
- package/dist/core/config/pathSafety.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/runMeshTestE2e.d.ts.map +1 -1
- package/dist/core/mesh/v2/compileMeshComposition.d.ts.map +1 -1
- package/dist/core/runners/runDev.d.ts.map +1 -1
- package/dist/core/runners/runProd.d.ts.map +1 -1
- package/dist/core/teardownCompose.d.ts +1 -0
- package/dist/core/teardownCompose.d.ts.map +1 -1
- package/dist/index.js +287 -125
- package/dist/index.js.map +1 -1
- package/dist/utils/paths.d.ts +2 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/runState.d.ts +1 -0
- package/dist/utils/runState.d.ts.map +1 -1
- package/package.json +6 -3
package/dist/bin.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, Argument } from 'commander';
|
|
3
3
|
import pc22 from 'picocolors';
|
|
4
|
-
import fs, { existsSync, readFileSync, mkdirSync, writeFileSync, statSync, unlinkSync, renameSync } from 'fs';
|
|
5
|
-
import
|
|
4
|
+
import fs, { existsSync, readFileSync, mkdirSync, writeFileSync, statSync, unlinkSync, renameSync, realpathSync, lstatSync, readlinkSync } from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { spawnSync, spawn } from 'child_process';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
@@ -79,18 +79,44 @@ function errorMessage(err) {
|
|
|
79
79
|
return String(err);
|
|
80
80
|
}
|
|
81
81
|
function resolveProjectDir(projectDir) {
|
|
82
|
-
return
|
|
82
|
+
return path.resolve(projectDir ?? process.cwd());
|
|
83
|
+
}
|
|
84
|
+
function isBindMount(source) {
|
|
85
|
+
if (!source) return false;
|
|
86
|
+
if (source.startsWith(".") || source.startsWith("/") || source.startsWith("~") || source.startsWith("\\")) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
if (/^[a-zA-Z]:[\\/]/.test(source)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
83
93
|
}
|
|
84
94
|
function isPathInside(parentDir, childPath) {
|
|
85
|
-
const absParent =
|
|
86
|
-
const absChild =
|
|
87
|
-
const rel =
|
|
88
|
-
return rel !== ".." && !rel.startsWith(".." +
|
|
95
|
+
const absParent = canonicalPath(parentDir);
|
|
96
|
+
const absChild = canonicalPath(path.resolve(parentDir, childPath));
|
|
97
|
+
const rel = path.relative(absParent, absChild);
|
|
98
|
+
return rel !== ".." && !rel.startsWith(".." + path.sep) && !rel.startsWith("../") && !path.isAbsolute(rel);
|
|
99
|
+
}
|
|
100
|
+
function canonicalPath(value) {
|
|
101
|
+
const absolute = path.resolve(value);
|
|
102
|
+
try {
|
|
103
|
+
return realpathSync(absolute);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (error.code !== "ENOENT") throw error;
|
|
106
|
+
try {
|
|
107
|
+
if (lstatSync(absolute).isSymbolicLink()) return canonicalPath(path.resolve(path.dirname(absolute), readlinkSync(absolute)));
|
|
108
|
+
} catch (linkError) {
|
|
109
|
+
if (linkError.code !== "ENOENT") throw linkError;
|
|
110
|
+
}
|
|
111
|
+
const parent = path.dirname(absolute);
|
|
112
|
+
if (parent === absolute) throw error;
|
|
113
|
+
return path.join(canonicalPath(parent), path.basename(absolute));
|
|
114
|
+
}
|
|
89
115
|
}
|
|
90
116
|
|
|
91
117
|
// src/utils/getBuildJson.ts
|
|
92
118
|
var getBuildJson = (projectDir = process.cwd()) => {
|
|
93
|
-
const absProjectDir = resolveProjectDir(projectDir), buildJsonPath =
|
|
119
|
+
const absProjectDir = resolveProjectDir(projectDir), buildJsonPath = path.join(absProjectDir, "build.json");
|
|
94
120
|
if (!existsSync(buildJsonPath)) throw new NotFoundError(`Build JSON file not found at ${buildJsonPath}. Please make sure build.json exists in the project root.`);
|
|
95
121
|
let rawData;
|
|
96
122
|
try {
|
|
@@ -111,6 +137,18 @@ var getBuildJson = (projectDir = process.cwd()) => {
|
|
|
111
137
|
}
|
|
112
138
|
return result.data;
|
|
113
139
|
};
|
|
140
|
+
function resolveInsideProject(projectDir, relativePath, context) {
|
|
141
|
+
if (!relativePath.trim()) throw new ConfigError({ ...context, value: relativePath, reason: "Path must not be empty" });
|
|
142
|
+
const resolved = path.resolve(projectDir, relativePath);
|
|
143
|
+
if (!isPathInside(projectDir, relativePath)) throw new ConfigError({ ...context, value: relativePath, reason: "Path escapes the project directory" });
|
|
144
|
+
return resolved;
|
|
145
|
+
}
|
|
146
|
+
function resolveApplicationDockerfile(projectDir, relativePath = "Dockerfile", stage) {
|
|
147
|
+
const context = { sourceFile: path.join(projectDir, "build.json"), configPath: "dockerfile", ...stage ? { stage } : {} };
|
|
148
|
+
const resolved = resolveInsideProject(projectDir, relativePath, context);
|
|
149
|
+
if (!existsSync(resolved) || !statSync(resolved).isFile()) throw new ConfigError({ ...context, value: relativePath, reason: `Application Dockerfile not found or not a regular file: ${resolved}` });
|
|
150
|
+
return resolved;
|
|
151
|
+
}
|
|
114
152
|
|
|
115
153
|
// src/core/checkers/constants.ts
|
|
116
154
|
var HADOLINT_IMAGE = process.env.HADOLINT_IMAGE || "hadolint/hadolint:v2.12.0";
|
|
@@ -155,15 +193,7 @@ ${ctx.detail}`);
|
|
|
155
193
|
// src/core/checkers/checkDockerfile.ts
|
|
156
194
|
function checkDockerfile(buildJson, projectDir) {
|
|
157
195
|
const dockerfileRel = buildJson.dockerfile || "Dockerfile";
|
|
158
|
-
const dockerfilePath =
|
|
159
|
-
if (!isPathInside(projectDir, dockerfilePath)) {
|
|
160
|
-
throw new ScriptError(
|
|
161
|
-
`Security error: Dockerfile path "${dockerfileRel}" escapes the project directory.`
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
if (!existsSync(dockerfilePath)) {
|
|
165
|
-
throw new ConfigError({ sourceFile: path4.join(projectDir, "build.json"), configPath: "dockerfile", value: dockerfileRel, composition: "service", reason: `Application Dockerfile not found at ${dockerfilePath}` });
|
|
166
|
-
}
|
|
196
|
+
const dockerfilePath = resolveApplicationDockerfile(projectDir, dockerfileRel);
|
|
167
197
|
const content = readFileSync(dockerfilePath, "utf-8");
|
|
168
198
|
console.log(pc22.cyan(`
|
|
169
199
|
\u{1F50D} Linting Dockerfile (${dockerfileRel})...`));
|
|
@@ -183,8 +213,8 @@ function getTemplatesDir() {
|
|
|
183
213
|
lastEnvTemplatesDir = envVal;
|
|
184
214
|
}
|
|
185
215
|
if (envVal) {
|
|
186
|
-
const envDir =
|
|
187
|
-
if (!fs.existsSync(envDir) || !fs.existsSync(
|
|
216
|
+
const envDir = path.resolve(envVal);
|
|
217
|
+
if (!fs.existsSync(envDir) || !fs.existsSync(path.join(envDir, "docker"))) {
|
|
188
218
|
throw new ScriptError(
|
|
189
219
|
`BUILDER_TEMPLATES_DIR is set to "${envVal}" but directory does not exist or lacks a "docker/" subdirectory (resolved: "${envDir}").`
|
|
190
220
|
);
|
|
@@ -194,18 +224,18 @@ function getTemplatesDir() {
|
|
|
194
224
|
if (cachedTemplatesDir && fs.existsSync(cachedTemplatesDir)) {
|
|
195
225
|
return cachedTemplatesDir;
|
|
196
226
|
}
|
|
197
|
-
const currentDir = typeof __dirname !== "undefined" ? __dirname :
|
|
227
|
+
const currentDir = typeof __dirname !== "undefined" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
|
|
198
228
|
const candidates = [
|
|
199
229
|
// When executing compiled output in dist/ (e.g. dist/templates)
|
|
200
|
-
|
|
201
|
-
|
|
230
|
+
path.resolve(currentDir, "templates"),
|
|
231
|
+
path.resolve(currentDir, "../templates"),
|
|
202
232
|
// When executing from src/ (e.g. src/core/templates.ts -> ../../templates)
|
|
203
|
-
|
|
233
|
+
path.resolve(currentDir, "../../templates"),
|
|
204
234
|
// Fallback relative to cwd
|
|
205
|
-
|
|
235
|
+
path.resolve(process.cwd(), "templates")
|
|
206
236
|
];
|
|
207
237
|
for (const cand of candidates) {
|
|
208
|
-
if (fs.existsSync(cand) && fs.existsSync(
|
|
238
|
+
if (fs.existsSync(cand) && fs.existsSync(path.join(cand, "docker"))) {
|
|
209
239
|
cachedTemplatesDir = cand;
|
|
210
240
|
return cand;
|
|
211
241
|
}
|
|
@@ -217,15 +247,15 @@ ${candidates.join("\n")}`
|
|
|
217
247
|
}
|
|
218
248
|
function getDockerComposeTemplate(filename) {
|
|
219
249
|
const templatesDir = getTemplatesDir();
|
|
220
|
-
const filePath =
|
|
250
|
+
const filePath = path.join(templatesDir, "docker", filename);
|
|
221
251
|
if (!fs.existsSync(filePath)) {
|
|
222
252
|
throw new ScriptError(`Docker compose template not found: ${filePath}`);
|
|
223
253
|
}
|
|
224
254
|
return filePath;
|
|
225
255
|
}
|
|
226
256
|
function getDockerfilePolicyDir() {
|
|
227
|
-
const policyDir =
|
|
228
|
-
if (!fs.existsSync(
|
|
257
|
+
const policyDir = path.join(getTemplatesDir(), "policy", "dockerfile");
|
|
258
|
+
if (!fs.existsSync(path.join(policyDir, "dockerfile.rego"))) throw new ScriptError(`Builder Dockerfile policy not found: ${policyDir}`);
|
|
229
259
|
return policyDir;
|
|
230
260
|
}
|
|
231
261
|
|
|
@@ -233,19 +263,12 @@ function getDockerfilePolicyDir() {
|
|
|
233
263
|
function checkDockerfileContract(build, projectDir) {
|
|
234
264
|
const root = resolveProjectDir(projectDir);
|
|
235
265
|
const relative = build.dockerfile ?? "Dockerfile";
|
|
236
|
-
|
|
237
|
-
if (!isPathInside(root, dockerfile) || !existsSync(dockerfile)) throw new ConfigError({ sourceFile: path4.join(root, "build.json"), configPath: "dockerfile", value: relative, composition: "service", reason: "Application Dockerfile missing or outside project" });
|
|
266
|
+
resolveApplicationDockerfile(root, relative);
|
|
238
267
|
const policyDir = getDockerfilePolicyDir();
|
|
239
268
|
console.log(pc22.cyan(`
|
|
240
269
|
\u{1F50D} Validating Builder Dockerfile contract (${relative})...`));
|
|
241
270
|
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 });
|
|
242
271
|
}
|
|
243
|
-
function resolveInsideProject(projectDir, relativePath, context) {
|
|
244
|
-
if (!relativePath.trim()) throw new ConfigError({ ...context, value: relativePath, reason: "Path must not be empty" });
|
|
245
|
-
const resolved = path4.resolve(projectDir, relativePath);
|
|
246
|
-
if (!isPathInside(projectDir, relativePath)) throw new ConfigError({ ...context, value: relativePath, reason: "Path escapes the project directory" });
|
|
247
|
-
return resolved;
|
|
248
|
-
}
|
|
249
272
|
function loadComposeDocument(absolutePath, context) {
|
|
250
273
|
const fail = (reason, value) => {
|
|
251
274
|
throw new ConfigError({ ...context, sourceFile: absolutePath, ...{} , reason });
|
|
@@ -279,7 +302,7 @@ function getDeclaredYamlFiles(build, projectDir) {
|
|
|
279
302
|
const files = [];
|
|
280
303
|
const seen = /* @__PURE__ */ new Set();
|
|
281
304
|
const add = (relativePath, source, kind, stage) => {
|
|
282
|
-
const absolutePath =
|
|
305
|
+
const absolutePath = path.resolve(projectDir, relativePath);
|
|
283
306
|
if (seen.has(absolutePath)) return;
|
|
284
307
|
seen.add(absolutePath);
|
|
285
308
|
files.push({ relativePath, absolutePath, source, kind, ...stage ? { stage } : {} });
|
|
@@ -305,6 +328,12 @@ function checkYamlFiles(build, projectDir) {
|
|
|
305
328
|
}
|
|
306
329
|
}
|
|
307
330
|
|
|
331
|
+
// src/core/composition/composeNetworks.ts
|
|
332
|
+
function normalizeNetworks(value) {
|
|
333
|
+
if (Array.isArray(value)) return Object.fromEntries(value.filter((name) => typeof name === "string").map((name) => [name, null]));
|
|
334
|
+
return value && typeof value === "object" ? { ...value } : {};
|
|
335
|
+
}
|
|
336
|
+
|
|
308
337
|
// src/core/config/endpointProperties.ts
|
|
309
338
|
function resolveEndpointProperty(endpoint, property, context) {
|
|
310
339
|
const published = () => {
|
|
@@ -487,7 +516,7 @@ function allocateHostPorts(projectDir, stage, intentsInDeterministicOrder, valid
|
|
|
487
516
|
}
|
|
488
517
|
return allocated;
|
|
489
518
|
}
|
|
490
|
-
const cachePath =
|
|
519
|
+
const cachePath = path.join(projectDir, AUTO_PORT_CACHE_RELATIVE_PATH);
|
|
491
520
|
let cached = {};
|
|
492
521
|
try {
|
|
493
522
|
if (existsSync(cachePath)) {
|
|
@@ -511,7 +540,7 @@ function allocateHostPorts(projectDir, stage, intentsInDeterministicOrder, valid
|
|
|
511
540
|
nextCache[intent.logicalPath] = selected;
|
|
512
541
|
}
|
|
513
542
|
if (intentsInDeterministicOrder.some((i) => i.requested === "AUTO")) {
|
|
514
|
-
mkdirSync(
|
|
543
|
+
mkdirSync(path.dirname(cachePath), { recursive: true });
|
|
515
544
|
const temp = `${cachePath}.${process.pid}.tmp`;
|
|
516
545
|
writeFileSync(temp, JSON.stringify({ version: AUTO_PORT_CACHE_VERSION, allocations: nextCache }, null, 2));
|
|
517
546
|
renameSync(temp, cachePath);
|
|
@@ -522,7 +551,7 @@ function normalizeProjectName(name, projectDir) {
|
|
|
522
551
|
let normalized = name.toLowerCase().replace(/[^a-z0-9_-]/g, "-").replace(/^[-_]+/, "").replace(/[-_]+$/, "");
|
|
523
552
|
if (!normalized || !/^[a-z0-9]/.test(normalized)) {
|
|
524
553
|
if (projectDir) {
|
|
525
|
-
const hash = crypto.createHash("sha1").update(
|
|
554
|
+
const hash = crypto.createHash("sha1").update(path.resolve(projectDir)).digest("hex").slice(0, 7);
|
|
526
555
|
return `project-${hash}`;
|
|
527
556
|
}
|
|
528
557
|
return "project";
|
|
@@ -532,7 +561,7 @@ function normalizeProjectName(name, projectDir) {
|
|
|
532
561
|
function deriveProjectName(name, stage, projectDir, options = {}) {
|
|
533
562
|
let base = normalizeProjectName(name, projectDir);
|
|
534
563
|
if (options.hash && projectDir) {
|
|
535
|
-
const hash = crypto.createHash("sha1").update(
|
|
564
|
+
const hash = crypto.createHash("sha1").update(path.resolve(projectDir)).digest("hex").slice(0, 7);
|
|
536
565
|
base = `${base}-${hash}`;
|
|
537
566
|
}
|
|
538
567
|
if (!stage) {
|
|
@@ -553,24 +582,66 @@ function deriveProjectName(name, stage, projectDir, options = {}) {
|
|
|
553
582
|
}
|
|
554
583
|
return `${base}-${s}`;
|
|
555
584
|
}
|
|
585
|
+
function parseVolume(mount) {
|
|
586
|
+
if (typeof mount === "string") {
|
|
587
|
+
const separators = [];
|
|
588
|
+
let start = 0;
|
|
589
|
+
for (let i = 0; i < mount.length; i++) {
|
|
590
|
+
if (mount[i] !== ":") continue;
|
|
591
|
+
if (i === start + 1 && /[a-z]/i.test(mount[start]) && /[\\/]/.test(mount[i + 1] ?? "")) continue;
|
|
592
|
+
separators.push(i);
|
|
593
|
+
start = i + 1;
|
|
594
|
+
}
|
|
595
|
+
const first = separators[0];
|
|
596
|
+
if (first === void 0) return { type: "volume", target: mount, suffix: "" };
|
|
597
|
+
const source = mount.slice(0, first), end = separators[1];
|
|
598
|
+
return { type: isBindMount(source) ? "bind" : "volume", source, target: mount.slice(first + 1, end), suffix: mount.slice(first) };
|
|
599
|
+
}
|
|
600
|
+
if (mount && typeof mount === "object") {
|
|
601
|
+
const value = mount;
|
|
602
|
+
return { type: String(value.type ?? "volume"), ...typeof value.source === "string" ? { source: value.source } : {}, target: String(value.target ?? ""), suffix: "" };
|
|
603
|
+
}
|
|
604
|
+
return void 0;
|
|
605
|
+
}
|
|
606
|
+
function rewriteVolumeSource(mount, source) {
|
|
607
|
+
const parsed = parseVolume(mount);
|
|
608
|
+
return typeof mount === "string" ? `${source}${parsed.suffix}` : { ...mount, source };
|
|
609
|
+
}
|
|
610
|
+
function namespaceVolume(mount, names) {
|
|
611
|
+
const parsed = parseVolume(mount);
|
|
612
|
+
const source = parsed?.type === "volume" && parsed.source ? names.get(parsed.source) : void 0;
|
|
613
|
+
return source ? rewriteVolumeSource(mount, source) : mount;
|
|
614
|
+
}
|
|
615
|
+
function isAnonymousVolume(mount) {
|
|
616
|
+
const parsed = parseVolume(mount);
|
|
617
|
+
return parsed?.type === "volume" && !parsed.source;
|
|
618
|
+
}
|
|
619
|
+
function isHostFilesystemRoot(source) {
|
|
620
|
+
const normalized = source.replaceAll("\\", "/");
|
|
621
|
+
if (/^[a-z]:\//i.test(normalized) || normalized.startsWith("//")) {
|
|
622
|
+
const windows = path.win32.normalize(source);
|
|
623
|
+
return windows === path.win32.parse(windows).root;
|
|
624
|
+
}
|
|
625
|
+
return path.posix.normalize(normalized) === "/";
|
|
626
|
+
}
|
|
627
|
+
function anonymousVolumeServices(services) {
|
|
628
|
+
return Object.entries(services).filter(([, service]) => Array.isArray(service.volumes) && service.volumes.some(isAnonymousVolume)).map(([name]) => name);
|
|
629
|
+
}
|
|
556
630
|
var posix = (p) => p.replace(/\\/g, "/");
|
|
557
631
|
function rebase(p, base, out) {
|
|
558
|
-
if (
|
|
559
|
-
const abs =
|
|
560
|
-
const rel =
|
|
632
|
+
if (path.isAbsolute(p) || /^[A-Za-z]:[\\/]/.test(p)) return posix(path.normalize(p));
|
|
633
|
+
const abs = path.resolve(base, p);
|
|
634
|
+
const rel = path.relative(out, abs);
|
|
561
635
|
const result = posix(isPathInside(out, rel) ? rel || "." : abs);
|
|
562
|
-
return result !== "." && !result.startsWith(".") && !
|
|
636
|
+
return result !== "." && !result.startsWith(".") && !path.isAbsolute(result) ? `./${result}` : result;
|
|
563
637
|
}
|
|
564
638
|
function volumeShort(v, base, out) {
|
|
565
|
-
const
|
|
566
|
-
if (
|
|
567
|
-
|
|
568
|
-
if (source === "" || source.startsWith("/") || source.startsWith("~") || /^[A-Za-z]:[\\/]/.test(source)) return v;
|
|
569
|
-
if (source.startsWith(".") || source.includes("/") || source.includes("\\")) parts[0] = rebase(source, base, out);
|
|
570
|
-
return parts.join(":");
|
|
639
|
+
const mount = parseVolume(v);
|
|
640
|
+
if (mount?.type !== "bind" || !mount.source || /^(?:[\\/]|~|[a-z]:)/i.test(mount.source)) return v;
|
|
641
|
+
return rewriteVolumeSource(v, rebase(mount.source, base, out));
|
|
571
642
|
}
|
|
572
643
|
function rebaseComposePaths(document, composeFilePath, outputProjectDir) {
|
|
573
|
-
const doc = structuredClone(document), base =
|
|
644
|
+
const doc = structuredClone(document), base = path.dirname(composeFilePath), out = path.resolve(outputProjectDir);
|
|
574
645
|
for (const svc of Object.values(doc.services ?? {})) {
|
|
575
646
|
if (typeof svc.build === "string") svc.build = rebase(svc.build, base, out);
|
|
576
647
|
else if (svc.build && typeof svc.build === "object") {
|
|
@@ -585,6 +656,52 @@ function rebaseComposePaths(document, composeFilePath, outputProjectDir) {
|
|
|
585
656
|
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);
|
|
586
657
|
return doc;
|
|
587
658
|
}
|
|
659
|
+
function rebaseAppOverridePaths(document, serviceProjectDir, outputProjectDir) {
|
|
660
|
+
const doc = structuredClone(document);
|
|
661
|
+
const base = path.resolve(serviceProjectDir);
|
|
662
|
+
const out = path.resolve(outputProjectDir);
|
|
663
|
+
for (const svc of Object.values(doc.services ?? {})) {
|
|
664
|
+
if (svc.build && typeof svc.build === "object" && !Array.isArray(svc.build)) {
|
|
665
|
+
const build = svc.build;
|
|
666
|
+
if (typeof build.context === "string") {
|
|
667
|
+
build.context = rebase(build.context, base, out);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
if (typeof svc.env_file === "string") {
|
|
671
|
+
svc.env_file = rebase(svc.env_file, base, out);
|
|
672
|
+
} else if (Array.isArray(svc.env_file)) {
|
|
673
|
+
svc.env_file = svc.env_file.map((entry) => {
|
|
674
|
+
if (typeof entry === "string") return rebase(entry, base, out);
|
|
675
|
+
if (entry && typeof entry === "object") {
|
|
676
|
+
const value = entry;
|
|
677
|
+
if (typeof value.path === "string") return { ...value, path: rebase(value.path, base, out) };
|
|
678
|
+
}
|
|
679
|
+
return entry;
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
if (Array.isArray(svc.volumes)) {
|
|
683
|
+
svc.volumes = svc.volumes.map((volume) => {
|
|
684
|
+
if (typeof volume === "string") return volumeShort(volume, base, out);
|
|
685
|
+
if (volume && typeof volume === "object") {
|
|
686
|
+
const value = volume;
|
|
687
|
+
if (value.type === "bind" && typeof value.source === "string") {
|
|
688
|
+
return { ...value, source: rebase(value.source, base, out) };
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return volume;
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
for (const kind of ["configs", "secrets"]) {
|
|
696
|
+
for (const definition of Object.values(doc[kind] ?? {})) {
|
|
697
|
+
if (definition && typeof definition === "object") {
|
|
698
|
+
const value = definition;
|
|
699
|
+
if (typeof value.file === "string") value.file = rebase(value.file, base, out);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return doc;
|
|
704
|
+
}
|
|
588
705
|
|
|
589
706
|
// src/core/composition/composeEnvironment.ts
|
|
590
707
|
function normalizeComposeEnvironment(value, context) {
|
|
@@ -637,13 +754,13 @@ function namespaceDependencyCompose(options) {
|
|
|
637
754
|
svc.network_mode = `service:${serviceNameMap.get(key) ?? key}`;
|
|
638
755
|
}
|
|
639
756
|
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);
|
|
640
|
-
if (Array.isArray(svc.volumes)) svc.volumes = svc.volumes.map((v) =>
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
757
|
+
if (Array.isArray(svc.volumes)) svc.volumes = svc.volumes.map((v) => namespaceVolume(v, volumeNameMap));
|
|
758
|
+
if (svc.networks === void 0 && svc.network_mode === void 0 && svc.extends === void 0 && networkNameMap.has("default")) svc.networks = { default: null };
|
|
759
|
+
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)}`;
|
|
760
|
+
if (svc.extends && typeof svc.extends === "object" && !svc.extends.file) {
|
|
761
|
+
const ref = svc.extends;
|
|
762
|
+
if (typeof ref.service === "string") ref.service = serviceNameMap.get(ref.service) ?? ref.service;
|
|
763
|
+
}
|
|
647
764
|
if (Array.isArray(svc.networks)) svc.networks = svc.networks.map((v) => typeof v === "string" ? networkNameMap.get(v) ?? v : v);
|
|
648
765
|
else if (svc.networks && typeof svc.networks === "object") svc.networks = rewriteKeys(svc.networks, networkNameMap);
|
|
649
766
|
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);
|
|
@@ -670,8 +787,8 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
|
|
|
670
787
|
if (svc.privileged === true) fail(`services.${name}.privileged`, `privileged services are forbidden`);
|
|
671
788
|
if (svc.container_name !== void 0) fail(`services.${name}.container_name`, `fixed container_name is forbidden`);
|
|
672
789
|
for (const v of Array.isArray(svc.volumes) ? svc.volumes : []) {
|
|
673
|
-
const
|
|
674
|
-
if (
|
|
790
|
+
const mount = parseVolume(v);
|
|
791
|
+
if (mount?.type === "bind" && mount.source && isHostFilesystemRoot(mount.source)) fail(`services.${name}.volumes`, "host root bind mounts are forbidden", v);
|
|
675
792
|
}
|
|
676
793
|
const internalRefs = [];
|
|
677
794
|
if (Array.isArray(svc.depends_on)) {
|
|
@@ -686,6 +803,12 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
|
|
|
686
803
|
if (Array.isArray(svc.volumes_from)) {
|
|
687
804
|
for (const ref of svc.volumes_from) if (typeof ref === "string") internalRefs.push(["volumes_from", ref.split(":")[0]]);
|
|
688
805
|
}
|
|
806
|
+
for (const key of ["ipc", "pid"]) if (typeof svc[key] === "string" && svc[key].startsWith("service:")) internalRefs.push([key, svc[key].slice(8)]);
|
|
807
|
+
if (svc.extends && typeof svc.extends === "object") {
|
|
808
|
+
const ref = svc.extends;
|
|
809
|
+
if (ref.file !== void 0) fail(`services.${name}.extends.file`, "external extends is unsupported for atomic dependency implementations");
|
|
810
|
+
if (typeof ref.service === "string") internalRefs.push(["extends.service", ref.service]);
|
|
811
|
+
}
|
|
689
812
|
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);
|
|
690
813
|
}
|
|
691
814
|
if (!Object.keys(dependency.endpoints).length) return;
|
|
@@ -702,11 +825,15 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
|
|
|
702
825
|
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`);
|
|
703
826
|
}
|
|
704
827
|
}
|
|
705
|
-
|
|
706
|
-
|
|
828
|
+
function canonicalBuildContext(value, baseDir) {
|
|
829
|
+
return canonicalPath(path.resolve(baseDir, value));
|
|
830
|
+
}
|
|
831
|
+
function isSameBuildContext(actual, expected, baseDir) {
|
|
832
|
+
return canonicalBuildContext(actual, baseDir) === canonicalBuildContext(expected, baseDir);
|
|
833
|
+
}
|
|
707
834
|
function validateAndPrepareAppOverride(document, context) {
|
|
708
835
|
const fail = (path20, reason, value) => {
|
|
709
|
-
throw new ConfigError({ sourceFile: context.file, configPath: path20, stage: context.stage, composition: "service", ...{} , reason });
|
|
836
|
+
throw new ConfigError({ sourceFile: context.file, configPath: path20, stage: context.stage, composition: "service", ...value === void 0 ? {} : { value }, reason });
|
|
710
837
|
};
|
|
711
838
|
const keys = Object.keys(document.services ?? {});
|
|
712
839
|
if (keys.length !== 1 || keys[0] !== "app") fail("services", "override must define exactly one service named app");
|
|
@@ -716,10 +843,24 @@ function validateAndPrepareAppOverride(document, context) {
|
|
|
716
843
|
const health = app.healthcheck;
|
|
717
844
|
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");
|
|
718
845
|
}
|
|
846
|
+
if (typeof app.build === "string") {
|
|
847
|
+
fail("services.app.build", "override cannot replace Builder-owned app build context; use object-form build.args for build arguments", app.build);
|
|
848
|
+
}
|
|
719
849
|
if (app.build && typeof app.build === "object") {
|
|
720
|
-
const
|
|
721
|
-
for (const
|
|
722
|
-
|
|
850
|
+
const build = app.build;
|
|
851
|
+
for (const key of ["target", "dockerfile"]) {
|
|
852
|
+
if (build[key] !== void 0) {
|
|
853
|
+
fail(`services.app.build.${key}`, "override cannot change Builder-owned build configuration");
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
if (build.context !== void 0) {
|
|
857
|
+
if (typeof build.context !== "string") {
|
|
858
|
+
fail("services.app.build.context", "override app build context must be a string", build.context);
|
|
859
|
+
}
|
|
860
|
+
if (!isSameBuildContext(build.context, context.expectedBuildContext, context.buildContextBaseDir)) {
|
|
861
|
+
fail("services.app.build.context", "override cannot change app build context", build.context);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
723
864
|
}
|
|
724
865
|
const env = normalizeComposeEnvironment(app.environment, "services.app.environment");
|
|
725
866
|
for (const k of ["EXEC_MODE", "INFRA_MODE"]) if (k in env) fail(`services.app.environment.${k}`, "override cannot set Builder-owned environment");
|
|
@@ -727,27 +868,25 @@ function validateAndPrepareAppOverride(document, context) {
|
|
|
727
868
|
const resourceKeys = ["volumes", "networks", "configs", "secrets"];
|
|
728
869
|
const resources = {};
|
|
729
870
|
for (const kind of resourceKeys) {
|
|
730
|
-
const defs = document[kind] ?? {};
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
else if (
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
const mapped = {};
|
|
742
|
-
for (const [name, def] of Object.entries(defs)) {
|
|
871
|
+
const defs = document[kind] ?? {}, refs2 = /* @__PURE__ */ new Set(), value = app[kind];
|
|
872
|
+
if (Array.isArray(value)) for (const ref of value) {
|
|
873
|
+
if (kind === "volumes") {
|
|
874
|
+
const volume = parseVolume(ref);
|
|
875
|
+
if (volume?.type === "volume" && volume.source) refs2.add(volume.source);
|
|
876
|
+
} else if (typeof ref === "string") refs2.add(ref);
|
|
877
|
+
else if (ref && typeof ref === "object" && typeof ref.source === "string") refs2.add(ref.source);
|
|
878
|
+
}
|
|
879
|
+
else if (value && typeof value === "object") for (const name of Object.keys(value)) refs2.add(name);
|
|
880
|
+
const names = /* @__PURE__ */ new Map(), mapped = {};
|
|
881
|
+
for (const [name, definition] of Object.entries(defs)) {
|
|
743
882
|
if (!refs2.has(name)) fail(`${kind}.${name}`, "override resource must be consumed by app");
|
|
744
883
|
const target = `app-override--${context.stage}--${kind.slice(0, -1)}--${name}`;
|
|
745
|
-
|
|
746
|
-
|
|
884
|
+
names.set(name, target);
|
|
885
|
+
mapped[target] = definition;
|
|
747
886
|
}
|
|
748
|
-
if (
|
|
749
|
-
if (app[kind]
|
|
750
|
-
else if (
|
|
887
|
+
if (names.size) resources[kind] = mapped;
|
|
888
|
+
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);
|
|
889
|
+
else if (value && typeof value === "object") app[kind] = Object.fromEntries(Object.entries(value).map(([name, definition]) => [names.get(name) ?? name, definition]));
|
|
751
890
|
}
|
|
752
891
|
return { app, resources };
|
|
753
892
|
}
|
|
@@ -858,10 +997,10 @@ function addPorts(service, endpointPairs) {
|
|
|
858
997
|
}
|
|
859
998
|
}
|
|
860
999
|
function compileServiceComposition(stage, projectDir, options = {}) {
|
|
861
|
-
const root = resolveProjectDir(projectDir), buildPath =
|
|
862
|
-
|
|
1000
|
+
const root = resolveProjectDir(projectDir), buildPath = path.join(root, "build.json"), raw = getBuildJson(root), effective = resolveBuildStage(raw, stage, buildPath), profile = getExecutionProfile(stage, Boolean(options.full));
|
|
1001
|
+
resolveApplicationDockerfile(root, raw.dockerfile ?? "Dockerfile", stage);
|
|
863
1002
|
const seed = getTemplateSeed(stage, Boolean(options.meshMode));
|
|
864
|
-
const rawName = options.projectNameOverride ?? raw.name ??
|
|
1003
|
+
const rawName = options.projectNameOverride ?? raw.name ?? path.basename(root);
|
|
865
1004
|
const projectName = deriveProjectName(rawName, stage);
|
|
866
1005
|
const namespaced = {};
|
|
867
1006
|
for (const [key, dep] of Object.entries(effective.dependencies).sort(([a], [b]) => a.localeCompare(b))) {
|
|
@@ -935,7 +1074,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
935
1074
|
}
|
|
936
1075
|
const appEnv = options.deferReferenceResolution ? ownEnv(effective, stage) : resolveEnv(ownEnv(effective, stage), registry, "app.env");
|
|
937
1076
|
let buildAppEnvironment = { ...appEnv };
|
|
938
|
-
const runtimeDotenv =
|
|
1077
|
+
const runtimeDotenv = path.join(root, `.env.${profile.runtimeStage}`);
|
|
939
1078
|
if (fs.existsSync(runtimeDotenv)) {
|
|
940
1079
|
const text = fs.readFileSync(runtimeDotenv, "utf8");
|
|
941
1080
|
for (const line of text.split(/\r?\n/)) {
|
|
@@ -945,14 +1084,14 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
945
1084
|
}
|
|
946
1085
|
const internal = { EXEC_MODE: profile.runtimeStage, INFRA_MODE: profile.integrated ? "integrated" : "isolated", ...getPrimaryEndpoint(effective.app.endpoints) ? { PORT: String(getPrimaryEndpoint(effective.app.endpoints)[1].port) } : {} };
|
|
947
1086
|
const appBuild = app.build && typeof app.build === "object" ? app.build : { context: "." };
|
|
948
|
-
const outputDir = options.composeOutputDir ?
|
|
949
|
-
const serviceContext =
|
|
1087
|
+
const outputDir = options.composeOutputDir ? path.resolve(options.composeOutputDir) : root;
|
|
1088
|
+
const serviceContext = path.relative(outputDir, root).replace(/\\/g, "/") || ".";
|
|
950
1089
|
appBuild.context = options.meshMode ? serviceContext : ".";
|
|
951
1090
|
if (raw.dockerfile) appBuild.dockerfile = raw.dockerfile;
|
|
952
1091
|
else delete appBuild.dockerfile;
|
|
953
1092
|
appBuild.target = profile.appTarget;
|
|
954
1093
|
app.build = appBuild;
|
|
955
|
-
app.env_file = [{ path: options.meshMode ?
|
|
1094
|
+
app.env_file = [{ path: options.meshMode ? path.posix.join(serviceContext, `.env.${profile.runtimeStage}`) : `.env.${profile.runtimeStage}`, required: false }];
|
|
956
1095
|
app.environment = { ...appEnv, ...options.externalAppEnv ? Object.fromEntries(Object.entries(options.externalAppEnv).map(([k, v]) => [k, v.replace(/\$/g, "$$$$")])) : {}, ...internal };
|
|
957
1096
|
if (stage === "dev") app.volumes = [`${options.meshMode && serviceContext !== "." ? `./${serviceContext}` : "."}:/app`, "/app/node_modules"];
|
|
958
1097
|
for (const [name, ep] of Object.entries(appEndpoints)) if (!options.meshMode && ep.effectivelyPublished) addPorts(app, [[ep, ep.publicPort]]);
|
|
@@ -973,9 +1112,24 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
973
1112
|
for (const [epName, ep] of Object.entries(depEndpoints[key])) dependency.endpoints[epName] = ep;
|
|
974
1113
|
}
|
|
975
1114
|
if (effective.overrideCompose) {
|
|
976
|
-
const overridePath = resolveInsideProject(root, effective.overrideCompose, {
|
|
977
|
-
|
|
978
|
-
|
|
1115
|
+
const overridePath = resolveInsideProject(root, effective.overrideCompose, {
|
|
1116
|
+
sourceFile: buildPath,
|
|
1117
|
+
configPath: "override-compose",
|
|
1118
|
+
stage
|
|
1119
|
+
});
|
|
1120
|
+
const loadedOverride = loadComposeDocument(overridePath, {
|
|
1121
|
+
sourceFile: buildPath,
|
|
1122
|
+
configPath: "override-compose",
|
|
1123
|
+
stage,
|
|
1124
|
+
composition: "service"
|
|
1125
|
+
});
|
|
1126
|
+
const overrideDocument = rebaseAppOverridePaths(loadedOverride, root, outputDir);
|
|
1127
|
+
const prepared = validateAndPrepareAppOverride(overrideDocument, {
|
|
1128
|
+
file: overridePath,
|
|
1129
|
+
stage,
|
|
1130
|
+
expectedBuildContext: String(appBuild.context),
|
|
1131
|
+
buildContextBaseDir: outputDir
|
|
1132
|
+
});
|
|
979
1133
|
for (const section of ["volumes", "networks", "configs", "secrets"]) if (prepared.resources[section]) mergeDocument(compose, { services: {}, [section]: prepared.resources[section] }, "app override");
|
|
980
1134
|
const rawOverrideEnv = normalizeComposeEnvironment(prepared.app.environment, "override-compose.services.app.environment");
|
|
981
1135
|
const overrideEnv = options.deferReferenceResolution ? rawOverrideEnv : resolveEnv(rawOverrideEnv, registry, "override-compose.services.app.environment");
|
|
@@ -988,7 +1142,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
988
1142
|
merged.build = appBuild;
|
|
989
1143
|
merged.env_file = app.env_file;
|
|
990
1144
|
merged.depends_on = app.depends_on;
|
|
991
|
-
merged.networks = { default: null, ...app.networks
|
|
1145
|
+
merged.networks = { ...!options.meshMode ? { default: null } : {}, ...normalizeNetworks(app.networks), ...normalizeNetworks(prepared.app.networks) };
|
|
992
1146
|
compose.services.app = merged;
|
|
993
1147
|
app = merged;
|
|
994
1148
|
}
|
|
@@ -1118,7 +1272,7 @@ var meshSchema = z.object({ $schema: z.string().optional(), name: z.string().opt
|
|
|
1118
1272
|
|
|
1119
1273
|
// src/core/mesh/getMeshJson.ts
|
|
1120
1274
|
function getMeshJson(projectDir = process.cwd()) {
|
|
1121
|
-
const absDir = resolveProjectDir(projectDir), meshPath =
|
|
1275
|
+
const absDir = resolveProjectDir(projectDir), meshPath = path.resolve(absDir, "mesh.json");
|
|
1122
1276
|
if (!existsSync(meshPath)) throw new NotFoundError(`mesh.json not found in directory: ${absDir}`);
|
|
1123
1277
|
let content;
|
|
1124
1278
|
try {
|
|
@@ -1171,9 +1325,9 @@ function resolveMeshStage(mesh, stage, sourceFile) {
|
|
|
1171
1325
|
function loadEffectiveMeshServices(meshDir, effectiveMesh, stage) {
|
|
1172
1326
|
const out = {};
|
|
1173
1327
|
for (const [name, svc] of Object.entries(effectiveMesh.services).sort(([a], [b]) => a.localeCompare(b))) {
|
|
1174
|
-
const abs = resolveInsideProject(meshDir, svc.path, { sourceFile:
|
|
1175
|
-
if (!fs.existsSync(abs) || !fs.statSync(abs).isDirectory()) throw new ConfigError({ sourceFile:
|
|
1176
|
-
const buildJsonPath =
|
|
1328
|
+
const abs = resolveInsideProject(meshDir, svc.path, { sourceFile: path.join(meshDir, "mesh.json"), configPath: `services.${name}.path`, stage });
|
|
1329
|
+
if (!fs.existsSync(abs) || !fs.statSync(abs).isDirectory()) throw new ConfigError({ sourceFile: path.join(meshDir, "mesh.json"), configPath: `services.${name}.path`, stage, composition: "mesh", value: svc.path, reason: "Mesh service directory does not exist" });
|
|
1330
|
+
const buildJsonPath = path.join(abs, "build.json"), build = getBuildJson(abs), effectiveBuild = resolveBuildStage(build, stage, buildJsonPath);
|
|
1177
1331
|
out[name] = { name, path: svc.path, absolutePath: abs, buildJsonPath, effectiveBuild, meshEnv: { ...svc.env ?? {} }, dependencyBindings: { ...svc.dependencies ?? {} }, dependsOn: [...svc.dependsOn ?? []], publish: [...svc.publish ?? []] };
|
|
1178
1332
|
}
|
|
1179
1333
|
return out;
|
|
@@ -1415,8 +1569,8 @@ function setEnv(service, env) {
|
|
|
1415
1569
|
service.environment = { ...current, ...env };
|
|
1416
1570
|
}
|
|
1417
1571
|
function compileMeshComposition(stage, meshDir, options = {}) {
|
|
1418
|
-
const meshPath =
|
|
1419
|
-
const rawName = raw.name ??
|
|
1572
|
+
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);
|
|
1573
|
+
const rawName = raw.name ?? path.basename(meshDir), projectName = deriveProjectName(rawName, stage, meshDir);
|
|
1420
1574
|
const fragments = {};
|
|
1421
1575
|
const compose = { name: projectName, services: {}, networks: { mesh: { driver: "bridge" } } };
|
|
1422
1576
|
for (const [name, svc] of Object.entries(services).sort(([a], [b]) => a.localeCompare(b))) {
|
|
@@ -1437,20 +1591,20 @@ function compileMeshComposition(stage, meshDir, options = {}) {
|
|
|
1437
1591
|
const owner = ep.networkHost;
|
|
1438
1592
|
const ownerService = compose.services[owner];
|
|
1439
1593
|
if (ownerService) {
|
|
1440
|
-
const old =
|
|
1594
|
+
const old = normalizeNetworks(ownerService.networks);
|
|
1441
1595
|
old[privateName] = null;
|
|
1442
1596
|
ownerService.networks = old;
|
|
1443
1597
|
}
|
|
1444
1598
|
}
|
|
1445
1599
|
for (const generated of Object.keys(fragment.compose.services).filter((k) => k.startsWith(`svc--${name}--dep--${dep}--`))) {
|
|
1446
1600
|
const ownerService = compose.services[generated];
|
|
1447
|
-
const old =
|
|
1601
|
+
const old = normalizeNetworks(ownerService.networks);
|
|
1448
1602
|
old[privateName] = null;
|
|
1449
1603
|
ownerService.networks = old;
|
|
1450
1604
|
}
|
|
1451
1605
|
}
|
|
1452
1606
|
}
|
|
1453
|
-
app.networks = networks;
|
|
1607
|
+
app.networks = { ...normalizeNetworks(app.networks), ...networks };
|
|
1454
1608
|
}
|
|
1455
1609
|
const publication = resolveMeshPublication(services, bindingMap, stage, meshPath), intents = [];
|
|
1456
1610
|
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))) {
|
|
@@ -1555,7 +1709,7 @@ function compileMeshComposition(stage, meshDir, options = {}) {
|
|
|
1555
1709
|
|
|
1556
1710
|
// src/core/mesh/checkers/checkMeshServices.ts
|
|
1557
1711
|
function checkMeshServices(mesh, meshDir) {
|
|
1558
|
-
const root = resolveProjectDir(meshDir), meshPath =
|
|
1712
|
+
const root = resolveProjectDir(meshDir), meshPath = path.join(root, "mesh.json");
|
|
1559
1713
|
const checked = /* @__PURE__ */ new Set();
|
|
1560
1714
|
for (const stage of ["dev", "prod", "test", "e2e"]) {
|
|
1561
1715
|
const effective = resolveMeshStage(mesh, stage, meshPath);
|
|
@@ -1585,11 +1739,11 @@ function checkMeshServices(mesh, meshDir) {
|
|
|
1585
1739
|
function checkMeshTester(mesh, meshDir, options = {}) {
|
|
1586
1740
|
const root = resolveProjectDir(meshDir);
|
|
1587
1741
|
if (!mesh.tester) {
|
|
1588
|
-
if (options.required) throw new ConfigError({ sourceFile:
|
|
1742
|
+
if (options.required) throw new ConfigError({ sourceFile: path.join(root, "mesh.json"), configPath: "tester", stage: "e2e", composition: "mesh", reason: "Global mesh E2E requires root tester" });
|
|
1589
1743
|
return;
|
|
1590
1744
|
}
|
|
1591
|
-
const file = resolveInsideProject(root, mesh.tester.compose, { sourceFile:
|
|
1592
|
-
loadComposeDocument(file, { sourceFile:
|
|
1745
|
+
const file = resolveInsideProject(root, mesh.tester.compose, { sourceFile: path.join(root, "mesh.json"), configPath: "tester.compose", stage: "e2e" });
|
|
1746
|
+
loadComposeDocument(file, { sourceFile: path.join(root, "mesh.json"), configPath: "tester.compose", stage: "e2e", composition: "mesh" });
|
|
1593
1747
|
compileMeshComposition("e2e", root, { validationMode: true });
|
|
1594
1748
|
}
|
|
1595
1749
|
|
|
@@ -1801,8 +1955,8 @@ async function teardownCompose(yamlConfig, projectDir, options = {}) {
|
|
|
1801
1955
|
}
|
|
1802
1956
|
const inputData = options.projectName ? void 0 : yamlConfig;
|
|
1803
1957
|
if (!removeVolumes) {
|
|
1804
|
-
const
|
|
1805
|
-
await runSpawn("docker",
|
|
1958
|
+
const services = yamlConfig.trim() ? anonymousVolumeServices(parse(yamlConfig)?.services ?? {}) : options.anonymousVolumeServices ?? [];
|
|
1959
|
+
if (services.length) await runSpawn("docker", [...baseArgs, "rm", "-s", "-f", "-v", ...services], absProjectDir, inputData, true, 15e3);
|
|
1806
1960
|
}
|
|
1807
1961
|
const downArgs = [...baseArgs, "down"];
|
|
1808
1962
|
if (removeVolumes) {
|
|
@@ -1859,12 +2013,12 @@ function redactYamlSecrets(yamlContent) {
|
|
|
1859
2013
|
return redacted;
|
|
1860
2014
|
}
|
|
1861
2015
|
function getRunStatePath(projectDir) {
|
|
1862
|
-
return
|
|
2016
|
+
return path.resolve(resolveProjectDir(projectDir), ".builder", "run.state");
|
|
1863
2017
|
}
|
|
1864
2018
|
function writeRunState(projectDir, state) {
|
|
1865
2019
|
try {
|
|
1866
2020
|
const absDir = resolveProjectDir(projectDir);
|
|
1867
|
-
const builderDir =
|
|
2021
|
+
const builderDir = path.resolve(absDir, ".builder");
|
|
1868
2022
|
if (!existsSync(builderDir)) {
|
|
1869
2023
|
mkdirSync(builderDir, { recursive: true });
|
|
1870
2024
|
}
|
|
@@ -1873,7 +2027,7 @@ function writeRunState(projectDir, state) {
|
|
|
1873
2027
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1874
2028
|
};
|
|
1875
2029
|
writeFileSync(
|
|
1876
|
-
|
|
2030
|
+
path.resolve(builderDir, "run.state"),
|
|
1877
2031
|
JSON.stringify(fullState, null, 2),
|
|
1878
2032
|
"utf-8"
|
|
1879
2033
|
);
|
|
@@ -1904,9 +2058,9 @@ function projectNamesForServiceStage(projectDir, stage) {
|
|
|
1904
2058
|
let rawName;
|
|
1905
2059
|
try {
|
|
1906
2060
|
const buildJson = getBuildJson(absDir);
|
|
1907
|
-
rawName = buildJson.name ||
|
|
2061
|
+
rawName = buildJson.name || path.basename(absDir);
|
|
1908
2062
|
} catch {
|
|
1909
|
-
rawName =
|
|
2063
|
+
rawName = path.basename(absDir);
|
|
1910
2064
|
}
|
|
1911
2065
|
const s = stage.toLowerCase();
|
|
1912
2066
|
if (s === "dev") {
|
|
@@ -1935,10 +2089,10 @@ function projectNamesForMeshStage(meshDir, stage) {
|
|
|
1935
2089
|
let serviceNames = [];
|
|
1936
2090
|
try {
|
|
1937
2091
|
const mesh = getMeshJson(absDir);
|
|
1938
|
-
rawMeshName = mesh.name ||
|
|
1939
|
-
serviceNames = Object.keys(resolveMeshStage(mesh, "test",
|
|
2092
|
+
rawMeshName = mesh.name || path.basename(absDir);
|
|
2093
|
+
serviceNames = Object.keys(resolveMeshStage(mesh, "test", path.join(absDir, "mesh.json")).services);
|
|
1940
2094
|
} catch {
|
|
1941
|
-
rawMeshName =
|
|
2095
|
+
rawMeshName = path.basename(absDir);
|
|
1942
2096
|
}
|
|
1943
2097
|
const s = stage.toLowerCase();
|
|
1944
2098
|
if (s === "dev") {
|
|
@@ -1993,6 +2147,7 @@ async function handleMeshDown(rawStage = "dev", options = {}) {
|
|
|
1993
2147
|
for (const proj of uniqueProjects) {
|
|
1994
2148
|
await teardownCompose("", meshDir, {
|
|
1995
2149
|
projectName: proj,
|
|
2150
|
+
...runState?.projectName === proj && runState.anonymousVolumeServices ? { anonymousVolumeServices: runState.anonymousVolumeServices } : {},
|
|
1996
2151
|
removeVolumes: Boolean(options.volumes)
|
|
1997
2152
|
});
|
|
1998
2153
|
}
|
|
@@ -2160,6 +2315,7 @@ async function runMeshDev(options = {}) {
|
|
|
2160
2315
|
await checkHostPortCollisions(hostPorts);
|
|
2161
2316
|
writeRunState(meshDir, {
|
|
2162
2317
|
projectName,
|
|
2318
|
+
anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
|
|
2163
2319
|
stage: "dev",
|
|
2164
2320
|
projectDir: meshDir
|
|
2165
2321
|
});
|
|
@@ -2201,6 +2357,7 @@ async function runMeshProd(options = {}) {
|
|
|
2201
2357
|
await checkHostPortCollisions(hostPorts);
|
|
2202
2358
|
writeRunState(meshDir, {
|
|
2203
2359
|
projectName,
|
|
2360
|
+
anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
|
|
2204
2361
|
stage: "prod",
|
|
2205
2362
|
projectDir: meshDir
|
|
2206
2363
|
});
|
|
@@ -2222,7 +2379,7 @@ async function runMeshProd(options = {}) {
|
|
|
2222
2379
|
return status;
|
|
2223
2380
|
}
|
|
2224
2381
|
async function runMeshTestUnit(options = {}) {
|
|
2225
|
-
const meshDir = resolveProjectDir(options.projectDir), meshPath =
|
|
2382
|
+
const meshDir = resolveProjectDir(options.projectDir), meshPath = path.join(meshDir, "mesh.json"), raw = getMeshJson(meshDir), effective = resolveMeshStage(raw, "test", meshPath), services = loadEffectiveMeshServices(meshDir, effective, "test");
|
|
2226
2383
|
console.log(pc22.bold(pc22.blue("\n[1/2] MESH SERVICE UNIT/ISOLATED TESTS\n")));
|
|
2227
2384
|
for (const [name, svc] of Object.entries(services).sort(([a], [b]) => a.localeCompare(b))) {
|
|
2228
2385
|
console.log(pc22.cyan(`-> Running isolated unit tests for [${name}]`));
|
|
@@ -2236,7 +2393,7 @@ async function runMeshTestUnit(options = {}) {
|
|
|
2236
2393
|
const resolved = resolveMeshEnvMap(env, refCtx, `services.${name}.env`);
|
|
2237
2394
|
const app = compiled.compose.services.app;
|
|
2238
2395
|
app.environment = { ...app.environment, ...resolvedBuild, ...resolved };
|
|
2239
|
-
const projectName = `${deriveProjectName(raw.name ??
|
|
2396
|
+
const projectName = `${deriveProjectName(raw.name ?? path.basename(meshDir), "dev")}-${name}-test`;
|
|
2240
2397
|
compiled.compose.name = projectName;
|
|
2241
2398
|
const yaml = stringify(compiled.compose);
|
|
2242
2399
|
if (options.debug) console.log(yaml);
|
|
@@ -2259,7 +2416,6 @@ async function runMeshTestUnit(options = {}) {
|
|
|
2259
2416
|
}
|
|
2260
2417
|
async function runMeshTestE2e(options = {}) {
|
|
2261
2418
|
const meshDir = resolveProjectDir(options.projectDir), mesh = getMeshJson(meshDir);
|
|
2262
|
-
if (!options.skipChecks) checkMesh(meshDir, { requireTester: true });
|
|
2263
2419
|
if (!mesh.tester) throw new ScriptError("Global mesh E2E requires root mesh.json.tester { compose, service, env? }");
|
|
2264
2420
|
const { yaml, testerServiceName } = compileMeshEnvironment("e2e", meshDir);
|
|
2265
2421
|
if (!testerServiceName) throw new ScriptError("Global mesh E2E tester runner could not be compiled.");
|
|
@@ -2300,6 +2456,9 @@ async function handleMeshUp(rawStage = "dev", options = {}) {
|
|
|
2300
2456
|
...options,
|
|
2301
2457
|
projectDir
|
|
2302
2458
|
};
|
|
2459
|
+
if (["dev", "prod", "test-unit", "test-e2e", "test"].includes(stage) && !options.skipChecks) {
|
|
2460
|
+
checkMesh(projectDir, { requireTester: stage === "test-e2e" || stage === "test" });
|
|
2461
|
+
}
|
|
2303
2462
|
switch (stage) {
|
|
2304
2463
|
case "dev":
|
|
2305
2464
|
return await runMeshDev(runOptions);
|
|
@@ -2456,6 +2615,7 @@ async function handleServiceDown(rawStage = "dev", options = {}) {
|
|
|
2456
2615
|
for (const proj of uniqueProjects) {
|
|
2457
2616
|
await teardownCompose("", projectDir, {
|
|
2458
2617
|
projectName: proj,
|
|
2618
|
+
...runState?.projectName === proj && runState.anonymousVolumeServices ? { anonymousVolumeServices: runState.anonymousVolumeServices } : {},
|
|
2459
2619
|
removeVolumes: Boolean(options.volumes)
|
|
2460
2620
|
});
|
|
2461
2621
|
}
|
|
@@ -2524,6 +2684,7 @@ var runDev = async (options) => {
|
|
|
2524
2684
|
await checkHostPortCollisions(hostPorts);
|
|
2525
2685
|
writeRunState(options.projectDir, {
|
|
2526
2686
|
projectName,
|
|
2687
|
+
anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
|
|
2527
2688
|
stage: "dev",
|
|
2528
2689
|
projectDir: options.projectDir
|
|
2529
2690
|
});
|
|
@@ -2567,6 +2728,7 @@ var runProd = async (options) => {
|
|
|
2567
2728
|
await checkHostPortCollisions(hostPorts);
|
|
2568
2729
|
writeRunState(options.projectDir, {
|
|
2569
2730
|
projectName,
|
|
2731
|
+
anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
|
|
2570
2732
|
stage: "prod",
|
|
2571
2733
|
projectDir: options.projectDir
|
|
2572
2734
|
});
|
|
@@ -2903,7 +3065,7 @@ async function handleExportEnv(rawStage, options = {}) {
|
|
|
2903
3065
|
const files = [];
|
|
2904
3066
|
try {
|
|
2905
3067
|
for (const snapshot of snapshots) {
|
|
2906
|
-
let filename =
|
|
3068
|
+
let filename = path.join(projectDir, `.env.${snapshot.stage}`);
|
|
2907
3069
|
while (true) {
|
|
2908
3070
|
let overwrite = false;
|
|
2909
3071
|
if (existsSync(filename)) {
|
|
@@ -2912,11 +3074,11 @@ async function handleExportEnv(rawStage, options = {}) {
|
|
|
2912
3074
|
if (!overwrite) {
|
|
2913
3075
|
const name = (await ask(`New filename for ${snapshot.stage} (relative to the service directory): `)).trim();
|
|
2914
3076
|
if (!name) continue;
|
|
2915
|
-
filename =
|
|
3077
|
+
filename = path.resolve(projectDir, name);
|
|
2916
3078
|
continue;
|
|
2917
3079
|
}
|
|
2918
3080
|
}
|
|
2919
|
-
mkdirSync(
|
|
3081
|
+
mkdirSync(path.dirname(filename), { recursive: true });
|
|
2920
3082
|
try {
|
|
2921
3083
|
writeFileSync(filename, snapshot.content, { encoding: "utf-8", flag: overwrite ? "w" : "wx", mode: 384 });
|
|
2922
3084
|
} catch (error) {
|