Skip to content

🎥 Make videos programmatically with React

`@remotion/cloudrun`: New `onlyAllocateCpuDuringRequestProcessing` flag

Jonny Burger2a9c1b808b60
diff --git a/packages/cli/src/parsed-cli.ts b/packages/cli/src/parsed-cli.ts
index 5e3c966e8a..eb3cc39fc8 100644
--- a/packages/cli/src/parsed-cli.ts
+++ b/packages/cli/src/parsed-cli.ts
@@ -31,6 +31,7 @@ export const BooleanFlags = [
'repro',
'compatible-only',
'force-path-style',
+ 'onlyAllocateCpuDuringRequestProcessing',
];
export const parsedCli = minimist<CommandLineOptions>(process.argv.slice(2), {
diff --git a/packages/cloudrun/src/api/deploy-service.ts b/packages/cloudrun/src/api/deploy-service.ts
index 797be85072..7bf37eb4f3 100644
--- a/packages/cloudrun/src/api/deploy-service.ts
+++ b/packages/cloudrun/src/api/deploy-service.ts
@@ -25,6 +25,7 @@ type InternalDeployServiceInput = {
region: string;
logLevel: LogLevel;
indent: boolean;
+ onlyAllocateCpuDuringRequestProcessing: boolean;
};
export type DeployServiceInput = {
performImageVersionValidation?: boolean;
@@ -36,6 +37,7 @@ export type DeployServiceInput = {
logLevel?: LogLevel;
projectID: string;
region: string;
+ onlyAllocateCpuDuringRequestProcessing?: boolean;
};
export type DeployServiceOutput = {
@@ -55,6 +57,7 @@ const deployServiceRaw = async ({
projectID,
region,
logLevel,
+ onlyAllocateCpuDuringRequestProcessing,
}: InternalDeployServiceInput): Promise<DeployServiceOutput> => {
validateGcpRegion(region);
validateProjectID(projectID);
@@ -99,6 +102,7 @@ const deployServiceRaw = async ({
timeoutSeconds,
minInstances,
maxInstances,
+ onlyAllocateCpuDuringRequestProcessing,
}),
},
serviceId: serviceName,
@@ -141,6 +145,7 @@ export const deployService = ({
projectID,
region,
logLevel,
+ onlyAllocateCpuDuringRequestProcessing,
}: DeployServiceInput): Promise<DeployServiceOutput> => {
return internalDeployService({
performImageVersionValidation,
@@ -153,5 +158,7 @@ export const deployService = ({
region,
logLevel: logLevel ?? 'info',
indent: false,
+ onlyAllocateCpuDuringRequestProcessing:
+ onlyAllocateCpuDuringRequestProcessing ?? false,
});
};
diff --git a/packages/cloudrun/src/api/helpers/construct-service-deploy-request.ts b/packages/cloudrun/src/api/helpers/construct-service-deploy-request.ts
index 88e75368fc..a29bf4113a 100644
--- a/packages/cloudrun/src/api/helpers/construct-service-deploy-request.ts
+++ b/packages/cloudrun/src/api/helpers/construct-service-deploy-request.ts
@@ -14,12 +14,14 @@ export const constructServiceTemplate = ({
timeoutSeconds,
minInstances,
maxInstances,
+ onlyAllocateCpuDuringRequestProcessing,
}: {
memoryLimit: string;
cpuLimit: string;
timeoutSeconds: number;
minInstances: number;
maxInstances: number;
+ onlyAllocateCpuDuringRequestProcessing: boolean;
}): google.cloud.run.v2.IRevisionTemplate => {
return {
scaling: {
@@ -39,6 +41,7 @@ export const constructServiceTemplate = ({
memory: memoryLimit,
cpu: cpuLimit,
},
+ cpuIdle: onlyAllocateCpuDuringRequestProcessing,
},
},
],
diff --git a/packages/cloudrun/src/cli/args.ts b/packages/cloudrun/src/cli/args.ts
index e5c5b49d6a..4d72c71291 100644
--- a/packages/cloudrun/src/cli/args.ts
+++ b/packages/cloudrun/src/cli/args.ts
@@ -10,6 +10,7 @@ type servicesCommandLineOptions = {
y: boolean;
yes: boolean;
force: boolean;
+ ['onlyAllocateCpuDuringRequestProcessing']: boolean;
f: boolean;
['max-retries']: number;
diff --git a/packages/cloudrun/src/cli/commands/services/deploy.ts b/packages/cloudrun/src/cli/commands/services/deploy.ts
index 995e885ca8..0e428312b8 100644
--- a/packages/cloudrun/src/cli/commands/services/deploy.ts
+++ b/packages/cloudrun/src/cli/commands/services/deploy.ts
@@ -30,6 +30,8 @@ export const cloudRunDeploySubcommand = async (logLevel: LogLevel) => {
const maxInstances = String(
parsedCloudrunCli.maxInstances ?? DEFAULT_MAX_INSTANCES,
);
+ const onlyAllocateCpuDuringRequestProcessing =
+ parsedCloudrunCli.onlyAllocateCpuDuringRequestProcessing ?? false;
const timeoutSeconds = parsedCloudrunCli.timeoutSeconds ?? DEFAULT_TIMEOUT;
if (!CliInternals.quietFlagProvided()) {
@@ -88,6 +90,7 @@ ${[
region,
logLevel,
indent: false,
+ onlyAllocateCpuDuringRequestProcessing,
});
if (!deployResult.fullName) {
diff --git a/packages/docs/docs/cloudrun/cli/services.mdx b/packages/docs/docs/cloudrun/cli/services.mdx
index 738d312e77..b13270d912 100644
--- a/packages/docs/docs/cloudrun/cli/services.mdx
+++ b/packages/docs/docs/cloudrun/cli/services.mdx
@@ -2,13 +2,20 @@
image: /generated/articles-docs-cloudrun-cli-services.png
id: services
sidebar_label: services
-title: "npx remotion cloudrun services"
+title: 'npx remotion cloudrun services'
slug: /cloudrun/cli/services
-crumb: "Cloud Run CLI Reference"
+crumb: 'Cloud Run CLI Reference'
---
<ExperimentalBadge>
-<p>Cloud Run is in <a href="/docs/cloudrun-alpha">Alpha</a>, which means APIs may change in any version and documentation is not yet finished. See the <a href="https://remotion.dev/changelog">changelog to stay up to date with breaking changes</a>.</p>
+ <p>
+ Cloud Run is in <a href="/docs/cloudrun-alpha">Alpha</a>, which means APIs
+ may change in any version and documentation is not yet finished. See the{' '}
+ <a href="https://remotion.dev/changelog">
+ changelog to stay up to date with breaking changes
+ </a>
+ .
+ </p>
</ExperimentalBadge>
The `npx remotion cloudrun services` command allows you to deploy, view and delete GCP Cloud Run services that can render videos and stills.
@@ -29,28 +36,50 @@ npx remotion cloudrun services deploy
Creates a new service in your GCP project. If a service exists in the same region, with the same Remotion version, with the same amount of memory, disk space and timeout duration, the name of the already deployed service will be returned instead.
<details>
-<summary>
-Example output
-</summary>
-<pre>
-Validating Deployment of Cloud Run Service:<br/><br/>
-Remotion Version: 3.3.95<br/>
-Memory Limit: 2Gi<br/>
-CPU Limit: 1.0<br/>
-Timeout: 300<br/>
-Project Name: remotion-example<br/>
-Region: us-east1<br/><br/>
-Deploying Cloud Run Service...<br/><br/><br/>
-Cloud Run Deployed!<br/><br/>
-Service name: remotion--3-3-95--mem512mi--cpu2--t-1200<br/>
-Version: 3.3.95<br/>
-CPU Limit: 2<br/>
-Memory Limit: 512Mi<br/>
-Timeout: 1200sec<br/>
-Region: us-east1<br/>
-Service URL: https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app<br/>
-GCP Console URL: https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs<br/><br/>
-</pre>
+ <summary>Example output</summary>
+ <pre>
+ Validating Deployment of Cloud Run Service:
+ <br />
+ <br />
+ Remotion Version: 3.3.95
+ <br />
+ Memory Limit: 2Gi
+ <br />
+ CPU Limit: 1.0
+ <br />
+ Timeout: 300
+ <br />
+ Project Name: remotion-example
+ <br />
+ Region: us-east1
+ <br />
+ <br />
+ Deploying Cloud Run Service...
+ <br />
+ <br />
+ <br />
+ Cloud Run Deployed!
+ <br />
+ <br />
+ Service name: remotion--3-3-95--mem512mi--cpu2--t-1200
+ <br />
+ Version: 3.3.95
+ <br />
+ CPU Limit: 2<br />
+ Memory Limit: 512Mi
+ <br />
+ Timeout: 1200sec
+ <br />
+ Region: us-east1
+ <br />
+ Service URL:
+ https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app
+ <br />
+ GCP Console URL:
+ https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs
+ <br />
+ <br />
+ </pre>
</details>
### `--region`
@@ -85,6 +114,11 @@ Timeout of the Cloud Run service. Default: 300 seconds.
Not to be confused with the [`--timeout` flag when rendering which defines the timeout for `delayRender()`](/docs/cli/render#--timeout).
:::
+### `--onlyAllocateCpuDuringRequestProcessing`<AvailableFrom v="4.0.221" />
+
+If this is set to true, `cpu_idle` will be set to `true` in the service manifest.
+CPU alloction will be disabled while no request is being processed, which can lead to significant cost savings.
+
### `--quiet`, `-q`
Only logs the service name, and 'Authenticated access granted'.
@@ -98,28 +132,49 @@ npx remotion cloudrun services ls
Lists the services that you have deployed to GCP in the [selected region](/docs/cloudrun/region-selection).
<details>
-<summary>
-Example output
-</summary>
-<pre>
-2 services in us-east1<br/><br/>
-Service name: remotion--3-3-95--mem512mi--cpu2--t-1200<br/>
-Version: 3.3.95<br/>
-CPU Limit: 2<br/>
-Memory Limit: 512Mi<br/>
-Timeout: 1200sec<br/>
-Region: us-east1<br/>
-Service URL: https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app<br/>
-GCP Console URL: https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs<br/><br/>
-Service name: remotion--3-3-82--mem512mi--cpu1-0--t-800<br/>
-Version: 3.3.82<br/>
-CPU Limit: 1.0<br/>
-Memory Limit: 512Mi<br/>
-Timeout: 800sec<br/>
-Region: us-east1<br/>
-Service URL: https://remotion--3-3-82--mem512mi--cpu1-0--t-800-1a2b3c4d5e-ue.a.run.app<br/>
-GCP Console URL: https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-82--mem512mi--cpu1-0--t-800/logs<br/><br/>
-</pre>
+ <summary>Example output</summary>
+ <pre>
+ 2 services in us-east1
+ <br />
+ <br />
+ Service name: remotion--3-3-95--mem512mi--cpu2--t-1200
+ <br />
+ Version: 3.3.95
+ <br />
+ CPU Limit: 2<br />
+ Memory Limit: 512Mi
+ <br />
+ Timeout: 1200sec
+ <br />
+ Region: us-east1
+ <br />
+ Service URL:
+ https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app
+ <br />
+ GCP Console URL:
+ https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs
+ <br />
+ <br />
+ Service name: remotion--3-3-82--mem512mi--cpu1-0--t-800
+ <br />
+ Version: 3.3.82
+ <br />
+ CPU Limit: 1.0
+ <br />
+ Memory Limit: 512Mi
+ <br />
+ Timeout: 800sec
+ <br />
+ Region: us-east1
+ <br />
+ Service URL:
+ https://remotion--3-3-82--mem512mi--cpu1-0--t-800-1a2b3c4d5e-ue.a.run.app
+ <br />
+ GCP Console URL:
+ https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-82--mem512mi--cpu1-0--t-800/logs
+ <br />
+ <br />
+ </pre>
</details>
### `--region`
@@ -176,32 +231,56 @@ npx remotion cloudrun services rmall
Removes all services from your GCP project for a certain region.
<details>
-<summary>
-Example output
-</summary>
-<pre>
-2 services in us-east1<br/><br/>
-Service name: remotion--3-3-95--mem512mi--cpu2--t-1200<br/>
-Version: 3.3.95<br/>
-CPU Limit: 2<br/>
-Memory Limit: 512Mi<br/>
-Timeout: 1200sec<br/>
-Region: us-east1<br/>
-Service URL: https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app<br/>
-GCP Console URL: https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs<br/><br/>
-Delete? (Y/n) n<br/>
-Skipping service - remotion--3-3-95--mem512mi--cpu2--t-1200.<br/><br/>
-Service name: remotion--3-3-82--mem512mi--cpu1-0--t-800<br/>
-Version: 3.3.82<br/>
-CPU Limit: 1.0<br/>
-Memory Limit: 512Mi<br/>
-Timeout: 800sec<br/>
-Region: us-east1<br/>
-Service URL: https://remotion--3-3-82--mem512mi--cpu1-0--t-800-1a2b3c4d5e-ue.a.run.app<br/>
-GCP Console URL: https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-82--mem512mi--cpu1-0--t-800/logs<br/><br/>
-Delete? (Y/n) n<br/>
-Skipping service - remotion--3-3-82--mem512mi--cpu1-0--t-800.<br/>
-</pre>
+ <summary>Example output</summary>
+ <pre>
+ 2 services in us-east1
+ <br />
+ <br />
+ Service name: remotion--3-3-95--mem512mi--cpu2--t-1200
+ <br />
+ Version: 3.3.95
+ <br />
+ CPU Limit: 2<br />
+ Memory Limit: 512Mi
+ <br />
+ Timeout: 1200sec
+ <br />
+ Region: us-east1
+ <br />
+ Service URL:
+ https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app
+ <br />
+ GCP Console URL:
+ https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs
+ <br />
+ <br />
+ Delete? (Y/n) n<br />
+ Skipping service - remotion--3-3-95--mem512mi--cpu2--t-1200.
+ <br />
+ <br />
+ Service name: remotion--3-3-82--mem512mi--cpu1-0--t-800
+ <br />
+ Version: 3.3.82
+ <br />
+ CPU Limit: 1.0
+ <br />
+ Memory Limit: 512Mi
+ <br />
+ Timeout: 800sec
+ <br />
+ Region: us-east1
+ <br />
+ Service URL:
+ https://remotion--3-3-82--mem512mi--cpu1-0--t-800-1a2b3c4d5e-ue.a.run.app
+ <br />
+ GCP Console URL:
+ https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-82--mem512mi--cpu1-0--t-800/logs
+ <br />
+ <br />
+ Delete? (Y/n) n<br />
+ Skipping service - remotion--3-3-82--mem512mi--cpu1-0--t-800.
+ <br />
+ </pre>
</details>
### `--region`
diff --git a/packages/docs/docs/cloudrun/deployservice.mdx b/packages/docs/docs/cloudrun/deployservice.mdx
index 7f2c134bf8..24551fafe0 100644
--- a/packages/docs/docs/cloudrun/deployservice.mdx
+++ b/packages/docs/docs/cloudrun/deployservice.mdx
@@ -3,11 +3,18 @@ image: /generated/articles-docs-cloudrun-deployservice.png
id: deployservice
title: deployService()
slug: /cloudrun/deployservice
-crumb: "Cloud Run API"
+crumb: 'Cloud Run API'
---
<ExperimentalBadge>
-<p>Cloud Run is in <a href="/docs/cloudrun-alpha">Alpha</a>, which means APIs may change in any version and documentation is not yet finished. See the <a href="https://remotion.dev/changelog">changelog to stay up to date with breaking changes</a>.</p>
+ <p>
+ Cloud Run is in <a href="/docs/cloudrun-alpha">Alpha</a>, which means APIs
+ may change in any version and documentation is not yet finished. See the{' '}
+ <a href="https://remotion.dev/changelog">
+ changelog to stay up to date with breaking changes
+ </a>
+ .
+ </p>
</ExperimentalBadge>
Creates a [GCP Cloud Run](https://cloud.google.com/run) service in your GCP project that will be able to render a video in the cloud.
@@ -20,14 +27,14 @@ If a service with the same Remotion version, memory limit, cpu limit and timeout
// @module: esnext
// @target: es2017
-import { deployService } from "@remotion/cloudrun";
+import {deployService} from '@remotion/cloudrun';
-const { shortName } = await deployService({
- memoryLimit: "2Gi",
- cpuLimit: "2.0",
+const {shortName} = await deployService({
+ memoryLimit: '2Gi',
+ cpuLimit: '2.0',
timeoutSeconds: 500,
- projectID: "my-remotion-project",
- region: "us-east1",
+ projectID: 'my-remotion-project',
+ region: 'us-east1',
});
console.log(shortName);
```
@@ -72,6 +79,11 @@ The [GCP region](/docs/cloudrun/region-selection) which you want to deploy the C
Default as true. This will validate that an image exists in the public Artifact Registry that matches the Remotion Version you are trying to deploy. Can be set false for a potential time saving.
+### `onlyAllocateCpuDuringRequestProcessing`<AvailableFrom v="4.0.221" />
+
+If this is set to true, `cpu_idle` will be set to `true` in the service manifest.
+CPU alloction will be disabled while no request is being processed, which can lead to significant cost savings.
+
## Return value
An object with the following values: