@solid-stack/builder 2.0.0 → 2.0.1
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 +202 -119
- 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.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.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 +202 -119
- 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") {
|
|
@@ -637,13 +708,13 @@ function namespaceDependencyCompose(options) {
|
|
|
637
708
|
svc.network_mode = `service:${serviceNameMap.get(key) ?? key}`;
|
|
638
709
|
}
|
|
639
710
|
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
|
-
|
|
711
|
+
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 && svc.extends === void 0 && networkNameMap.has("default")) svc.networks = { default: null };
|
|
713
|
+
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
|
+
}
|
|
647
718
|
if (Array.isArray(svc.networks)) svc.networks = svc.networks.map((v) => typeof v === "string" ? networkNameMap.get(v) ?? v : v);
|
|
648
719
|
else if (svc.networks && typeof svc.networks === "object") svc.networks = rewriteKeys(svc.networks, networkNameMap);
|
|
649
720
|
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 +741,8 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
|
|
|
670
741
|
if (svc.privileged === true) fail(`services.${name}.privileged`, `privileged services are forbidden`);
|
|
671
742
|
if (svc.container_name !== void 0) fail(`services.${name}.container_name`, `fixed container_name is forbidden`);
|
|
672
743
|
for (const v of Array.isArray(svc.volumes) ? svc.volumes : []) {
|
|
673
|
-
const
|
|
674
|
-
if (
|
|
744
|
+
const mount = parseVolume(v);
|
|
745
|
+
if (mount?.type === "bind" && mount.source && isHostFilesystemRoot(mount.source)) fail(`services.${name}.volumes`, "host root bind mounts are forbidden", v);
|
|
675
746
|
}
|
|
676
747
|
const internalRefs = [];
|
|
677
748
|
if (Array.isArray(svc.depends_on)) {
|
|
@@ -686,6 +757,12 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
|
|
|
686
757
|
if (Array.isArray(svc.volumes_from)) {
|
|
687
758
|
for (const ref of svc.volumes_from) if (typeof ref === "string") internalRefs.push(["volumes_from", ref.split(":")[0]]);
|
|
688
759
|
}
|
|
760
|
+
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
|
+
}
|
|
689
766
|
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
767
|
}
|
|
691
768
|
if (!Object.keys(dependency.endpoints).length) return;
|
|
@@ -705,8 +782,8 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
|
|
|
705
782
|
|
|
706
783
|
// src/core/composition/validateOverrideCompose.ts
|
|
707
784
|
function validateAndPrepareAppOverride(document, context) {
|
|
708
|
-
const fail = (
|
|
709
|
-
throw new ConfigError({ sourceFile: context.file, configPath:
|
|
785
|
+
const fail = (path19, reason, value) => {
|
|
786
|
+
throw new ConfigError({ sourceFile: context.file, configPath: path19, stage: context.stage, composition: "service", ...{} , reason });
|
|
710
787
|
};
|
|
711
788
|
const keys = Object.keys(document.services ?? {});
|
|
712
789
|
if (keys.length !== 1 || keys[0] !== "app") fail("services", "override must define exactly one service named app");
|
|
@@ -727,27 +804,25 @@ function validateAndPrepareAppOverride(document, context) {
|
|
|
727
804
|
const resourceKeys = ["volumes", "networks", "configs", "secrets"];
|
|
728
805
|
const resources = {};
|
|
729
806
|
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)) {
|
|
807
|
+
const defs = document[kind] ?? {}, refs2 = /* @__PURE__ */ new Set(), value = app[kind];
|
|
808
|
+
if (Array.isArray(value)) for (const ref of value) {
|
|
809
|
+
if (kind === "volumes") {
|
|
810
|
+
const volume = parseVolume(ref);
|
|
811
|
+
if (volume?.type === "volume" && volume.source) refs2.add(volume.source);
|
|
812
|
+
} else if (typeof ref === "string") refs2.add(ref);
|
|
813
|
+
else if (ref && typeof ref === "object" && typeof ref.source === "string") refs2.add(ref.source);
|
|
814
|
+
}
|
|
815
|
+
else if (value && typeof value === "object") for (const name of Object.keys(value)) refs2.add(name);
|
|
816
|
+
const names = /* @__PURE__ */ new Map(), mapped = {};
|
|
817
|
+
for (const [name, definition] of Object.entries(defs)) {
|
|
743
818
|
if (!refs2.has(name)) fail(`${kind}.${name}`, "override resource must be consumed by app");
|
|
744
819
|
const target = `app-override--${context.stage}--${kind.slice(0, -1)}--${name}`;
|
|
745
|
-
|
|
746
|
-
|
|
820
|
+
names.set(name, target);
|
|
821
|
+
mapped[target] = definition;
|
|
747
822
|
}
|
|
748
|
-
if (
|
|
749
|
-
if (app[kind]
|
|
750
|
-
else if (
|
|
823
|
+
if (names.size) resources[kind] = mapped;
|
|
824
|
+
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);
|
|
825
|
+
else if (value && typeof value === "object") app[kind] = Object.fromEntries(Object.entries(value).map(([name, definition]) => [names.get(name) ?? name, definition]));
|
|
751
826
|
}
|
|
752
827
|
return { app, resources };
|
|
753
828
|
}
|
|
@@ -858,10 +933,10 @@ function addPorts(service, endpointPairs) {
|
|
|
858
933
|
}
|
|
859
934
|
}
|
|
860
935
|
function compileServiceComposition(stage, projectDir, options = {}) {
|
|
861
|
-
const root = resolveProjectDir(projectDir), buildPath =
|
|
862
|
-
|
|
936
|
+
const root = resolveProjectDir(projectDir), buildPath = path.join(root, "build.json"), raw = getBuildJson(root), effective = resolveBuildStage(raw, stage, buildPath), profile = getExecutionProfile(stage, Boolean(options.full));
|
|
937
|
+
resolveApplicationDockerfile(root, raw.dockerfile ?? "Dockerfile", stage);
|
|
863
938
|
const seed = getTemplateSeed(stage, Boolean(options.meshMode));
|
|
864
|
-
const rawName = options.projectNameOverride ?? raw.name ??
|
|
939
|
+
const rawName = options.projectNameOverride ?? raw.name ?? path.basename(root);
|
|
865
940
|
const projectName = deriveProjectName(rawName, stage);
|
|
866
941
|
const namespaced = {};
|
|
867
942
|
for (const [key, dep] of Object.entries(effective.dependencies).sort(([a], [b]) => a.localeCompare(b))) {
|
|
@@ -935,7 +1010,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
935
1010
|
}
|
|
936
1011
|
const appEnv = options.deferReferenceResolution ? ownEnv(effective, stage) : resolveEnv(ownEnv(effective, stage), registry, "app.env");
|
|
937
1012
|
let buildAppEnvironment = { ...appEnv };
|
|
938
|
-
const runtimeDotenv =
|
|
1013
|
+
const runtimeDotenv = path.join(root, `.env.${profile.runtimeStage}`);
|
|
939
1014
|
if (fs.existsSync(runtimeDotenv)) {
|
|
940
1015
|
const text = fs.readFileSync(runtimeDotenv, "utf8");
|
|
941
1016
|
for (const line of text.split(/\r?\n/)) {
|
|
@@ -945,14 +1020,14 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
945
1020
|
}
|
|
946
1021
|
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
1022
|
const appBuild = app.build && typeof app.build === "object" ? app.build : { context: "." };
|
|
948
|
-
const outputDir = options.composeOutputDir ?
|
|
949
|
-
const serviceContext =
|
|
1023
|
+
const outputDir = options.composeOutputDir ? path.resolve(options.composeOutputDir) : root;
|
|
1024
|
+
const serviceContext = path.relative(outputDir, root).replace(/\\/g, "/") || ".";
|
|
950
1025
|
appBuild.context = options.meshMode ? serviceContext : ".";
|
|
951
1026
|
if (raw.dockerfile) appBuild.dockerfile = raw.dockerfile;
|
|
952
1027
|
else delete appBuild.dockerfile;
|
|
953
1028
|
appBuild.target = profile.appTarget;
|
|
954
1029
|
app.build = appBuild;
|
|
955
|
-
app.env_file = [{ path: options.meshMode ?
|
|
1030
|
+
app.env_file = [{ path: options.meshMode ? path.posix.join(serviceContext, `.env.${profile.runtimeStage}`) : `.env.${profile.runtimeStage}`, required: false }];
|
|
956
1031
|
app.environment = { ...appEnv, ...options.externalAppEnv ? Object.fromEntries(Object.entries(options.externalAppEnv).map(([k, v]) => [k, v.replace(/\$/g, "$$$$")])) : {}, ...internal };
|
|
957
1032
|
if (stage === "dev") app.volumes = [`${options.meshMode && serviceContext !== "." ? `./${serviceContext}` : "."}:/app`, "/app/node_modules"];
|
|
958
1033
|
for (const [name, ep] of Object.entries(appEndpoints)) if (!options.meshMode && ep.effectivelyPublished) addPorts(app, [[ep, ep.publicPort]]);
|
|
@@ -975,7 +1050,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
975
1050
|
if (effective.overrideCompose) {
|
|
976
1051
|
const overridePath = resolveInsideProject(root, effective.overrideCompose, { sourceFile: buildPath, configPath: "override-compose", stage });
|
|
977
1052
|
const odoc = rebaseComposePaths(loadComposeDocument(overridePath, { sourceFile: buildPath, configPath: "override-compose", stage, composition: "service" }), overridePath, options.composeOutputDir ?? root);
|
|
978
|
-
const prepared = validateAndPrepareAppOverride(odoc, { file: overridePath, stage, expectedBuildContext: options.meshMode ?
|
|
1053
|
+
const prepared = validateAndPrepareAppOverride(odoc, { file: overridePath, stage, expectedBuildContext: options.meshMode ? path.relative(options.composeOutputDir ?? root, root).replace(/\\/g, "/") || "." : "." });
|
|
979
1054
|
for (const section of ["volumes", "networks", "configs", "secrets"]) if (prepared.resources[section]) mergeDocument(compose, { services: {}, [section]: prepared.resources[section] }, "app override");
|
|
980
1055
|
const rawOverrideEnv = normalizeComposeEnvironment(prepared.app.environment, "override-compose.services.app.environment");
|
|
981
1056
|
const overrideEnv = options.deferReferenceResolution ? rawOverrideEnv : resolveEnv(rawOverrideEnv, registry, "override-compose.services.app.environment");
|
|
@@ -988,7 +1063,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
|
|
|
988
1063
|
merged.build = appBuild;
|
|
989
1064
|
merged.env_file = app.env_file;
|
|
990
1065
|
merged.depends_on = app.depends_on;
|
|
991
|
-
merged.networks = { default: null, ...app.networks
|
|
1066
|
+
merged.networks = { ...!options.meshMode ? { default: null } : {}, ...normalizeNetworks(app.networks), ...normalizeNetworks(prepared.app.networks) };
|
|
992
1067
|
compose.services.app = merged;
|
|
993
1068
|
app = merged;
|
|
994
1069
|
}
|
|
@@ -1118,7 +1193,7 @@ var meshSchema = z.object({ $schema: z.string().optional(), name: z.string().opt
|
|
|
1118
1193
|
|
|
1119
1194
|
// src/core/mesh/getMeshJson.ts
|
|
1120
1195
|
function getMeshJson(projectDir = process.cwd()) {
|
|
1121
|
-
const absDir = resolveProjectDir(projectDir), meshPath =
|
|
1196
|
+
const absDir = resolveProjectDir(projectDir), meshPath = path.resolve(absDir, "mesh.json");
|
|
1122
1197
|
if (!existsSync(meshPath)) throw new NotFoundError(`mesh.json not found in directory: ${absDir}`);
|
|
1123
1198
|
let content;
|
|
1124
1199
|
try {
|
|
@@ -1171,9 +1246,9 @@ function resolveMeshStage(mesh, stage, sourceFile) {
|
|
|
1171
1246
|
function loadEffectiveMeshServices(meshDir, effectiveMesh, stage) {
|
|
1172
1247
|
const out = {};
|
|
1173
1248
|
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 =
|
|
1249
|
+
const abs = resolveInsideProject(meshDir, svc.path, { sourceFile: path.join(meshDir, "mesh.json"), configPath: `services.${name}.path`, stage });
|
|
1250
|
+
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" });
|
|
1251
|
+
const buildJsonPath = path.join(abs, "build.json"), build = getBuildJson(abs), effectiveBuild = resolveBuildStage(build, stage, buildJsonPath);
|
|
1177
1252
|
out[name] = { name, path: svc.path, absolutePath: abs, buildJsonPath, effectiveBuild, meshEnv: { ...svc.env ?? {} }, dependencyBindings: { ...svc.dependencies ?? {} }, dependsOn: [...svc.dependsOn ?? []], publish: [...svc.publish ?? []] };
|
|
1178
1253
|
}
|
|
1179
1254
|
return out;
|
|
@@ -1415,8 +1490,8 @@ function setEnv(service, env) {
|
|
|
1415
1490
|
service.environment = { ...current, ...env };
|
|
1416
1491
|
}
|
|
1417
1492
|
function compileMeshComposition(stage, meshDir, options = {}) {
|
|
1418
|
-
const meshPath =
|
|
1419
|
-
const rawName = raw.name ??
|
|
1493
|
+
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
|
+
const rawName = raw.name ?? path.basename(meshDir), projectName = deriveProjectName(rawName, stage, meshDir);
|
|
1420
1495
|
const fragments = {};
|
|
1421
1496
|
const compose = { name: projectName, services: {}, networks: { mesh: { driver: "bridge" } } };
|
|
1422
1497
|
for (const [name, svc] of Object.entries(services).sort(([a], [b]) => a.localeCompare(b))) {
|
|
@@ -1437,20 +1512,20 @@ function compileMeshComposition(stage, meshDir, options = {}) {
|
|
|
1437
1512
|
const owner = ep.networkHost;
|
|
1438
1513
|
const ownerService = compose.services[owner];
|
|
1439
1514
|
if (ownerService) {
|
|
1440
|
-
const old =
|
|
1515
|
+
const old = normalizeNetworks(ownerService.networks);
|
|
1441
1516
|
old[privateName] = null;
|
|
1442
1517
|
ownerService.networks = old;
|
|
1443
1518
|
}
|
|
1444
1519
|
}
|
|
1445
1520
|
for (const generated of Object.keys(fragment.compose.services).filter((k) => k.startsWith(`svc--${name}--dep--${dep}--`))) {
|
|
1446
1521
|
const ownerService = compose.services[generated];
|
|
1447
|
-
const old =
|
|
1522
|
+
const old = normalizeNetworks(ownerService.networks);
|
|
1448
1523
|
old[privateName] = null;
|
|
1449
1524
|
ownerService.networks = old;
|
|
1450
1525
|
}
|
|
1451
1526
|
}
|
|
1452
1527
|
}
|
|
1453
|
-
app.networks = networks;
|
|
1528
|
+
app.networks = { ...normalizeNetworks(app.networks), ...networks };
|
|
1454
1529
|
}
|
|
1455
1530
|
const publication = resolveMeshPublication(services, bindingMap, stage, meshPath), intents = [];
|
|
1456
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))) {
|
|
@@ -1555,7 +1630,7 @@ function compileMeshComposition(stage, meshDir, options = {}) {
|
|
|
1555
1630
|
|
|
1556
1631
|
// src/core/mesh/checkers/checkMeshServices.ts
|
|
1557
1632
|
function checkMeshServices(mesh, meshDir) {
|
|
1558
|
-
const root = resolveProjectDir(meshDir), meshPath =
|
|
1633
|
+
const root = resolveProjectDir(meshDir), meshPath = path.join(root, "mesh.json");
|
|
1559
1634
|
const checked = /* @__PURE__ */ new Set();
|
|
1560
1635
|
for (const stage of ["dev", "prod", "test", "e2e"]) {
|
|
1561
1636
|
const effective = resolveMeshStage(mesh, stage, meshPath);
|
|
@@ -1585,11 +1660,11 @@ function checkMeshServices(mesh, meshDir) {
|
|
|
1585
1660
|
function checkMeshTester(mesh, meshDir, options = {}) {
|
|
1586
1661
|
const root = resolveProjectDir(meshDir);
|
|
1587
1662
|
if (!mesh.tester) {
|
|
1588
|
-
if (options.required) throw new ConfigError({ sourceFile:
|
|
1663
|
+
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
1664
|
return;
|
|
1590
1665
|
}
|
|
1591
|
-
const file = resolveInsideProject(root, mesh.tester.compose, { sourceFile:
|
|
1592
|
-
loadComposeDocument(file, { sourceFile:
|
|
1666
|
+
const file = resolveInsideProject(root, mesh.tester.compose, { sourceFile: path.join(root, "mesh.json"), configPath: "tester.compose", stage: "e2e" });
|
|
1667
|
+
loadComposeDocument(file, { sourceFile: path.join(root, "mesh.json"), configPath: "tester.compose", stage: "e2e", composition: "mesh" });
|
|
1593
1668
|
compileMeshComposition("e2e", root, { validationMode: true });
|
|
1594
1669
|
}
|
|
1595
1670
|
|
|
@@ -1801,8 +1876,8 @@ async function teardownCompose(yamlConfig, projectDir, options = {}) {
|
|
|
1801
1876
|
}
|
|
1802
1877
|
const inputData = options.projectName ? void 0 : yamlConfig;
|
|
1803
1878
|
if (!removeVolumes) {
|
|
1804
|
-
const
|
|
1805
|
-
await runSpawn("docker",
|
|
1879
|
+
const services = yamlConfig.trim() ? anonymousVolumeServices(parse(yamlConfig)?.services ?? {}) : options.anonymousVolumeServices ?? [];
|
|
1880
|
+
if (services.length) await runSpawn("docker", [...baseArgs, "rm", "-s", "-f", "-v", ...services], absProjectDir, inputData, true, 15e3);
|
|
1806
1881
|
}
|
|
1807
1882
|
const downArgs = [...baseArgs, "down"];
|
|
1808
1883
|
if (removeVolumes) {
|
|
@@ -1859,12 +1934,12 @@ function redactYamlSecrets(yamlContent) {
|
|
|
1859
1934
|
return redacted;
|
|
1860
1935
|
}
|
|
1861
1936
|
function getRunStatePath(projectDir) {
|
|
1862
|
-
return
|
|
1937
|
+
return path.resolve(resolveProjectDir(projectDir), ".builder", "run.state");
|
|
1863
1938
|
}
|
|
1864
1939
|
function writeRunState(projectDir, state) {
|
|
1865
1940
|
try {
|
|
1866
1941
|
const absDir = resolveProjectDir(projectDir);
|
|
1867
|
-
const builderDir =
|
|
1942
|
+
const builderDir = path.resolve(absDir, ".builder");
|
|
1868
1943
|
if (!existsSync(builderDir)) {
|
|
1869
1944
|
mkdirSync(builderDir, { recursive: true });
|
|
1870
1945
|
}
|
|
@@ -1873,7 +1948,7 @@ function writeRunState(projectDir, state) {
|
|
|
1873
1948
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1874
1949
|
};
|
|
1875
1950
|
writeFileSync(
|
|
1876
|
-
|
|
1951
|
+
path.resolve(builderDir, "run.state"),
|
|
1877
1952
|
JSON.stringify(fullState, null, 2),
|
|
1878
1953
|
"utf-8"
|
|
1879
1954
|
);
|
|
@@ -1904,9 +1979,9 @@ function projectNamesForServiceStage(projectDir, stage) {
|
|
|
1904
1979
|
let rawName;
|
|
1905
1980
|
try {
|
|
1906
1981
|
const buildJson = getBuildJson(absDir);
|
|
1907
|
-
rawName = buildJson.name ||
|
|
1982
|
+
rawName = buildJson.name || path.basename(absDir);
|
|
1908
1983
|
} catch {
|
|
1909
|
-
rawName =
|
|
1984
|
+
rawName = path.basename(absDir);
|
|
1910
1985
|
}
|
|
1911
1986
|
const s = stage.toLowerCase();
|
|
1912
1987
|
if (s === "dev") {
|
|
@@ -1935,10 +2010,10 @@ function projectNamesForMeshStage(meshDir, stage) {
|
|
|
1935
2010
|
let serviceNames = [];
|
|
1936
2011
|
try {
|
|
1937
2012
|
const mesh = getMeshJson(absDir);
|
|
1938
|
-
rawMeshName = mesh.name ||
|
|
1939
|
-
serviceNames = Object.keys(resolveMeshStage(mesh, "test",
|
|
2013
|
+
rawMeshName = mesh.name || path.basename(absDir);
|
|
2014
|
+
serviceNames = Object.keys(resolveMeshStage(mesh, "test", path.join(absDir, "mesh.json")).services);
|
|
1940
2015
|
} catch {
|
|
1941
|
-
rawMeshName =
|
|
2016
|
+
rawMeshName = path.basename(absDir);
|
|
1942
2017
|
}
|
|
1943
2018
|
const s = stage.toLowerCase();
|
|
1944
2019
|
if (s === "dev") {
|
|
@@ -1993,6 +2068,7 @@ async function handleMeshDown(rawStage = "dev", options = {}) {
|
|
|
1993
2068
|
for (const proj of uniqueProjects) {
|
|
1994
2069
|
await teardownCompose("", meshDir, {
|
|
1995
2070
|
projectName: proj,
|
|
2071
|
+
...runState?.projectName === proj && runState.anonymousVolumeServices ? { anonymousVolumeServices: runState.anonymousVolumeServices } : {},
|
|
1996
2072
|
removeVolumes: Boolean(options.volumes)
|
|
1997
2073
|
});
|
|
1998
2074
|
}
|
|
@@ -2160,6 +2236,7 @@ async function runMeshDev(options = {}) {
|
|
|
2160
2236
|
await checkHostPortCollisions(hostPorts);
|
|
2161
2237
|
writeRunState(meshDir, {
|
|
2162
2238
|
projectName,
|
|
2239
|
+
anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
|
|
2163
2240
|
stage: "dev",
|
|
2164
2241
|
projectDir: meshDir
|
|
2165
2242
|
});
|
|
@@ -2201,6 +2278,7 @@ async function runMeshProd(options = {}) {
|
|
|
2201
2278
|
await checkHostPortCollisions(hostPorts);
|
|
2202
2279
|
writeRunState(meshDir, {
|
|
2203
2280
|
projectName,
|
|
2281
|
+
anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
|
|
2204
2282
|
stage: "prod",
|
|
2205
2283
|
projectDir: meshDir
|
|
2206
2284
|
});
|
|
@@ -2222,7 +2300,7 @@ async function runMeshProd(options = {}) {
|
|
|
2222
2300
|
return status;
|
|
2223
2301
|
}
|
|
2224
2302
|
async function runMeshTestUnit(options = {}) {
|
|
2225
|
-
const meshDir = resolveProjectDir(options.projectDir), meshPath =
|
|
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");
|
|
2226
2304
|
console.log(pc22.bold(pc22.blue("\n[1/2] MESH SERVICE UNIT/ISOLATED TESTS\n")));
|
|
2227
2305
|
for (const [name, svc] of Object.entries(services).sort(([a], [b]) => a.localeCompare(b))) {
|
|
2228
2306
|
console.log(pc22.cyan(`-> Running isolated unit tests for [${name}]`));
|
|
@@ -2236,7 +2314,7 @@ async function runMeshTestUnit(options = {}) {
|
|
|
2236
2314
|
const resolved = resolveMeshEnvMap(env, refCtx, `services.${name}.env`);
|
|
2237
2315
|
const app = compiled.compose.services.app;
|
|
2238
2316
|
app.environment = { ...app.environment, ...resolvedBuild, ...resolved };
|
|
2239
|
-
const projectName = `${deriveProjectName(raw.name ??
|
|
2317
|
+
const projectName = `${deriveProjectName(raw.name ?? path.basename(meshDir), "dev")}-${name}-test`;
|
|
2240
2318
|
compiled.compose.name = projectName;
|
|
2241
2319
|
const yaml = stringify(compiled.compose);
|
|
2242
2320
|
if (options.debug) console.log(yaml);
|
|
@@ -2259,7 +2337,6 @@ async function runMeshTestUnit(options = {}) {
|
|
|
2259
2337
|
}
|
|
2260
2338
|
async function runMeshTestE2e(options = {}) {
|
|
2261
2339
|
const meshDir = resolveProjectDir(options.projectDir), mesh = getMeshJson(meshDir);
|
|
2262
|
-
if (!options.skipChecks) checkMesh(meshDir, { requireTester: true });
|
|
2263
2340
|
if (!mesh.tester) throw new ScriptError("Global mesh E2E requires root mesh.json.tester { compose, service, env? }");
|
|
2264
2341
|
const { yaml, testerServiceName } = compileMeshEnvironment("e2e", meshDir);
|
|
2265
2342
|
if (!testerServiceName) throw new ScriptError("Global mesh E2E tester runner could not be compiled.");
|
|
@@ -2300,6 +2377,9 @@ async function handleMeshUp(rawStage = "dev", options = {}) {
|
|
|
2300
2377
|
...options,
|
|
2301
2378
|
projectDir
|
|
2302
2379
|
};
|
|
2380
|
+
if (["dev", "prod", "test-unit", "test-e2e", "test"].includes(stage) && !options.skipChecks) {
|
|
2381
|
+
checkMesh(projectDir, { requireTester: stage === "test-e2e" || stage === "test" });
|
|
2382
|
+
}
|
|
2303
2383
|
switch (stage) {
|
|
2304
2384
|
case "dev":
|
|
2305
2385
|
return await runMeshDev(runOptions);
|
|
@@ -2456,6 +2536,7 @@ async function handleServiceDown(rawStage = "dev", options = {}) {
|
|
|
2456
2536
|
for (const proj of uniqueProjects) {
|
|
2457
2537
|
await teardownCompose("", projectDir, {
|
|
2458
2538
|
projectName: proj,
|
|
2539
|
+
...runState?.projectName === proj && runState.anonymousVolumeServices ? { anonymousVolumeServices: runState.anonymousVolumeServices } : {},
|
|
2459
2540
|
removeVolumes: Boolean(options.volumes)
|
|
2460
2541
|
});
|
|
2461
2542
|
}
|
|
@@ -2524,6 +2605,7 @@ var runDev = async (options) => {
|
|
|
2524
2605
|
await checkHostPortCollisions(hostPorts);
|
|
2525
2606
|
writeRunState(options.projectDir, {
|
|
2526
2607
|
projectName,
|
|
2608
|
+
anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
|
|
2527
2609
|
stage: "dev",
|
|
2528
2610
|
projectDir: options.projectDir
|
|
2529
2611
|
});
|
|
@@ -2567,6 +2649,7 @@ var runProd = async (options) => {
|
|
|
2567
2649
|
await checkHostPortCollisions(hostPorts);
|
|
2568
2650
|
writeRunState(options.projectDir, {
|
|
2569
2651
|
projectName,
|
|
2652
|
+
anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
|
|
2570
2653
|
stage: "prod",
|
|
2571
2654
|
projectDir: options.projectDir
|
|
2572
2655
|
});
|
|
@@ -2903,7 +2986,7 @@ async function handleExportEnv(rawStage, options = {}) {
|
|
|
2903
2986
|
const files = [];
|
|
2904
2987
|
try {
|
|
2905
2988
|
for (const snapshot of snapshots) {
|
|
2906
|
-
let filename =
|
|
2989
|
+
let filename = path.join(projectDir, `.env.${snapshot.stage}`);
|
|
2907
2990
|
while (true) {
|
|
2908
2991
|
let overwrite = false;
|
|
2909
2992
|
if (existsSync(filename)) {
|
|
@@ -2912,11 +2995,11 @@ async function handleExportEnv(rawStage, options = {}) {
|
|
|
2912
2995
|
if (!overwrite) {
|
|
2913
2996
|
const name = (await ask(`New filename for ${snapshot.stage} (relative to the service directory): `)).trim();
|
|
2914
2997
|
if (!name) continue;
|
|
2915
|
-
filename =
|
|
2998
|
+
filename = path.resolve(projectDir, name);
|
|
2916
2999
|
continue;
|
|
2917
3000
|
}
|
|
2918
3001
|
}
|
|
2919
|
-
mkdirSync(
|
|
3002
|
+
mkdirSync(path.dirname(filename), { recursive: true });
|
|
2920
3003
|
try {
|
|
2921
3004
|
writeFileSync(filename, snapshot.content, { encoding: "utf-8", flag: overwrite ? "w" : "wx", mode: 384 });
|
|
2922
3005
|
} catch (error) {
|