Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
"@dfinity/ic-management": "^6.1.1",
"@dfinity/identity": "^2.3.0",
"@dfinity/principal": "^2.3.0",
"@junobuild/admin": "^0.5.0-next-2025-06-04.1",
"@junobuild/cdn": "^0.1.0-next-2025-06-04.1",
"@junobuild/cli-tools": "^0.2.0-next-2025-06-04.1",
"@junobuild/admin": "^0.5.0-next-2025-06-04.3",
"@junobuild/cdn": "^0.1.0-next-2025-06-04.3",
"@junobuild/cli-tools": "^0.2.0-next-2025-06-04.3",
"@junobuild/config": "^0.1.8",
"@junobuild/config-loader": "^0.2.1",
"@junobuild/core": "^0.1.15-next-2025-06-04.1",
"@junobuild/core": "^0.1.15-next-2025-06-04.3",
"@junobuild/did-tools": "^0.2.1",
"@junobuild/storage": "^0.2.0-next-2025-06-04.1",
"@junobuild/storage": "^0.2.0-next-2025-06-04.3",
"@junobuild/utils": "^0.1.3",
"chokidar": "^4.0.3",
"conf": "^13.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {logHelpFunctionsUpgrade} from '../help/functions.upgrade.help';
import {build} from '../services/functions/build/build.services';
import {eject} from '../services/functions/eject/eject.services';
import {publish} from '../services/functions/publish.services';
import {upgradeFunctions} from '../services/functions/upgrade.services';
import {upgradeFunctions} from '../services/functions/upgrade/upgrade.services';

export const functions = async (args?: string[]) => {
const [subCommand] = args ?? [];
Expand Down
6 changes: 3 additions & 3 deletions src/constants/help.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export const OPTION_KEEP_STAGED = `${yellow('-k, --keep-staged')} Keep stage
export const OPTION_HASH = `${yellow('--hash')} The expected hash of all included changes (for verification).`;
export const OPTION_HELP = `${yellow('-h, --help')} Output usage information.`;
export const OPTION_SRC = `${yellow('-s, --src')} A path to a specific local gzipped WASM file to publish.`;
export const OPTIONS_UPGRADE = `${yellow('-r, --reset')} Reset to the initial state.
${yellow('--clear-chunks')} Clear any previously uploaded WASM chunks (applies if the WASM size is greater than 2MB).
${yellow('--no-snapshot')} Skip creating a snapshot before upgrading.`;
export const OPTIONS_UPGRADE = `${yellow('--clear-chunks')} Clear any previously uploaded WASM chunks (applies if the WASM size is greater than 2MB).
${yellow('--no-snapshot')} Skip creating a snapshot before upgrading.
${yellow('-r, --reset')} Reset to the initial state.`;

export const NOTE_KEEP_STAGED = `The option ${yellow('--keep-staged')} only applies when ${yellow('--no-apply')} is NOT used (i.e. the change is applied immediately).`;
12 changes: 10 additions & 2 deletions src/help/functions.upgrade.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ import {TITLE} from './help';
const usage = `Usage: ${green('juno')} ${cyan('functions')} ${magenta('upgrade')} ${yellow('[options]')}

Options:
${OPTION_SRC}
${yellow('--cdn')} Select a previously published WASM file from the CDN (interactive).
${yellow('--cdn-path')} Use a specific published WASM file from the CDN.
${OPTIONS_UPGRADE}
${OPTION_HELP}`;
${OPTION_SRC}
${OPTION_HELP}

Notes:

- If no option is provided, the default local build output will be used.
- If ${yellow('--src')} is specified, it takes precedence over any CDN options.
- Use ${yellow('--cdn')} to interactively select from recent published releases.`;

const doc = `${FUNCTIONS_UPGRADE_DESCRIPTION}

Expand Down
17 changes: 0 additions & 17 deletions src/services/functions/upgrade.services.ts

This file was deleted.

41 changes: 41 additions & 0 deletions src/services/functions/upgrade/upgrade.cdn.list.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {COLLECTION_CDN_RELEASES} from '@junobuild/cli-tools';
import {type Asset, listAssets} from '@junobuild/core';
import {DEPLOY_LIST_ASSETS_PAGINATION} from '../../../constants/deploy.constants';
import type {SatelliteParametersWithId} from '../../../types/satellite';
import {last} from '../../../utils/array.utils';

export const listCdnAssets = async ({
startAfter,
satellite,
traverseAll = false
}: {
startAfter?: string;
satellite: SatelliteParametersWithId;
traverseAll?: boolean;
}): Promise<Asset[]> => {
const {items, items_length, matches_length} = await listAssets({
collection: COLLECTION_CDN_RELEASES,
satellite,
filter: {
order: {
desc: true,
field: 'created_at'
},
paginate: {
startAfter,
limit: DEPLOY_LIST_ASSETS_PAGINATION
}
}
});

if (items_length > matches_length && traverseAll) {
const nextItems = await listCdnAssets({
startAfter: last(items)?.fullPath,
satellite,
traverseAll
});
return [...items, ...nextItems];
}

return items;
};
95 changes: 95 additions & 0 deletions src/services/functions/upgrade/upgrade.cdn.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {isNullish, nonNullish, notEmptyString} from '@dfinity/utils';
import {assertAnswerCtrlC, hasArgs, nextArg} from '@junobuild/cli-tools';
import {yellow} from 'kleur';
import prompts from 'prompts';
import {CDN_RELEASES_FULL_PATH} from '../../../constants/functions.constants';
import {type SatelliteParametersWithId} from '../../../types/satellite';
import {defaultSatelliteDomain} from '../../../utils/domain.utils';
import {logUpgradeResult} from '../../../utils/upgrade.utils';
import {upgradeSatelliteWithCdn} from '../../modules/upgrade/upgrade.satellite.services';
import {listCdnAssets} from './upgrade.cdn.list.services';

export const upgradeWithCdn = async ({
args,
satellite
}: {
args?: string[];
satellite: SatelliteParametersWithId;
}) => {
const cdnPath = hasArgs({args, options: ['--cdn-path']})
? nextArg({args, option: '--cdn-path'})
: undefined;

const fullPath = cdnPath ?? (await selectCdnFullPath({satellite}));

if (isNullish(fullPath)) {
return;
}

const customHost = URL.parse(defaultSatelliteDomain(satellite.satelliteId))?.hostname;

const cdn = {
url: process.env.CONTAINER_URL ?? defaultSatelliteDomain(satellite.satelliteId),
path: fullPath,
...(nonNullish(customHost) && {customHost})
};

const result = await upgradeSatelliteWithCdn({
args,
cdn,
satellite
});

logUpgradeResult({
...result,
successMessage: 'Satellite successfully upgraded with serverless functions.'
});
};

const selectCdnFullPath = async (params: {
satellite: SatelliteParametersWithId;
}): Promise<AssetFullPathToken | undefined> => {
const assets = await collectCdnAssets(params);

if (assets.length === 0) {
console.log(yellow('No published WASM files found in the CDN.'));
return undefined;
}

return await promptCdnFullPath({assets});
};

type AssetFullPathToken = string;

interface AssetForPrompt {
title: string;
value: AssetFullPathToken;
}

const collectCdnAssets = async (params: {
satellite: SatelliteParametersWithId;
}): Promise<AssetForPrompt[]> => {
const assets = await listCdnAssets(params);

return assets.map(({fullPath, description, token}) => ({
title: `${fullPath.replace(`${CDN_RELEASES_FULL_PATH}/`, '')}${notEmptyString(description) ? ` (${description})` : ''}`,
value: `${fullPath}${notEmptyString(token) ? `?token=${token}` : ''}`
}));
};

const promptCdnFullPath = async ({
assets
}: {
assets: AssetForPrompt[];
}): Promise<AssetFullPathToken> => {
const {fullPath}: {fullPath: AssetFullPathToken} = await prompts({
type: 'select',
name: 'fullPath',
message: 'Which published WASM would you like to use?',
choices: assets
});

assertAnswerCtrlC(fullPath);

return fullPath;
};
36 changes: 36 additions & 0 deletions src/services/functions/upgrade/upgrade.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {hasArgs, nextArg} from '@junobuild/cli-tools';
import {SATELLITE_OUTPUT} from '../../../constants/dev.constants';
import {type SatelliteParametersWithId} from '../../../types/satellite';
import {assertConfigAndLoadSatelliteContext} from '../../../utils/satellite.utils';
import {upgradeSatelliteWithSrc} from '../../modules/upgrade/upgrade.satellite.services';
import {upgradeWithCdn} from './upgrade.cdn.services';

export const upgradeFunctions = async (args?: string[]) => {
const {satellite} = await assertConfigAndLoadSatelliteContext(args);

const cdnOption = hasArgs({args, options: ['--cdn', '--cdn-path']});

const fn = cdnOption ? upgradeWithCdn : upgradeWithSrc;

await fn({
args,
satellite
});
};

const upgradeWithSrc = async ({
args,
satellite
}: {
args?: string[];
satellite: SatelliteParametersWithId;
}) => {
const srcArgs = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'});
const src = srcArgs ?? `${SATELLITE_OUTPUT}.gz`;

await upgradeSatelliteWithSrc({
args,
src,
satellite
});
};
Loading