Skip to content

🎥 Make videos programmatically with React

cloudrun docs

Matt McGillivray6d4ff4e9b59f
diff --git a/packages/cloudrun/src/api/iam-validation/testPermissions.ts b/packages/cloudrun/src/api/iam-validation/testPermissions.ts
index 524cddcd00..68780207f1 100644
--- a/packages/cloudrun/src/api/iam-validation/testPermissions.ts
+++ b/packages/cloudrun/src/api/iam-validation/testPermissions.ts
@@ -12,7 +12,7 @@ type TestResult = {
};
type TestPermissionsInput = {
- onTest?: (result: TestResult) => void;
+ onTest: (result: TestResult) => void;
};
type TestPermissionsOutput = {
@@ -22,12 +22,12 @@ type TestPermissionsOutput = {
/**
* @description Test the permissions on the service account match the permissions required.
* @see [Remotion-Documentation](http://remotion.dev/docs/cloudrun/testpermissions)
- * @see [Cloudrun-Documentation](https://cloud.google.com/resource-manager/reference/rest/v1/projects/testIamPermissions)
+ * @see [Cloudrun-Documentation](https://cloud.google.com/resource-manager/reference/rest/v3/projects/testIamPermissions)
* @param {(result: TestResult) => void} params.onTest Function to run on each test result
* @returns {Promise<TestPermissionsOutput>} Returns array of TestResult objects
*/
export const testPermissions = async (
- params: TestPermissionsInput
+ params?: TestPermissionsInput
): Promise<TestPermissionsOutput> => {
const resourceManagerClient = getResourceManagerClient();
@@ -57,11 +57,11 @@ export const testPermissions = async (
if (returnedPermissions.includes(permission)) {
const thisResult = {decision: true, permissionName: permission};
results.push(thisResult);
- params.onTest?.(thisResult);
+ params?.onTest(thisResult);
} else {
const thisResult = {decision: false, permissionName: permission};
results.push(thisResult);
- params.onTest?.(thisResult);
+ params?.onTest(thisResult);
}
});
diff --git a/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar b/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar
index 31d8f5e82f..57dbe0f74a 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/index.ts b/packages/cloudrun/src/index.ts
index 2216a7252a..f6673f8aa9 100644
--- a/packages/cloudrun/src/index.ts
+++ b/packages/cloudrun/src/index.ts
@@ -11,9 +11,11 @@ import {getRegions} from './api/get-regions';
import {getServiceInfo} from './api/get-service-info';
import {getServices} from './api/get-services';
import {getSites} from './api/get-sites';
+import {testPermissions} from './api/iam-validation/testPermissions';
import type {RenderMediaOnCloudrunInput} from './api/render-media-on-cloudrun';
import {renderMediaOnCloudrun} from './api/render-media-on-cloudrun';
import {renderStillOnCloudrun} from './api/render-still-on-cloudrun';
+import {speculateServiceName} from './api/speculate-service-name';
import type {RenderMediaOnCloudrunOutput} from './functions/helpers/payloads';
import {CloudrunInternals} from './internals';
import type {GcpRegion} from './pricing/gcp-regions';
@@ -31,6 +33,8 @@ export {
getServiceInfo,
getRegions,
getSites,
+ speculateServiceName,
+ testPermissions,
};
export type {
GcpRegion,
diff --git a/packages/docs/docs/cloudrun/getsites.md b/packages/docs/docs/cloudrun/getsites.md
new file mode 100644
index 0000000000..30f494263a
--- /dev/null
+++ b/packages/docs/docs/cloudrun/getsites.md
@@ -0,0 +1,105 @@
+---
+image: /generated/articles-docs-cloudrun-getsites.png
+id: getsites
+title: getSites()
+slug: /cloudrun/getsites
+crumb: "Cloud Run API"
+---
+
+Gets an array of Remotion projects in Cloud Storage, in your GCP project.
+
+The projects are located in the `sites/` subdirectory of your Cloud Storage bucket. Remember - you should only have one bucket for Remotion Cloud Run per region, therefore you do not need to specify the name of the bucket for this function.
+
+## Example
+
+Gets all sites and logs information about them.
+
+```ts twoslash
+// @module: ESNext
+// @target: ESNext
+import { getSites } from "@remotion/cloudrun";
+
+const { sites, buckets } = await getSites("europe-west4");
+
+for (const site of sites) {
+ console.log(site.id); // A unique ID for referring to that project
+ console.log(site.bucketName); // In which bucket the site resides in.
+ console.log(site.bucketRegion); // In which region the bucket resides in.
+ console.log(site.serveUrl); // URL of the deployed site that you can pass to `renderMediaOnCloudRun()`
+}
+
+for (const bucket of buckets) {
+ console.log(bucket.name); // The name of the Cloud Storage bucket.
+ console.log(bucket.creationDate); // A unix timestamp of when the site was created.
+ console.log(bucket.region); // 'europe-west4'
+}
+```
+
+## Arguments
+
+An object with the following properties:
+
+### `region`
+
+The [GCP region](/docs/cloudrun/region-selection) which you want to query. Alternatively, you can pass 'all regions' to return sites across all regions.
+
+```ts twoslash
+// @module: ESNext
+// @target: ESNext
+import { getSites } from "@remotion/cloudrun";
+
+const { sites, buckets } = await getSites("all regions");
+```
+
+## Return value
+
+A promise resolving to an object with the following properties:
+
+### `sites`
+
+An array of deployed Remotion projects that you can use for rendering.
+
+Each items contains the following properties:
+
+#### `id`
+
+A unique identifier for that project.
+
+#### `bucketName`
+
+The bucket in which the project resides in.
+
+#### `bucketRegion`
+
+The region in which the bucket resides in.
+
+#### `serveUrl`
+
+URL of the deployed site. You can pass it into [`renderMediaOnCloudRun()`](/docs/cloudrun/rendermediaoncloudrun) to render a video or audio.
+
+### `buckets`
+
+An array of all buckets in the selected region in your account that start with `remotioncloudrun-`.
+
+:::info
+You should only have [1 bucket](/docs/cloudrun/multiple-buckets) per region for all your Remotion projects.
+:::
+
+Each item contains the following properties:
+
+#### `region`
+
+The region the bucket resides in.
+
+#### `name`
+
+The name of the bucket. Cloud Storage buckets have globally unique names.
+
+#### `creationDate`
+
+A UNIX timestamp of the point when the bucket was first created.
+
+## See also
+
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/cloudrun/src/api/get-sites.ts)
+- [deleteSite()](/docs/cloudrun/deletesite)
diff --git a/packages/docs/docs/cloudrun/speculateservicename.md b/packages/docs/docs/cloudrun/speculateservicename.md
index 1333ed77b7..f78eec6823 100644
--- a/packages/docs/docs/cloudrun/speculateservicename.md
+++ b/packages/docs/docs/cloudrun/speculateservicename.md
@@ -1 +1,76 @@
-TODO
+---
+image: /generated/articles-docs-cloudrun-speculateServiceName.png
+id: speculateservicename
+title: speculateServiceName()
+slug: /cloudrun/speculateservicename
+crumb: "Cloud Run API"
+---
+
+Speculate the name of the Cloud Run service that will be created by [deployService()](/docs/cloudrun/deployservice) or its CLI equivalent, [`npx remotion cloudrun services deploy`](/docs/cloudrun/cli/services). This could be useful in cases when the configuration of the Cloud Run service is known in advance, and the name of the service is needed.
+
+If you are not sure whether a service exists, use [`getServiceInfo()`](/docs/cloudrun/getserviceinfo) and catch the error that gets thrown if it does not exist.
+
+If you want to get a list of deployed services, use [`getServices()`](/docs/cloudrun/getservices) instead.
+
+## Service name pattern
+
+The service name depends on the following parameters:
+
+- Remotion version
+- Memory Limit
+- CPU Limit
+- Timeout in seconds
+
+The name of the service resembles the following pattern:
+
+```
+remotion--3-3-96--mem2gi--cpu1-0--t-1900
+ ^^^^^^ ^^^ ^^^ ^^^
+ | | | |-- Timeout in seconds
+ | | |----------- Cpu limit
+ | |------------------- Memory limit
+ |--------------------------- Remotion version with dots replaced by dashes
+```
+
+## Example
+
+```ts twoslash
+// @module: esnext
+// @target: es2017
+
+import { speculateServiceName } from "@remotion/cloudrun";
+
+const speculatedServiceName = speculateServiceName({
+ memoryLimit: "2Gi",
+ cpuLimit: "2",
+ timeoutSeconds: 300,
+});
+
+console.log(speculatedServiceName); // remotion--3-3-96--mem2gi--cpu2-0--t-300
+```
+
+## Arguments
+
+An object with the following properties:
+
+### `memoryLimit`
+
+The upper bound on the amount of RAM that the Cloud Run service can consume.
+
+### `cpuLimit`
+
+The maximum number of CPU cores that the Cloud Run service can use to process requests.
+
+### `timeoutSeconds`
+
+The timeout that has been assigned to the Cloud Run service.
+
+## Return value
+
+A string with the speculated name of the service.
+
+## See also
+
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/cloudrun/src/api/speculate-service-name.ts)
+- [deployService()](/docs/cloudrun/deployservice)
+- CLI version of `deployService()`: [`npx remotion cloudrun services deploy`](/docs/cloudrun/cli/services#deploy)
diff --git a/packages/docs/docs/cloudrun/testpermissions.md b/packages/docs/docs/cloudrun/testpermissions.md
new file mode 100644
index 0000000000..52adc3ff87
--- /dev/null
+++ b/packages/docs/docs/cloudrun/testpermissions.md
@@ -0,0 +1,70 @@
+---
+image: /generated/articles-docs-cloudrun-testpermissions.png
+id: testpermissions
+title: testPermissions()
+slug: /cloudrun/testpermissions
+crumb: "Cloud Run API"
+---
+
+Makes a call to the [Test Iam Permissions](https://cloud.google.com/resource-manager/reference/rest/v3/projects/testIamPermissions) method of the Resource Manager API in GCP, which returns the list of permissions the Service Account has on the GCP Project. This is then validated against the list of permissions required for the version of Remotion.
+
+The CLI equivalent is `npx remotion cloudrun permissions`.
+
+The function does not reject with an error if a permission is missing, rather the missing permission is indicated in the return value.
+
+## Example
+
+```ts twoslash
+// @module: esnext
+// @target: es2017
+
+import { testPermissions } from "@remotion/cloudrun";
+
+const { results } = await testPermissions();
+
+for (const result of results) {
+ console.log(result.decision); // "allowed"
+ console.log(result.permissionName); // "iam.serviceAccounts.actAs"
+}
+```
+
+## Arguments
+
+An object with the following property:
+
+### `onTest?`
+
+_optional_
+
+A callback function that gets called every time a new test has been executed. This allows you to react to new test results coming in much faster than waiting for the return value of the function. Example:
+
+```ts twoslash
+// @module: esnext
+// @target: es2017
+
+import { testPermissions } from "@remotion/cloudrun";
+
+const { results } = await testPermissions({
+ onTest: (result) => {
+ console.log(result.decision); // "allowed"
+ console.log(result.permissionName); // "iam.serviceAccounts.actAs"
+ },
+});
+```
+
+## Return value
+
+**An array of objects** containing simulation results of each necessary permission. The objects contain the following keys:
+
+### `decision`
+
+Either `true` or `false`.
+
+### `permissionName`
+
+The identifier of the required permission. See the [Permissions page](/docs/cloudrun/permissions) to see a list of required permissions.
+
+## See also
+
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/cloudrun/src/api/iam-validation/testPermissions.ts)
+- [Permissions](/docs/cloudrun/permissions)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 8af63573c3..e744c43ca9 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -236,9 +236,11 @@ module.exports = {
"cloudrun/speculateservicename",
"cloudrun/deploysite",
"cloudrun/deletesite",
+ "cloudrun/getsites",
"cloudrun/getorcreatebucket",
"cloudrun/rendermediaoncloudrun",
"cloudrun/renderstilloncloudrun",
+ "cloudrun/testpermissions",
],
},
{