Skip to content

Commit

Permalink
feat: redo custom domains after upgrade reset
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Dec 22, 2023
1 parent 20bfef5 commit 7977695
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 24 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@dfinity/candid": "^0.20.2",
"@dfinity/identity": "^0.20.2",
"@dfinity/principal": "^0.20.2",
"@junobuild/admin": "^0.0.38-next-2023-12-21",
"@junobuild/admin": "^0.0.38-next-2023-12-22",
"@junobuild/core-peer": "^0.0.3-next-2023-12-21",
"@junobuild/utils": "^0.0.16-next-2023-12-21",
"conf": "^12.0.0",
Expand Down
67 changes: 51 additions & 16 deletions src/commands/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
checkUpgradeVersion,
listCustomDomains,
missionControlVersion,
orbiterVersion,
satelliteVersion,
Expand All @@ -21,7 +22,7 @@ import {
ORBITER_WASM_NAME,
SATELLITE_WASM_NAME
} from '../constants/constants';
import {upgradeWasmCdn, upgradeWasmLocal} from '../services/upgrade.services';
import {redoCustomDomains, upgradeWasmCdn, upgradeWasmLocal} from '../services/upgrade.services';
import type {AssetKey} from '../types/asset-key';
import {actorParameters} from '../utils/actor.utils';
import {hasArgs, nextArg} from '../utils/args.utils';
Expand Down Expand Up @@ -154,24 +155,21 @@ const upgradeSatelliteRelease = async ({
const displayHint = `satellite "${satelliteKey(satellite.satelliteId ?? '')}"`;
const version = await selectVersion({currentVersion, assetKey: SATELLITE_WASM_NAME, displayHint});

if (version === undefined) {
if (isNullish(version)) {
return;
}

const reset = await confirmReset({args, assetKey: 'satellite'});

const upgradeSatelliteWasm = async ({wasm_module}: {wasm_module: Uint8Array}) => {
await upgradeSatelliteAdmin({
satellite,
wasm_module,
// TODO: option to be removed
deprecated: compare(currentVersion, '0.0.7') < 0,
deprecatedNoScope: compare(currentVersion, '0.0.9') < 0,
...(reset && {reset})
});
};
const upgrade = async (params: {
upgrade: ({wasm_module}: {wasm_module: Uint8Array}) => Promise<void>;
reset?: boolean;
}) => upgradeWasmCdn({version, assetKey: 'satellite', ...params});

Check failure on line 165 in src/commands/upgrade.ts

View workflow job for this annotation

GitHub Actions / lint

Returning an awaited promise is required in this context

await upgradeWasmCdn({version, assetKey: 'satellite', upgrade: upgradeSatelliteWasm, reset});
await executeUpgradeSatellite({
satellite,
args,
currentVersion,
upgrade
});
};

const upgradeSatelliteCustom = async ({
Expand All @@ -193,8 +191,38 @@ const upgradeSatelliteCustom = async ({
satellite
});

const upgrade = async (params: {
upgrade: ({wasm_module}: {wasm_module: Uint8Array}) => Promise<void>;
reset?: boolean;
}) => upgradeWasmLocal({src, ...params});

Check failure on line 197 in src/commands/upgrade.ts

View workflow job for this annotation

GitHub Actions / lint

Returning an awaited promise is required in this context

await executeUpgradeSatellite({
satellite,
args,
currentVersion,
upgrade
});
};

const executeUpgradeSatellite = async ({
satellite,
args,
currentVersion,
upgrade
}: {
satellite: SatelliteParameters;
args?: string[];
currentVersion: string;
upgrade: (params: {
upgrade: ({wasm_module}: {wasm_module: Uint8Array}) => Promise<void>;
reset?: boolean;
}) => Promise<void>;
}) => {
const reset = await confirmReset({args, assetKey: 'satellite'});

// Information we want to try to redo once the satellite has been updated and resetted
const customDomains = reset ? await listCustomDomains({satellite}) : [];

const upgradeSatelliteWasm = async ({wasm_module}: {wasm_module: Uint8Array}) => {
await upgradeSatelliteAdmin({
satellite,
Expand All @@ -206,7 +234,14 @@ const upgradeSatelliteCustom = async ({
});
};

await upgradeWasmLocal({src, upgrade: upgradeSatelliteWasm, reset});
await upgrade({
upgrade: upgradeSatelliteWasm,
reset
});

if (reset && customDomains.length > 0) {
await redoCustomDomains({satellite, domains: customDomains});
}
};

const updateMissionControlRelease = async (missionControlParameters: MissionControlParameters) => {
Expand Down
11 changes: 11 additions & 0 deletions src/services/upgrade.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {JUNO_CDN_URL} from '../constants/constants';
import type {AssetKey} from '../types/asset-key';
import {downloadFromURL} from '../utils/download.utils';
import {NEW_CMD_LINE, confirmAndExit} from '../utils/prompt.utils';

Check failure on line 8 in src/services/upgrade.services.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `;⏎import·{·CustomDomain,·SatelliteParameters,·setCustomDomains·}·from·"@junobuild/admin"`
import { CustomDomain, SatelliteParameters, setCustomDomains } from "@junobuild/admin";

Check failure on line 9 in src/services/upgrade.services.ts

View workflow job for this annotation

GitHub Actions / lint

Imports "CustomDomain" and "SatelliteParameters" are only used as types

const executeUpgradeWasm = async ({
upgrade,
Expand Down Expand Up @@ -106,3 +107,13 @@ export const upgradeWasmCdn = async ({
throw err;
}
};

export const redoCustomDomains = async (params: {satellite: SatelliteParameters; domains: CustomDomain[]}) => {

Check failure on line 111 in src/services/upgrade.services.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `satellite:·SatelliteParameters;·domains:·CustomDomain[]` with `⏎··satellite:·SatelliteParameters;⏎··domains:·CustomDomain[];⏎`
const spinner = ora('Setting back custom domains...').start();

try {
await setCustomDomains(params);
} finally {
spinner.stop();
}
}

Check failure on line 119 in src/services/upgrade.services.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;⏎`

0 comments on commit 7977695

Please sign in to comment.