🎥 Make videos programmatically with React
removing compositions command from cloudrun cli
Matt McGillivray491157b4eb3f
diff --git a/packages/cloudrun/gcpInstaller/gcpInstaller.tar b/packages/cloudrun/gcpInstaller/gcpInstaller.tarindex e9e00266f9..8868333336 100644Binary files a/packages/cloudrun/gcpInstaller/gcpInstaller.tar and b/packages/cloudrun/gcpInstaller/gcpInstaller.tar differdiff --git a/packages/cloudrun/src/api/get-compositions-on-gcp.ts b/packages/cloudrun/src/api/get-compositions-on-gcp.tsdeleted file mode 100644index 14f701110e..0000000000--- a/packages/cloudrun/src/api/get-compositions-on-gcp.ts+++ /dev/null@@ -1,19 +0,0 @@-import {getCompositions} from '@remotion/renderer';-import type {TCompMetadata, z} from 'remotion';--export type GetCompositionsOnGcpInput = {serveUrl: string};--export type GetCompositionsOnGcpOutput = TCompMetadata<z.ZodTypeAny, unknown>[];--/**- * @description Returns the compositions from a serveUrl- * @link https://remotion.dev/docs/lambda/getcompositionsOnGcp- * @param params.serveUrl The URL of the deployed project- * @returns The compositions- */-export const getCompositionsOnGcp = async ({- serveUrl,-}: GetCompositionsOnGcpInput): Promise<GetCompositionsOnGcpOutput> => {- const comps = await getCompositions(serveUrl);- return comps;-};diff --git a/packages/cloudrun/src/api/helpers/get-cloudrun-endpoint.ts b/packages/cloudrun/src/api/helpers/get-cloudrun-endpoint.tsnew file mode 100644index 0000000000..4a451e9984--- /dev/null+++ b/packages/cloudrun/src/api/helpers/get-cloudrun-endpoint.ts@@ -0,0 +1,51 @@+import {validateCloudRunUrl} from '../../shared/validate-cloudrun-url';+import {validateRegion} from '../../shared/validate-region';+import {validateServiceName} from '../../shared/validate-service-name';+import {getServiceInfo} from '../get-service-info';++export type RenderMediaOnCloudrunInput = {+ cloudRunUrl?: string;+ serviceName?: string;+ region?: string;+};++/**+ * @description Triggers a render on a GCP Cloud Run service given a composition and a Cloud Run URL.+ * @see [Documentation](https://remotion.dev/docs/lambda/renderMediaOnGcp)+ * @param params.cloudRunUrl The url of the Cloud Run service that should be used+ * @param params.serviceName The name of the Cloud Run service that should be used+ * @param params.serveUrl The URL of the deployed project+ * @returns {Promise<string>} See documentation for detailed structure+ */++export const getCloudrunEndpoint = async ({+ cloudRunUrl,+ serviceName,+ region,+}: RenderMediaOnCloudrunInput): Promise<string> => {+ if (!cloudRunUrl && !serviceName)+ throw new Error('Either cloudRunUrl or serviceName must be provided');+ if (cloudRunUrl && serviceName)+ throw new Error(+ 'Either cloudRunUrl or serviceName must be provided, not both'+ );++ let cloudRunEndpoint = '';+ if (cloudRunUrl) {+ validateCloudRunUrl(cloudRunUrl);+ cloudRunEndpoint = cloudRunUrl;+ }++ if (serviceName) {+ if (!region)+ throw new Error(+ 'If determining Cloudrun Url from serviceName, region must be provided'+ );+ validateServiceName(serviceName);+ const validatedRegion = validateRegion(region);+ const {uri} = await getServiceInfo({serviceName, region: validatedRegion});+ cloudRunEndpoint = uri;+ }++ return cloudRunEndpoint;+};diff --git a/packages/cloudrun/src/api/render-media-on-cloudrun.ts b/packages/cloudrun/src/api/render-media-on-cloudrun.tsindex c3ecc95644..d4b8a99bd7 100644--- a/packages/cloudrun/src/api/render-media-on-cloudrun.ts+++ b/packages/cloudrun/src/api/render-media-on-cloudrun.ts@@ -1,18 +1,15 @@import type {ChromiumOptions, FrameRange} from '@remotion/renderer';import got from 'got/dist/source';-import {validateCloudRunUrl} from '../shared/validate-cloudrun-url';import type {CloudrunCodec} from '../shared/validate-gcp-codec';import {validateCloudrunCodec} from '../shared/validate-gcp-codec';import {validatePrivacy} from '../shared/validate-privacy';-import {validateRegion} from '../shared/validate-region';import {validateServeUrl} from '../shared/validate-serveurl';-import {validateServiceName} from '../shared/validate-service-name';-import {getServiceInfo} from './get-service-info';import {getAuthClientForUrl} from './helpers/get-auth-client-for-url';+import {getCloudrunEndpoint} from './helpers/get-cloudrun-endpoint';export type RenderMediaOnCloudrunInput = {authenticatedRequest: boolean;- cloudRunUrl: string;+ cloudRunUrl?: string;serviceName?: string;region?: string;serveUrl?: string;@@ -121,23 +118,11 @@ export const renderMediaOnCloudrun = async ({validateServeUrl(serveUrl);if (privacy) validatePrivacy(privacy);- if (!cloudRunUrl && !serviceName)- throw new Error('Either cloudRunUrl or serviceName must be provided');- if (cloudRunUrl && serviceName)- throw new Error(- 'Either cloudRunUrl or serviceName must be provided, not both'- );-- if (cloudRunUrl) {- validateCloudRunUrl(cloudRunUrl);- }-- if (serviceName) {- validateServiceName(serviceName);- const validatedRegion = validateRegion(region);- const {uri} = await getServiceInfo({serviceName, region: validatedRegion});- cloudRunUrl = uri;- }+ const cloudRunEndpoint = await getCloudrunEndpoint({+ cloudRunUrl,+ serviceName,+ region,+ });const data = {composition,@@ -164,15 +149,16 @@ export const renderMediaOnCloudrun = async ({outputFile,forceWidth,forceHeight,+ type: 'media',};if (authenticatedRequest) {- const client = await getAuthClientForUrl(cloudRunUrl);+ const client = await getAuthClientForUrl(cloudRunEndpoint);const authenticatedDataPromise = new Promise((resolve, reject) => {client.request({- url: cloudRunUrl,+ url: cloudRunEndpoint,method: 'POST',data,responseType: 'stream',@@ -205,7 +191,7 @@ export const renderMediaOnCloudrun = async ({const dataPromise = new Promise((resolve, reject) => {got.stream- .post(cloudRunUrl, {json: data})+ .post(cloudRunEndpoint, {json: data}).on('data', (chunk) => {const chunkResponse = JSON.parse(chunk.toString());if (chunkResponse.response) {diff --git a/packages/cloudrun/src/api/render-still-on-cloudrun.ts b/packages/cloudrun/src/api/render-still-on-cloudrun.tsindex 4631cfbf51..61b4e288db 100644--- a/packages/cloudrun/src/api/render-still-on-cloudrun.ts+++ b/packages/cloudrun/src/api/render-still-on-cloudrun.ts@@ -1,16 +1,13 @@import type {ChromiumOptions, StillImageFormat} from '@remotion/renderer';import got from 'got';-import {validateCloudRunUrl} from '../shared/validate-cloudrun-url';import {validatePrivacy} from '../shared/validate-privacy';-import {validateRegion} from '../shared/validate-region';import {validateServeUrl} from '../shared/validate-serveurl';-import {validateServiceName} from '../shared/validate-service-name';-import {getServiceInfo} from './get-service-info';import {getAuthClientForUrl} from './helpers/get-auth-client-for-url';+import {getCloudrunEndpoint} from './helpers/get-cloudrun-endpoint';export type RenderStillOnCloudrunInput = {authenticatedRequest: boolean;- cloudRunUrl: string;+ cloudRunUrl?: string;serviceName?: string;region?: string;serveUrl: string;@@ -79,23 +76,11 @@ export const renderStillOnCloudrun = async ({validateServeUrl(serveUrl);if (privacy) validatePrivacy(privacy);- if (!cloudRunUrl && !serviceName)- throw new Error('Either cloudRunUrl or serviceName must be provided');- if (cloudRunUrl && serviceName)- throw new Error(- 'Either cloudRunUrl or serviceName must be provided, not both'- );-- if (cloudRunUrl) {- validateCloudRunUrl(cloudRunUrl);- }-- if (serviceName) {- validateServiceName(serviceName);- const validatedRegion = validateRegion(region);- const {uri} = await getServiceInfo({serviceName, region: validatedRegion});- cloudRunUrl = uri;- }+ const cloudRunEndpoint = await getCloudrunEndpoint({+ cloudRunUrl,+ serviceName,+ region,+ });const data = {composition,@@ -112,10 +97,11 @@ export const renderStillOnCloudrun = async ({forceWidth,forceHeight,frame: frame ?? 0,+ type: 'still',};if (authenticatedRequest) {- const client = await getAuthClientForUrl(cloudRunUrl);+ const client = await getAuthClientForUrl(cloudRunEndpoint);const authenticatedResponse = await client.request({url: cloudRunUrl,@@ -126,7 +112,7 @@ export const renderStillOnCloudrun = async ({}const response: RenderStillOnCloudrunOutput = await got- .post(cloudRunUrl, {json: data})+ .post(cloudRunEndpoint, {json: data}).json();return response;};diff --git a/packages/cloudrun/src/cli/commands/compositions.ts b/packages/cloudrun/src/cli/commands/compositions.tsdeleted file mode 100644index 97b055d863..0000000000--- a/packages/cloudrun/src/cli/commands/compositions.ts+++ /dev/null@@ -1,43 +0,0 @@-import {CliInternals} from '@remotion/cli';-import {getCompositionsOnGcp} from '../../api/get-compositions-on-gcp';-import {getOrCreateBucket} from '../../api/get-or-create-bucket';-import {BINARY_NAME} from '../../shared/constants';-import {validateServeUrl} from '../../shared/validate-serveurl';-import {quit} from '../helpers/quit';-import {Log} from '../log';--export const COMPOSITIONS_COMMAND = 'compositions';--export const compositionsCommand = async (args: string[]) => {- const serveArg = args[0];-- if (!serveArg) {- Log.error('No serve URL argument passed.');- Log.info(- 'Pass an additional argument specifying a URL, or site name, where your Remotion project is hosted.'- );- Log.info();- Log.info(`${BINARY_NAME} ${COMPOSITIONS_COMMAND} <serve-url>`);- quit(1);- }-- let serveUrl = '';-- if (!serveArg.startsWith('https://') && !serveArg.startsWith('http://')) {- const siteName = serveArg;- Log.info('Remotion site-name passed, constructing serve url...');- const {bucketName} = await getOrCreateBucket();- serveUrl = `https://storage.googleapis.com/${bucketName}/sites/${siteName}/index.html`;- Log.info(`<serve-url> constructed: ${serveUrl}\n`);- } else {- serveUrl = serveArg;- }-- validateServeUrl(serveUrl);-- const comps = await getCompositionsOnGcp({- serveUrl,- });-- CliInternals.printCompositions(comps);-};diff --git a/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts b/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.tsindex ca7b32e384..d20a86b42e 100644--- a/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts+++ b/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts@@ -7,6 +7,7 @@ import {BINARY_NAME,DEFAULT_OUTPUT_PRIVACY,} from '../../../../shared/constants';+import {convertToServeUrl} from '../../../../shared/convert-to-serve-url';import {validatePrivacy} from '../../../../shared/validate-privacy';import {validateServeUrl} from '../../../../shared/validate-serveurl';import {parsedCloudrunCli} from '../../../args';@@ -34,7 +35,7 @@ export const renderArgsCheck = async (subcommand: string, args: string[]) => {const siteName = serveUrl;Log.info('Remotion site-name passed, constructing serve url...');const {bucketName} = await getOrCreateBucket();- serveUrl = `https://storage.googleapis.com/${bucketName}/sites/${siteName}/index.html`;+ serveUrl = convertToServeUrl({urlOrId: siteName, bucketName});Log.info(`<serve-url> constructed: ${serveUrl}\n`);}diff --git a/packages/cloudrun/src/cli/help.ts b/packages/cloudrun/src/cli/help.tsindex a422695067..7ce860cd2a 100644--- a/packages/cloudrun/src/cli/help.ts+++ b/packages/cloudrun/src/cli/help.ts@@ -1,6 +1,5 @@import {CliInternals} from '@remotion/cli';import {BINARY_NAME} from '../shared/constants';-import {COMPOSITIONS_COMMAND} from './commands/compositions';import {PERMISSIONS_COMMAND} from './commands/permissions';import {REGIONS_COMMAND} from './commands/regions';import {RENDER_COMMAND} from './commands/render';@@ -36,12 +35,6 @@ export const printHelp = () => {Log.info(`${BINARY_NAME} ${SITES_COMMAND}`);Log.info(CliInternals.chalk.gray('Deploy and manage Remotion projects.'));- Log.info();- Log.info(`${BINARY_NAME} ${COMPOSITIONS_COMMAND}`);- Log.info(- CliInternals.chalk.gray('Print list of composition IDs from a serve URL.')- );-Log.info();Log.info(`${BINARY_NAME} ${PERMISSIONS_COMMAND}`);Log.info(diff --git a/packages/cloudrun/src/cli/index.ts b/packages/cloudrun/src/cli/index.tsindex d0ee4a360f..d08d73be05 100644--- a/packages/cloudrun/src/cli/index.ts+++ b/packages/cloudrun/src/cli/index.ts@@ -1,8 +1,4 @@import {parsedCloudrunCli} from './args';-import {- compositionsCommand,- COMPOSITIONS_COMMAND,-} from './commands/compositions';import {permissionsCommand, PERMISSIONS_COMMAND} from './commands/permissions';import {regionsCommand, REGIONS_COMMAND} from './commands/regions';import {renderCommand, RENDER_COMMAND} from './commands/render';@@ -30,10 +26,6 @@ const matchCommand = (args: string[], remotionRoot: string) => {return sitesCommand(args.slice(1), remotionRoot);}- if (args[0] === COMPOSITIONS_COMMAND) {- return compositionsCommand(args.slice(1));- }-if (args[0] === REGIONS_COMMAND) {return regionsCommand();}diff --git a/packages/cloudrun/src/client.ts b/packages/cloudrun/src/client.tsindex 8dbb1a86ef..08ebc0edb2 100644--- a/packages/cloudrun/src/client.ts+++ b/packages/cloudrun/src/client.ts@@ -1,10 +1,6 @@-import {getCompositionsOnGcp} from './api/get-compositions-on-gcp';-// import {getFunctions} from './api/get-functions';-// import {getRenderProgress} from './api/get-render-progress';-// import {getSites} from './api/get-sites';import {renderMediaOnCloudrun} from './api/render-media-on-cloudrun';import {renderStillOnCloudrun} from './api/render-still-on-cloudrun';import type {GcpRegion} from './pricing/gcp-regions';-export {renderMediaOnCloudrun, renderStillOnCloudrun, getCompositionsOnGcp};+export {renderMediaOnCloudrun, renderStillOnCloudrun};export type {GcpRegion};diff --git a/packages/cloudrun/src/shared/constants.ts b/packages/cloudrun/src/shared/constants.tsindex 706112eb50..fa9f3eddbc 100644--- a/packages/cloudrun/src/shared/constants.ts+++ b/packages/cloudrun/src/shared/constants.ts@@ -1,4 +1,12 @@+import type {+ ChromiumOptions,+ PixelFormat,+ ProResProfile,+ StillImageFormat,+ VideoImageFormat,+} from '@remotion/renderer';import type {GcpRegion} from '../pricing/gcp-regions';+import type {CloudrunCodec} from './validate-gcp-codec';export const DEFAULT_REGION: GcpRegion = 'us-east1';export const BINARY_NAME = 'remotion cloudrun';@@ -16,3 +24,83 @@ export const inputPropsKey = (hash: string) => {export type Privacy = 'public' | 'private';export const DEFAULT_OUTPUT_PRIVACY: Privacy = 'public';++export enum CloudrunRoutines {+ info = 'info',+ media = 'media',+ still = 'still',+}++export type DownloadBehavior =+ | {+ type: 'play-in-browser';+ }+ | {+ type: 'download';+ fileName: string | null;+ };++export type CloudrunPayloads = {+ info: {+ type: CloudrunRoutines.info;+ };+ media: {+ concurrencyPerLambda: number;+ type: CloudrunRoutines.media;+ serveUrl: string;+ frameRange: [number, number];+ chunk: number;+ bucketName: string;+ composition: string;+ fps: number;+ height: number;+ width: number;+ durationInFrames: number;+ retriesLeft: number;+ inputProps: string;+ renderId: string;+ imageFormat: VideoImageFormat;+ codec: CloudrunCodec;+ crf: number | undefined;+ proResProfile: ProResProfile | undefined;+ pixelFormat: PixelFormat | undefined;+ jpegQuality: number | undefined;+ envVariables: Record<string, string> | undefined;+ privacy: Privacy;+ attempt: number;+ timeoutInMilliseconds: number;+ chromiumOptions: ChromiumOptions;+ scale: number;+ everyNthFrame: number;+ muted: boolean;+ audioBitrate: string | null;+ videoBitrate: string | null;+ launchFunctionConfig: {+ version: string;+ };+ };+ still: {+ type: CloudrunRoutines.still;+ serveUrl: string;+ composition: string;+ inputProps: string;+ imageFormat: StillImageFormat;+ envVariables: Record<string, string> | undefined;+ attempt: number;+ jpegQuality: number | undefined;+ maxRetries: number;+ frame: number;+ privacy: Privacy;+ outName: string;+ timeoutInMilliseconds: number;+ chromiumOptions: ChromiumOptions;+ scale: number;+ downloadBehavior: DownloadBehavior | null;+ version: string;+ forceHeight: number | null;+ forceWidth: number | null;+ bucketName: string | null;+ };+};++export type CloudrunPayload = CloudrunPayloads[CloudrunRoutines];diff --git a/packages/cloudrun/src/shared/convert-to-serve-url.ts b/packages/cloudrun/src/shared/convert-to-serve-url.tsnew file mode 100644index 0000000000..a662f175cc--- /dev/null+++ b/packages/cloudrun/src/shared/convert-to-serve-url.ts@@ -0,0 +1,21 @@+import {DOCS_URL} from './docs-url';++export const convertToServeUrl = ({+ urlOrId,+ bucketName,+}: {+ urlOrId: string;+ bucketName: string;+}) => {+ if (urlOrId.startsWith('src/')) {+ throw new Error(+ `Remotion Lambda can only render based on a URL in the cloud. It seems like you passed a local file: ${urlOrId}. Read the setup guide for Remotion Lambda ${DOCS_URL}/docs/cloudrun/setup`+ );+ }++ if (urlOrId.startsWith('http://') || urlOrId.startsWith('https://')) {+ return urlOrId;+ }++ return `https://storage.googleapis.com/${bucketName}/sites/${urlOrId}/index.html`;+};diff --git a/packages/cloudrun/src/shared/docs-url.ts b/packages/cloudrun/src/shared/docs-url.tsnew file mode 100644index 0000000000..fb978efe57--- /dev/null+++ b/packages/cloudrun/src/shared/docs-url.ts@@ -0,0 +1 @@+export const DOCS_URL = 'https://remotion.dev';diff --git a/packages/docs/docs/cloudrun/cli.md b/packages/docs/docs/cloudrun/cli.mdindex e443d69120..364e9e986e 100644--- a/packages/docs/docs/cloudrun/cli.md+++ b/packages/docs/docs/cloudrun/cli.md@@ -14,5 +14,4 @@ To use the Remotion Cloudrun CLI, you first need to [install it](/docs/cloudrun/- [services](/docs/cloudrun/cli/services)- [render](/docs/cloudrun/cli/render)- [permissions](/docs/cloudrun/cli/permissions)-- [compositions](/docs/cloudrun/cli/compositions)- [regions](/docs/cloudrun/cli/regions)diff --git a/packages/docs/docs/cloudrun/cli/compositions.md b/packages/docs/docs/cloudrun/cli/compositions.mddeleted file mode 100644index 0aa2be3c44..0000000000--- a/packages/docs/docs/cloudrun/cli/compositions.md+++ /dev/null@@ -1,87 +0,0 @@-----image: /generated/articles-docs-cloudrun-cli-compositions.png-title: npx remotion cloudrun compositions-sidebar_label: compositions-crumb: "Cloud Run CLI Reference"------_Available from v3.3.2._--Print list of composition IDs from a serve URL, fetched from inside a Lambda function.--```bash-npx remotion lambda compositions <serve-url>-```--- The serve URL is obtained by deploying a project to Remotion using the [`sites create`](/docs/lambda/cli/sites#create) command or calling [`deploySite()`](/docs/lambda/deploysite).--Note that you can also get the compositions of a site that is hosted on Lambda using [`npx remotion compositions`](/docs/cli/compositions). Vice versa, you can also get the compositions from a serve URL that is not hosted on AWS Lambda using `npx remotion lambda compositions`.--You should use `npx remotion lambda compositions` if you cannot use [`npx remotion compositions`](/docs/cli/compositions) because the machine cannot run Chrome.--## Example commands--Rendering a still:--```-npx remotion lambda compositions https://remotionlambda-abcdef.s3.eu-central-1.amazonaws.com/sites/testbed/index.html-```--## Flags--### `--props`--[React Props that can be retrieved using `getInputProps()`.](/docs/get-input-props) Must be a serialized JSON string (`--props='{"hello": "world"}'`) or a path to a JSON file (`./path/to/props.json`).--:::info-Inline JSON string isn't supported on Windows because it removes the `"` character, use a temporary file instead.-:::--### `--config`--Specify a location for the Remotion config file.--### `--env-file`--Specify a location for a dotenv file. Default `.env`.--### `--log`--[Set the log level](/docs/config#setlevel). Increase or decrease the amount of output. Acceptable values: `error`, `warn`, `info` (_default_), `verbose`--:::info-If you don't feel like passing command line flags every time, consider creating a `remotion.config.ts` [config file](/docs/config).-:::--### `--timeout`--Define how long it may take to resolve all [`delayRender()`](/docs/delay-render) calls before the composition fetching times out in milliseconds. Default: `30000`.--:::info-Not to be confused with the [`--timeout` flag when deploying a Lambda function](/docs/lambda/cli/functions#--timeout).-:::--### `--ignore-certificate-errors`--Results in invalid SSL certificates in Chrome, such as self-signed ones, being ignored.--### `--disable-web-security`--This will most notably disable CORS in Chrome among other security features.--### `--disable-headless`--Opens an actual browser to observe the composition fetching.--### `--quiet`, `--q`--Only prints the composition IDs, separated by a space.--### `--force-bucket-name` <AvailableFrom v="3.3.42" />--Specify a specific bucket name to be used. [This is not recommended](/docs/lambda/multiple-buckets), instead let Remotion discover the right bucket automatically.--## See also--- [`getCompositionsOnLambda()`](/docs/lambda/getcompositionsonlambda)-- [`npx remotion compositions`](/docs/cli/compositions)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex ad3781edd0..c2a5d0200e 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -44,7 +44,6 @@ module.exports = {"cloudrun/cli/services","cloudrun/cli/render","cloudrun/cli/permissions",- "cloudrun/cli/compositions","cloudrun/cli/regions",],},