Skip to content

Commit

Permalink
Merge pull request #4706 from remotion-dev/extract-entire-lambda-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBurger authored Jan 9, 2025
2 parents e167fb9 + 8a146e3 commit d9e78ce
Show file tree
Hide file tree
Showing 128 changed files with 1,819 additions and 1,421 deletions.
8 changes: 7 additions & 1 deletion packages/cli/src/lambda-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export const lambdaCommand = async (
});
const {LambdaInternals} = require(path);

await LambdaInternals.executeCommand(args, remotionRoot, logLevel, null);
await LambdaInternals.executeCommand(
args,
remotionRoot,
logLevel,
null,
null,
);
process.exit(0);
} catch (err) {
const manager = StudioServerInternals.getPackageManager(
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/docs/webcodecs/can-reencode-audio-track.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ You can obtain an `AudioTrack` using [`parseMedia()`](/docs/media-parser/parse-m
import {parseMedia} from '@remotion/media-parser';
import {canReencodeAudioTrack} from '@remotion/webcodecs';

const {audioTracks} = await parseMedia({
const {tracks} = await parseMedia({
src: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
fields: {
tracks: true,
},
});

for (const track of audioTracks) {
for (const track of tracks.audioTracks) {
await canReencodeAudioTrack({
track,
audioCodec: 'opus',
Expand Down
5 changes: 2 additions & 3 deletions packages/lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"scripts": {
"formatting": "prettier src --check",
"lint": "eslint src",
"testlambda": "vitest src/test/integration --run",
"test": "vitest src/test/unit --run",
"testlambda": "bun test src/test/integration",
"test": "bun test src/test/unit",
"make": "tsc -d && bun build.ts",
"prepublishOnly": "bun build.ts && bun ensure-version-match.js"
},
Expand Down Expand Up @@ -45,7 +45,6 @@
"@types/minimist": "1.2.2",
"@types/prompt": "^1.1.0",
"pureimage": "0.4.13",
"vitest": "0.31.1",
"zip-lib": "^0.7.2",
"@remotion/eslint-config-internal": "workspace:*",
"eslint": "9.14.0"
Expand Down
22 changes: 0 additions & 22 deletions packages/lambda/src/api/__mocks__/clean-items.ts

This file was deleted.

26 changes: 0 additions & 26 deletions packages/lambda/src/api/__mocks__/create-function.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/lambda/src/api/__mocks__/delete-function.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/lambda/src/api/__mocks__/get-functions.ts

This file was deleted.

13 changes: 7 additions & 6 deletions packages/lambda/src/api/delete-function.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {DeleteFunctionCommand} from '@aws-sdk/client-lambda';
import type {AwsRegion} from '../regions';
import type {
DeleteFunction,
DeleteFunctionInput as GenericDeleteFunctionInput,
} from '@remotion/serverless';
import type {AwsProvider} from '../functions/aws-implementation';
import {getLambdaClient} from '../shared/aws-clients';

export type DeleteFunctionInput = {
region: AwsRegion;
functionName: string;
};
export type DeleteFunctionInput = GenericDeleteFunctionInput<AwsProvider>;

/*
* @description Deletes a deployed Lambda function based on its name.
* @see [Documentation](https://remotion.dev/docs/lambda/deletefunction)
*/
export const deleteFunction = async ({
export const deleteFunction: DeleteFunction<AwsProvider> = async ({
region,
functionName,
}: DeleteFunctionInput): Promise<void> => {
Expand Down
3 changes: 1 addition & 2 deletions packages/lambda/src/api/delete-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import type {AwsProvider} from '../functions/aws-implementation';
import {awsImplementation} from '../functions/aws-implementation';
import type {AwsRegion} from '../regions';
import {getAccountId} from '../shared/get-account-id';
import {cleanItems} from './clean-items';

export type DeleteRenderInput = {
Expand All @@ -25,7 +24,7 @@ export const internalDeleteRender = async (
forcePathStyle: boolean;
},
) => {
const expectedBucketOwner = await getAccountId({
const expectedBucketOwner = await input.providerSpecifics.getAccountId({
region: input.region,
});
const progress = await getOverallProgressFromStorage({
Expand Down
3 changes: 1 addition & 2 deletions packages/lambda/src/api/delete-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {getSitesKey} from '../defaults';
import type {AwsProvider} from '../functions/aws-implementation';
import {awsImplementation} from '../functions/aws-implementation';
import type {AwsRegion} from '../regions';
import {getAccountId} from '../shared/get-account-id';
import {cleanItems} from './clean-items';

type MandatoryParameters = {
Expand Down Expand Up @@ -37,7 +36,7 @@ export const internalDeleteSite = async ({
}: DeleteSiteInput & {
providerSpecifics: ProviderSpecifics<AwsProvider>;
}): Promise<DeleteSiteOutput> => {
const accountId = await getAccountId({region});
const accountId = await providerSpecifics.getAccountId({region});

let files = await providerSpecifics.listObjects({
bucketName,
Expand Down
44 changes: 27 additions & 17 deletions packages/lambda/src/api/deploy-function.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import type {LogLevel} from '@remotion/renderer';
import {wrapWithErrorHandling} from '@remotion/renderer/error-handling';
import type {
CloudProvider,
FullClientSpecifics,
ProviderSpecifics,
} from '@remotion/serverless';
import {VERSION} from 'remotion/version';
import {getFunctions} from '../api/get-functions';
import {awsImplementation} from '../functions/aws-implementation';
import {awsFullClientSpecifics} from '../functions/full-client-implementation';
import type {AwsRegion} from '../regions';
import {
DEFAULT_CLOUDWATCH_RETENTION_PERIOD,
DEFAULT_EPHEMERAL_STORAGE_IN_MB,
RENDER_FN_PREFIX,
} from '../shared/constants';
import {FUNCTION_ZIP_ARM64} from '../shared/function-zip-path';
import {getAccountId} from '../shared/get-account-id';
import {
validateRuntimePreference,
type RuntimePreference,
} from '../shared/get-layers';
import {LAMBDA_VERSION_STRING} from '../shared/lambda-version-string';
import {validateAwsRegion} from '../shared/validate-aws-region';
import {validateCustomRoleArn} from '../shared/validate-custom-role-arn';
import {validateDiskSizeInMb} from '../shared/validate-disk-size-in-mb';
import {validateMemorySize} from '../shared/validate-memory-size';
import {validateCloudWatchRetentionPeriod} from '../shared/validate-retention-period';
import {validateTimeout} from '../shared/validate-timeout';
import {createFunction} from './create-function';
import {speculateFunctionName} from './speculate-function-name';

type MandatoryParameters = {
createCloudWatchLogGroup: boolean;
Expand Down Expand Up @@ -50,8 +53,12 @@ export type DeployFunctionOutput = {
alreadyExisted: boolean;
};

export const internalDeployFunction = async (
params: MandatoryParameters & OptionalParameters,
export const internalDeployFunction = async <Provider extends CloudProvider>(
params: MandatoryParameters &
OptionalParameters & {
providerSpecifics: ProviderSpecifics<Provider>;
fullClientSpecifics: FullClientSpecifics<Provider>;
},
): Promise<DeployFunctionOutput> => {
validateMemorySize(params.memorySizeInMb);
validateTimeout(params.timeoutInSeconds);
Expand All @@ -61,15 +68,16 @@ export const internalDeployFunction = async (
validateCustomRoleArn(params.customRoleArn);
validateRuntimePreference(params.runtimePreference);

const fnNameRender = [
`${RENDER_FN_PREFIX}${LAMBDA_VERSION_STRING}`,
`mem${params.memorySizeInMb}mb`,
`disk${params.diskSizeInMb}mb`,
`${params.timeoutInSeconds}sec`,
].join('-');
const accountId = await getAccountId({region: params.region});
const functionName = speculateFunctionName({
diskSizeInMb: params.diskSizeInMb,
memorySizeInMb: params.memorySizeInMb,
timeoutInSeconds: params.timeoutInSeconds,
});
const accountId = await params.providerSpecifics.getAccountId({
region: params.region,
});

const fns = await getFunctions({
const fns = await params.providerSpecifics.getFunctions({
compatibleOnly: true,
region: params.region,
});
Expand All @@ -82,11 +90,11 @@ export const internalDeployFunction = async (
f.diskSizeInMb === params.diskSizeInMb,
);

const created = await createFunction({
const created = await params.fullClientSpecifics.createFunction({
createCloudWatchLogGroup: params.createCloudWatchLogGroup,
region: params.region,
zipFile: FUNCTION_ZIP_ARM64,
functionName: fnNameRender,
functionName,
accountId,
memorySizeInMb: params.memorySizeInMb,
timeoutInSeconds: params.timeoutInSeconds,
Expand Down Expand Up @@ -158,5 +166,7 @@ export const deployFunction = ({
vpcSubnetIds,
vpcSecurityGroupIds,
runtimePreference: runtimePreference ?? 'default',
providerSpecifics: awsImplementation,
fullClientSpecifics: awsFullClientSpecifics,
});
};
29 changes: 16 additions & 13 deletions packages/lambda/src/api/deploy-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ import {type GitSource, type WebpackOverrideFn} from '@remotion/bundler';
import type {ToOptions} from '@remotion/renderer';
import type {BrowserSafeApis} from '@remotion/renderer/client';
import {wrapWithErrorHandling} from '@remotion/renderer/error-handling';
import type {ProviderSpecifics} from '@remotion/serverless';
import type {
FullClientSpecifics,
ProviderSpecifics,
UploadDirProgress,
} from '@remotion/serverless';
import {validateBucketName, validatePrivacy} from '@remotion/serverless/client';
import fs from 'node:fs';
import type {AwsProvider} from '../functions/aws-implementation';
import {awsImplementation} from '../functions/aws-implementation';
import {awsFullClientSpecifics} from '../functions/full-client-implementation';
import type {AwsRegion} from '../regions';
import {bundleSite} from '../shared/bundle-site';
import {getSitesKey} from '../shared/constants';
import {getAccountId} from '../shared/get-account-id';
import {getS3DiffOperations} from '../shared/get-s3-operations';
import {makeS3ServeUrl} from '../shared/make-s3-url';
import {validateAwsRegion} from '../shared/validate-aws-region';
import {validateSiteName} from '../shared/validate-site-name';
import type {UploadDirProgress} from './upload-dir';
import {uploadDir} from './upload-dir';

type MandatoryParameters = {
entryPoint: string;
Expand Down Expand Up @@ -66,9 +67,11 @@ const mandatoryDeploySite = async ({
throwIfSiteExists,
providerSpecifics,
forcePathStyle,
fullClientSpecifics,
}: MandatoryParameters &
OptionalParameters & {
providerSpecifics: ProviderSpecifics<AwsProvider>;
fullClientSpecifics: FullClientSpecifics<AwsProvider>;
}): DeploySiteOutput => {
validateAwsRegion(region);
validateBucketName(bucketName, {
Expand All @@ -78,7 +81,7 @@ const mandatoryDeploySite = async ({
validateSiteName(siteName);
validatePrivacy(privacy, false);

const accountId = await getAccountId({region});
const accountId = await providerSpecifics.getAccountId({region});

const bucketExists = await providerSpecifics.bucketExists({
bucketName,
Expand All @@ -101,7 +104,7 @@ const mandatoryDeploySite = async ({
prefix: `${subFolder}/`,
forcePathStyle,
}),
bundleSite({
fullClientSpecifics.bundleSite({
publicPath: `/${subFolder}/`,
webpackOverride: options?.webpackOverride ?? ((f) => f),
enableCaching: options?.enableCaching ?? true,
Expand Down Expand Up @@ -142,12 +145,13 @@ const mandatoryDeploySite = async ({
totalBytes = bytes;
options.onDiffingProgress?.(bytes, false);
},
fullClientSpecifics,
});

options.onDiffingProgress?.(totalBytes, true);

await Promise.all([
uploadDir({
fullClientSpecifics.uploadDir({
bucket: bucketName,
region,
localDir: bundled,
Expand All @@ -170,11 +174,9 @@ const mandatoryDeploySite = async ({
),
]);

if (!process.env.VITEST) {
fs.rmSync(bundled, {
recursive: true,
});
}
fs.rmSync(bundled, {
recursive: true,
});

return {
serveUrl: makeS3ServeUrl({bucketName, subFolder, region}),
Expand Down Expand Up @@ -207,5 +209,6 @@ export const deploySite = (args: DeploySiteInput) => {
throwIfSiteExists: args.throwIfSiteExists ?? false,
providerSpecifics: awsImplementation,
forcePathStyle: args.forcePathStyle ?? false,
fullClientSpecifics: awsFullClientSpecifics,
});
};
3 changes: 1 addition & 2 deletions packages/lambda/src/api/download-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {awsImplementation} from '../functions/aws-implementation';
import type {LambdaReadFileProgress} from '../functions/helpers/read-with-progress';
import {lambdaDownloadFileWithProgress} from '../functions/helpers/read-with-progress';
import type {AwsRegion} from '../regions';
import {getAccountId} from '../shared/get-account-id';

export type DownloadMediaInput = {
region: AwsRegion;
Expand All @@ -36,7 +35,7 @@ export const internalDownloadMedia = async (
forcePathStyle: boolean;
},
): Promise<DownloadMediaOutput> => {
const expectedBucketOwner = await getAccountId({
const expectedBucketOwner = await input.providerSpecifics.getAccountId({
region: input.region,
});
const overallProgress = await getOverallProgressFromStorage({
Expand Down
Loading

0 comments on commit d9e78ce

Please sign in to comment.