@caelo-cms/provisioning 0.12.4 → 0.12.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/agent-db.js +8 -3
- package/dist/cli-routing.d.ts.map +1 -1
- package/dist/cli-routing.js +6 -5
- package/dist/cli-routing.js.map +1 -1
- package/dist/cli.js +18 -1
- package/dist/cli.js.map +1 -1
- package/dist/gcp-names.d.ts +51 -0
- package/dist/gcp-names.d.ts.map +1 -1
- package/dist/gcp-names.js +75 -0
- package/dist/gcp-names.js.map +1 -1
- package/dist/infra-contract.d.ts +1 -1
- package/dist/infra-contract.d.ts.map +1 -1
- package/dist/infra-contract.js +42 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/install-state.d.ts +8 -0
- package/dist/install-state.d.ts.map +1 -1
- package/dist/install-state.js +12 -0
- package/dist/install-state.js.map +1 -1
- package/dist/install-version.d.ts +110 -0
- package/dist/install-version.d.ts.map +1 -0
- package/dist/install-version.js +162 -0
- package/dist/install-version.js.map +1 -0
- package/dist/lifecycle.d.ts +6 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +46 -1
- package/dist/lifecycle.js.map +1 -1
- package/dist/release-candidate.d.ts +67 -0
- package/dist/release-candidate.d.ts.map +1 -0
- package/dist/release-candidate.js +138 -0
- package/dist/release-candidate.js.map +1 -0
- package/dist/reporting-job-setup.d.ts +102 -0
- package/dist/reporting-job-setup.d.ts.map +1 -0
- package/dist/reporting-job-setup.js +347 -0
- package/dist/reporting-job-setup.js.map +1 -0
- package/dist/self-hosted-upgrade.d.ts.map +1 -1
- package/dist/self-hosted-upgrade.js +18 -3
- package/dist/self-hosted-upgrade.js.map +1 -1
- package/dist/stack-contract.d.ts +30 -5
- package/dist/stack-contract.d.ts.map +1 -1
- package/dist/stack-contract.js +74 -10
- package/dist/stack-contract.js.map +1 -1
- package/dist/upgrade/admin-image-jobs.d.ts +13 -5
- package/dist/upgrade/admin-image-jobs.d.ts.map +1 -1
- package/dist/upgrade/admin-image-jobs.js +22 -2
- package/dist/upgrade/admin-image-jobs.js.map +1 -1
- package/dist/upgrade/converge.d.ts.map +1 -1
- package/dist/upgrade/converge.js +99 -9
- package/dist/upgrade/converge.js.map +1 -1
- package/dist/upgrade/release-images.d.ts +6 -2
- package/dist/upgrade/release-images.d.ts.map +1 -1
- package/dist/upgrade/release-images.js +5 -5
- package/dist/upgrade/release-images.js.map +1 -1
- package/dist/upgrader-iam-preflight.d.ts.map +1 -1
- package/dist/upgrader-iam-preflight.js +19 -1
- package/dist/upgrader-iam-preflight.js.map +1 -1
- package/dist/upgrader-setup.d.ts.map +1 -1
- package/dist/upgrader-setup.js +16 -1
- package/dist/upgrader-setup.js.map +1 -1
- package/dist/wizard.d.ts +7 -0
- package/dist/wizard.d.ts.map +1 -1
- package/dist/wizard.js +20 -5
- package/dist/wizard.js.map +1 -1
- package/dist/wizards/gcp-cost.d.ts +7 -11
- package/dist/wizards/gcp-cost.d.ts.map +1 -1
- package/dist/wizards/gcp-cost.js +47 -36
- package/dist/wizards/gcp-cost.js.map +1 -1
- package/dist/wizards/gcp-firebase.d.ts +4 -0
- package/dist/wizards/gcp-firebase.d.ts.map +1 -1
- package/dist/wizards/gcp-firebase.js +2 -0
- package/dist/wizards/gcp-firebase.js.map +1 -1
- package/dist/wizards/gcp-install-job.d.ts +10 -0
- package/dist/wizards/gcp-install-job.d.ts.map +1 -1
- package/dist/wizards/gcp-install-job.js +41 -10
- package/dist/wizards/gcp-install-job.js.map +1 -1
- package/dist/wizards/gcp.d.ts +7 -0
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +191 -9
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/cli-routing.test.ts +1 -1
- package/src/cli-routing.ts +6 -5
- package/src/cli.ts +18 -1
- package/src/cpu-idle.test.ts +7 -2
- package/src/gcp-names.ts +87 -0
- package/src/infra-contract.test.ts +6 -3
- package/src/infra-contract.ts +42 -1
- package/src/install-state.ts +12 -0
- package/src/install-version.test.ts +366 -0
- package/src/install-version.ts +205 -0
- package/src/lifecycle.ts +65 -3
- package/src/release-candidate.test.ts +191 -0
- package/src/release-candidate.ts +172 -0
- package/src/reporting-job-setup.test.ts +392 -0
- package/src/reporting-job-setup.ts +431 -0
- package/src/self-hosted-upgrade.ts +18 -3
- package/src/stack-contract.test.ts +24 -0
- package/src/stack-contract.ts +87 -9
- package/src/stack-converge-secrets.test.ts +2 -0
- package/src/stack-converge.test.ts +3 -3
- package/src/upgrade/admin-image-jobs.ts +35 -6
- package/src/upgrade/converge.ts +137 -8
- package/src/upgrade/release-images.test.ts +2 -2
- package/src/upgrade/release-images.ts +6 -4
- package/src/upgrade/upgrade.test.ts +165 -4
- package/src/upgrader-iam-preflight.test.ts +58 -0
- package/src/upgrader-iam-preflight.ts +21 -0
- package/src/upgrader-job.test.ts +3 -0
- package/src/upgrader-setup.test.ts +6 -0
- package/src/upgrader-setup.ts +18 -0
- package/src/wizard.ts +30 -5
- package/src/wizards/gcp-cost.test.ts +11 -13
- package/src/wizards/gcp-cost.ts +49 -36
- package/src/wizards/gcp-firebase.ts +6 -0
- package/src/wizards/gcp-install-job.ts +46 -12
- package/src/wizards/gcp.ts +250 -7
- package/stacks/aws/index.ts +10 -0
- package/stacks/azure/index.ts +10 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "bun:test";
|
|
4
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join, resolve } from "node:path";
|
|
7
|
+
import { chooseImageDigests } from "./deployed-release.js";
|
|
8
|
+
import {
|
|
9
|
+
attachedInstallVersionProblem,
|
|
10
|
+
decideInstallVersion,
|
|
11
|
+
installRecordFromManifest,
|
|
12
|
+
launcherRecordsRelease,
|
|
13
|
+
OLDEST_INSTALLABLE_RELEASE,
|
|
14
|
+
releaseToConfirm,
|
|
15
|
+
} from "./install-version.js";
|
|
16
|
+
|
|
17
|
+
const d = (c: string) => `sha256:${c.repeat(64)}`;
|
|
18
|
+
|
|
19
|
+
describe("decideInstallVersion (#1558)", () => {
|
|
20
|
+
it("leaves the wizard's usual choice alone without --version", () => {
|
|
21
|
+
expect(
|
|
22
|
+
decideInstallVersion({ requested: undefined, deployed: false, recordedVersion: undefined }),
|
|
23
|
+
).toEqual({ kind: "none" });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("installs the named release on an install that is not provisioned yet", () => {
|
|
27
|
+
expect(
|
|
28
|
+
decideInstallVersion({
|
|
29
|
+
requested: "v0.12.5-rc.1",
|
|
30
|
+
deployed: false,
|
|
31
|
+
recordedVersion: "0.12.4",
|
|
32
|
+
}),
|
|
33
|
+
).toEqual({ kind: "install", version: "0.12.5-rc.1" });
|
|
34
|
+
expect(
|
|
35
|
+
decideInstallVersion({ requested: "0.12.4", deployed: false, recordedVersion: undefined }),
|
|
36
|
+
).toEqual({ kind: "install", version: "0.12.4" });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("keeps the release a provisioned install runs when it is the one named", () => {
|
|
40
|
+
expect(
|
|
41
|
+
decideInstallVersion({
|
|
42
|
+
requested: "0.12.5-rc.1",
|
|
43
|
+
deployed: true,
|
|
44
|
+
recordedVersion: "0.12.5-rc.1",
|
|
45
|
+
}),
|
|
46
|
+
).toEqual({ kind: "keep", version: "0.12.5-rc.1" });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("never changes the release of a provisioned install: that is upgrade's job", () => {
|
|
50
|
+
const r = decideInstallVersion({
|
|
51
|
+
requested: "0.12.5",
|
|
52
|
+
deployed: true,
|
|
53
|
+
recordedVersion: "0.12.4",
|
|
54
|
+
});
|
|
55
|
+
expect(r.kind).toBe("refuse");
|
|
56
|
+
const error = r.kind === "refuse" ? r.error : "";
|
|
57
|
+
expect(error).toContain("already runs v0.12.4");
|
|
58
|
+
expect(error).toContain("bunx @caelo-cms/provisioning@0.12.5 upgrade --version 0.12.5");
|
|
59
|
+
const unknown = decideInstallVersion({
|
|
60
|
+
requested: "0.12.5",
|
|
61
|
+
deployed: true,
|
|
62
|
+
recordedVersion: undefined,
|
|
63
|
+
});
|
|
64
|
+
expect(unknown.kind === "refuse" && unknown.error).toContain("already runs a release");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("refuses a release from before the MCP-Auth-Proxy, which this installer deploys", () => {
|
|
68
|
+
for (const requested of ["0.11.0", "0.11.9", "0.10.69"]) {
|
|
69
|
+
const r = decideInstallVersion({ requested, deployed: false, recordedVersion: undefined });
|
|
70
|
+
expect(r.kind).toBe("refuse");
|
|
71
|
+
expect(r.kind === "refuse" && r.error).toContain(`v${OLDEST_INSTALLABLE_RELEASE} or later`);
|
|
72
|
+
}
|
|
73
|
+
expect(
|
|
74
|
+
decideInstallVersion({
|
|
75
|
+
requested: OLDEST_INSTALLABLE_RELEASE,
|
|
76
|
+
deployed: false,
|
|
77
|
+
recordedVersion: undefined,
|
|
78
|
+
}).kind,
|
|
79
|
+
).toBe("install");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("refuses anything that is not a release version", () => {
|
|
83
|
+
for (const requested of ["latest", "rc", "0.12", "0.12.4; rm -rf /", ""]) {
|
|
84
|
+
const r = decideInstallVersion({ requested, deployed: false, recordedVersion: undefined });
|
|
85
|
+
expect(r.kind).toBe("refuse");
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("installRecordFromManifest", () => {
|
|
91
|
+
const digests = {
|
|
92
|
+
admin: d("a"),
|
|
93
|
+
gateway: d("b"),
|
|
94
|
+
ops: d("c"),
|
|
95
|
+
"mcp-auth-proxy": d("e"),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
it("records the three images the stack deploys and the version", () => {
|
|
99
|
+
expect(installRecordFromManifest({ version: "0.12.5-rc.1", digests })).toEqual({
|
|
100
|
+
ok: true,
|
|
101
|
+
digests: { admin: d("a"), gateway: d("b"), "mcp-auth-proxy": d("e") },
|
|
102
|
+
version: "0.12.5-rc.1",
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("refuses a release from before the MCP-Auth-Proxy", () => {
|
|
107
|
+
const { "mcp-auth-proxy": _, ...old } = digests;
|
|
108
|
+
const r = installRecordFromManifest({ version: "0.11.9", digests: old });
|
|
109
|
+
expect(r.ok).toBe(false);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Regression: the job-mode launcher recorded only admin + gateway, and the
|
|
113
|
+
// job's release choice refuses a record without the MCP-Auth-Proxy since
|
|
114
|
+
// #1328, so every Cloud Shell fresh install stopped at "Choosing the
|
|
115
|
+
// release images".
|
|
116
|
+
it("writes a record the install job's release choice accepts", async () => {
|
|
117
|
+
const record = installRecordFromManifest({ version: "0.12.4", digests });
|
|
118
|
+
if (!record.ok) throw new Error(record.error);
|
|
119
|
+
const unused = async (): Promise<never> => {
|
|
120
|
+
throw new Error("not reached");
|
|
121
|
+
};
|
|
122
|
+
const choice = await chooseImageDigests({
|
|
123
|
+
recorded: record.digests,
|
|
124
|
+
deployed: false,
|
|
125
|
+
readLive: unused,
|
|
126
|
+
resolveLatest: unused,
|
|
127
|
+
});
|
|
128
|
+
expect(choice).toEqual({ ok: true, source: "recorded", digests: record.digests });
|
|
129
|
+
const before = await chooseImageDigests({
|
|
130
|
+
recorded: { admin: d("a"), gateway: d("b") },
|
|
131
|
+
deployed: false,
|
|
132
|
+
readLive: unused,
|
|
133
|
+
resolveLatest: unused,
|
|
134
|
+
});
|
|
135
|
+
expect(before.ok).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe("launcherRecordsRelease", () => {
|
|
140
|
+
const full = { admin: d("a"), gateway: d("b"), "mcp-auth-proxy": d("e") };
|
|
141
|
+
|
|
142
|
+
it("never records once the first pulumi up succeeded", () => {
|
|
143
|
+
for (const requested of [true, false]) {
|
|
144
|
+
expect(launcherRecordsRelease({ deployed: true, requested, recorded: null })).toBe(false);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("records a named version, a first run, and over a record without the proxy", () => {
|
|
149
|
+
expect(launcherRecordsRelease({ deployed: false, requested: true, recorded: full })).toBe(true);
|
|
150
|
+
expect(launcherRecordsRelease({ deployed: false, requested: false, recorded: null })).toBe(
|
|
151
|
+
true,
|
|
152
|
+
);
|
|
153
|
+
expect(
|
|
154
|
+
launcherRecordsRelease({
|
|
155
|
+
deployed: false,
|
|
156
|
+
requested: false,
|
|
157
|
+
recorded: { admin: d("a"), gateway: d("b") },
|
|
158
|
+
}),
|
|
159
|
+
).toBe(true);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("keeps a complete record when no version was named", () => {
|
|
163
|
+
expect(launcherRecordsRelease({ deployed: false, requested: false, recorded: full })).toBe(
|
|
164
|
+
false,
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("attachedInstallVersionProblem (#1558 review)", () => {
|
|
170
|
+
// A project whose install job runs or finished is followed or shown, never
|
|
171
|
+
// passed through the wizard's check: --version is settled here instead.
|
|
172
|
+
it("lets the job's own release through, and a run without --version", () => {
|
|
173
|
+
expect(attachedInstallVersionProblem("v0.12.5-rc.1", "0.12.5-rc.1")).toBeNull();
|
|
174
|
+
expect(attachedInstallVersionProblem(undefined, "0.12.4")).toBeNull();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("refuses another release with the upgrade command instead of ignoring it", () => {
|
|
178
|
+
const problem = attachedInstallVersionProblem("0.12.5", "0.12.4") ?? "";
|
|
179
|
+
expect(problem).toContain("already runs v0.12.4");
|
|
180
|
+
expect(problem).toContain("bunx @caelo-cms/provisioning@0.12.5 upgrade --version 0.12.5");
|
|
181
|
+
expect(attachedInstallVersionProblem("0.12.5", undefined)).toContain("already runs a release");
|
|
182
|
+
expect(attachedInstallVersionProblem("latest", "0.12.4")).toContain("not a release version");
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe("releaseToConfirm (#1558 review)", () => {
|
|
187
|
+
const full = { admin: d("a"), gateway: d("b"), "mcp-auth-proxy": d("e") };
|
|
188
|
+
const none = { kind: "none" } as const;
|
|
189
|
+
|
|
190
|
+
it("names the release --version installs, in either run mode", () => {
|
|
191
|
+
for (const runMode of ["job", "local"] as const) {
|
|
192
|
+
expect(
|
|
193
|
+
releaseToConfirm({
|
|
194
|
+
decision: { kind: "install", version: "0.12.5-rc.1" },
|
|
195
|
+
runMode,
|
|
196
|
+
cliVersion: "0.12.4",
|
|
197
|
+
deployed: false,
|
|
198
|
+
recorded: null,
|
|
199
|
+
}),
|
|
200
|
+
).toBe("0.12.5-rc.1");
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("names the CLI's own release when the job-mode launcher installs it", () => {
|
|
205
|
+
// `bunx @caelo-cms/provisioning@0.12.5-rc.1` in Cloud Shell, no --version.
|
|
206
|
+
expect(
|
|
207
|
+
releaseToConfirm({
|
|
208
|
+
decision: none,
|
|
209
|
+
runMode: "job",
|
|
210
|
+
cliVersion: "0.12.5-rc.1",
|
|
211
|
+
deployed: false,
|
|
212
|
+
recorded: null,
|
|
213
|
+
}),
|
|
214
|
+
).toBe("0.12.5-rc.1");
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("names nothing when the run installs no new release", () => {
|
|
218
|
+
const base = { decision: none, cliVersion: "0.12.5-rc.1" } as const;
|
|
219
|
+
// Local mode without --version resolves `latest`, never a candidate.
|
|
220
|
+
expect(
|
|
221
|
+
releaseToConfirm({ ...base, runMode: "local", deployed: false, recorded: null }),
|
|
222
|
+
).toBeNull();
|
|
223
|
+
// A provisioned install keeps what it runs; so does a complete record.
|
|
224
|
+
expect(
|
|
225
|
+
releaseToConfirm({ ...base, runMode: "job", deployed: true, recorded: null }),
|
|
226
|
+
).toBeNull();
|
|
227
|
+
expect(
|
|
228
|
+
releaseToConfirm({ ...base, runMode: "job", deployed: false, recorded: full }),
|
|
229
|
+
).toBeNull();
|
|
230
|
+
expect(
|
|
231
|
+
releaseToConfirm({
|
|
232
|
+
decision: { kind: "keep", version: "0.12.5-rc.1" },
|
|
233
|
+
runMode: "job",
|
|
234
|
+
cliVersion: "0.12.5-rc.1",
|
|
235
|
+
deployed: true,
|
|
236
|
+
recorded: full,
|
|
237
|
+
}),
|
|
238
|
+
).toBeNull();
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe("recordLaunchRelease (#1558 review: under the launch lock)", () => {
|
|
243
|
+
// installRoot() resolves ~ through os.homedir(), which reads HOME once at
|
|
244
|
+
// process start: each case runs in a child bun process with its own HOME
|
|
245
|
+
// (as install-state.test.ts does), its ops bucket a directory there.
|
|
246
|
+
const PROJECT = "acme-site";
|
|
247
|
+
const INSTALL_ID = "gcp-acme-site";
|
|
248
|
+
const meta = {
|
|
249
|
+
installId: INSTALL_ID,
|
|
250
|
+
provider: "gcp",
|
|
251
|
+
projectId: PROJECT,
|
|
252
|
+
domain: "acme.example",
|
|
253
|
+
ownerEmail: "owner@acme.example",
|
|
254
|
+
region: "europe-west1",
|
|
255
|
+
createdAt: "2026-11-10T00:00:00.000Z",
|
|
256
|
+
stateBackend: {
|
|
257
|
+
kind: "gcs",
|
|
258
|
+
bucket: `${PROJECT}-caelo-ops`,
|
|
259
|
+
kmsKey: `projects/${PROJECT}/locations/europe-west1/keyRings/caelo/cryptoKeys/pulumi-state`,
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
const rc = {
|
|
263
|
+
digests: { admin: d("1"), gateway: d("2"), "mcp-auth-proxy": d("3") },
|
|
264
|
+
version: "0.12.5-rc.1",
|
|
265
|
+
};
|
|
266
|
+
const other = { admin: d("a"), gateway: d("b"), "mcp-auth-proxy": d("e") };
|
|
267
|
+
const fresh = { lastCompletedStep: null, steps: {} };
|
|
268
|
+
const provisioned = {
|
|
269
|
+
lastCompletedStep: `pulumi-up-${PROJECT}`,
|
|
270
|
+
steps: { [`pulumi-up-${PROJECT}`]: {} },
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Run `steps` (JS; `m` is install-state, `v` install-version, `put(file,
|
|
275
|
+
* value)` writes the bucket) in a child process whose HOME holds the
|
|
276
|
+
* install's local mirror and whose gcloud is the bucket directory.
|
|
277
|
+
*/
|
|
278
|
+
function inChild(
|
|
279
|
+
start: { readonly install: unknown; readonly progress: unknown },
|
|
280
|
+
steps: string,
|
|
281
|
+
): { readonly out: unknown; readonly install: Record<string, unknown> } {
|
|
282
|
+
const home = mkdtempSync(join(tmpdir(), "caelo-launch-"));
|
|
283
|
+
try {
|
|
284
|
+
const mirror = join(home, `.caelo-${INSTALL_ID}`);
|
|
285
|
+
const objects = join(home, "bucket");
|
|
286
|
+
mkdirSync(mirror, { recursive: true });
|
|
287
|
+
mkdirSync(objects);
|
|
288
|
+
writeFileSync(join(mirror, "install.json"), JSON.stringify(meta));
|
|
289
|
+
writeFileSync(join(objects, "install.json"), JSON.stringify(start.install));
|
|
290
|
+
writeFileSync(join(objects, "progress.json"), JSON.stringify(start.progress));
|
|
291
|
+
const script = `
|
|
292
|
+
const { existsSync, readFileSync, writeFileSync } = await import("node:fs");
|
|
293
|
+
const m = await import(${JSON.stringify(resolve(import.meta.dir, "install-state.ts"))});
|
|
294
|
+
const v = await import(${JSON.stringify(resolve(import.meta.dir, "install-version.ts"))});
|
|
295
|
+
const objects = ${JSON.stringify(objects)};
|
|
296
|
+
const at = (url) => objects + "/" + url.split("/").pop();
|
|
297
|
+
const put = (file, value) => writeFileSync(objects + "/" + file, JSON.stringify(value));
|
|
298
|
+
m.setStateStoreGcloud((args, input) => {
|
|
299
|
+
const [, verb, a, b] = args;
|
|
300
|
+
if (verb === "cat") {
|
|
301
|
+
return existsSync(at(a))
|
|
302
|
+
? { ok: true, stdout: readFileSync(at(a), "utf8"), stderr: "", exitCode: 0 }
|
|
303
|
+
: { ok: false, stdout: "", stderr: "One or more URLs matched no objects.", exitCode: 1 };
|
|
304
|
+
}
|
|
305
|
+
if (verb === "cp" && a === "-") {
|
|
306
|
+
writeFileSync(at(b), input ?? "");
|
|
307
|
+
return { ok: true, stdout: "", stderr: "", exitCode: 0 };
|
|
308
|
+
}
|
|
309
|
+
throw new Error("unexpected gcloud " + args.join(" "));
|
|
310
|
+
});
|
|
311
|
+
const ID = ${JSON.stringify(INSTALL_ID)};
|
|
312
|
+
const PROJECT = ${JSON.stringify(PROJECT)};
|
|
313
|
+
const RC = ${JSON.stringify(rc)};
|
|
314
|
+
${steps}`;
|
|
315
|
+
const child = Bun.spawnSync([process.execPath, "-e", script], {
|
|
316
|
+
env: { ...process.env, HOME: home },
|
|
317
|
+
stderr: "pipe",
|
|
318
|
+
});
|
|
319
|
+
expect(new TextDecoder().decode(child.stderr)).toBe("");
|
|
320
|
+
expect(child.exitCode).toBe(0);
|
|
321
|
+
return {
|
|
322
|
+
out: JSON.parse(new TextDecoder().decode(child.stdout)),
|
|
323
|
+
install: JSON.parse(readFileSync(join(objects, "install.json"), "utf8")),
|
|
324
|
+
};
|
|
325
|
+
} finally {
|
|
326
|
+
rmSync(home, { recursive: true, force: true });
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
it("records the named release on an install that is not provisioned yet", () => {
|
|
331
|
+
const r = inChild(
|
|
332
|
+
{ install: meta, progress: fresh },
|
|
333
|
+
`console.log(JSON.stringify(v.recordLaunchRelease(ID, PROJECT, "0.12.5-rc.1", RC)));`,
|
|
334
|
+
);
|
|
335
|
+
expect(r.out).toEqual({ ok: true });
|
|
336
|
+
expect(r.install.imageDigests).toEqual(rc.digests);
|
|
337
|
+
expect(r.install.releaseVersion).toBe("0.12.5-rc.1");
|
|
338
|
+
}, 30_000);
|
|
339
|
+
|
|
340
|
+
it("decides from the bucket as it is now, not from this process's first read", () => {
|
|
341
|
+
// The launcher read the install while it was new; then another
|
|
342
|
+
// launcher's job provisioned it with 0.12.4 before this one got the lock.
|
|
343
|
+
const r = inChild(
|
|
344
|
+
{ install: meta, progress: fresh },
|
|
345
|
+
`const before = [m.readMetadata(ID).releaseVersion ?? null, m.isStepDone(ID, "pulumi-up-" + PROJECT)];
|
|
346
|
+
put("install.json", ${JSON.stringify({ ...meta, imageDigests: other, releaseVersion: "0.12.4" })});
|
|
347
|
+
put("progress.json", ${JSON.stringify(provisioned)});
|
|
348
|
+
console.log(JSON.stringify({ before, result: v.recordLaunchRelease(ID, PROJECT, "0.12.5-rc.1", RC) }));`,
|
|
349
|
+
);
|
|
350
|
+
const out = r.out as { before: unknown; result: { ok: boolean; error?: string } };
|
|
351
|
+
expect(out.before).toEqual([null, false]);
|
|
352
|
+
expect(out.result.ok).toBe(false);
|
|
353
|
+
expect(out.result.error).toContain("already runs v0.12.4");
|
|
354
|
+
expect(r.install.releaseVersion).toBe("0.12.4");
|
|
355
|
+
expect(r.install.imageDigests).toEqual(other);
|
|
356
|
+
}, 30_000);
|
|
357
|
+
|
|
358
|
+
it("keeps another launcher's complete record when no version was named", () => {
|
|
359
|
+
const r = inChild(
|
|
360
|
+
{ install: { ...meta, imageDigests: other, releaseVersion: "0.12.4" }, progress: fresh },
|
|
361
|
+
`console.log(JSON.stringify(v.recordLaunchRelease(ID, PROJECT, undefined, RC)));`,
|
|
362
|
+
);
|
|
363
|
+
expect(r.out).toEqual({ ok: true });
|
|
364
|
+
expect(r.install.imageDigests).toEqual(other);
|
|
365
|
+
}, 30_000);
|
|
366
|
+
});
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `--version` on a gcp / gcp-firebase install (#1558): which release a
|
|
5
|
+
* wizard run installs when the operator names one, and what the install
|
|
6
|
+
* job's launcher records for it.
|
|
7
|
+
*
|
|
8
|
+
* Without `--version` a new install resolves the registry's `latest` tag
|
|
9
|
+
* (local mode) or the CLI's own release (job mode). With it, the named
|
|
10
|
+
* release, so a release candidate can be scratch-installed before any
|
|
11
|
+
* install is offered it. The installer still never changes the version of
|
|
12
|
+
* an install that runs: that is `upgrade`'s job, which migrates the
|
|
13
|
+
* database before it shifts traffic. Nothing is migrated before the first
|
|
14
|
+
* `pulumi up` succeeded (wizards/gcp.ts), so until then a recorded release
|
|
15
|
+
* may still be replaced.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { provisioningCommand } from "@caelo-cms/shared";
|
|
19
|
+
import {
|
|
20
|
+
forgetCachedState,
|
|
21
|
+
type ImageDigests,
|
|
22
|
+
isStepDone,
|
|
23
|
+
readMetadata,
|
|
24
|
+
recordedImageDigests,
|
|
25
|
+
recordImageDigests,
|
|
26
|
+
} from "./install-state.js";
|
|
27
|
+
import { compareSemver, manifestServiceImages, type ReleaseManifest } from "./release-manifest.js";
|
|
28
|
+
import { canonicalReleaseTag } from "./upgrade/release-images.js";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The oldest release `--version` installs: the first with its own
|
|
32
|
+
* MCP-Auth-Proxy image (#1328). This installer deploys the proxy next to the
|
|
33
|
+
* admin and the gateway, so it has nothing to deploy for an older release,
|
|
34
|
+
* and the release choice refuses a record without one
|
|
35
|
+
* (deployed-release.ts chooseImageDigests).
|
|
36
|
+
*/
|
|
37
|
+
export const OLDEST_INSTALLABLE_RELEASE = "0.11.10";
|
|
38
|
+
|
|
39
|
+
/** What `--version` means for one wizard run. */
|
|
40
|
+
export type InstallVersionDecision =
|
|
41
|
+
/** No `--version`: the wizard's usual choice (wizards/gcp.ts chooseImageDigests). */
|
|
42
|
+
| { readonly kind: "none" }
|
|
43
|
+
/** The install already runs this release; the run converges, nothing else. */
|
|
44
|
+
| { readonly kind: "keep"; readonly version: string }
|
|
45
|
+
/** Resolve, verify and record this release before anything is created. */
|
|
46
|
+
| { readonly kind: "install"; readonly version: string }
|
|
47
|
+
| { readonly kind: "refuse"; readonly error: string };
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Decide what `--version` does for an install.
|
|
51
|
+
*
|
|
52
|
+
* @param input.deployed - whether the install's first `pulumi up` succeeded
|
|
53
|
+
* (from then on its database may be migrated by the release it runs).
|
|
54
|
+
* @param input.recordedVersion - install.json's `releaseVersion`.
|
|
55
|
+
*/
|
|
56
|
+
export function decideInstallVersion(input: {
|
|
57
|
+
readonly requested: string | undefined;
|
|
58
|
+
readonly deployed: boolean;
|
|
59
|
+
readonly recordedVersion: string | undefined;
|
|
60
|
+
}): InstallVersionDecision {
|
|
61
|
+
if (input.requested === undefined) return { kind: "none" };
|
|
62
|
+
const tag = canonicalReleaseTag(input.requested);
|
|
63
|
+
if (!tag) {
|
|
64
|
+
return {
|
|
65
|
+
kind: "refuse",
|
|
66
|
+
error: `--version ${JSON.stringify(input.requested)} is not a release version. Name one like 0.12.4 or 0.12.5-rc.1 (https://github.com/caelo-cms/caelo-cms/releases).`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const version = tag.replace(/^v/, "");
|
|
70
|
+
if (input.deployed && input.recordedVersion === version) return { kind: "keep", version };
|
|
71
|
+
if (compareSemver(version, OLDEST_INSTALLABLE_RELEASE) < 0) {
|
|
72
|
+
return {
|
|
73
|
+
kind: "refuse",
|
|
74
|
+
error: `v${version} predates the MCP-Auth-Proxy (#1328), which this installer deploys next to the admin and the gateway: --version installs v${OLDEST_INSTALLABLE_RELEASE} or later.`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (!input.deployed) return { kind: "install", version };
|
|
78
|
+
const runs = input.recordedVersion ? `v${input.recordedVersion}` : "a release";
|
|
79
|
+
return {
|
|
80
|
+
kind: "refuse",
|
|
81
|
+
error: `This install already runs ${runs}. Re-running the installer converges its cloud setup and never changes the release; to move it to v${version}, run: ${provisioningCommand(version, ["upgrade", "--version", version])}`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The release a job-mode install records before its job starts, from the
|
|
87
|
+
* release's signed manifest: the three images the stack deploys and the
|
|
88
|
+
* version. Every image the stack runs must be named, or the job's release
|
|
89
|
+
* choice refuses the record (deployed-release.ts chooseImageDigests).
|
|
90
|
+
*/
|
|
91
|
+
export function installRecordFromManifest(
|
|
92
|
+
manifest: Pick<ReleaseManifest, "version" | "digests">,
|
|
93
|
+
):
|
|
94
|
+
| { readonly ok: true; readonly digests: ImageDigests; readonly version: string }
|
|
95
|
+
| { readonly ok: false; readonly error: string } {
|
|
96
|
+
const images = manifestServiceImages(manifest);
|
|
97
|
+
if (!images.ok) return images;
|
|
98
|
+
return {
|
|
99
|
+
ok: true,
|
|
100
|
+
digests: {
|
|
101
|
+
admin: images.images.admin.digest,
|
|
102
|
+
gateway: images.images.gateway.digest,
|
|
103
|
+
"mcp-auth-proxy": images.images["mcp-auth-proxy"].digest,
|
|
104
|
+
},
|
|
105
|
+
version: manifest.version,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Whether the launcher records the release it verified. Never once the
|
|
111
|
+
* install's first `pulumi up` succeeded; before that when the operator named
|
|
112
|
+
* a version, when nothing is recorded yet, or when the record lacks the
|
|
113
|
+
* MCP-Auth-Proxy (written by a launcher from before it recorded one).
|
|
114
|
+
*/
|
|
115
|
+
export function launcherRecordsRelease(input: {
|
|
116
|
+
readonly deployed: boolean;
|
|
117
|
+
readonly requested: boolean;
|
|
118
|
+
readonly recorded: ImageDigests | null;
|
|
119
|
+
}): boolean {
|
|
120
|
+
if (input.deployed) return false;
|
|
121
|
+
return input.requested || input.recorded === null || !input.recorded["mcp-auth-proxy"];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Why `--version` cannot apply to a project whose install job runs or has
|
|
126
|
+
* finished, or null. Such a run attaches to the job or shows its result
|
|
127
|
+
* instead of running the wizard again, so it never reaches the wizard's
|
|
128
|
+
* check: the job installs (or installed) the release it recorded, and a
|
|
129
|
+
* different named release is refused here with the upgrade command.
|
|
130
|
+
*/
|
|
131
|
+
export function attachedInstallVersionProblem(
|
|
132
|
+
requested: string | undefined,
|
|
133
|
+
recordedVersion: string | undefined,
|
|
134
|
+
): string | null {
|
|
135
|
+
if (requested === undefined) return null;
|
|
136
|
+
const decision = decideInstallVersion({ requested, deployed: true, recordedVersion });
|
|
137
|
+
return decision.kind === "refuse" ? decision.error : null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Record the release the install job about to start deploys: under the
|
|
142
|
+
* launcher's lock, from the install's bucket as it is now (another launcher
|
|
143
|
+
* may have recorded a release, or an earlier job taken the install past its
|
|
144
|
+
* first `pulumi up`, since this process first read it). A named version an
|
|
145
|
+
* install provisioned since the wizard's check does not run is refused, as
|
|
146
|
+
* the wizard refuses it up front ({@link decideInstallVersion}).
|
|
147
|
+
*
|
|
148
|
+
* @param requested - `--version`, or undefined for the CLI's own release.
|
|
149
|
+
* @param record - the verified release ({@link installRecordFromManifest}).
|
|
150
|
+
*/
|
|
151
|
+
export function recordLaunchRelease(
|
|
152
|
+
installId: string,
|
|
153
|
+
projectId: string,
|
|
154
|
+
requested: string | undefined,
|
|
155
|
+
record: { readonly digests: ImageDigests; readonly version: string },
|
|
156
|
+
): { readonly ok: true } | { readonly ok: false; readonly error: string } {
|
|
157
|
+
forgetCachedState(installId);
|
|
158
|
+
const current = readMetadata(installId);
|
|
159
|
+
if (!current) return { ok: false, error: `No install.json for install '${installId}'.` };
|
|
160
|
+
const deployed = isStepDone(installId, `pulumi-up-${projectId}`);
|
|
161
|
+
if (requested !== undefined) {
|
|
162
|
+
const again = decideInstallVersion({
|
|
163
|
+
requested,
|
|
164
|
+
deployed,
|
|
165
|
+
recordedVersion: current.releaseVersion,
|
|
166
|
+
});
|
|
167
|
+
if (again.kind === "refuse") return { ok: false, error: again.error };
|
|
168
|
+
}
|
|
169
|
+
if (
|
|
170
|
+
launcherRecordsRelease({
|
|
171
|
+
deployed,
|
|
172
|
+
requested: requested !== undefined,
|
|
173
|
+
recorded: recordedImageDigests(current),
|
|
174
|
+
})
|
|
175
|
+
) {
|
|
176
|
+
recordImageDigests(installId, record.digests, record.version);
|
|
177
|
+
}
|
|
178
|
+
return { ok: true };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The release a wizard run is about to install, for the release-candidate
|
|
183
|
+
* confirmation: the one `--version` names, else in job mode the CLI's own
|
|
184
|
+
* release when the launcher records it for the new install (a release
|
|
185
|
+
* candidate's installer installs that candidate). Null when the run installs
|
|
186
|
+
* no new release: local mode without `--version` resolves `latest`, never a
|
|
187
|
+
* candidate, and a provisioned install keeps what it runs.
|
|
188
|
+
*/
|
|
189
|
+
export function releaseToConfirm(input: {
|
|
190
|
+
readonly decision: InstallVersionDecision;
|
|
191
|
+
readonly runMode: "job" | "local";
|
|
192
|
+
readonly cliVersion: string;
|
|
193
|
+
readonly deployed: boolean;
|
|
194
|
+
readonly recorded: ImageDigests | null;
|
|
195
|
+
}): string | null {
|
|
196
|
+
if (input.decision.kind === "install") return input.decision.version;
|
|
197
|
+
if (input.decision.kind !== "none" || input.runMode !== "job") return null;
|
|
198
|
+
return launcherRecordsRelease({
|
|
199
|
+
deployed: input.deployed,
|
|
200
|
+
requested: false,
|
|
201
|
+
recorded: input.recorded,
|
|
202
|
+
})
|
|
203
|
+
? input.cliVersion
|
|
204
|
+
: null;
|
|
205
|
+
}
|
package/src/lifecycle.ts
CHANGED
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
provisionerServiceAccountEmail,
|
|
49
49
|
} from "./provisioner-identity.js";
|
|
50
50
|
import { assertRegionUnchanged } from "./regions.js";
|
|
51
|
+
import { confirmReleaseCandidate, resolveChannelVersion } from "./release-candidate.js";
|
|
51
52
|
import type { ReleaseManifest } from "./release-manifest.js";
|
|
52
53
|
import {
|
|
53
54
|
type HttpFetch,
|
|
@@ -407,9 +408,70 @@ interface UpgradeOpts {
|
|
|
407
408
|
* so it works on a machine (or a fresh Cloud Shell) with no local copy.
|
|
408
409
|
*/
|
|
409
410
|
readonly project?: string;
|
|
411
|
+
/**
|
|
412
|
+
* #1558 — `--accept-release-candidate`: an upgrade to a release candidate
|
|
413
|
+
* goes ahead without the prompt (where none can ask, it needs this).
|
|
414
|
+
*/
|
|
415
|
+
readonly acceptReleaseCandidate?: boolean;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** {@link UpgradeOpts} once the target is an exact version or `latest` (#1558). */
|
|
419
|
+
type SettledUpgradeOpts = Omit<UpgradeOpts, "channel">;
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Settle the release an upgrade rolls to, before any install is touched:
|
|
423
|
+
* `--channel rc|beta` becomes its newest release (the registry has no moving
|
|
424
|
+
* channel tag), and a release candidate needs the operator's confirmation
|
|
425
|
+
* (release-candidate.ts). Null when the upgrade must not start; the reason
|
|
426
|
+
* is printed and the exit code set.
|
|
427
|
+
*/
|
|
428
|
+
async function settleUpgradeTarget(opts: UpgradeOpts): Promise<SettledUpgradeOpts | null> {
|
|
429
|
+
const { channel, ...settled } = opts;
|
|
430
|
+
let version = settled.version;
|
|
431
|
+
if (version === undefined && (channel === "rc" || channel === "beta")) {
|
|
432
|
+
const newest = await resolveChannelVersion(channel);
|
|
433
|
+
if (!newest.ok) {
|
|
434
|
+
log.error(
|
|
435
|
+
red(
|
|
436
|
+
`Could not look up the newest ${channel} release (${newest.reason}). Nothing was changed; pass --version x.y.z instead.`,
|
|
437
|
+
),
|
|
438
|
+
);
|
|
439
|
+
process.exitCode = 1;
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
log.info(
|
|
443
|
+
`--channel ${channel}: the newest ${channel} or stable release is v${newest.version}.`,
|
|
444
|
+
);
|
|
445
|
+
version = newest.version;
|
|
446
|
+
}
|
|
447
|
+
if (version !== undefined) {
|
|
448
|
+
const decision = await confirmReleaseCandidate(
|
|
449
|
+
{
|
|
450
|
+
version,
|
|
451
|
+
action: "upgrade",
|
|
452
|
+
interactive: process.stdin.isTTY === true,
|
|
453
|
+
accepted: opts.acceptReleaseCandidate === true,
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
warn: (lines) => log.warn(yellow(lines.join("\n"))),
|
|
457
|
+
confirm: async (message) => {
|
|
458
|
+
const answer = await confirm({ message, initialValue: false });
|
|
459
|
+
return !isCancel(answer) && answer === true;
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
);
|
|
463
|
+
if (!decision.ok) {
|
|
464
|
+
cancel(decision.message);
|
|
465
|
+
process.exitCode = decision.reason === "declined" ? 0 : 1;
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return { ...settled, ...(version !== undefined ? { version } : {}) };
|
|
410
470
|
}
|
|
411
471
|
|
|
412
|
-
export async function upgradeCommand(
|
|
472
|
+
export async function upgradeCommand(options: UpgradeOpts = {}): Promise<void> {
|
|
473
|
+
const opts = await settleUpgradeTarget(options);
|
|
474
|
+
if (!opts) return;
|
|
413
475
|
if (opts.project) {
|
|
414
476
|
if (!(await gcpPreflight({ cosign: false }))) {
|
|
415
477
|
process.exitCode = 1;
|
|
@@ -520,7 +582,7 @@ async function upgradeKeylessProvisioner(installId: string, projectId: string):
|
|
|
520
582
|
async function upgradeInstall(
|
|
521
583
|
installId: string,
|
|
522
584
|
meta: InstallMetadata,
|
|
523
|
-
opts:
|
|
585
|
+
opts: SettledUpgradeOpts,
|
|
524
586
|
): Promise<boolean> {
|
|
525
587
|
// #656 — earlier installers checkpointed database URLs with role
|
|
526
588
|
// passwords (and the setup link) into progress.json. Scrub them first,
|
|
@@ -581,7 +643,7 @@ async function upgradeInstall(
|
|
|
581
643
|
async function upgradeLockedInstall(
|
|
582
644
|
installId: string,
|
|
583
645
|
meta: InstallMetadata,
|
|
584
|
-
opts:
|
|
646
|
+
opts: SettledUpgradeOpts,
|
|
585
647
|
provider: "gcp" | "gcp-firebase",
|
|
586
648
|
projectId: string,
|
|
587
649
|
): Promise<boolean> {
|