@caelo-cms/provisioning 0.11.20 → 0.11.21

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.
Files changed (57) hide show
  1. package/dist/admin-internal-google.d.ts +13 -1
  2. package/dist/admin-internal-google.d.ts.map +1 -1
  3. package/dist/admin-internal-google.js +47 -0
  4. package/dist/admin-internal-google.js.map +1 -1
  5. package/dist/agent/command.d.ts +1 -1
  6. package/dist/cli-routing.d.ts.map +1 -1
  7. package/dist/cli-routing.js +2 -2
  8. package/dist/cli-routing.js.map +1 -1
  9. package/dist/cli.js +5 -0
  10. package/dist/cli.js.map +1 -1
  11. package/dist/converge-checkpoint.d.ts +6 -0
  12. package/dist/converge-checkpoint.d.ts.map +1 -1
  13. package/dist/dns/manual.d.ts +5 -1
  14. package/dist/dns/manual.d.ts.map +1 -1
  15. package/dist/dns/manual.js +2 -1
  16. package/dist/dns/manual.js.map +1 -1
  17. package/dist/install-job-runner.d.ts.map +1 -1
  18. package/dist/install-job-runner.js +4 -3
  19. package/dist/install-job-runner.js.map +1 -1
  20. package/dist/install-job.d.ts +25 -1
  21. package/dist/install-job.d.ts.map +1 -1
  22. package/dist/install-job.js +72 -3
  23. package/dist/install-job.js.map +1 -1
  24. package/dist/operator-access.d.ts +7 -2
  25. package/dist/operator-access.d.ts.map +1 -1
  26. package/dist/operator-access.js +37 -6
  27. package/dist/operator-access.js.map +1 -1
  28. package/dist/project-status.d.ts +95 -0
  29. package/dist/project-status.d.ts.map +1 -0
  30. package/dist/project-status.js +213 -0
  31. package/dist/project-status.js.map +1 -0
  32. package/dist/state-attach.d.ts +17 -0
  33. package/dist/state-attach.d.ts.map +1 -1
  34. package/dist/state-attach.js +27 -9
  35. package/dist/state-attach.js.map +1 -1
  36. package/dist/wizards/gcp-install-job.d.ts +27 -4
  37. package/dist/wizards/gcp-install-job.d.ts.map +1 -1
  38. package/dist/wizards/gcp-install-job.js +62 -32
  39. package/dist/wizards/gcp-install-job.js.map +1 -1
  40. package/dist/wizards/gcp.d.ts +3 -0
  41. package/dist/wizards/gcp.d.ts.map +1 -1
  42. package/dist/wizards/gcp.js +10 -4
  43. package/dist/wizards/gcp.js.map +1 -1
  44. package/package.json +2 -2
  45. package/src/admin-internal-google.ts +48 -0
  46. package/src/cli-routing.ts +3 -2
  47. package/src/cli.ts +5 -0
  48. package/src/dns/manual.ts +4 -1
  49. package/src/install-job-runner.ts +4 -2
  50. package/src/install-job.ts +86 -4
  51. package/src/operator-access.test.ts +43 -0
  52. package/src/operator-access.ts +38 -6
  53. package/src/project-status.test.ts +462 -0
  54. package/src/project-status.ts +306 -0
  55. package/src/state-attach.ts +46 -16
  56. package/src/wizards/gcp-install-job.ts +91 -46
  57. package/src/wizards/gcp.ts +14 -7
@@ -0,0 +1,306 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * `cms-provision status --project <id>` (#822): where an install stands, on
5
+ * any machine. The install job keeps running after the Cloud Shell tab is
6
+ * gone, and a reset Cloud Shell has no `~/.caelo-*` left, so this command
7
+ * needs nothing but a signed-in gcloud identity: it reads the project
8
+ * (install.json, install-job.json and progress.json in the ops bucket, the
9
+ * Owner setup link in Secret Manager) and writes nothing, here or there.
10
+ *
11
+ * The setup link is a secret (#656). It goes to a terminal only: with stdout
12
+ * piped or redirected it stays unprinted, so it can't land in a CI log or a
13
+ * file. Once Owner setup is done the command says so instead of showing a
14
+ * used link.
15
+ */
16
+
17
+ import { log } from "@clack/prompts";
18
+ import { bold, cyan, dim, green, red, yellow } from "kleur/colors";
19
+ import { z } from "zod";
20
+ import type { AdminInternalResult, GoogleAdminTarget } from "./admin-internal.js";
21
+ import { readOwnerSetupState } from "./admin-internal-google.js";
22
+ import {
23
+ type DnsRecordGroups,
24
+ formatDnsRecordGroups,
25
+ groupDnsRecords,
26
+ type InstallDnsRecord,
27
+ } from "./dns/groups.js";
28
+ import { checkRecord } from "./dns/manual.js";
29
+ import { checkGcloudAuth, gcloud } from "./gcloud.js";
30
+ import type { GcloudRunner } from "./gcloud-retry.js";
31
+ import {
32
+ INSTALL_SETUP_LINK_SECRET,
33
+ isGcpProjectId,
34
+ readRecordedStackOutputs,
35
+ readSetupLink,
36
+ recordedDnsRecords,
37
+ } from "./install-job.js";
38
+ import { readProjectInstall } from "./state-attach.js";
39
+ import { realSyncGcloud, type SyncGcloud } from "./state-store.js";
40
+ import {
41
+ type InstallJobView,
42
+ installerCommand,
43
+ installJobViewLines,
44
+ readInstallJobView,
45
+ } from "./wizards/gcp-install-job.js";
46
+
47
+ /** The parts of install.json this command reads. */
48
+ const InstallRecordSchema = z.object({
49
+ installId: z.string().min(1),
50
+ provider: z.enum(["gcp", "gcp-firebase"]),
51
+ domain: z.string().min(1),
52
+ ownerEmail: z.string().min(1),
53
+ projectId: z.string().min(1),
54
+ region: z.string().min(1).nullable().default(null),
55
+ });
56
+ type InstallRecord = z.infer<typeof InstallRecordSchema>;
57
+
58
+ /** The DNS records of an install that public DNS does not answer yet. */
59
+ export interface DnsToSet extends DnsRecordGroups<InstallDnsRecord> {
60
+ /** How many records the install knows about, set or not; 0 before the stack ran. */
61
+ readonly total: number;
62
+ }
63
+
64
+ /** Where Owner setup stands, as far as this command can tell. */
65
+ export type OwnerSetup =
66
+ /** The install has not got far enough for a link to exist. */
67
+ | { readonly kind: "not-yet" }
68
+ /** An Owner exists; the link is used. */
69
+ | { readonly kind: "done" }
70
+ /** Setup is open, or could not be checked ({@link unverified} says why). */
71
+ | { readonly kind: "link"; readonly link: string; readonly unverified: string | null }
72
+ /** A link exists, but stdout is not a terminal. */
73
+ | { readonly kind: "withheld" }
74
+ /** No link in Secret Manager. */
75
+ | { readonly kind: "no-link" }
76
+ /** Reading the link failed; the message says what the account needs. */
77
+ | { readonly kind: "error"; readonly message: string };
78
+
79
+ /** Everything `status --project` shows. */
80
+ export interface ProjectStatus {
81
+ readonly install: InstallRecord;
82
+ readonly job: InstallJobView | null;
83
+ /** Whether the stack ran (its outputs are recorded). */
84
+ readonly provisioned: boolean;
85
+ readonly adminUrl: string | null;
86
+ readonly dns: DnsToSet;
87
+ readonly owner: OwnerSetup;
88
+ }
89
+
90
+ /** Side effects of {@link readProjectStatus}, injectable for tests. */
91
+ export interface ProjectStatusDeps {
92
+ readonly run: GcloudRunner;
93
+ readonly syncRun: SyncGcloud;
94
+ /** Whether public DNS answers the record with its value. */
95
+ readonly resolves: (record: InstallDnsRecord) => Promise<boolean>;
96
+ /** Whether the admin still offers Owner setup ({@link readOwnerSetupState}). */
97
+ readonly ownerSetupState: (
98
+ target: GoogleAdminTarget,
99
+ ) => Promise<AdminInternalResult<"open" | "done">>;
100
+ /** Whether stdout is a terminal: the only place the setup link may go. */
101
+ readonly isTerminal: boolean;
102
+ }
103
+
104
+ /** The admin's origin from the stack's outputs; null before the stack ran. */
105
+ export function adminUrlFromOutputs(
106
+ provider: InstallRecord["provider"],
107
+ outputs: Record<string, unknown>,
108
+ ): string | null {
109
+ // gcp-firebase binds admin.<domain> only on request; the setup link and
110
+ // the install's summary use the Cloud Run URL there (wizards/gcp.ts).
111
+ if (provider === "gcp-firebase") {
112
+ const url = outputs.adminCloudRunUrlOut;
113
+ return typeof url === "string" && url !== "" ? url : null;
114
+ }
115
+ const host = outputs.adminDomainOut;
116
+ return typeof host === "string" && host !== "" ? `https://${host}` : null;
117
+ }
118
+
119
+ /**
120
+ * Split `records` by what still has to happen: a record public DNS already
121
+ * answers is dropped, the rest fall into {@link groupDnsRecords}'s two groups.
122
+ */
123
+ export async function dnsRecordsToSet(
124
+ records: readonly InstallDnsRecord[],
125
+ domain: string,
126
+ resolves: ProjectStatusDeps["resolves"],
127
+ ): Promise<DnsToSet> {
128
+ const unique = [
129
+ ...new Map(records.map((r) => [`${r.type}:${r.hostname}:${r.value}`, r])).values(),
130
+ ];
131
+ const answered = await Promise.all(unique.map(resolves));
132
+ const open = unique.filter((_, i) => !answered[i]);
133
+ return { ...groupDnsRecords(open, domain), total: unique.length };
134
+ }
135
+
136
+ /** Where {@link readOwnerSetupState} reaches the admin; null without a recorded region. */
137
+ function adminTarget(install: InstallRecord): GoogleAdminTarget | null {
138
+ const { provider, projectId, domain, region } = install;
139
+ if (provider === "gcp") return { provider, projectId, domain };
140
+ return region ? { provider, projectId, region } : null;
141
+ }
142
+
143
+ async function readOwnerSetup(
144
+ args: {
145
+ readonly install: InstallRecord;
146
+ readonly adminUrl: string | null;
147
+ readonly job: InstallJobView | null;
148
+ readonly provisioned: boolean;
149
+ },
150
+ deps: ProjectStatusDeps,
151
+ ): Promise<OwnerSetup> {
152
+ const unfinished = args.job ? args.job.decision.kind !== "done" : !args.provisioned;
153
+ if (unfinished || args.adminUrl === null) return { kind: "not-yet" };
154
+ let link: string | null;
155
+ try {
156
+ link = await readSetupLink(deps.run, args.install.projectId);
157
+ } catch (e) {
158
+ return { kind: "error", message: e instanceof Error ? e.message : String(e) };
159
+ }
160
+ if (link === null) return { kind: "no-link" };
161
+ const target = adminTarget(args.install);
162
+ const state: AdminInternalResult<"open" | "done"> = target
163
+ ? await deps.ownerSetupState(target)
164
+ : { ok: false, error: "install.json records no region" };
165
+ if (state.ok && state.value === "done") return { kind: "done" };
166
+ if (!deps.isTerminal) return { kind: "withheld" };
167
+ return { kind: "link", link, unverified: state.ok ? null : state.error };
168
+ }
169
+
170
+ /**
171
+ * Read where the install in `projectId` stands from the project alone.
172
+ *
173
+ * @throws when a read fails, with what to do about it
174
+ */
175
+ export async function readProjectStatus(
176
+ projectId: string,
177
+ deps: ProjectStatusDeps,
178
+ ): Promise<ProjectStatus> {
179
+ const record = readProjectInstall(projectId, deps.syncRun);
180
+ if (!record.ok) throw new Error(record.error);
181
+ const parsed = InstallRecordSchema.safeParse(JSON.parse(record.text));
182
+ if (!parsed.success) {
183
+ throw new Error(
184
+ `install.json of ${projectId} is not a Google Cloud install this CLI understands (${parsed.error.message}). Run this command with the CLI of the release the install runs.`,
185
+ );
186
+ }
187
+ const install = parsed.data;
188
+ const job = await readInstallJobView(install, deps);
189
+ const outputs = readRecordedStackOutputs(projectId, deps.syncRun);
190
+ const provisioned = Object.keys(outputs).length > 0;
191
+ const adminUrl = adminUrlFromOutputs(install.provider, outputs);
192
+ const dns = await dnsRecordsToSet(
193
+ [...recordedDnsRecords(outputs), ...(job?.status.dnsRecords ?? [])],
194
+ install.domain,
195
+ deps.resolves,
196
+ );
197
+ const owner = await readOwnerSetup({ install, adminUrl, job, provisioned }, deps);
198
+ return { install, job, provisioned, adminUrl, dns, owner };
199
+ }
200
+
201
+ function jobLines(s: ProjectStatus): string[] {
202
+ if (s.job) return installJobViewLines(s.job, s.install);
203
+ return s.provisioned
204
+ ? ["Install job: none. This install ran from a terminal, not through the job."]
205
+ : [`Install job: not started. Start or resume it: ${installerCommand(s.install)}`];
206
+ }
207
+
208
+ function dnsLines(s: ProjectStatus): string[] {
209
+ const { dns, install } = s;
210
+ if (dns.total === 0) {
211
+ return ["DNS: not known yet; the install reports its records once its resources exist."];
212
+ }
213
+ const lines =
214
+ dns.setNow.length + dns.atGoLive.length === 0
215
+ ? [`DNS: ${green(`all set (${dns.total} of ${dns.total}).`)}`]
216
+ : [
217
+ `DNS records still to set for ${bold(install.domain)}:`,
218
+ ...formatDnsRecordGroups(dns, install.domain).map((l) => ` ${l}`),
219
+ ];
220
+ // The staging host's records reach the status document only through the
221
+ // job; a terminal install or an older job recorded none there.
222
+ if (!s.job?.status.dnsRecords) {
223
+ lines.push(dim(" The staging host's records are under Settings → Updates in the admin."));
224
+ }
225
+ return lines;
226
+ }
227
+
228
+ function ownerLines(s: ProjectStatus): string[] {
229
+ const { owner, install, adminUrl } = s;
230
+ const command = installerCommand(install);
231
+ switch (owner.kind) {
232
+ case "not-yet":
233
+ return ["Owner setup: the link appears here when the install has finished."];
234
+ case "done":
235
+ return [`Owner setup: ${green("done.")} Sign in at ${cyan(adminUrl ?? "")}`];
236
+ case "withheld":
237
+ return [
238
+ `Owner setup: ${yellow("a link is stored, but it is a secret and only goes to a terminal.")} Run this command in your own terminal, without a pipe or redirect.`,
239
+ ];
240
+ case "no-link":
241
+ return [
242
+ `Owner setup: no link is stored in this project (${INSTALL_SETUP_LINK_SECRET}). If Owner setup is done, sign in at ${cyan(adminUrl ?? "")}`,
243
+ ` If it is not, this finishes the install and stores a link: ${command}`,
244
+ ];
245
+ case "error":
246
+ return [`Owner setup: ${red(owner.message)}`];
247
+ case "link":
248
+ return [
249
+ `Owner setup: open this link in your browser, signed in as ${install.ownerEmail}. Do not share it.`,
250
+ ` ${bold(cyan(owner.link))}`,
251
+ ...(owner.unverified === null
252
+ ? []
253
+ : [
254
+ yellow(
255
+ ` Could not check whether it was already used (${owner.unverified}). A used link just opens the sign-in page.`,
256
+ ),
257
+ ]),
258
+ ];
259
+ }
260
+ }
261
+
262
+ /** {@link ProjectStatus} as text. Holds the setup link only for {@link OwnerSetup} `link`. */
263
+ export function projectStatusLines(s: ProjectStatus): string[] {
264
+ return [
265
+ `Install: ${bold(s.install.installId)} ${dim(`(${s.install.provider})`)}`,
266
+ `Domain: ${bold(s.install.domain)}`,
267
+ `Project: ${bold(s.install.projectId)}`,
268
+ ...jobLines(s),
269
+ `Admin: ${s.adminUrl ? cyan(s.adminUrl) : "not known yet"}`,
270
+ ...dnsLines(s),
271
+ ...ownerLines(s),
272
+ ];
273
+ }
274
+
275
+ /** What to tell the operator about a failure of the command. */
276
+ export function projectStatusFailure(e: unknown): string {
277
+ if ((e as NodeJS.ErrnoException | undefined)?.code === "ENOENT") {
278
+ return "gcloud is not installed on this machine. Install the Google Cloud CLI (https://cloud.google.com/sdk/docs/install) or use Cloud Shell, run `gcloud auth login`, then run this command again.";
279
+ }
280
+ return e instanceof Error ? e.message : String(e);
281
+ }
282
+
283
+ /** `status --project <id>`: print where the install stands; exit 1 when part of it can't be read. */
284
+ export async function projectStatusCommand(argv: readonly string[]): Promise<void> {
285
+ const projectId = argv[argv.indexOf("--project") + 1] ?? "";
286
+ if (!isGcpProjectId(projectId) || argv.includes("--install")) {
287
+ console.error("Usage: cms-provision status --project <gcp-project-id>");
288
+ process.exit(2);
289
+ }
290
+ try {
291
+ const auth = await checkGcloudAuth();
292
+ if (!auth.ok) throw new Error(auth.error);
293
+ const status = await readProjectStatus(projectId, {
294
+ run: gcloud,
295
+ syncRun: realSyncGcloud,
296
+ resolves: checkRecord,
297
+ ownerSetupState: (target) => readOwnerSetupState(target),
298
+ isTerminal: process.stdout.isTTY === true,
299
+ });
300
+ for (const line of projectStatusLines(status)) console.log(line);
301
+ if (status.owner.kind === "error") process.exitCode = 1;
302
+ } catch (e) {
303
+ log.error(red(projectStatusFailure(e)));
304
+ process.exit(1);
305
+ }
306
+ }
@@ -29,33 +29,35 @@ export type AttachResult =
29
29
  /** Install ids are `<provider>-<slug>` (install-state.ts deriveInstallId). */
30
30
  const INSTALL_ID = /^[a-z0-9][a-z0-9-]{0,80}$/;
31
31
 
32
+ /** The install record in a project's ops bucket, checked. */
33
+ export type ProjectInstallRecord =
34
+ | {
35
+ readonly ok: true;
36
+ readonly installId: string;
37
+ readonly domain: string;
38
+ /** install.json exactly as the bucket held it. */
39
+ readonly text: string;
40
+ }
41
+ | { readonly ok: false; readonly error: string };
42
+
32
43
  /**
33
- * Attach the install in `projectId` to this machine.
34
- *
35
- * @param deps.run gcloud runner (tests pass a fake bucket)
36
- * @param deps.rootFor `~/.caelo-<id>` for an install id
37
- * @param deps.hasLocalState whether a dir holds a local Pulumi stack
44
+ * Read and check `gs://<project>-caelo-ops/install/install.json`, touching
45
+ * nothing on this machine: shared by `attach` and `status --project`, which
46
+ * has to work with no local install directory at all (#822).
38
47
  */
39
- export function attachInstall(
40
- projectId: string,
41
- deps: {
42
- run: SyncGcloud;
43
- rootFor: (installId: string) => string;
44
- hasLocalState: (root: string) => boolean;
45
- },
46
- ): AttachResult {
48
+ export function readProjectInstall(projectId: string, run: SyncGcloud): ProjectInstallRecord {
47
49
  const bucket = opsBucketName(projectId);
48
50
  let text: string | null;
49
51
  try {
50
52
  // Peek: the directory to mirror into isn't known (or checked) yet.
51
- text = new GcsStateStore(bucket, "/nonexistent", deps.run).peek("install.json");
53
+ text = new GcsStateStore(bucket, "/nonexistent", run).peek("install.json");
52
54
  } catch (e) {
53
55
  return { ok: false, error: e instanceof Error ? e.message : String(e) };
54
56
  }
55
57
  if (text === null) {
56
58
  return {
57
59
  ok: false,
58
- error: `gs://${bucket} holds no install.json. If this install's state is still on the machine that installed it, run \`${selfCommand("state", "migrate")}\` there first.`,
60
+ error: `gs://${bucket} holds no install.json. Check the project id. If this install's state is still on the machine that installed it, run \`${selfCommand("state", "migrate")}\` there first.`,
59
61
  };
60
62
  }
61
63
  let remote: {
@@ -95,6 +97,34 @@ export function attachInstall(
95
97
  };
96
98
  }
97
99
 
100
+ return {
101
+ ok: true,
102
+ installId,
103
+ domain: typeof remote.domain === "string" ? remote.domain : installId,
104
+ text,
105
+ };
106
+ }
107
+
108
+ /**
109
+ * Attach the install in `projectId` to this machine.
110
+ *
111
+ * @param deps.run gcloud runner (tests pass a fake bucket)
112
+ * @param deps.rootFor `~/.caelo-<id>` for an install id
113
+ * @param deps.hasLocalState whether a dir holds a local Pulumi stack
114
+ */
115
+ export function attachInstall(
116
+ projectId: string,
117
+ deps: {
118
+ run: SyncGcloud;
119
+ rootFor: (installId: string) => string;
120
+ hasLocalState: (root: string) => boolean;
121
+ },
122
+ ): AttachResult {
123
+ const bucket = opsBucketName(projectId);
124
+ const record = readProjectInstall(projectId, deps.run);
125
+ if (!record.ok) return record;
126
+ const { installId, domain, text } = record;
127
+
98
128
  const root = deps.rootFor(installId);
99
129
  const localText = new LocalStateStore(root).read("install.json");
100
130
  // Local Pulumi state blocks the attach whether or not an install.json
@@ -126,7 +156,7 @@ export function attachInstall(
126
156
  return {
127
157
  ok: true,
128
158
  installId,
129
- domain: typeof remote.domain === "string" ? remote.domain : installId,
159
+ domain,
130
160
  status,
131
161
  };
132
162
  }
@@ -13,7 +13,7 @@
13
13
  import { CAELO_VERSION } from "@caelo-cms/shared";
14
14
  import { cancel, confirm, isCancel, log, note } from "@clack/prompts";
15
15
  import { bold, cyan, dim, green, red, yellow } from "kleur/colors";
16
- import { formatDnsRecordGroups, groupDnsRecords, type InstallDnsRecord } from "../dns/groups.js";
16
+ import { formatDnsRecordGroups, groupDnsRecords } from "../dns/groups.js";
17
17
  import { activeAccount, gcloud } from "../gcloud.js";
18
18
  import type { GcloudRunner, Sleep } from "../gcloud-retry.js";
19
19
  import { realSleep } from "../gcloud-retry.js";
@@ -30,7 +30,9 @@ import {
30
30
  opsImageRef,
31
31
  readExecutionLogs,
32
32
  readInstallJobStatus,
33
+ readRecordedStackOutputs,
33
34
  readSetupLink,
35
+ recordedDnsRecords,
34
36
  startInstallJob,
35
37
  storeInstallSecretValue,
36
38
  } from "../install-job.js";
@@ -178,20 +180,35 @@ function logsHint(projectId: string, region: string): string {
178
180
  return `gcloud run jobs executions list --job=${INSTALL_JOB_NAME} --region=${region} --project=${projectId}`;
179
181
  }
180
182
 
181
- /** Print that closing the tab is fine; exit 130 on Ctrl-C with the re-attach hint. */
182
- function announceDetachable(projectId: string, execution: string): void {
183
+ /**
184
+ * What the terminal says before it hands the install to the job (#822): the
185
+ * tab may close, and the one command that shows where the install stands
186
+ * from any terminal.
187
+ */
188
+ export function handoffLines(projectId: string): string[] {
189
+ return [
190
+ bold(yellow("You may close this tab now.")),
191
+ "The install keeps running in your Google Cloud project. To see where it stands",
192
+ "(phase, DNS records, admin URL, Owner setup link), run this in any terminal",
193
+ "signed in to gcloud:",
194
+ "",
195
+ ` ${bold(cyan(selfCommand("status", "--project", projectId)))}`,
196
+ ];
197
+ }
198
+
199
+ /** Print {@link handoffLines}, highlighted. */
200
+ function announceHandoff(projectId: string): void {
201
+ note(handoffLines(projectId).join("\n"), "The install runs on its own from here");
202
+ }
203
+
204
+ /** Name the job being followed; exit 130 on Ctrl-C with the way back. */
205
+ function announceFollowing(projectId: string, execution: string): void {
183
206
  log.info(
184
- [
185
- `The install runs in your project as Cloud Run job ${bold(INSTALL_JOB_NAME)} (execution ${dim(execution)}).`,
186
- dim(
187
- "Closing this tab, Ctrl-C or Cloud Shell's idle timeout does not stop it. To follow it again, re-open the",
188
- ),
189
- dim(`"Open in Cloud Shell" link (or re-run the same command) and pick project ${projectId}.`),
190
- ].join("\n"),
207
+ `The install runs in your project as Cloud Run job ${bold(INSTALL_JOB_NAME)} (execution ${dim(execution)}).`,
191
208
  );
192
209
  process.once("SIGINT", () => {
193
210
  process.stdout.write(
194
- `\nStopped following. The install keeps running in ${projectId}; re-run to attach again.\n`,
211
+ `\nStopped following. The install keeps running in ${projectId}; to see where it stands: ${selfCommand("status", "--project", projectId)}\n`,
195
212
  );
196
213
  process.exit(130);
197
214
  });
@@ -201,7 +218,7 @@ function announceDetachable(projectId: string, execution: string): void {
201
218
  async function followToTheEnd(meta: InstallMetadata, execution: string): Promise<void> {
202
219
  const projectId = meta.projectId ?? "";
203
220
  const region = meta.region ?? "";
204
- announceDetachable(projectId, execution);
221
+ announceFollowing(projectId, execution);
205
222
  const outcome = await tailInstallJob({ projectId, region, execution });
206
223
  if (outcome.kind === "succeeded") {
207
224
  await showResult(meta);
@@ -234,21 +251,7 @@ async function showResult(meta: InstallMetadata): Promise<void> {
234
251
  // The records from the stack's outputs, as the pulumi-up step recorded
235
252
  // them — not from the log, which a re-run after the install no longer shows.
236
253
  // Uncached: this process may hold progress.json from before the job ran.
237
- const progressText = new GcsStateStore(
238
- opsBucketName(projectId),
239
- installRoot(meta.installId),
240
- realSyncGcloud,
241
- ).peek("progress.json");
242
- const progress = progressText
243
- ? (JSON.parse(progressText) as { steps?: Record<string, unknown> })
244
- : {};
245
- const pulumiUp = progress.steps?.[`pulumi-up-${projectId}`] as
246
- | { outputs?: Record<string, unknown> }
247
- | undefined;
248
- const outputs = pulumiUp?.outputs ?? {};
249
- const records = Array.isArray(outputs.dnsRecordsRequiredOut)
250
- ? (outputs.dnsRecordsRequiredOut as InstallDnsRecord[])
251
- : [];
254
+ const records = recordedDnsRecords(readRecordedStackOutputs(projectId, realSyncGcloud));
252
255
  const dnsLines =
253
256
  records.length > 0
254
257
  ? [
@@ -295,6 +298,7 @@ export async function launchInstallJob(opts: {
295
298
  if (!meta) throw new Error(`No install.json for install '${installId}'.`);
296
299
  const decision = await decide(gcloud, realSyncGcloud, { projectId, region });
297
300
  if (decision.kind === "attach") {
301
+ announceHandoff(projectId);
298
302
  await followToTheEnd(meta, decision.status.execution);
299
303
  return;
300
304
  }
@@ -345,8 +349,10 @@ export async function launchInstallJob(opts: {
345
349
  const now = await decide(gcloud, realSyncGcloud, { projectId, region });
346
350
  if (now.kind !== "start") {
347
351
  release();
348
- if (now.kind === "attach") await followToTheEnd(meta, now.status.execution);
349
- else await showResult(meta);
352
+ if (now.kind === "attach") {
353
+ announceHandoff(projectId);
354
+ await followToTheEnd(meta, now.status.execution);
355
+ } else await showResult(meta);
350
356
  return;
351
357
  }
352
358
  // Automatic DNS in the job (dns/cloudflare.ts) when this shell has a
@@ -369,6 +375,7 @@ export async function launchInstallJob(opts: {
369
375
  `DNS: the job sets the records through Cloudflare (token stored in Secret Manager as ${INSTALL_CLOUDFLARE_TOKEN_SECRET}).`,
370
376
  );
371
377
  }
378
+ announceHandoff(projectId);
372
379
  const started = await startInstallJob(gcloud, {
373
380
  projectId,
374
381
  region,
@@ -460,6 +467,7 @@ export async function prepareJobModeInstall(opts: {
460
467
  if (!meta.region) return { kind: "existing", meta };
461
468
  const decision = await decide(gcloud, realSyncGcloud, { projectId, region: meta.region });
462
469
  if (decision.kind === "attach") {
470
+ announceHandoff(projectId);
463
471
  await followToTheEnd(meta, decision.status.execution);
464
472
  return { kind: "handled" };
465
473
  }
@@ -470,37 +478,74 @@ export async function prepareJobModeInstall(opts: {
470
478
  return { kind: "existing", meta };
471
479
  }
472
480
 
481
+ /** The command that follows or resumes the install in `meta`'s project, on any machine. */
482
+ export function installerCommand(meta: Pick<InstallMetadata, "provider" | "projectId">): string {
483
+ return selfCommand(
484
+ "--provider",
485
+ meta.provider,
486
+ "--install-job",
487
+ "--project-id",
488
+ meta.projectId ?? "<gcp-project-id>",
489
+ );
490
+ }
491
+
492
+ /** How the install job stands: what the bucket records and what that means. */
493
+ export interface InstallJobView {
494
+ readonly status: InstallJobStatus;
495
+ readonly decision: InstallJobDecision;
496
+ }
497
+
473
498
  /**
474
- * `status`'s view of the install job: what the bucket records and, for a
475
- * run that claims to be running, whether its execution still is. Empty
476
- * when the install never used the job.
499
+ * What the bucket records about the install job and, for a run that claims
500
+ * to be running, whether its execution still is. Null when the install
501
+ * never used the job.
477
502
  */
478
- export async function installJobStatusLines(
479
- meta: InstallMetadata,
480
- deps: { run: GcloudRunner; syncRun: SyncGcloud } = { run: gcloud, syncRun: realSyncGcloud },
481
- ): Promise<string[]> {
482
- if (!meta.projectId || !meta.region) return [];
503
+ export async function readInstallJobView(
504
+ meta: Pick<InstallMetadata, "projectId" | "region">,
505
+ deps: { run: GcloudRunner; syncRun: SyncGcloud },
506
+ ): Promise<InstallJobView | null> {
507
+ if (!meta.projectId || !meta.region) return null;
483
508
  const status = readInstallJobStatus(opsBucketName(meta.projectId), deps.syncRun);
484
- if (!status) return [];
485
- const decision = decideInstallJob(
486
- status,
509
+ if (!status) return null;
510
+ const live =
487
511
  status.state === "running"
488
512
  ? await describeExecution(deps.run, {
489
513
  projectId: meta.projectId,
490
514
  region: meta.region,
491
515
  execution: status.execution,
492
516
  })
493
- : null,
494
- );
495
- const head = `Install job: ${status.state} — ${status.phase} ${dim(`(v${status.caeloVersion}, execution ${status.execution}, updated ${status.updatedAt})`)}`;
496
- const lines = [head];
517
+ : null;
518
+ return { status, decision: decideInstallJob(status, live) };
519
+ }
520
+
521
+ /** {@link InstallJobView} as `status` prints it, with the command that goes on from there. */
522
+ export function installJobViewLines(
523
+ view: InstallJobView,
524
+ meta: Pick<InstallMetadata, "provider" | "projectId">,
525
+ ): string[] {
526
+ const { status, decision } = view;
527
+ const lines = [
528
+ `Install job: ${status.state} — ${status.phase} ${dim(`(v${status.caeloVersion}, execution ${status.execution}, updated ${status.updatedAt})`)}`,
529
+ ];
497
530
  if (status.detail) lines.push(` ${status.detail}`);
498
531
  if (decision.kind === "attach") {
499
- lines.push(` Follow it: re-run the installer for project ${meta.projectId} (it attaches).`);
532
+ lines.push(` Follow it live: ${installerCommand(meta)}`);
500
533
  } else if (decision.kind === "start") {
501
534
  lines.push(
502
- ` Not finished (${decision.why}). Re-run the installer for project ${meta.projectId}; it resumes where this run stopped.`,
535
+ ` Not finished (${decision.why}). Resume it where this run stopped: ${installerCommand(meta)}`,
503
536
  );
504
537
  }
505
538
  return lines;
506
539
  }
540
+
541
+ /**
542
+ * `status`'s view of the install job as text. Empty when the install never
543
+ * used the job.
544
+ */
545
+ export async function installJobStatusLines(
546
+ meta: InstallMetadata,
547
+ deps: { run: GcloudRunner; syncRun: SyncGcloud } = { run: gcloud, syncRun: realSyncGcloud },
548
+ ): Promise<string[]> {
549
+ const view = await readInstallJobView(meta, deps);
550
+ return view ? installJobViewLines(view, meta) : [];
551
+ }
@@ -80,12 +80,7 @@ import {
80
80
  upgraderServiceAccountEmail,
81
81
  } from "../gcp-names.js";
82
82
  import { INFRA_CONTRACT_VERSION } from "../infra-contract.js";
83
- import {
84
- INSTALL_JOB_NAME,
85
- INSTALL_JOB_ROLES,
86
- INSTALL_SETUP_LINK_SECRET,
87
- storeSetupLink,
88
- } from "../install-job.js";
83
+ import { INSTALL_JOB_NAME, INSTALL_JOB_ROLES, storeSetupLink } from "../install-job.js";
89
84
  import {
90
85
  adoptStateBackend,
91
86
  ensureInstallDir,
@@ -349,6 +344,8 @@ export interface GcpConvergeOpts {
349
344
  readonly setupLink: "print" | "secret";
350
345
  /** Called as each step starts — the install job records it in the bucket. */
351
346
  readonly onPhase?: (phase: string, detail?: string) => void;
347
+ /** Called with DNS records the stack's outputs don't carry (the staging host's, #822). */
348
+ readonly onDnsRecords?: (records: InstallDnsRecord[]) => void;
352
349
  }
353
350
 
354
351
  /**
@@ -578,6 +575,7 @@ export async function runGcpConverge(opts: GcpConvergeOpts): Promise<void> {
578
575
  domain,
579
576
  installStagingHost(meta),
580
577
  imageDigests,
578
+ opts.onDnsRecords ?? (() => {}),
581
579
  );
582
580
 
583
581
  // === 11.3. The quality-audit job: parallel Lighthouse runs (#875) ===
@@ -1610,6 +1608,7 @@ async function stepStagingGateway(
1610
1608
  domain: string,
1611
1609
  stagingHost: string,
1612
1610
  imageDigests: ImageDigests,
1611
+ onDnsRecords: (records: InstallDnsRecord[]) => void,
1613
1612
  ): Promise<boolean> {
1614
1613
  const s = spinner();
1615
1614
  s.start(`Setting up the staging gateway behind the staging gate (${stagingHost})...`);
@@ -1634,6 +1633,14 @@ async function stepStagingGateway(
1634
1633
  if (edge.dnsRecords.length > 0) {
1635
1634
  log.info(` DNS for ${stagingHost} (Settings → Updates shows the same):`);
1636
1635
  for (const d of edge.dnsRecords) log.info(` ${d.name} ${d.type} ${d.value}`);
1636
+ onDnsRecords(
1637
+ edge.dnsRecords.map((d) => ({
1638
+ hostname: d.name,
1639
+ type: d.type,
1640
+ value: d.value,
1641
+ purpose: `Protected staging site (${stagingHost})`,
1642
+ })),
1643
+ );
1637
1644
  }
1638
1645
  return true;
1639
1646
  }
@@ -2596,7 +2603,7 @@ async function stepFinalize(installId: string, setupLink: "print" | "secret"): P
2596
2603
  const setupLinkLine =
2597
2604
  setupLink === "print"
2598
2605
  ? ` ${cyan(String(bootstrapUrl))}`
2599
- : ` ${dim(`(shown in your Cloud Shell terminal; or: gcloud secrets versions access latest --secret=${INSTALL_SETUP_LINK_SECRET} --project=${meta.projectId})`)}`;
2606
+ : ` ${dim(`(shown in your Cloud Shell terminal; or, from any terminal: ${selfCommand("status", "--project", meta.projectId)})`)}`;
2600
2607
 
2601
2608
  // Both providers report their records in `dnsRecordsRequiredOut`; the
2602
2609
  // summary lists them in two groups so the main-domain records that take a