Skip to content

🎥 Make videos programmatically with React

changes from last couple of days

Matt McGillivraycaf11bfff710
diff --git a/packages/cloudrun/package.json b/packages/cloudrun/package.json
index 7167848238..58ab80e7be 100644
--- a/packages/cloudrun/package.json
+++ b/packages/cloudrun/package.json
@@ -39,11 +39,15 @@
"exports": {
"./package.json": "./package.json",
".": "./dist/index.js",
+ "./defaults": "./dist/defaults.js",
"./regions": "./dist/regions.js",
"./permissions.json": "./dist/shared/sa-permissions.json"
},
"typesVersions": {
">=1.0": {
+ "defaults": [
+ "dist/defaults.d.ts"
+ ],
"regions": [
"dist/regions.d.ts"
]
diff --git a/packages/cloudrun/src/api/deploy-service.ts b/packages/cloudrun/src/api/deploy-service.ts
index 33a492cb9f..587ececf93 100644
--- a/packages/cloudrun/src/api/deploy-service.ts
+++ b/packages/cloudrun/src/api/deploy-service.ts
@@ -1,3 +1,8 @@
+import {
+ DEFAULT_MAX_INSTANCES,
+ DEFAULT_MIN_INSTANCES,
+ DEFAULT_TIMEOUT,
+} from '../shared/constants';
import {generateServiceName} from '../shared/generate-service-name';
import {validateGcpRegion} from '../shared/validate-gcp-region';
import {validateImageRemotionVersion} from '../shared/validate-image-remotion-version';
@@ -11,6 +16,8 @@ export type DeployServiceInput = {
memoryLimit?: string;
cpuLimit?: string;
timeoutSeconds?: number;
+ minInstances?: number;
+ maxInstances?: number;
projectID: string;
region: string;
};
@@ -38,6 +45,8 @@ export const deployService = async ({
memoryLimit,
cpuLimit,
timeoutSeconds,
+ minInstances,
+ maxInstances,
projectID,
region,
}: DeployServiceInput): Promise<DeployServiceOutput> => {
@@ -56,7 +65,15 @@ export const deployService = async ({
}
if (!timeoutSeconds) {
- timeoutSeconds = 300;
+ timeoutSeconds = DEFAULT_TIMEOUT;
+ }
+
+ if (!minInstances) {
+ minInstances = DEFAULT_MIN_INSTANCES;
+ }
+
+ if (!maxInstances) {
+ maxInstances = DEFAULT_MAX_INSTANCES;
}
const parent = `projects/${projectID}/locations/${region}`;
@@ -94,6 +111,8 @@ export const deployService = async ({
memoryLimit,
cpuLimit,
timeoutSeconds,
+ minInstances,
+ maxInstances,
}),
},
serviceId: serviceName,
diff --git a/packages/cloudrun/src/api/get-or-create-bucket.ts b/packages/cloudrun/src/api/get-or-create-bucket.ts
index d6a0963983..5adfb95201 100644
--- a/packages/cloudrun/src/api/get-or-create-bucket.ts
+++ b/packages/cloudrun/src/api/get-or-create-bucket.ts
@@ -33,9 +33,11 @@ export const getOrCreateBucket = async (
if (remotionBuckets.length > 1) {
throw new Error(
- `You have multiple buckets (${remotionBuckets.map(
- (b) => b.name
- )}) starting with "${REMOTION_BUCKET_PREFIX}". This is an error, please delete buckets so that you have one maximum.`
+ `You have multiple buckets (${remotionBuckets
+ .map((b) => b.name)
+ .join(', ')}) in your Cloud Storage region (${
+ params.region
+ }) starting with "${REMOTION_BUCKET_PREFIX}". This is an error, please delete buckets so that you have one maximum.`
);
}
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 62aa940d82..652de7c686 100644
--- a/packages/cloudrun/src/api/helpers/construct-service-deploy-request.ts
+++ b/packages/cloudrun/src/api/helpers/construct-service-deploy-request.ts
@@ -1,15 +1,30 @@
import {VERSION} from 'remotion/version';
+// taken from within the @google-cloud/run package, can't import it directly
+enum ExecutionEnvironment {
+ EXECUTION_ENVIRONMENT_UNSPECIFIED = 0,
+ EXECUTION_ENVIRONMENT_GEN1 = 1,
+ EXECUTION_ENVIRONMENT_GEN2 = 2,
+}
+
export const constructServiceTemplate = ({
memoryLimit,
cpuLimit,
timeoutSeconds,
+ minInstances,
+ maxInstances,
}: {
memoryLimit: string;
cpuLimit: string;
timeoutSeconds: number;
+ minInstances: number;
+ maxInstances: number;
}) => {
return {
+ scaling: {
+ minInstanceCount: minInstances,
+ maxInstanceCount: maxInstances,
+ },
timeout: {
seconds: timeoutSeconds,
},
@@ -24,5 +39,7 @@ export const constructServiceTemplate = ({
},
},
],
+ maxInstanceRequestConcurrency: 1,
+ executionEnvironment: ExecutionEnvironment.EXECUTION_ENVIRONMENT_GEN1,
};
};
diff --git a/packages/cloudrun/src/cli/commands/services/deploy.ts b/packages/cloudrun/src/cli/commands/services/deploy.ts
index 923e315e27..2617dbef0a 100644
--- a/packages/cloudrun/src/cli/commands/services/deploy.ts
+++ b/packages/cloudrun/src/cli/commands/services/deploy.ts
@@ -2,6 +2,11 @@ import {CliInternals} from '@remotion/cli';
import {VERSION} from 'remotion/version';
import {displayServiceInfo, LEFT_COL} from '.';
import {deployService} from '../../../api/deploy-service';
+import {
+ DEFAULT_MAX_INSTANCES,
+ DEFAULT_MIN_INSTANCES,
+ DEFAULT_TIMEOUT,
+} from '../../../shared/constants';
import {generateServiceName} from '../../../shared/generate-service-name';
import {validateGcpRegion} from '../../../shared/validate-gcp-region';
import {validateImageRemotionVersion} from '../../../shared/validate-image-remotion-version';
@@ -17,7 +22,13 @@ export const cloudRunDeploySubcommand = async () => {
const projectID = process.env.REMOTION_GCP_PROJECT_ID as string;
const memoryLimit = String(parsedCloudrunCli.memoryLimit ?? '2Gi');
const cpuLimit = String(parsedCloudrunCli.cpuLimit ?? '1.0');
- const timeoutSeconds = parsedCloudrunCli.timeoutSeconds ?? 300;
+ const minInstances = String(
+ parsedCloudrunCli.minInstances ?? DEFAULT_MIN_INSTANCES
+ );
+ const maxInstances = String(
+ parsedCloudrunCli.maxInstances ?? DEFAULT_MAX_INSTANCES
+ );
+ const timeoutSeconds = parsedCloudrunCli.timeoutSeconds ?? DEFAULT_TIMEOUT;
if (!CliInternals.quietFlagProvided()) {
Log.info(
@@ -29,6 +40,9 @@ ${[
'Remotion Version: '.padEnd(LEFT_COL, ' ') + ' ' + VERSION,
'Memory Limit: '.padEnd(LEFT_COL, ' ') + ' ' + memoryLimit,
'CPU Limit: '.padEnd(LEFT_COL, ' ') + ' ' + cpuLimit,
+ 'Minimum Instances: '.padEnd(LEFT_COL, ' ') + ' ' + minInstances,
+ 'Maximum Instances: '.padEnd(LEFT_COL, ' ') + ' ' + maxInstances,
+ 'CPU Limit: '.padEnd(LEFT_COL, ' ') + ' ' + cpuLimit,
'Timeout: '.padEnd(LEFT_COL, ' ') + ' ' + timeoutSeconds,
'Project Name: '.padEnd(LEFT_COL, ' ') + ' ' + projectID,
'Region: '.padEnd(LEFT_COL, ' ') + ' ' + region,
diff --git a/packages/cloudrun/src/cli/commands/services/index.ts b/packages/cloudrun/src/cli/commands/services/index.ts
index 163cb31b5a..2705d720c4 100644
--- a/packages/cloudrun/src/cli/commands/services/index.ts
+++ b/packages/cloudrun/src/cli/commands/services/index.ts
@@ -10,7 +10,7 @@ import {servicesRmallCommand, SERVICES_RMALL_SUBCOMMAND} from './rmall';
export const SERVICES_COMMAND = 'services';
-export const LEFT_COL = 18;
+export const LEFT_COL = 20;
export const displayServiceInfo = (service: ServiceInfo) => {
return [
diff --git a/packages/cloudrun/src/defaults.ts b/packages/cloudrun/src/defaults.ts
new file mode 100644
index 0000000000..2d0232d4d1
--- /dev/null
+++ b/packages/cloudrun/src/defaults.ts
@@ -0,0 +1 @@
+export * from './shared/constants';
diff --git a/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar b/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar
index cf684e58dc..1c0082f2e3 100644
Binary files a/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar and b/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar differ
diff --git a/packages/cloudrun/src/shared/constants.ts b/packages/cloudrun/src/shared/constants.ts
index 706112eb50..2160361774 100644
--- a/packages/cloudrun/src/shared/constants.ts
+++ b/packages/cloudrun/src/shared/constants.ts
@@ -16,3 +16,7 @@ export const inputPropsKey = (hash: string) => {
export type Privacy = 'public' | 'private';
export const DEFAULT_OUTPUT_PRIVACY: Privacy = 'public';
+
+export const DEFAULT_TIMEOUT = 300;
+export const DEFAULT_MIN_INSTANCES = 0;
+export const DEFAULT_MAX_INSTANCES = 100;
diff --git a/packages/docs/components/cloudrun/default-timeout.tsx b/packages/docs/components/cloudrun/default-timeout.tsx
new file mode 100644
index 0000000000..43159e3ad0
--- /dev/null
+++ b/packages/docs/components/cloudrun/default-timeout.tsx
@@ -0,0 +1,6 @@
+import { DEFAULT_TIMEOUT } from "@remotion/cloudrun/defaults";
+import React from "react";
+
+export const DefaultTimeout: React.FC = () => {
+ return <span>{DEFAULT_TIMEOUT}</span>;
+};
diff --git a/packages/docs/components/cloudrun/sa-permissions.tsx b/packages/docs/components/cloudrun/sa-permissions.tsx
index 433f61c2c8..de03ba88ae 100644
--- a/packages/docs/components/cloudrun/sa-permissions.tsx
+++ b/packages/docs/components/cloudrun/sa-permissions.tsx
@@ -8,7 +8,6 @@ type Permission = {
}
export const SAPermissionList: React.FC = () => {
- console.log(permissionsJson.list)
return (
<div>
<pre>{permissionsJson.list.map((permission: Permission) => {
@@ -19,7 +18,6 @@ export const SAPermissionList: React.FC = () => {
};
export const SAPermissionTable: React.FC = () => {
- console.log(permissionsJson.list)
return (
<table>
<tr>
diff --git a/packages/docs/docs/cloudrun/checklist.md b/packages/docs/docs/cloudrun/checklist.md
new file mode 100644
index 0000000000..72831dd075
--- /dev/null
+++ b/packages/docs/docs/cloudrun/checklist.md
@@ -0,0 +1,50 @@
+---
+image: /generated/articles-docs-cloudrun-checklist.png
+id: checklist
+sidebar_label: Production Checklist
+title: Production Checklist
+slug: /cloudrun/checklist
+crumb: "Cloud Run"
+---
+
+import {DefaultTimeout} from '../../components/cloudrun/default-timeout';
+
+You have implemented your solution with Remotion Cloud Run and are ready to launch your project into the world. Congrats!
+Before you go live, go through this checklist to make sure Cloud Run is running stable.
+
+### Optimizing for memory
+
+Adding too much memory to your Cloud Run services can make rendering more costly. Reducing the memory of your service by 25% will also decrease your cost by 25%! Redeploy your service multiple times and lower the memory size as much as possible until you feel you hit the sweet spot between low costs and confidence that your video will render reliably.
+
+### Maximum file size
+
+The output file size on Cloud Run is constrained by the memory limit, minus the size of the supporting software for Remotion Cloud Run running on the service. Adjust the disk space parameter of Cloud Run to accommodate for the maximum video length that you would like to support. Test the file sizes of your outputs and make sure they don't run at risk of exceeding the limit.
+If your video is based on user input, prevent your users from rendering very long videos that would exceed the space available in Remotion Cloud Run.
+
+### Permissions
+
+Make sure your GCP Service Account only has as many permissions as needed and store your credentials as environment variables. Review the [Permissions](/docs/cloudrun/permissions) page to see what the minimum amount of permissions is.
+
+### Selecting the right concurrency
+
+Using the Remotion API, services will be deployed with a concurrency of 1 (i.e no concurrency). This is to ensure no issues arise from shared CPU and memory of unrelated renders. If you wish to change this, you will need to click 'Edit and Deploy New Revision' from within the Cloud Run section of the GCP Console, and select the desired concurrency.
+
+### Selecting the right instance limit
+
+By default, the Cloud Run service will have a minimum number of instances set to 0, and a maximum instance limit of 100. If more than 100 simultaneous render requests are made at once, a 503 service unavailable will be returned. [Read more about the instance limit here](/docs/cloudrun/instancecount).
+
+### Bucket privacy
+
+By default the rendered videos are publicly accessible in your bucket. Use the `privacy` setting in [`renderMediaOnCloudrun()`](/docs/cloudrun/rendermediaoncloudrun) and [`renderStillOnCloudrun()`](/docs/cloudrun/renderstilloncloudrun) to make renders private if you'd like so.
+
+### Rate limiting
+
+Consider if it's possible for a user to invoke many video renders that will end up on your GCP bill, and implement a rate limiter to prevent a malicious actor from rendering many videos.
+
+### Timeout
+
+The default timeout for your Cloud Run service is <DefaultTimeout /> seconds. Measure and adjust the timeout for your needs and make sure it is high enough so that your video render will not fail.
+
+### Valid Company license
+
+Companies with more than 3 people need to buy cloud rendering seats in order to use Remotion Cloud Run. Please familiarize yourself with the [license](https://github.com/remotion-dev/remotion/blob/main/LICENSE.md) and [buy the necessary cloud seats](https://companies.remotion.dev/) before launching.
diff --git a/packages/docs/docs/cloudrun/cli/services.md b/packages/docs/docs/cloudrun/cli/services.md
index 422be48bb5..aba2c49049 100644
--- a/packages/docs/docs/cloudrun/cli/services.md
+++ b/packages/docs/docs/cloudrun/cli/services.md
@@ -61,6 +61,18 @@ The upper bound on the amount of RAM that the Cloud Run service can consume. Def
The maximum number of CPU cores that the Cloud Run service can use to process requests. Default: 1.0.
+### `--minInstances`
+
+The minimum number of service instances to have available, regardless of requests. Default: 0.
+
+:::note
+Any running instances, even if they are not performing a render, will be billable in GCP. The default minimum number of instances is zero, which means that when no requests are made to your service, you are not billed.
+:::
+
+### `--maxInstances`
+
+The maximum number of service instances that can be create by GCP in response to incoming requests. Default: 100.
+
### `--timeoutSeconds`
Timeout of the Cloud Run service. Default: 300 seconds.
diff --git a/packages/docs/docs/cloudrun/deployservice.md b/packages/docs/docs/cloudrun/deployservice.md
index 51b6c4244d..41642b2e86 100644
--- a/packages/docs/docs/cloudrun/deployservice.md
+++ b/packages/docs/docs/cloudrun/deployservice.md
@@ -40,6 +40,18 @@ The upper bound on the amount of RAM that the Cloud Run service can consume. By
The maximum number of CPU cores that the Cloud Run service can use to process requests. The default is 1. As the CPU limit is raised, there is a [corresponding minimum Memory Limit](https://cloud.google.com/run/docs/configuring/cpu#setting) that must be observed.
+### `minInstances`
+
+The minimum number of service instances to have available, regardless of requests. The default is 0. Some users may wish to increase the minimum instances so that renders are started faster, though this would only reduce cold start time for simultaneous renders up to that minimum limit. [Read more about the minimum instance limit here](/docs/cloudrun/instancecount#minimum-instance-count)
+
+:::warning
+Any running instances, even if they are not performing a render, will be billable in GCP. The default minimum number of instances is zero, which means that when no requests are made to your service, you are not billed.
+:::
+
+### `maxInstances`
+
+The maximum number of service instances that can be create by GCP in response to incoming requests. The default is 100. [Read more about the maximum instance limit here](/docs/cloudrun/instancecount#maximum-instance-count)
+
### `timeoutSeconds`
How long the Cloud Run Service may run before it gets killed. Must be below 3600 seconds.
diff --git a/packages/docs/docs/cloudrun/instancecount.md b/packages/docs/docs/cloudrun/instancecount.md
new file mode 100644
index 0000000000..ef534e37f6
--- /dev/null
+++ b/packages/docs/docs/cloudrun/instancecount.md
@@ -0,0 +1,32 @@
+---
+image: /generated/articles-docs-cloudrun-instancecount.png
+id: instancecount
+sidebar_label: Instance Count
+title: Instance Count
+slug: /cloudrun/instancecount
+crumb: "Cloud Run"
+---
+
+Remotion Cloud Run will scale up and down as required to account for the number of requests being made to the service. By default, there is no concurrency in the Remotion services. This means that only one render will occur on an instance. When another request is made, GCP will spin up another Cloud Run instance to perform that render.
+
+### Minimum instance count
+
+By default, the Cloud Run service will have a minimum number of instances set to 0. The advantage of this is that it can scale to zero, so if no users are requesting your service, you will not be billed. You may wish to increase the minimum instances so that renders are started faster, though this would only remove cold start time for simultaneous renders up to that minimum limit.
+
+:::warning
+Any running instances, even if they are not performing a render, will be billable in GCP. The default minimum number of instances is zero, which means that when no requests are made to your service, you are not billed.
+:::
+
+### Maximum instance count
+
+This is the maximum number of instances that can be created at one time, with the default set to 100. The maximum that can be set in GCP is also 100 - [more information around limits can be found here](https://cloud.google.com/run/docs/configuring/max-instances#limits). If the maximum number of instances is exceeded, further requests will fail with a `503 service unavailable` response. GCP provides Cloud Tasks for queueing requests, [which can be used in conjunction with Cloud Run](https://cloud.google.com/run/docs/triggering/using-tasks).
+
+:::note
+You may wish to provide a low maximum instance limit for certain tiers of your product, and have a higher instance limit for higher tier plans. This can be achieved by deploying multiple Cloud Run services and calling them within your product as required.
+:::
+
+## See also
+
+- Cloud Run CLI - Deploy service with [maximum](/docs/cloudrun/deployservice#maxinstances) and [minimum](/docs/cloudrun/deployservice#mininstances) limits.
+- Cloud Run Node API - Deploy service with [maximum](/docs/cloudrun/deployservice#maxinstances) and [minimum](/docs/cloudrun/deployservice#mininstances) limits.
+- GCP documentation around [max instance limits](https://cloud.google.com/run/docs/configuring/max-instances#limits).
\ No newline at end of file
diff --git a/packages/docs/docs/cloudrun/multiple-buckets.md b/packages/docs/docs/cloudrun/multiple-buckets.md
new file mode 100644
index 0000000000..658d7d846b
--- /dev/null
+++ b/packages/docs/docs/cloudrun/multiple-buckets.md
@@ -0,0 +1,26 @@
+---
+image: /generated/articles-docs-cloudrun-multiple-buckets.png
+title: Multiple buckets in Remotion Cloud Run
+slug: /cloudrun/multiple-buckets
+sidebar_label: Multiple buckets
+crumb: "@remotion/cloudrun"
+---
+
+Remotion Cloud Run supports **1 bucket per region and project** that you use Remotion Cloud Run in. It is not necessary to create multiple buckets because:
+
+- A Cloud Storage bucket is an effectively infinitely scalable storage solution.
+- Remotion will perfectly isolate each render so they do not interfere with another.
+- You can give sites a unique identifier to separate production and development environments.
+- The Remotion Cloud Run service is a binary that does not change with your codebase.
+
+You might intuitively create multiple buckets because you have multiple environments, but it is usually not needed.
+
+## Deleting extraneous buckets
+
+If you got an error message
+
+```
+You have multiple buckets [remotioncloudrun-1a2b3c4d, remotioncloudrun-howDidThisHappen] in your Cloud Storage region [us-east1] starting with "remotioncloudrun-".
+```
+
+delete the extraneous buckets in the GCP console to fix the error.
\ No newline at end of file
diff --git a/packages/docs/docs/cloudrun/uninstall.md b/packages/docs/docs/cloudrun/uninstall.md
new file mode 100644
index 0000000000..8fcae82b55
--- /dev/null
+++ b/packages/docs/docs/cloudrun/uninstall.md
@@ -0,0 +1,32 @@
+---
+image: /generated/articles-docs-cloudRun-uninstall.png
+id: uninstall
+title: Uninstall Cloud Run
+slug: /cloudRun/uninstall
+---
+
+Of course we are bummed if you decided not to use Remotion Cloud Run anymore. We are very receptive to feedback if you'd like to share it with us.
+
+If you would like to remove **all Remotion Cloud Run related objects** from your infrastructure, you can follow these steps.
+
+:::warning
+This will remove all videos already rendered, and break your programs that are using Remotion Cloud Run to render videos.
+:::
+
+## Delete Cloud Run Services
+
+You can delete all services using the following command. The `yes` flag is already included, if you run this, it will delete all services without confirmation.
+
+```
+npx remotion cloudRun services rmall -y
+```
+
+## Delete projects
+
+```
+npx remotion cloudRun sites rmall -y
+```
+
+## Delete renders and artifacts
+
+Delete all Cloud Storage buckets starting with `remotioncloudrun-` from your GCP Project.
\ No newline at end of file
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index a59112a2bb..f62aff2f39 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -539,7 +539,11 @@ module.exports = {
"cloudrun/generate-env",
"cloudrun/region-selection",
"cloudrun/faq",
+ "cloudrun/checklist",
+ "cloudrun/instancecount",
+ "cloudrun/multiple-buckets",
"cloudrun/upgrading",
+ "cloudrun/uninstall",
],
},
{