@prisma/composer-cli 0.39.0-dev.3 → 0.39.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{app-configuration-file-Cw9autUL-CPnePaG6.mjs → app-configuration-file-Bbfq5PR3-CYdGtitc.mjs} +39 -39
- package/dist/app-configuration-file-Bbfq5PR3-CYdGtitc.mjs.map +1 -0
- package/dist/{dev-current-D8GwJQex-D4xWpddG.mjs → dev-current-Dp3jvXGN-D70LmiKM.mjs} +5 -5
- package/dist/{dev-current-D8GwJQex-D4xWpddG.mjs.map → dev-current-Dp3jvXGN-D70LmiKM.mjs.map} +1 -1
- package/dist/{dev-environment-name-6eEr5PW8-DuiDkcM6.mjs → dev-environment-name-6eEr5PW8-kDiScOL8.mjs} +2 -2
- package/dist/{dev-environment-name-6eEr5PW8-DuiDkcM6.mjs.map → dev-environment-name-6eEr5PW8-kDiScOL8.mjs.map} +1 -1
- package/dist/{dist-qqNor5kl.mjs → dist-BDdABTj4.mjs} +2 -2
- package/dist/{dist-qqNor5kl.mjs.map → dist-BDdABTj4.mjs.map} +1 -1
- package/dist/{execute-deploy-destroy-1SIH5uAu-SJMSVJ-C.mjs → execute-deploy-destroy-J0buFSWK-9ELg3Sll.mjs} +302 -71
- package/dist/execute-deploy-destroy-J0buFSWK-9ELg3Sll.mjs.map +1 -0
- package/dist/{execute-dev-xPaS5SAl-Pf5LvC3G.mjs → execute-dev-B5YaMqpD-B_vgpelT.mjs} +11 -13
- package/dist/{execute-dev-xPaS5SAl-Pf5LvC3G.mjs.map → execute-dev-B5YaMqpD-B_vgpelT.mjs.map} +1 -1
- package/dist/{execute-dev-current-DsAsDBB1-C_Pqg6lv.mjs → execute-dev-current-C7le-kh2-Dg2L_3P3.mjs} +6 -6
- package/dist/{execute-dev-current-DsAsDBB1-C_Pqg6lv.mjs.map → execute-dev-current-C7le-kh2-Dg2L_3P3.mjs.map} +1 -1
- package/dist/{redaction-CqdeMBKw-B6ldtfDI.d.mts → family-D52hWFMF-Cj-y7XrD.d.mts} +199 -92
- package/dist/family-D52hWFMF-Cj-y7XrD.d.mts.map +1 -0
- package/dist/family.d.mts +1 -1
- package/dist/family.mjs +221 -197
- package/dist/family.mjs.map +1 -1
- package/dist/{generate-dev-stack-BEpqJ3AH-BwP97FIX.mjs → generate-dev-stack-BEpqJ3AH-B7o7JyER.mjs} +2 -2
- package/dist/{generate-dev-stack-BEpqJ3AH-BwP97FIX.mjs.map → generate-dev-stack-BEpqJ3AH-B7o7JyER.mjs.map} +1 -1
- package/dist/{list-deployed-BAKSI43Y.mjs → list-deployed-Cq5EKrVn.mjs} +4 -4
- package/dist/list-deployed-Cq5EKrVn.mjs.map +1 -0
- package/dist/{redaction-C-NnlVUh-xg-a8RGt.mjs → redaction-CjMYXtGp-CYefSG9A.mjs} +17 -6
- package/dist/redaction-CjMYXtGp-CYefSG9A.mjs.map +1 -0
- package/dist/{run-alchemy-CyciV8i0-Djfa6x3a.mjs → run-alchemy-BlYyc4Oh-BnFv0AaY.mjs} +70 -4
- package/dist/run-alchemy-BlYyc4Oh-BnFv0AaY.mjs.map +1 -0
- package/dist/testing.d.mts +4 -4
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +4 -74
- package/dist/testing.mjs.map +1 -1
- package/dist/{validate-environment-DyW59rJ7-B1PoUO20.mjs → validate-environment-XwVDifWN-BtzIWXJF.mjs} +9 -6
- package/dist/validate-environment-XwVDifWN-BtzIWXJF.mjs.map +1 -0
- package/package.json +9 -9
- package/dist/app-configuration-file-Cw9autUL-CPnePaG6.mjs.map +0 -1
- package/dist/execute-deploy-destroy-1SIH5uAu-SJMSVJ-C.mjs.map +0 -1
- package/dist/list-deployed-BAKSI43Y.mjs.map +0 -1
- package/dist/preflight-transport-DJjTWvyH-C98XN-K2.mjs +0 -76
- package/dist/preflight-transport-DJjTWvyH-C98XN-K2.mjs.map +0 -1
- package/dist/redaction-C-NnlVUh-xg-a8RGt.mjs.map +0 -1
- package/dist/redaction-CqdeMBKw-B6ldtfDI.d.mts.map +0 -1
- package/dist/run-alchemy-CyciV8i0-Djfa6x3a.mjs.map +0 -1
- package/dist/validate-environment-DyW59rJ7-B1PoUO20.mjs.map +0 -1
|
@@ -1,60 +1,55 @@
|
|
|
1
|
-
import { a as nodeAddresses, i as validateEnvironmentName, o as secretsKeys, r as runPipeline } from "./validate-environment-
|
|
2
|
-
import { c as redactThrown, l as redactUnsetPlatformVariable, m as noComposerExportMessage, n as SecretRedaction, o as redactError, s as redactSummary } from "./redaction-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { c as toStructured, s as requireContainerForEnvironment } from "./dev-current-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { a as nodeAddresses, i as validateEnvironmentName, o as secretsKeys, r as runPipeline } from "./validate-environment-XwVDifWN-BtzIWXJF.mjs";
|
|
2
|
+
import { c as redactThrown, i as credentialLookingValues, l as redactUnsetPlatformVariable, m as noComposerExportMessage, n as SecretRedaction, o as redactError, r as StreamRedactor, s as redactSummary } from "./redaction-CjMYXtGp-CYefSG9A.mjs";
|
|
3
|
+
import { i as CliStructuredError, n as ok, o as InternalError, r as okVoid, s as blindCast, t as notOk } from "./result-DlBttLS8.mjs";
|
|
4
|
+
import { a as containerEnv, c as preflightEnvVarName, i as spawnAlchemy, n as alchemyInvocation, r as reproduceCommand } from "./run-alchemy-BlYyc4Oh-BnFv0AaY.mjs";
|
|
5
|
+
import { c as toStructured, s as requireContainerForEnvironment } from "./dev-current-Dp3jvXGN-D70LmiKM.mjs";
|
|
6
|
+
import { a as removeLeftoverAppConfigurationFiles, i as refuseSecretsInRootInput, r as prepareSecondProcess, t as deployAppConfigurationFile } from "./app-configuration-file-Bbfq5PR3-CYdGtitc.mjs";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
8
|
import * as fs from "node:fs";
|
|
9
9
|
import * as path from "node:path";
|
|
10
|
+
import "node:util";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
10
12
|
import { randomUUID } from "node:crypto";
|
|
11
|
-
//#region ../../0-framework/3-tooling/cli/dist/deployment-summary-
|
|
13
|
+
//#region ../../0-framework/3-tooling/cli/dist/deployment-summary-YP7eMPJI.mjs
|
|
12
14
|
/**
|
|
13
|
-
* The deploy result
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* references (ADR-0033) — so the writer projects it down to what CAN.
|
|
19
|
-
*
|
|
20
|
-
* The summary is best-effort by contract: the writer never fails the child
|
|
21
|
-
* over it, and the reader maps absent or malformed to `undefined`. So is the
|
|
22
|
-
* failure cause the child leaves beside it when it exits non-zero.
|
|
15
|
+
* The deploy result as data, and what a stack file run as a child hands back
|
|
16
|
+
* to the CLI: the summary file the report hook writes, and the failure cause
|
|
17
|
+
* the child records when it exits non-zero. `DeploymentResult` holds live
|
|
18
|
+
* graph nodes (ADR-0033), so the summary keeps only what can be serialized.
|
|
19
|
+
* Both files are best-effort: a write failure never fails the child.
|
|
23
20
|
*/
|
|
24
21
|
/** Env var the deploy operation sets on the alchemy child: when present,
|
|
25
22
|
* the report hook also writes the JSON DeploymentSummary there. */
|
|
26
23
|
const DEPLOYMENT_RESULT_FILE_ENV = "PRISMA_COMPOSER_DEPLOYMENT_RESULT_FILE";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
raw = fs.readFileSync(resultFilePath, "utf8");
|
|
38
|
-
} catch {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
let parsed;
|
|
42
|
-
try {
|
|
43
|
-
parsed = JSON.parse(raw);
|
|
44
|
-
} catch {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (!isRecord(parsed) || typeof parsed["app"] !== "string" || !Array.isArray(parsed["nodes"])) return;
|
|
48
|
-
for (const node of parsed["nodes"]) {
|
|
49
|
-
if (!isRecord(node) || typeof node["address"] !== "string" || !Array.isArray(node["entities"])) return;
|
|
50
|
-
for (const entity of node["entities"]) if (!isRecord(entity) || typeof entity["kind"] !== "string" || typeof entity["id"] !== "string") return;
|
|
51
|
-
}
|
|
52
|
-
return blindCast(parsed);
|
|
24
|
+
/** Pure projection: keeps app, each node's address/entities and the findings, drops the in-process `node`. */
|
|
25
|
+
function toDeploymentSummary(result) {
|
|
26
|
+
return {
|
|
27
|
+
app: result.app,
|
|
28
|
+
nodes: result.nodes.map((node) => ({
|
|
29
|
+
address: node.address,
|
|
30
|
+
entities: node.entities
|
|
31
|
+
})),
|
|
32
|
+
findings: result.findings
|
|
33
|
+
};
|
|
53
34
|
}
|
|
54
35
|
/** The child's failure cause rides beside the result file, so the one env var names both and the parent's cleanup removes both. */
|
|
55
36
|
function engineFailureFilePath(resultFilePath) {
|
|
56
37
|
return `${resultFilePath}.failure.txt`;
|
|
57
38
|
}
|
|
39
|
+
/** Fits the platform's 5000-character build `errorMessage` with room for the exit-status prefix. */
|
|
40
|
+
const ENGINE_FAILURE_CAUSE_LIMIT = 1e3;
|
|
41
|
+
/** Alchemy's advice to rerun its own CLI with `--adopt` or to import a resource with adoption, which a Composer user has no way to do. */
|
|
42
|
+
const ALCHEMY_ADOPT_ADVICE = [
|
|
43
|
+
[/Re-run with `--adopt` \(or wrap the effect in `adopt\(true\)`\) to take it over\./g, "Something other than this app holds it. Remove that resource, then deploy again."],
|
|
44
|
+
[/Re-run with `--adopt` \(or wrap the effect in `adopt\(true\)`\) to replace it anyway\./g, "Remove that resource, then deploy again."],
|
|
45
|
+
[/\(re-deploy with --adopt to take ownership, then destroy\)/g, "(remove it by hand)"],
|
|
46
|
+
[/Import it with explicit adoption (?:instead of silently taking it over|or choose a different [\w ]+ name)\./g, "Something other than this app holds it. Remove that resource, then deploy again."],
|
|
47
|
+
[/; rerun with adoption enabled if it is the intended [\w ]+\./g, ". Remove that resource, then deploy again."]
|
|
48
|
+
];
|
|
49
|
+
/** Replaces Alchemy CLI advice in engine output with steps that work from Composer. */
|
|
50
|
+
function withComposerAdvice(text) {
|
|
51
|
+
return ALCHEMY_ADOPT_ADVICE.reduce((current, [advice, replacement]) => current.replace(advice, replacement), text);
|
|
52
|
+
}
|
|
58
53
|
/** Parent half: the cause the child recorded, passed through `redact`, or undefined when it recorded none. The child redacts only what its own environment names as a credential; the parent also knows the known secrets. */
|
|
59
54
|
function readEngineFailureCause(resultFilePath, redact) {
|
|
60
55
|
let cause;
|
|
@@ -65,6 +60,10 @@ function readEngineFailureCause(resultFilePath, redact) {
|
|
|
65
60
|
}
|
|
66
61
|
return cause.length > 0 ? redact(cause) : void 0;
|
|
67
62
|
}
|
|
63
|
+
/** A failure cause capped to fit the platform build's error message. */
|
|
64
|
+
function capFailureCause(cause) {
|
|
65
|
+
return cause.length <= ENGINE_FAILURE_CAUSE_LIMIT ? cause : `${cause.slice(0, ENGINE_FAILURE_CAUSE_LIMIT - 1)}…`;
|
|
66
|
+
}
|
|
68
67
|
//#endregion
|
|
69
68
|
//#region ../../0-framework/3-tooling/cli/dist/run-report-CmBz2-xc.mjs
|
|
70
69
|
/** Names the file to write the run report to, when `--report` is not passed. */
|
|
@@ -107,7 +106,75 @@ function writeRunReport(filePath, report) {
|
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
108
|
//#endregion
|
|
110
|
-
//#region ../../0-framework/3-tooling/cli/dist/execute-deploy-destroy-
|
|
109
|
+
//#region ../../0-framework/3-tooling/cli/dist/execute-deploy-destroy-J0buFSWK.mjs
|
|
110
|
+
var version = "0.39.0-dev.5";
|
|
111
|
+
const ENTRY = "@prisma/composer/internal/converge";
|
|
112
|
+
const CONTRACT_ENTRY = "@prisma/composer/internal/converge-contract";
|
|
113
|
+
/** The Composer version this host runs; every Composer package carries the same one. */
|
|
114
|
+
const HOST_COMPOSER_VERSION = version;
|
|
115
|
+
function unresolvable(appDir, detail, cause) {
|
|
116
|
+
return new CliStructuredError("DEPS.CONVERGE_UNRESOLVABLE", `Could not load the converge from the app's @prisma/composer in "${appDir}": ${detail}`, {
|
|
117
|
+
why: "`prisma deploy` runs the lowering and Alchemy from the app's own install of @prisma/composer, so the app, its extensions and Alchemy share one copy of alchemy.",
|
|
118
|
+
fix: "Install @prisma/composer in the app, at the same version as the Composer the `prisma` CLI runs.",
|
|
119
|
+
...cause === void 0 ? {} : { cause }
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function installedVersion(require) {
|
|
123
|
+
try {
|
|
124
|
+
const parsed = JSON.parse(fs.readFileSync(require.resolve("@prisma/composer/package.json"), "utf8"));
|
|
125
|
+
return typeof parsed === "object" && parsed !== null && "version" in parsed && typeof parsed.version === "string" ? parsed.version : void 0;
|
|
126
|
+
} catch {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async function importFile(appDir, file) {
|
|
131
|
+
try {
|
|
132
|
+
return await import(pathToFileURL(file).href);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
throw unresolvable(appDir, `${file} failed to load: ${error instanceof Error ? error.message : String(error)}`, error);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function contractMismatch(host, app) {
|
|
138
|
+
const appVersion = app.version ?? "an unknown version";
|
|
139
|
+
const update = app.contract < host.contract ? `Upgrade the app's @prisma/composer to a release that speaks converge contract ${host.contract}, such as ${host.version}.` : `Upgrade the \`prisma\` CLI to one that runs a Composer speaking converge contract ${app.contract}, such as ${appVersion}.`;
|
|
140
|
+
return new CliStructuredError("DEPS.CONVERGE_CONTRACT_MISMATCH", `The app's @prisma/composer ${appVersion} speaks converge contract ${app.contract}, and the \`prisma\` CLI's Composer ${host.version} speaks contract ${host.contract}.`, {
|
|
141
|
+
why: "Deploy calls the app's @prisma/composer from the CLI's Composer, and the two read each other's data only when they speak the same converge contract.",
|
|
142
|
+
fix: update
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The app's `lower` and converge, from the install `appDir` resolves. Reads the app's
|
|
147
|
+
* converge contract before loading anything else. Raises
|
|
148
|
+
* DEPS.CONVERGE_UNRESOLVABLE when the install is missing or predates the
|
|
149
|
+
* in-process converge, and DEPS.CONVERGE_CONTRACT_MISMATCH when it speaks
|
|
150
|
+
* another contract than `host`.
|
|
151
|
+
*/
|
|
152
|
+
async function loadAppConvergeEntry(appDir, host = {
|
|
153
|
+
contract: 2,
|
|
154
|
+
version: HOST_COMPOSER_VERSION
|
|
155
|
+
}) {
|
|
156
|
+
const require = createRequire(path.join(appDir, "package.json"));
|
|
157
|
+
let contractFile;
|
|
158
|
+
let file;
|
|
159
|
+
try {
|
|
160
|
+
contractFile = require.resolve(CONTRACT_ENTRY);
|
|
161
|
+
file = require.resolve(ENTRY);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
throw unresolvable(appDir, `${CONTRACT_ENTRY} or ${ENTRY} does not resolve.`, error);
|
|
164
|
+
}
|
|
165
|
+
const { CONVERGE_CONTRACT: appContract } = await importFile(appDir, contractFile);
|
|
166
|
+
if (typeof appContract !== "number") throw unresolvable(appDir, `${contractFile} exports no CONVERGE_CONTRACT.`);
|
|
167
|
+
if (appContract !== host.contract) throw contractMismatch(host, {
|
|
168
|
+
contract: appContract,
|
|
169
|
+
version: installedVersion(require)
|
|
170
|
+
});
|
|
171
|
+
const { lower: appLower, convergeInProcess } = await importFile(appDir, file);
|
|
172
|
+
if (typeof appLower !== "function" || typeof convergeInProcess !== "function") throw unresolvable(appDir, `${file} exports no lower and convergeInProcess.`);
|
|
173
|
+
return blindCast({
|
|
174
|
+
lower: appLower,
|
|
175
|
+
converge: convergeInProcess
|
|
176
|
+
});
|
|
177
|
+
}
|
|
111
178
|
/** Pipeline step 6: writes a regenerated-every-run, independently runnable stack module at `.prisma-composer/alchemy.run.ts`. */
|
|
112
179
|
const GENERATED_DIR = ".prisma-composer";
|
|
113
180
|
const GENERATED_FILE = "alchemy.run.ts";
|
|
@@ -199,7 +266,7 @@ function hasNoLocalDeployState(cwd) {
|
|
|
199
266
|
*/
|
|
200
267
|
function deploySteps(onEvent) {
|
|
201
268
|
const open = /* @__PURE__ */ new Map();
|
|
202
|
-
const keyOf = (step) => step.name === "assemble-service" ? `${step.name}:${step.address}` : step.name;
|
|
269
|
+
const keyOf = (step) => step.name === "assemble-service" ? `${step.name}:${step.address}` : step.name === "apply-resource" ? `${step.name}:${step.resourceId}` : step.name;
|
|
203
270
|
const emit = (event) => {
|
|
204
271
|
try {
|
|
205
272
|
onEvent?.(event);
|
|
@@ -238,6 +305,16 @@ function deploySteps(onEvent) {
|
|
|
238
305
|
failOpen() {
|
|
239
306
|
for (const { step } of [...open.values()].reverse()) finish(step, "failed");
|
|
240
307
|
},
|
|
308
|
+
isOpen(step) {
|
|
309
|
+
return open.has(keyOf(step));
|
|
310
|
+
},
|
|
311
|
+
message(severity, text) {
|
|
312
|
+
emit({
|
|
313
|
+
kind: "message",
|
|
314
|
+
severity,
|
|
315
|
+
text
|
|
316
|
+
});
|
|
317
|
+
},
|
|
241
318
|
emit
|
|
242
319
|
};
|
|
243
320
|
}
|
|
@@ -253,7 +330,8 @@ async function executeDeploy(input, deps, cwd) {
|
|
|
253
330
|
reportId: input.reportId,
|
|
254
331
|
reportPath: resolveRunReportPath(input.reportPath, process.env[RUN_REPORT_FILE_ENV], cwd),
|
|
255
332
|
steps: deploySteps(input.onEvent),
|
|
256
|
-
|
|
333
|
+
signal: input.signal,
|
|
334
|
+
redaction: deps.redaction ?? new SecretRedaction(process.env)
|
|
257
335
|
});
|
|
258
336
|
if (!outcome.ok) return outcome;
|
|
259
337
|
return ok({ summary: outcome.value });
|
|
@@ -270,6 +348,7 @@ async function executeDestroy(input, deps, cwd) {
|
|
|
270
348
|
reportId: void 0,
|
|
271
349
|
reportPath: void 0,
|
|
272
350
|
steps: deploySteps(void 0),
|
|
351
|
+
signal: void 0,
|
|
273
352
|
redaction: new SecretRedaction(process.env)
|
|
274
353
|
});
|
|
275
354
|
if (!outcome.ok) return outcome;
|
|
@@ -308,8 +387,8 @@ async function attachReporters(reporters, containers, redaction) {
|
|
|
308
387
|
}
|
|
309
388
|
}));
|
|
310
389
|
}
|
|
311
|
-
/** Every session's contribution to the
|
|
312
|
-
function
|
|
390
|
+
/** Every session's contribution to the apply's environment, so reporting that happens inside the apply can find the run. */
|
|
391
|
+
function reporterEnv(reporters, redaction) {
|
|
313
392
|
const env = {};
|
|
314
393
|
for (const { extensionId, reporter } of reporters) try {
|
|
315
394
|
Object.assign(env, reporter.childEnv());
|
|
@@ -323,9 +402,9 @@ function reporterChildEnv(reporters, redaction) {
|
|
|
323
402
|
function truncate(value, limit) {
|
|
324
403
|
return value.length <= limit ? value : `${value.slice(0, limit - 1)}…`;
|
|
325
404
|
}
|
|
326
|
-
/** An interrupted converge
|
|
405
|
+
/** An interrupted converge — reported as `cancelled`, never as `failed`. */
|
|
327
406
|
function wasInterrupted(failure) {
|
|
328
|
-
return typeof failure.meta?.["signal"] === "string";
|
|
407
|
+
return failure.code === "DEPLOY.INTERRUPTED" || typeof failure.meta?.["signal"] === "string";
|
|
329
408
|
}
|
|
330
409
|
/**
|
|
331
410
|
* Ends every reporting session, whatever the run did. Sessions never reject
|
|
@@ -399,9 +478,10 @@ async function runStackPipeline(action, opts) {
|
|
|
399
478
|
else opts.steps.fail({ name: "record" });
|
|
400
479
|
return outcome;
|
|
401
480
|
}
|
|
402
|
-
/** The pipeline both actions share: validate, resolve containers,
|
|
403
|
-
*
|
|
404
|
-
* teardown/removal suffix. The value is only
|
|
481
|
+
/** The pipeline both actions share: validate, resolve containers, then for
|
|
482
|
+
* deploy preflight and the in-process converge, and for destroy the stack
|
|
483
|
+
* file, the alchemy child and the teardown/removal suffix. The value is only
|
|
484
|
+
* ever a summary for deploy. */
|
|
405
485
|
async function runStackPipelineInner(action, opts, reporters) {
|
|
406
486
|
const { entry, config: composerConfig, name, environment, cwd, onEvent, deps, steps } = opts;
|
|
407
487
|
steps.start({ name: "prepare" });
|
|
@@ -412,6 +492,13 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
412
492
|
if (CliStructuredError.is(error)) return notOk(error);
|
|
413
493
|
throw error;
|
|
414
494
|
}
|
|
495
|
+
let appConvergeEntry;
|
|
496
|
+
if (action === "deploy") {
|
|
497
|
+
const loaded = await prepareAppConvergeEntry(deps, path.dirname(path.resolve(cwd, composerConfig.file)));
|
|
498
|
+
if (!loaded.ok) return loaded;
|
|
499
|
+
appConvergeEntry = loaded.value;
|
|
500
|
+
}
|
|
501
|
+
const platformCredentials = deps.credentials;
|
|
415
502
|
if (action === "destroy" && hasNoLocalDeployState(cwd)) onEvent?.({
|
|
416
503
|
kind: "no-local-deploy-state",
|
|
417
504
|
cwd
|
|
@@ -420,7 +507,8 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
420
507
|
let containers;
|
|
421
508
|
let alchemyStage;
|
|
422
509
|
const preflightPayloads = /* @__PURE__ */ new Map();
|
|
423
|
-
|
|
510
|
+
const unset = [];
|
|
511
|
+
const preflightTransportEnv = {};
|
|
424
512
|
try {
|
|
425
513
|
pipeline = await runPipeline(entry, name, environment, cwd, composerConfig, {
|
|
426
514
|
runAssembler: deps.runAssembler,
|
|
@@ -454,6 +542,7 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
454
542
|
steps.finish({ name: "assemble" });
|
|
455
543
|
const { graph, name: resolvedName } = pipeline;
|
|
456
544
|
const config = pipeline.configSource.value;
|
|
545
|
+
if (action === "deploy") refuseSecretsInRootInput(graph.appConfigurationRead, opts.redaction.knownSecrets, "A deploy sends every plain value Load read to the platform as plain configuration, and never sends a secret that way.");
|
|
457
546
|
steps.start({ name: "connect" });
|
|
458
547
|
if (action === "deploy") reporters.push(...await beginReporters(config.extensions, {
|
|
459
548
|
appName: resolvedName,
|
|
@@ -461,7 +550,7 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
461
550
|
environment,
|
|
462
551
|
cwd,
|
|
463
552
|
reportId: opts.reportId,
|
|
464
|
-
credentials:
|
|
553
|
+
credentials: platformCredentials
|
|
465
554
|
}, opts.redaction));
|
|
466
555
|
containers = /* @__PURE__ */ new Map();
|
|
467
556
|
for (const extension of config.extensions) {
|
|
@@ -471,14 +560,14 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
471
560
|
const instance = await extension.container.ensure({
|
|
472
561
|
appName: resolvedName,
|
|
473
562
|
environment
|
|
474
|
-
},
|
|
563
|
+
}, platformCredentials);
|
|
475
564
|
requireContainerForEnvironment(action, extension.id, extension.container, instance, environment);
|
|
476
565
|
containers.set(extension.id, instance);
|
|
477
566
|
} else {
|
|
478
567
|
const instance = await extension.container.locate({
|
|
479
568
|
appName: resolvedName,
|
|
480
569
|
environment
|
|
481
|
-
},
|
|
570
|
+
}, platformCredentials);
|
|
482
571
|
if (instance === void 0) throw new CliStructuredError("DEPLOY.TARGET_NOT_FOUND", `Nothing deployed for ${resolvedName} in the environment ${environment}.`, { fix: "Deploy it first." });
|
|
483
572
|
requireContainerForEnvironment(action, extension.id, extension.container, instance, environment);
|
|
484
573
|
containers.set(extension.id, instance);
|
|
@@ -490,7 +579,6 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
490
579
|
await attachReporters(reporters, containers, opts.redaction);
|
|
491
580
|
alchemyStage = containers.get(config.state.extension)?.alchemyStage ?? environment;
|
|
492
581
|
steps.finish({ name: "connect" });
|
|
493
|
-
const unset = [];
|
|
494
582
|
if (action === "deploy") {
|
|
495
583
|
steps.start({ name: "preflight" });
|
|
496
584
|
let checked = 0;
|
|
@@ -507,7 +595,7 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
507
595
|
environment,
|
|
508
596
|
configuration: pipeline.configuration,
|
|
509
597
|
secrets: pipeline.secrets,
|
|
510
|
-
credentials:
|
|
598
|
+
credentials: platformCredentials,
|
|
511
599
|
report
|
|
512
600
|
});
|
|
513
601
|
if (payload !== void 0) preflightPayloads.set(extension.id, payload);
|
|
@@ -515,11 +603,6 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
515
603
|
throw toStructured("DEPLOY.PREFLIGHT_FAILED", error);
|
|
516
604
|
}
|
|
517
605
|
}
|
|
518
|
-
try {
|
|
519
|
-
preflightTransportEnv = preflightEnv(preflightPayloads);
|
|
520
|
-
} catch (error) {
|
|
521
|
-
throw toStructured("DEPLOY.PREFLIGHT_FAILED", error);
|
|
522
|
-
}
|
|
523
606
|
steps.finish({ name: "preflight" }, {
|
|
524
607
|
checked,
|
|
525
608
|
unset: unset.length
|
|
@@ -529,12 +612,18 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
529
612
|
findings: { unset }
|
|
530
613
|
});
|
|
531
614
|
}
|
|
532
|
-
for (const extension of config.extensions) preflightTransportEnv[preflightEnvVarName(extension.id)]
|
|
533
|
-
Object.assign(preflightTransportEnv, preflightFindingsEnv({ unset }));
|
|
615
|
+
if (action === "destroy") for (const extension of config.extensions) preflightTransportEnv[preflightEnvVarName(extension.id)] = "";
|
|
534
616
|
} catch (error) {
|
|
535
617
|
if (CliStructuredError.is(error)) return notOk(error);
|
|
536
618
|
throw error;
|
|
537
619
|
}
|
|
620
|
+
if (appConvergeEntry !== void 0) return convergeDeploy(opts, pipeline, appConvergeEntry, {
|
|
621
|
+
containers,
|
|
622
|
+
stage: alchemyStage,
|
|
623
|
+
preflightPayloads,
|
|
624
|
+
findings: { unset },
|
|
625
|
+
env: reporterEnv(reporters, opts.redaction)
|
|
626
|
+
});
|
|
538
627
|
let stackPath;
|
|
539
628
|
const resultFilePath = path.join(cwd, ".prisma-composer", `deployment-result-${String(process.pid)}-${randomUUID()}.json`);
|
|
540
629
|
let handover;
|
|
@@ -568,7 +657,7 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
568
657
|
containerEnv: containerEnv(containers),
|
|
569
658
|
preflightEnv: preflightTransportEnv,
|
|
570
659
|
env: {
|
|
571
|
-
...
|
|
660
|
+
...reporterEnv(reporters, opts.redaction),
|
|
572
661
|
...handover.env,
|
|
573
662
|
[DEPLOYMENT_RESULT_FILE_ENV]: resultFilePath
|
|
574
663
|
},
|
|
@@ -635,7 +724,7 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
635
724
|
const instance = containers.get(extension.id);
|
|
636
725
|
if (instance === void 0) continue;
|
|
637
726
|
try {
|
|
638
|
-
await extension.container.remove(instance,
|
|
727
|
+
await extension.container.remove(instance, platformCredentials);
|
|
639
728
|
} catch (error) {
|
|
640
729
|
throw toStructured("DEPLOY.CONTAINER_REMOVE_FAILED", error);
|
|
641
730
|
}
|
|
@@ -645,7 +734,6 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
645
734
|
if (CliStructuredError.is(error)) return notOk(error);
|
|
646
735
|
throw error;
|
|
647
736
|
}
|
|
648
|
-
if (action === "deploy") return ok(redactSummary(readDeploymentSummary(resultFilePath), opts.redaction));
|
|
649
737
|
return ok(void 0);
|
|
650
738
|
} finally {
|
|
651
739
|
try {
|
|
@@ -655,7 +743,150 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
655
743
|
handover?.removeFile();
|
|
656
744
|
}
|
|
657
745
|
}
|
|
746
|
+
/** Loaded before anything is created, so a missing or incompatible install fails first. */
|
|
747
|
+
async function prepareAppConvergeEntry(deps, appDir) {
|
|
748
|
+
try {
|
|
749
|
+
return ok(deps.appConvergeEntry ?? await loadAppConvergeEntry(appDir));
|
|
750
|
+
} catch (error) {
|
|
751
|
+
if (CliStructuredError.is(error)) return notOk(error);
|
|
752
|
+
throw error;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
/** One Alchemy progress event as the deploy's step events: each resource is a step inside `apply`. */
|
|
756
|
+
function reportConvergeEvent(steps, event, redact) {
|
|
757
|
+
if (event.kind === "log") {
|
|
758
|
+
steps.message(event.severity, redact(withComposerAdvice(event.text)));
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
const step = {
|
|
762
|
+
name: "apply-resource",
|
|
763
|
+
resourceId: event.fqn,
|
|
764
|
+
resourceType: event.resourceType,
|
|
765
|
+
status: event.status
|
|
766
|
+
};
|
|
767
|
+
switch (event.phase) {
|
|
768
|
+
case "running":
|
|
769
|
+
if (!steps.isOpen(step)) steps.start(step);
|
|
770
|
+
return;
|
|
771
|
+
case "done":
|
|
772
|
+
if (!steps.isOpen(step)) steps.start(step);
|
|
773
|
+
steps.finish(step);
|
|
774
|
+
return;
|
|
775
|
+
case "failed":
|
|
776
|
+
if (!steps.isOpen(step)) steps.start(step);
|
|
777
|
+
steps.fail(step);
|
|
778
|
+
if (event.message !== void 0) steps.message("warn", redact(`${event.fqn}: ${withComposerAdvice(event.message)}`));
|
|
779
|
+
return;
|
|
780
|
+
case "pending": return;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function reasonsText(reasons) {
|
|
784
|
+
return reasons.map(({ tag, message }) => tag === "Error" || tag === "Unknown" || message.startsWith(tag) ? message : `${tag}: ${message}`).join("\n");
|
|
785
|
+
}
|
|
786
|
+
/** The structured failure a converge that did not apply settles as. */
|
|
787
|
+
function convergeFailure(outcome, redact) {
|
|
788
|
+
switch (outcome.kind) {
|
|
789
|
+
case "interrupted": return new CliStructuredError("DEPLOY.INTERRUPTED", "The deploy was interrupted.", {
|
|
790
|
+
why: "It stopped while Alchemy planned or applied it. Resources it had already changed stay as they are.",
|
|
791
|
+
fix: "Deploy again to finish."
|
|
792
|
+
});
|
|
793
|
+
case "refused": return outcome.reason === "already-running" ? new CliStructuredError("DEPLOY.CONVERGE_RUNNING", "Another deploy is already running in this process.", {
|
|
794
|
+
why: "A deploy sets the process's environment and working directory while Alchemy runs, so two cannot overlap.",
|
|
795
|
+
fix: "Wait for the other deploy to finish, or run this one in its own process."
|
|
796
|
+
}) : new CliStructuredError("DEPLOY.WORKER_THREAD", "Deploy cannot run in a worker thread when its cwd is not the process working directory.", {
|
|
797
|
+
why: "Alchemy reads `.env` and keeps `.alchemy` in the working directory, and a worker thread cannot change it.",
|
|
798
|
+
fix: "Call deploy from the main thread, or with the process's working directory as its cwd."
|
|
799
|
+
});
|
|
800
|
+
case "failed": {
|
|
801
|
+
const cause = capFailureCause(redact(withComposerAdvice(reasonsText(outcome.reasons))));
|
|
802
|
+
return new CliStructuredError("DEPLOY.ENGINE_FAILED", `Alchemy could not deploy the app.\n${cause}`, { meta: {
|
|
803
|
+
engineCause: cause,
|
|
804
|
+
reasons: outcome.reasons.map(({ tag, message }) => ({
|
|
805
|
+
tag,
|
|
806
|
+
message: redact(message)
|
|
807
|
+
}))
|
|
808
|
+
} });
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return new CliStructuredError("DEPLOY.ENGINE_FAILED", "The converge ended with an outcome this Composer does not know.");
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Alchemy's terminal text as `info` messages, one per complete line, redacted. A secret split
|
|
815
|
+
* across writes or lines is still found, because the text passes through a `StreamRedactor`
|
|
816
|
+
* before it is cut into lines. `end` sends the last line that has no line break.
|
|
817
|
+
*/
|
|
818
|
+
function interactionMessages(steps, redaction) {
|
|
819
|
+
const stream = new StreamRedactor(redaction.allValues());
|
|
820
|
+
let partial = "";
|
|
821
|
+
const send = (text, last) => {
|
|
822
|
+
const lines = (partial + text).split("\n");
|
|
823
|
+
partial = last ? "" : lines.pop() ?? "";
|
|
824
|
+
for (const line of lines) if (line.trim() !== "") steps.message("info", redaction.redact(line));
|
|
825
|
+
};
|
|
826
|
+
return {
|
|
827
|
+
push: (text) => send(stream.push(text), false),
|
|
828
|
+
end: () => send(stream.end(), true)
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Deploy's converge: lowers the app with the containers and preflight
|
|
833
|
+
* payloads this run resolved, then plans and applies it in this process.
|
|
834
|
+
* The report hook runs inside the apply, here, so the summary comes back as
|
|
835
|
+
* a value.
|
|
836
|
+
*/
|
|
837
|
+
async function convergeDeploy(opts, pipeline, entry, resolved) {
|
|
838
|
+
const { cwd, environment, steps } = opts;
|
|
839
|
+
const config = pipeline.configSource.value;
|
|
840
|
+
const env = resolved.env;
|
|
841
|
+
opts.redaction.addCredentialLookingValues(credentialLookingValues(env));
|
|
842
|
+
const redact = (text) => opts.redaction.redact(text);
|
|
843
|
+
let summary;
|
|
844
|
+
const root = pipeline.graph.root.node;
|
|
845
|
+
if (root.kind !== "module") throw new InternalError("runPipeline admitted a root that is not a module");
|
|
846
|
+
steps.start({ name: "apply" });
|
|
847
|
+
let stack;
|
|
848
|
+
try {
|
|
849
|
+
stack = entry.lower(root, config, {
|
|
850
|
+
name: pipeline.name,
|
|
851
|
+
environment,
|
|
852
|
+
appConfigurationRead: pipeline.graph.appConfigurationRead,
|
|
853
|
+
firstProcessNodeAddresses: nodeAddresses(pipeline.graph),
|
|
854
|
+
bundles: pipeline.assembled.bundles,
|
|
855
|
+
containers: resolved.containers,
|
|
856
|
+
preflightPayloads: resolved.preflightPayloads,
|
|
857
|
+
findings: resolved.findings,
|
|
858
|
+
credentials: opts.deps.credentials,
|
|
859
|
+
report: (result) => {
|
|
860
|
+
summary = toDeploymentSummary(result);
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
} catch (error) {
|
|
864
|
+
if (CliStructuredError.is(error)) return notOk(error);
|
|
865
|
+
return notOk(new CliStructuredError("DEPLOY.ENGINE_FAILED", redact(error instanceof Error ? error.message : String(error))));
|
|
866
|
+
}
|
|
867
|
+
const output = interactionMessages(steps, opts.redaction);
|
|
868
|
+
let outcome;
|
|
869
|
+
try {
|
|
870
|
+
outcome = await entry.converge({
|
|
871
|
+
operation: "deploy",
|
|
872
|
+
stack,
|
|
873
|
+
stage: resolved.stage,
|
|
874
|
+
cwd,
|
|
875
|
+
env,
|
|
876
|
+
signal: opts.signal,
|
|
877
|
+
onEvent: (event) => reportConvergeEvent(steps, event, redact),
|
|
878
|
+
output: (text) => output.push(text)
|
|
879
|
+
});
|
|
880
|
+
} catch (error) {
|
|
881
|
+
return notOk(new CliStructuredError("DEPLOY.ENGINE_FAILED", redact(`Alchemy could not deploy the app.\n${error instanceof Error ? error.message : String(error)}`)));
|
|
882
|
+
} finally {
|
|
883
|
+
output.end();
|
|
884
|
+
}
|
|
885
|
+
if (outcome.kind !== "applied") return notOk(convergeFailure(outcome, redact));
|
|
886
|
+
steps.finish({ name: "apply" });
|
|
887
|
+
return ok(redactSummary(summary, opts.redaction));
|
|
888
|
+
}
|
|
658
889
|
//#endregion
|
|
659
890
|
export { executeDeploy, executeDestroy };
|
|
660
891
|
|
|
661
|
-
//# sourceMappingURL=execute-deploy-destroy-
|
|
892
|
+
//# sourceMappingURL=execute-deploy-destroy-J0buFSWK-9ELg3Sll.mjs.map
|