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
32 changes: 24 additions & 8 deletions src/services/assets/deploy/deploy.execute.services.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {nonNullish} from '@dfinity/utils';
import type {
DeployParams,
DeployResult,
Expand All @@ -8,6 +9,7 @@ import type {
UploadFileWithProposal
} from '@junobuild/cli-tools';
import {postDeploy as cliPostDeploy, preDeploy as cliPreDeploy} from '@junobuild/cli-tools';
import type {SatelliteConfig} from '@junobuild/config';
import {type Asset} from '@junobuild/core';
import {red} from 'kleur';
import {lstatSync} from 'node:fs';
Expand All @@ -26,29 +28,33 @@ export type UploadFileFnParamsWithProposal = UploadFileFnParams & {proposalId: b

export const executeDeployWithProposal = async ({
deployFn,
uploadFileFn
uploadFileFn,
options
}: {
args?: string[];
deployFn: (params: DeployFnParams<UploadFileWithProposal>) => Promise<DeployResultWithProposal>;
uploadFileFn: (params: UploadFileFnParamsWithProposal) => Promise<void>;
options: {deprecatedGzip?: string};
}): Promise<DeployResultWithProposal> => {
return await executeDeploy<UploadFileStorageWithProposal, DeployResultWithProposal>({
deployFn,
uploadFileFn
uploadFileFn,
options
});
};

export const executeDeployImmediate = async ({
deployFn,
uploadFileFn
uploadFileFn,
options
}: {
args?: string[];
deployFn: (params: DeployFnParams) => Promise<DeployResult>;
uploadFileFn: (params: UploadFileFnParams) => Promise<void>;
options: {deprecatedGzip?: string};
}): Promise<DeployResult> => {
return await executeDeploy<UploadFileStorage, DeployResult>({
deployFn,
uploadFileFn
uploadFileFn,
options
});
};

Expand All @@ -57,16 +63,26 @@ const executeDeploy = async <
R extends DeployResult | DeployResultWithProposal
>({
deployFn,
uploadFileFn
uploadFileFn,
options
}: {
deployFn: (params: DeployFnParams<(params: P) => Promise<void>>) => Promise<R>;
uploadFileFn: (params: P & {satellite: SatelliteParametersWithId}) => Promise<void>;
options: {deprecatedGzip?: string};
}): Promise<R> => {
const assertMemory = async () => {
await assertSatelliteMemorySize();
};

const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext();
const {satellite, satelliteConfig: satelliteConfigRead} =
await assertConfigAndLoadSatelliteContext();

const gzip = satelliteConfigRead.gzip ?? options.deprecatedGzip;

const satelliteConfig: SatelliteConfig = {
...satelliteConfigRead,
...(nonNullish(gzip) && {gzip})
};

const listExistingAssets = async ({startAfter}: {startAfter?: string}): Promise<Asset[]> =>
await listAssets({
Expand Down
49 changes: 36 additions & 13 deletions src/services/deploy.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,51 @@ import {clearProposalStagedAssets} from './changes/changes.clear.services';
import {getSatelliteVersion} from './version.services';

export const deploy = async (args?: string[]) => {
// TODO: Remove fetching the version. We use it for backwards compatibility reasons.
const result = await getSatelliteVersion();

if (result.result === 'error') {
return;
}

// TODO: There was an issue in Satellite that prevented gzipping HTML files.
// This was fixed in version v0.1.1. However, for backward compatibility, we
// fall back to not gzipping HTML files in earlier versions. While gzipping HTML
// 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 clearOption = hasArgs({args, options: ['--clear']});
const immediate = hasArgs({args, options: ['-i', '--immediate']});

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

// TODO: Remove this check once backward compatibility is no longer needed.
// Without falling back to `deploy --immediate`, we can't roll out GitHub Actions support
// without requiring developers to either upgrade their Satellites or add the `--immediate` flag in CI.
// To ease the release, we temporarily check the version.
const result = await getSatelliteVersion();

if (result.result === 'error') {
return;
}

if (compare(result.version, '0.1.0') < 0) {
console.log(
`${yellow('[Warn]')} Your Satellite is outdated. Please upgrade to take full advantage of the new deployment flow.`
);
await deployImmediate({clearOption});
await deployImmediate({clearOption, deprecatedGzip});
return;
}

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

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

const deployFn = async ({
Expand Down Expand Up @@ -104,7 +119,8 @@ const deployWithProposal = async ({args, clearOption}: {args?: string[]; clearOp

const result = await executeDeployWithProposal({
deployFn,
uploadFileFn
uploadFileFn,
options: {deprecatedGzip}
});

if (result.result !== 'deployed') {
Expand All @@ -119,7 +135,13 @@ const deployWithProposal = async ({args, clearOption}: {args?: string[]; clearOp
});
};

const deployImmediate = async ({clearOption}: {clearOption: boolean}) => {
const deployImmediate = async ({
clearOption,
deprecatedGzip
}: {
clearOption: boolean;
deprecatedGzip: string | undefined;
}) => {
if (clearOption) {
await clear();
}
Expand Down Expand Up @@ -150,6 +172,7 @@ const deployImmediate = async ({clearOption}: {clearOption: boolean}) => {

await executeDeployImmediate({
deployFn,
uploadFileFn
uploadFileFn,
options: {deprecatedGzip}
});
};