Skip to content

Commit ee4eaa7

Browse files
committed
Show progress while preparing platform commands.
1 parent 9921eec commit ee4eaa7

6 files changed

Lines changed: 196 additions & 75 deletions

File tree

‎packages/void/src/cli/platform-lifecycle.ts‎

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
text,
1616
} from '@voidzero-dev/vite-plus-prompts';
1717
import { resolve } from 'pathslash';
18-
import { printSuccess, cliCommandName, createSpinner, formatUrl, note, pc } from './output.ts';
18+
import { printSuccess, cliCommandName, formatUrl, note, pc } from './output.ts';
1919
import {
2020
selectInstallationAppAccess,
2121
prepareInstallationAppAccess,
@@ -61,6 +61,7 @@ import {
6161
revalidatePlatformInstallAction,
6262
type PlatformExternalHyperdrive,
6363
} from './platform-plan.ts';
64+
import { createPlatformProgress, withPlatformProgress } from './platform-progress.ts';
6465
import {
6566
acquirePlatformLifecycleLock,
6667
assertPlatformInstallationSlugAvailable,
@@ -154,16 +155,16 @@ export async function runPlatformLifecycleCommand(commandArgs: PlatformArgs): Pr
154155
return;
155156
}
156157
if (commandArgs.subcommand === 'discover') {
158+
log.step('Preparing platform discovery');
157159
const credential = await resolvePlatformCloudflareCredential();
158160
const client = new PlatformCloudflareClient(credential.token);
159-
const accounts = await readAccounts(client);
161+
const accounts = await withPlatformProgress('Reading Cloudflare accounts', () =>
162+
readAccounts(client),
163+
);
160164
const accountId = await selectAccount(accounts, commandArgs.account);
161165
const { recoverPlatformInstallations } = await import('./platform-recovery.ts');
162-
const recovered = await recoverPlatformInstallations(
163-
client,
164-
accountId,
165-
undefined,
166-
commandArgs.selector,
166+
const recovered = await withPlatformProgress('Discovering platform installations', () =>
167+
recoverPlatformInstallations(client, accountId, undefined, commandArgs.selector),
167168
);
168169
if (recovered.length === 0) {
169170
log.info(`No recoverable Void platform installations were found in ${accountId}.`);
@@ -191,6 +192,7 @@ export async function runPlatformLifecycleCommand(commandArgs: PlatformArgs): Pr
191192
assertNoninteractivePlatformMutationAcknowledged(args, process.stdin.isTTY === true);
192193

193194
console.log();
195+
log.step('Preparing platform installation');
194196
let existing = args.resume ? resolveInstallationManifest(args.name) : null;
195197
let selectedInstall = false;
196198
let selectedDraft = false;
@@ -367,7 +369,9 @@ export async function runPlatformLifecycleCommand(commandArgs: PlatformArgs): Pr
367369
return existing.deployment.installationSlug;
368370
});
369371
let client = new PlatformCloudflareClient(operatorCredential.token);
370-
const accounts = await readAccounts(client);
372+
const accounts = await withPlatformProgress('Reading Cloudflare accounts', () =>
373+
readAccounts(client),
374+
);
371375
const accountId = existing ? existing.account.id : await selectAccount(accounts, args.account);
372376
if (
373377
existing &&
@@ -463,20 +467,7 @@ export async function runPlatformLifecycleCommand(commandArgs: PlatformArgs): Pr
463467
dedicatedZone = catchAll;
464468
}
465469
const release = args.plan ? null : acquirePlatformLifecycleLock(accountId, installationSlug);
466-
let progress: ReturnType<typeof createSpinner> | undefined;
467-
const startProgress = (message: string) => {
468-
const active = createSpinner({
469-
// Clack stops its animation on cancellation. Forward that cancellation
470-
// to the CLI's existing signal coordinator (or normal process termination).
471-
onCancel: () => {
472-
if (!process.emit('SIGINT')) {
473-
process.exit(130);
474-
}
475-
},
476-
});
477-
active.start(message);
478-
return active;
479-
};
470+
let progress: ReturnType<typeof createPlatformProgress> | undefined;
480471
// Set while a step uses an unclaimed database URL, which a resume may still replace.
481472
let usingUnboundDatabase = false;
482473
try {
@@ -504,7 +495,7 @@ export async function runPlatformLifecycleCommand(commandArgs: PlatformArgs): Pr
504495
'platform: DATABASE_URL is required to verify an interrupted installation before resuming it.',
505496
);
506497
}
507-
progress = startProgress('Reading the saved installation');
498+
progress = createPlatformProgress('Reading the saved installation');
508499
usingUnboundDatabase = !isPlatformInstallDatabaseBound(checkpoint, existing);
509500
const authoritative = await readPlatformDatabaseLifecycleManifest(
510501
databaseUrl,
@@ -760,7 +751,9 @@ export async function runPlatformLifecycleCommand(commandArgs: PlatformArgs): Pr
760751
enableSandbox: runtime.manifest.safetyProtocols.sandboxDrain >= 3,
761752
deploymentExecution: runtime.manifest.deploymentExecution === 1,
762753
};
763-
let plan = await createPlatformInstallPlan(client, planInput, existing, planOptions);
754+
let plan = await withPlatformProgress('Preparing installation plan', () =>
755+
createPlatformInstallPlan(client, planInput, existing, planOptions),
756+
);
764757
assertPlatformRuntimeLogsSupported(plan.deployment, runtime.manifest);
765758
const commandOptions = {
766759
commandName: cliCommandName(),
@@ -1259,7 +1252,7 @@ export async function runPlatformLifecycleCommand(commandArgs: PlatformArgs): Pr
12591252
interactive: process.stdin.isTTY === true && process.stdout.isTTY === true && !args.yes,
12601253
command: `${cliCommandName()} platform install --resume --name ${existing.id}`,
12611254
});
1262-
progress = startProgress('Installing the platform');
1255+
progress = createPlatformProgress('Installing the platform');
12631256
if (credentialSetup) {
12641257
// Stop treating this as an untouched local draft before any database claim is attempted.
12651258
saveValues({
@@ -1305,7 +1298,7 @@ export async function runPlatformLifecycleCommand(commandArgs: PlatformArgs): Pr
13051298
saveAuthenticationValues,
13061299
{ client, ownershipNonce: manifest.ownershipNonce, yes: args.yes },
13071300
);
1308-
progress = startProgress('Continuing platform installation');
1301+
progress = createPlatformProgress('Continuing platform installation');
13091302
return {
13101303
...result,
13111304
accessProvisioningJson: values.accessProvisioningJson,
@@ -1329,7 +1322,7 @@ export async function runPlatformLifecycleCommand(commandArgs: PlatformArgs): Pr
13291322
checkpoint: values,
13301323
save: saveAuthenticationValues,
13311324
});
1332-
progress = startProgress('Continuing platform installation');
1325+
progress = createPlatformProgress('Continuing platform installation');
13331326
return setupJson;
13341327
},
13351328
}

‎packages/void/src/cli/platform-management.ts‎

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '@void/platform';
1515
import { confirm, isCancel, log, outro, select } from '@voidzero-dev/vite-plus-prompts';
1616
import { ensurePlatformAccessToken } from './cf-access.ts';
17-
import { printSuccess, createSpinner, formatUrl, note, pc } from './output.ts';
17+
import { printSuccess, formatUrl, note, pc } from './output.ts';
1818
import { activatePlatformAccessCredentials } from './platform-access-setup.ts';
1919
import { turnOffInstalledProjectZeroTrust } from './platform-app-access.ts';
2020
import type { PlatformArgs } from './platform-args.ts';
@@ -72,6 +72,7 @@ import {
7272
resourceMarkerProblem,
7373
revalidatePlatformInstallAction,
7474
} from './platform-plan.ts';
75+
import { createPlatformProgress, withPlatformProgress } from './platform-progress.ts';
7576
import {
7677
acquirePlatformLifecycleLock,
7778
listInstallationManifests,
@@ -280,6 +281,7 @@ export async function runInstalledPlatformCommand(args: PlatformArgs): Promise<v
280281
throw new Error(`platform: Unsupported lifecycle command ${args.subcommand}.`);
281282
}
282283
assertNoninteractivePlatformMutationAcknowledged(args, process.stdin.isTTY === true);
284+
log.step(`Preparing platform ${args.subcommand}`);
283285
const timingStart = performance.now();
284286
let timingPrevious = timingStart;
285287
const markPhase = (phase: string) => {
@@ -297,25 +299,27 @@ export async function runInstalledPlatformCommand(args: PlatformArgs): Promise<v
297299
savedManagementToken: readInstallationRecoverySecrets(manifest)?.managementApiToken,
298300
});
299301
const operatorClient = new PlatformCloudflareClient(operatorCredential.token);
300-
await verifyPlatformCloudflareCredential(operatorClient, {
301-
account: manifest.account,
302-
source: operatorCredential.source,
303-
r2Buckets:
304-
args.subcommand === 'disable' || args.subcommand === 'uninstall'
305-
? []
306-
: manifest.resources
307-
.filter((resource) => resource.kind === 'r2-bucket')
308-
.map((resource) => resource.name),
309-
allowMissingR2Buckets: args.subcommand === 'repair',
310-
});
302+
await withPlatformProgress('Checking Cloudflare access', () =>
303+
verifyPlatformCloudflareCredential(operatorClient, {
304+
account: manifest.account,
305+
source: operatorCredential.source,
306+
r2Buckets:
307+
args.subcommand === 'disable' || args.subcommand === 'uninstall'
308+
? []
309+
: manifest.resources
310+
.filter((resource) => resource.kind === 'r2-bucket')
311+
.map((resource) => resource.name),
312+
allowMissingR2Buckets: args.subcommand === 'repair',
313+
}),
314+
);
311315
markPhase('operator credential');
312316
const runtime =
313317
args.subcommand === 'uninstall' || args.subcommand === 'disable'
314318
? null
315319
: loadPlatformRuntime(args.runtime);
316320
const rollbackSourceRuntime =
317321
args.subcommand === 'rollback' ? loadPlatformRuntime(args.fromRuntime) : null;
318-
let progress: ReturnType<typeof createSpinner> | undefined;
322+
let progress: ReturnType<typeof createPlatformProgress> | undefined;
319323
let reportResult: (() => void) | undefined;
320324

321325
const execute = async (
@@ -447,15 +451,17 @@ export async function runInstalledPlatformCommand(args: PlatformArgs): Promise<v
447451
installationSlug: deployment.installationSlug,
448452
zoneName: deployment.application.zoneName,
449453
};
450-
const plan = await createPlatformInstallPlan(client, planInput, manifest, {
451-
authoritativeProvisionIntents: databaseCheckpointExists,
452-
repairMissing: args.subcommand === 'repair',
453-
allowUnverifiedAiGateway: args.plan,
454-
includeEmailGateway: runtime!.manifest.artifacts.emailGateway !== undefined,
455-
enableSandbox: runtime!.manifest.safetyProtocols.sandboxDrain >= 3,
456-
deploymentExecution: runtime!.manifest.deploymentExecution === 1,
457-
allowRuntimeLogsChange: args.subcommand === 'upgrade',
458-
});
454+
const plan = await withPlatformProgress(`Preparing ${args.subcommand} plan`, () =>
455+
createPlatformInstallPlan(client, planInput, manifest, {
456+
authoritativeProvisionIntents: databaseCheckpointExists,
457+
repairMissing: args.subcommand === 'repair',
458+
allowUnverifiedAiGateway: args.plan,
459+
includeEmailGateway: runtime!.manifest.artifacts.emailGateway !== undefined,
460+
enableSandbox: runtime!.manifest.safetyProtocols.sandboxDrain >= 3,
461+
deploymentExecution: runtime!.manifest.deploymentExecution === 1,
462+
allowRuntimeLogsChange: args.subcommand === 'upgrade',
463+
}),
464+
);
459465
assertPlatformRuntimeLogsSupported(plan.deployment, runtime!.manifest);
460466
markPhase('plan');
461467
note(
@@ -669,14 +675,7 @@ export async function runInstalledPlatformCommand(args: PlatformArgs): Promise<v
669675
command: platformLifecycleResumeCommand({ ...args, yes: false }, manifest.id),
670676
});
671677
markPhase('outside changes');
672-
progress = createSpinner({
673-
// Preserve the subprocess signal coordinator used by platform installs.
674-
onCancel: () => {
675-
if (!process.emit('SIGINT')) {
676-
process.exit(130);
677-
}
678-
},
679-
});
678+
progress = createPlatformProgress();
680679
progress.start(
681680
args.subcommand === 'upgrade'
682681
? 'Upgrading the platform'
@@ -863,10 +862,8 @@ export async function runInstalledPlatformCommand(args: PlatformArgs): Promise<v
863862
'platform: DATABASE_URL is required to safely serialize lifecycle changes across hosts.',
864863
);
865864
}
866-
const releaseDatabase = await acquirePlatformDatabaseLifecycleLock(
867-
databaseUrl,
868-
current.id,
869-
current.ownershipNonce,
865+
const releaseDatabase = await withPlatformProgress('Reading platform state', () =>
866+
acquirePlatformDatabaseLifecycleLock(databaseUrl, current.id, current.ownershipNonce),
870867
);
871868
markPhase('database lock');
872869
try {
@@ -1077,7 +1074,9 @@ export async function disablePlatform(
10771074
planOnly: boolean,
10781075
dependencies: PlatformManagementDependencies = {},
10791076
): Promise<void> {
1080-
const manifest = await recoverDurablyMarkedProvisionIntents(client, initialManifest);
1077+
const manifest = await withPlatformProgress('Reading platform resources', () =>
1078+
recoverDurablyMarkedProvisionIntents(client, initialManifest),
1079+
);
10811080
const saveCheckpoint = (state: PlatformInstallationManifest) =>
10821081
writeLifecycleCheckpoint(client, state, dependencies.checkpoint);
10831082
const saveRemoteManifest = (state: PlatformInstallationManifest) =>
@@ -1144,7 +1143,9 @@ export async function uninstallPlatform(
11441143
args: Extract<PlatformArgs, { subcommand: 'uninstall' }>,
11451144
dependencies: PlatformManagementDependencies = {},
11461145
): Promise<void> {
1147-
const manifest = await recoverDurablyMarkedProvisionIntents(client, initialManifest);
1146+
const manifest = await withPlatformProgress('Reading platform resources', () =>
1147+
recoverDurablyMarkedProvisionIntents(client, initialManifest),
1148+
);
11481149
const saveCheckpoint = (state: PlatformInstallationManifest) =>
11491150
writeLifecycleCheckpoint(client, state, dependencies.checkpoint);
11501151
const saveRemoteManifest = (state: PlatformInstallationManifest) =>
@@ -1161,11 +1162,15 @@ export async function uninstallPlatform(
11611162
const hasRoutingCheckpoint = routingKv?.state === 'ready' || reopenedRouting;
11621163
const interactive = dependencies.interactive ?? process.stdin.isTTY;
11631164
const confirmAction = dependencies.confirm ?? promptForConfirmation;
1164-
const zeroTrust = await assertProjectZeroTrustAllowsUninstall(dependencies.readProjectZeroTrust, {
1165-
canTurnOff: !!dependencies.turnOffProjectZeroTrust,
1166-
});
1165+
const zeroTrust = await withPlatformProgress('Checking project access', () =>
1166+
assertProjectZeroTrustAllowsUninstall(dependencies.readProjectZeroTrust, {
1167+
canTurnOff: !!dependencies.turnOffProjectZeroTrust,
1168+
}),
1169+
);
11671170
if (purgeResources) {
1168-
await assertNoPlatformProjects(dependencies.readProjects);
1171+
await withPlatformProgress('Checking platform projects', () =>
1172+
assertNoPlatformProjects(dependencies.readProjects),
1173+
);
11691174
}
11701175
if (args.plan || (interactive && !args.yes)) {
11711176
note(
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createSpinner } from './output.ts';
2+
3+
export function createPlatformProgress(message?: string): ReturnType<typeof createSpinner> {
4+
const progress = createSpinner({
5+
onCancel: () => {
6+
// Keep the installer's subprocess signal coordinator in charge of cancellation.
7+
if (!process.emit('SIGINT')) {
8+
process.exit(130);
9+
}
10+
},
11+
});
12+
if (message !== undefined) {
13+
progress.start(message);
14+
}
15+
return progress;
16+
}
17+
18+
/** Clear a preflight phase before a plan, prompt, or error takes over the terminal. */
19+
export async function withPlatformProgress<T>(
20+
message: string,
21+
action: () => Promise<T>,
22+
): Promise<T> {
23+
const progress = createPlatformProgress(message);
24+
try {
25+
return await action();
26+
} finally {
27+
progress.clear();
28+
}
29+
}

0 commit comments

Comments
 (0)