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
28 changes: 14 additions & 14 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"@dfinity/zod-schemas": "^1.1.0",
"@junobuild/admin": "^2.0.0",
"@junobuild/cdn": "^1.1.0",
"@junobuild/cli-tools": "^0.6.0",
"@junobuild/cli-tools": "^0.6.1",
"@junobuild/config": "^2.0.0",
"@junobuild/config-loader": "^0.4.1",
"@junobuild/core": "^1.1.0",
"@junobuild/core": "^1.1.1",
"@junobuild/did-tools": "^0.2.4",
"@junobuild/ic-client": "^1.1.0",
"@junobuild/storage": "^1.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/help/deploy.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {TITLE} from './help';
const usage = `Usage: ${green('juno')} ${cyan('deploy')} ${yellow('[options]')}

Options:
${yellow('--batch')} Number of files to upload in parallel per batch (default: 20).
${yellow('--clear')} Clear existing app files before proceeding with deployment.
${yellow('--config')} Apply configuration after deployment succeeds.
${yellow('--no-apply')} Submit the deployment as a change but do not apply it yet.
Expand Down
21 changes: 13 additions & 8 deletions src/services/assets/_deploy/deploy.execute.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {red} from 'kleur';
import {lstatSync} from 'node:fs';
import {
type DeployFnParams,
type DeployOptions,
type UploadFileFnParams,
type UploadFn,
type UploadInput,
Expand All @@ -26,7 +27,7 @@ export const executeDeployWithProposal = async ({
options,
...rest
}: {
options: {deprecatedGzip?: string};
options: DeployOptions;
} & UploadFn<UploadFileStorage, DeployResultWithProposal>): Promise<DeployResultWithProposal> => {
return await executeDeploy<UploadFileStorage, DeployResultWithProposal>({
options,
Expand All @@ -41,7 +42,7 @@ export const executeDeployImmediate = async ({
}: {
deployFn: (params: DeployFnParams) => Promise<DeployResult>;
uploadFn: (params: UploadFileFnParams) => Promise<void>;
options: {deprecatedGzip?: string};
options: DeployOptions;
}): Promise<DeployResult> => {
return await executeDeploy<UploadFileStorage, DeployResult>({
deployFn,
Expand All @@ -55,19 +56,19 @@ const executeDeploy = async <
P extends UploadFileStorage,
R extends DeployResult | DeployResultWithProposal
>({
options,
options: {deprecatedGzip, ...restOptions},
...rest
}: {
options: {deprecatedGzip?: string};
options: DeployOptions;
} & UploadFn<P, R>): Promise<R> => {
const {satellite, satelliteConfig: satelliteConfigRead} =
await assertConfigAndLoadSatelliteContext();

const precompress =
satelliteConfigRead.precompress ??
(nonNullish(options.deprecatedGzip)
(nonNullish(deprecatedGzip)
? {
pattern: options.deprecatedGzip
pattern: deprecatedGzip
}
: undefined);

Expand All @@ -80,6 +81,7 @@ const executeDeploy = async <

const result = await deployWithMethod<P, R>({
...rest,
...restOptions,
satellite,
satelliteConfig
});
Expand All @@ -100,12 +102,14 @@ const deployWithMethod = async <
deployFn,
uploadFn,
method,
uploadBatchSize,
satellite,
satelliteConfig
}: {
satellite: SatelliteParametersWithId;
satelliteConfig: SatelliteConfig;
} & UploadFn<P, R>): Promise<R> => {
} & Omit<DeployOptions, 'deprecatedGzip'> &
UploadFn<P, R>): Promise<R> => {
const assertMemory = async () => {
await assertSatelliteMemorySize();
};
Expand All @@ -120,7 +124,8 @@ const deployWithMethod = async <
config: satelliteConfig,
listAssets: listExistingAssets,
assertSourceDirExists,
assertMemory
assertMemory,
uploadBatchSize
};

if (method === 'batch') {
Expand Down
13 changes: 8 additions & 5 deletions src/services/assets/_deploy/deploy.individual.services.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import type {DeployResult} from '@junobuild/cli-tools';
import {deploy as cliDeploy} from '@junobuild/cli-tools';
import {uploadBlob} from '@junobuild/core';
import type {DeployFnParams, UploadFileFnParams} from '../../../types/deploy';
import {
type DeployFnParams,
type DeployOptions,
type UploadFileFnParams
} from '../../../types/deploy';
import {clear} from '../clear.services';
import {executeDeployImmediate} from './deploy.execute.services';

export const deployImmediate = async ({
clearOption,
deprecatedGzip
...restOptions
}: {
clearOption: boolean;
deprecatedGzip: string | undefined;
}) => {
} & DeployOptions) => {
if (clearOption) {
await clear();
}
Expand Down Expand Up @@ -45,6 +48,6 @@ export const deployImmediate = async ({
await executeDeployImmediate({
deployFn,
uploadFn,
options: {deprecatedGzip}
options: restOptions
});
};
14 changes: 8 additions & 6 deletions src/services/assets/_deploy/deploy.with-proposal.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import {
import type {UploadAsset} from '@junobuild/storage';
import {
type DeployFnParams,
type DeployOptions,
type UploadFileFnParamsWithProposal,
type UploadFilesFnParamsWithProposal
} from '../../../types/deploy';
import type {SatelliteParametersWithId} from '../../../types/satellite';
import {executeDeployWithProposal} from './deploy.execute.services';

interface DeployWithProposalParams {
type DeployWithProposalParams = DeployOptions & {
clearOption: boolean;
deprecatedGzip: string | undefined;
noCommit: boolean;
}
};

export const deployWithProposal = async ({
withBatch,
Expand All @@ -35,6 +35,7 @@ export const deployWithProposal = async ({

const uploadFilesIndividually = async ({
deprecatedGzip,
uploadBatchSize,
...cliParams
}: DeployWithProposalParams): Promise<DeployResultWithProposal> => {
const uploadFn = async ({
Expand Down Expand Up @@ -64,13 +65,14 @@ const uploadFilesIndividually = async ({
return await executeDeployWithProposal({
deployFn,
uploadFn,
options: {deprecatedGzip},
options: {deprecatedGzip, uploadBatchSize},
method: 'individual'
});
};

const uploadFilesWithBatch = async ({
deprecatedGzip,
uploadBatchSize,
...cliParams
}: DeployWithProposalParams): Promise<DeployResultWithProposal> => {
const uploadFn = async ({files, satellite, ...rest}: UploadFilesFnParamsWithProposal) => {
Expand All @@ -95,7 +97,7 @@ const uploadFilesWithBatch = async ({
deployFn,
uploadFn,
method: 'batch',
options: {deprecatedGzip}
options: {deprecatedGzip, uploadBatchSize}
});
};

Expand All @@ -109,7 +111,7 @@ const deployWithUpload = async ({
upload: UploadIndividually<UploadFileWithProposal> | UploadWithBatch<UploadFilesWithProposal>;
};
satellite: SatelliteParametersWithId;
cliParams: Omit<DeployWithProposalParams, 'deprecatedGzip'>;
cliParams: Omit<DeployWithProposalParams, 'deprecatedGzip' | 'uploadBatchSize'>;
}): Promise<DeployResultWithProposal> =>
await cliDeployWithProposal({
deploy: {
Expand Down
45 changes: 32 additions & 13 deletions src/services/assets/deploy.services.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {hasArgs} from '@junobuild/cli-tools';
import {isEmptyString} from '@dfinity/utils';
import {hasArgs, nextArg} from '@junobuild/cli-tools';
import {yellow} from 'kleur';
import {compare} from 'semver';
import {type DeployOptions} from '../../types/deploy';
import {clearProposalStagedAssets} from '../changes/changes.clear.services';
import {getSatelliteVersion} from '../version.services';
import {deployImmediate} from './_deploy/deploy.individual.services';
Expand All @@ -20,11 +22,13 @@ export const deploy = async (args?: string[]) => {
// wouldn't harm usage, it might prevent crawlers from properly fetching content.
const deprecatedGzip = compare(result.version, '0.1.1') < 0 ? '**/*.+(css|js|mjs)' : undefined;

const {value: uploadBatchSize} = parseUploadBatchSize(args);

const clearOption = hasArgs({args, options: ['--clear']});
const immediate = hasArgs({args, options: ['-i', '--immediate']});

if (immediate) {
await deployImmediate({clearOption, deprecatedGzip});
await deployImmediate({clearOption, deprecatedGzip, uploadBatchSize});
return;
}

Expand All @@ -36,35 +40,30 @@ export const deploy = async (args?: string[]) => {
console.log(
`${yellow('[Warn]')} Your Satellite is outdated. Please upgrade to take full advantage of the new deployment flow.`
);
await deployImmediate({clearOption, deprecatedGzip});
await deployImmediate({clearOption, deprecatedGzip, uploadBatchSize});
return;
}

// TODO: use version for batch
// const withBatch = compare(result.version, '0.1.2') >= 0;
const withBatch = true;

await deployWithProposal({args, clearOption, deprecatedGzip, withBatch});
await deployWithProposal({args, clearOption, deprecatedGzip, uploadBatchSize, withBatch});
};

const deployWithProposal = async ({
args,
clearOption,
withBatch,
deprecatedGzip
...rest
}: {
args?: string[];
clearOption: boolean;
withBatch: boolean;
deprecatedGzip: string | undefined;
}) => {
} & DeployOptions) => {
const noCommit = hasArgs({args, options: ['--no-apply']});

const result = await executeDeployWithProposal({
withBatch,
clearOption,
deprecatedGzip,
noCommit
noCommit,
...rest
});

if (result.result !== 'deployed') {
Expand All @@ -78,3 +77,23 @@ const deployWithProposal = async ({
proposalId
});
};

const parseUploadBatchSize = (args?: string[]): {valid: boolean; value?: number} => {
const batchArg = nextArg({args, option: '--batch'});

if (isEmptyString(batchArg)) {
return {valid: true};
}

const batch = parseInt(batchArg);

if (isNaN(batch)) {
return {valid: false};
}

if (batch <= 0) {
return {valid: false};
}

return {valid: true, value: batch};
};
5 changes: 5 additions & 0 deletions src/types/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import type {
import type {OnUploadProgress} from '@junobuild/storage';
import type {SatelliteParametersWithId} from './satellite';

export interface DeployOptions {
deprecatedGzip?: string;
uploadBatchSize: number | undefined;
}

export interface DeployFnParams<T = UploadFile> {
deploy: {params: DeployParams; upload: T};
satellite: SatelliteParametersWithId;
Expand Down