diff --git a/src/services/upgrade/upgrade-assert.services.ts b/src/services/upgrade/upgrade-assert.services.ts index 9a78b1e..3daafbd 100644 --- a/src/services/upgrade/upgrade-assert.services.ts +++ b/src/services/upgrade/upgrade-assert.services.ts @@ -2,10 +2,10 @@ import {satelliteBuildType, type BuildType, type SatelliteParameters} from '@jun import {gunzipFile, isGzip} from '@junobuild/cli-tools'; import {isNullish, nonNullish} from '@junobuild/utils'; import {cyan, yellow} from 'kleur'; -import {type UpgradeWasm, type UpgradeWasmModule} from '../../types/upgrade'; +import type {AssertWasmModule, UpgradeWasm} from '../../types/upgrade'; import {NEW_CMD_LINE, confirmAndExit} from '../../utils/prompt.utils'; -const wasmBuildType = async ({wasmModule}: UpgradeWasmModule): Promise => { +const wasmBuildType = async ({wasmModule}: AssertWasmModule): Promise => { const buffer = Buffer.from(wasmModule); const wasm = isGzip(buffer) @@ -29,7 +29,7 @@ const wasmBuildType = async ({wasmModule}: UpgradeWasmModule): Promise { +}: {satellite: SatelliteParameters} & AssertWasmModule) => { // TODO: Workaround for agent-js. Disable console.warn. // See https://github.com/dfinity/agent-js/issues/843 // eslint-disable-next-line @typescript-eslint/unbound-method diff --git a/src/services/upgrade/upgrade.mission-control.services.ts b/src/services/upgrade/upgrade.mission-control.services.ts index dee29da..47625bd 100644 --- a/src/services/upgrade/upgrade.mission-control.services.ts +++ b/src/services/upgrade/upgrade.mission-control.services.ts @@ -121,5 +121,10 @@ const upgradeMissionControlCustom = async ({ }); }; - return await upgradeWasmLocal({src, nocheck, upgrade: upgradeMissionControlWasm}); + return await upgradeWasmLocal({ + src, + nocheck, + assetKey: 'mission_control', + upgrade: upgradeMissionControlWasm + }); }; diff --git a/src/services/upgrade/upgrade.orbiter.services.ts b/src/services/upgrade/upgrade.orbiter.services.ts index 675872c..3fcb26f 100644 --- a/src/services/upgrade/upgrade.orbiter.services.ts +++ b/src/services/upgrade/upgrade.orbiter.services.ts @@ -83,7 +83,13 @@ const upgradeOrbiterCustom = async ({ }); }; - return await upgradeWasmLocal({src, nocheck, upgrade: upgradeOrbiterWasm, reset}); + return await upgradeWasmLocal({ + src, + nocheck, + assetKey: 'orbiter', + upgrade: upgradeOrbiterWasm, + reset + }); }; const updateOrbiterRelease = async ({ diff --git a/src/services/upgrade/upgrade.satellite.services.ts b/src/services/upgrade/upgrade.satellite.services.ts index 3940c9b..078b8ce 100644 --- a/src/services/upgrade/upgrade.satellite.services.ts +++ b/src/services/upgrade/upgrade.satellite.services.ts @@ -10,7 +10,7 @@ import {cyan, red} from 'kleur'; import {compare} from 'semver'; import {junoConfigExist, readJunoConfig} from '../../configs/juno.config'; import {SATELLITE_WASM_NAME} from '../../constants/constants'; -import type {UpgradeWasm, UpgradeWasmModule} from '../../types/upgrade'; +import type {AssertWasmModule, UpgradeWasm, UpgradeWasmModule} from '../../types/upgrade'; import {configEnv} from '../../utils/config.utils'; import {consoleNoConfigFound} from '../../utils/msg.utils'; import {NEW_CMD_LINE} from '../../utils/prompt.utils'; @@ -82,7 +82,7 @@ const upgradeSatelliteCustom = async ({ const upgrade = async ( params: Pick ): Promise<{success: boolean; err?: unknown}> => { - return await upgradeWasmLocal({src, nocheck, ...params}); + return await upgradeWasmLocal({src, assetKey: 'satellite', nocheck, ...params}); }; return await executeUpgradeSatellite({ @@ -162,7 +162,7 @@ const executeUpgradeSatellite = async ({ }); }; - const assert = async (params: UpgradeWasmModule) => { + const assert = async (params: AssertWasmModule) => { await assertSatelliteBuildType({satellite, ...params}); }; diff --git a/src/services/upgrade/upgrade.services.ts b/src/services/upgrade/upgrade.services.ts index 6bb456d..5903ea2 100644 --- a/src/services/upgrade/upgrade.services.ts +++ b/src/services/upgrade/upgrade.services.ts @@ -1,6 +1,7 @@ import { checkUpgradeVersion, setCustomDomains, + UpgradeCodeProgress, UpgradeCodeUnchangedError, type CustomDomain, type SatelliteParameters @@ -26,18 +27,37 @@ const executeUpgradeWasm = async ({ hash, assert, reset = false, - nocheck -}: UpgradeWasm) => { + nocheck, + assetKey +}: {assetKey: AssetKey} & UpgradeWasm) => { if (!nocheck) { await assert?.({wasmModule: wasm}); await assertUpgradeHash({hash, reset}); } - const spinner = ora(`Upgrading Wasm${reset ? ' and resetting state' : ''}...`).start(); + const spinner = ora().start(); + + const onProgress = (process: UpgradeCodeProgress) => { + switch (process) { + case UpgradeCodeProgress.AssertingExistingCode: + spinner.text = 'Validating if an update is needed...'; + break; + case UpgradeCodeProgress.StoppingCanister: + spinner.text = `Stopping ${assetKey} before update...`; + break; + case UpgradeCodeProgress.UpgradingCode: + spinner.text = `Upgrading${reset ? ' and resetting state' : ''}...`; + break; + case UpgradeCodeProgress.RestartingCanister: + spinner.text = `Restarting ${assetKey}...`; + break; + } + }; try { await upgrade({ - wasmModule: wasm + wasmModule: wasm, + onProgress }); } finally { spinner.stop(); @@ -49,9 +69,11 @@ export const upgradeWasmLocal = async ({ upgrade, reset, assert, - nocheck + nocheck, + assetKey }: { src: string; + assetKey: AssetKey; } & Pick): Promise<{ success: boolean; err?: unknown; @@ -72,7 +94,7 @@ export const upgradeWasmLocal = async ({ spinner.stop(); - await executeUpgradeWasm({upgrade, wasm, hash, reset, assert, nocheck}); + await executeUpgradeWasm({upgrade, wasm, hash, reset, assert, nocheck, assetKey}); return {success: true}; } catch (err: unknown) { @@ -120,7 +142,7 @@ export const upgradeWasmCdn = async ({ spinner.stop(); - await executeUpgradeWasm({upgrade, wasm, hash, reset, assert, nocheck}); + await executeUpgradeWasm({upgrade, wasm, hash, reset, assert, nocheck, assetKey}); return {success: true}; } catch (err: unknown) { diff --git a/src/types/upgrade.ts b/src/types/upgrade.ts index 3c3a56d..0c2e7be 100644 --- a/src/types/upgrade.ts +++ b/src/types/upgrade.ts @@ -1,12 +1,15 @@ -import type {InstallCodeParams} from '@dfinity/ic-management'; +import type {UpgradeCodeParams} from '@junobuild/admin'; -export type UpgradeWasmModule = Pick; +export type UpgradeWasmModule = Pick & + Required>; + +export type AssertWasmModule = Pick; export interface UpgradeWasm { wasm: Buffer; hash: string; upgrade: (params: UpgradeWasmModule) => Promise; - assert?: (params: UpgradeWasmModule) => Promise; + assert?: (params: AssertWasmModule) => Promise; reset?: boolean; nocheck: boolean; }