Skip to content

🎥 Make videos programmatically with React

cloud run documentation

Matt McGillivray80f2e9d2f0f9
diff --git a/packages/cloudrun/src/api/deploy-site.ts b/packages/cloudrun/src/api/deploy-site.ts
index 9d3d22977d..8347ed5709 100644
--- a/packages/cloudrun/src/api/deploy-site.ts
+++ b/packages/cloudrun/src/api/deploy-site.ts
@@ -19,9 +19,11 @@ export type DeploySiteInput = {
onBundleProgress?: (progress: number) => void;
onUploadProgress?: (upload: UploadDirProgress) => void;
webpackOverride?: WebpackOverrideFn;
+ ignoreRegisterRootWarning?: boolean;
enableCaching?: boolean;
publicDir?: string | null;
rootDir?: string;
+ bypassBucketNameValidation?: boolean;
};
};
@@ -67,12 +69,15 @@ export const deploySite = async ({
bucketName,
prefix: subFolder,
}),
- bundleSite(entryPoint, options?.onBundleProgress ?? (() => undefined), {
+ bundleSite({
publicPath: `/${bucketName}/${subFolder}/`,
webpackOverride: options?.webpackOverride ?? ((f) => f),
enableCaching: options?.enableCaching ?? true,
publicDir: options?.publicDir,
rootDir: options?.rootDir,
+ ignoreRegisterRootWarning: options?.ignoreRegisterRootWarning,
+ onProgress: options?.onBundleProgress ?? (() => undefined),
+ entryPoint,
}),
]);
diff --git a/packages/cloudrun/src/api/get-or-create-bucket.ts b/packages/cloudrun/src/api/get-or-create-bucket.ts
index b23df792dc..d6a0963983 100644
--- a/packages/cloudrun/src/api/get-or-create-bucket.ts
+++ b/packages/cloudrun/src/api/get-or-create-bucket.ts
@@ -17,6 +17,7 @@ export type GetOrCreateBucketInput = {
export type GetOrCreateBucketOutput = {
bucketName: string;
+ alreadyExisted: boolean;
};
/**
* @description Creates a bucket for Remotion Cloud Run in your GCP Project, in a particular region. If one already exists, it will get returned instead.
@@ -42,6 +43,7 @@ export const getOrCreateBucket = async (
params?.updateBucketState?.('Using existing bucket');
return {
bucketName: remotionBuckets[0].name,
+ alreadyExisted: true,
};
}
@@ -56,7 +58,7 @@ export const getOrCreateBucket = async (
params.updateBucketState?.('Created bucket');
- return {bucketName};
+ return {bucketName, alreadyExisted: false};
}
throw new Error(
diff --git a/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar b/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar
index dbcf885dd8..31d8f5e82f 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 6eb841bbf7..2216a7252a 100644
--- a/packages/cloudrun/src/index.ts
+++ b/packages/cloudrun/src/index.ts
@@ -1,4 +1,5 @@
import {deleteService} from './api/delete-service';
+import {deleteSite} from './api/delete-site';
import type {
DeployServiceInput,
DeployServiceOutput,
@@ -15,11 +16,13 @@ import {renderMediaOnCloudrun} from './api/render-media-on-cloudrun';
import {renderStillOnCloudrun} from './api/render-still-on-cloudrun';
import type {RenderMediaOnCloudrunOutput} from './functions/helpers/payloads';
import {CloudrunInternals} from './internals';
+import type {GcpRegion} from './pricing/gcp-regions';
export {
CloudrunInternals,
deployService,
deploySite,
+ deleteSite,
deleteService,
getServices,
getOrCreateBucket,
@@ -30,6 +33,7 @@ export {
getSites,
};
export type {
+ GcpRegion,
DeployServiceInput,
DeployServiceOutput,
RenderMediaOnCloudrunOutput,
diff --git a/packages/docs/docs/cloudrun/deletesite.md b/packages/docs/docs/cloudrun/deletesite.md
new file mode 100644
index 0000000000..ea3990f1fd
--- /dev/null
+++ b/packages/docs/docs/cloudrun/deletesite.md
@@ -0,0 +1,63 @@
+---
+image: /generated/articles-docs-cloudrun-deletesite.png
+id: deletesite
+title: deleteSite()
+slug: /cloudrun/deletesite
+crumb: "Cloud Run API"
+---
+
+Removes a Remotion project from your Cloud Storage bucket.
+
+Each project is located in the `sites/` subdirectory of your Cloud Storage bucket. Calling this function is equivalent of deleting all files inside a subfolder of your `sites/` subdirectory.
+
+## Example
+
+Gets all sites and deletes them.
+
+```ts twoslash
+// @module: ESNext
+// @target: ESNext
+import { GcpRegion, deleteSite, getSites } from "@remotion/cloudrun";
+
+const region: GcpRegion = "australia-southeast1";
+
+const { sites } = await getSites(region);
+
+for (const site of sites) {
+ await deleteSite({
+ bucketName: site.bucketName,
+ siteName: site.id,
+ });
+ console.log(`Site ${site.id} deleted.`);
+}
+```
+
+## Arguments
+
+An object with the following properties:
+
+### `bucketName`
+
+_string_
+
+The name of the Cloud Storage bucket in which your site resides in.
+
+### `siteName`
+
+_string_
+
+The unique ID of the project you want to delete.
+
+## Return value
+
+A promise resolving to an object with the following property:
+
+### `totalSizeInBytes`
+
+Nothing. If the deletion failed, the service rejects with an error.
+
+## See also
+
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/cloudrun/src/api/delete-site.ts)
+- [getSites()](/docs/cloudrun/getsites)
+- [deploySite()](/docs/cloudrun/deploysite)
diff --git a/packages/docs/docs/cloudrun/deploysite.md b/packages/docs/docs/cloudrun/deploysite.md
index 1333ed77b7..bfcf87be7c 100644
--- a/packages/docs/docs/cloudrun/deploysite.md
+++ b/packages/docs/docs/cloudrun/deploysite.md
@@ -1 +1,131 @@
-TODO
+---
+image: /generated/articles-docs-cloudrun-deploysite.png
+id: deploysite
+title: deploySite()
+slug: /cloudrun/deploysite
+crumb: "Cloud Run API"
+---
+
+Takes a Remotion project, bundles it and uploads it to an Cloud Storage bucket. Once uploaded, a Cloud Run service can render any composition in the Remotion project by specifying the URL.
+
+- If you make changes locally, you need to redeploy the site. You can use [`siteName`](#sitename) to overwrite the previous site.
+- Note that the Remotion project will be deployed to a subdirectory, not the root of the domain. Therefore you must ensure that if you have specified paths in your Remotion project, they are able to handle this scenario.
+- Before calling this function, you should create a bucket, see [`getOrCreateBucket()`](/docs/cloudrun/getorcreatebucket).
+
+## Example
+
+```ts twoslash
+// @module: esnext
+// @target: es2017
+import { deploySite } from "@remotion/cloudrun";
+import path from "path";
+
+const { serveUrl } = await deploySite({
+ entryPoint: path.resolve(process.cwd(), "src/index.ts"),
+ bucketName: "remotioncloudrun-c7fsl3d",
+ options: {
+ onBundleProgress: (progress) => {
+ // Progress is between 0 and 100
+ console.log(`Bundle progress: ${progress}%`);
+ },
+ onUploadProgress: ({
+ totalFiles,
+ filesUploaded,
+ totalSize,
+ sizeUploaded,
+ }) => {
+ console.log(
+ `Upload progress: Total files ${totalFiles}, Files uploaded ${filesUploaded}, Total size ${totalSize}, Size uploaded ${sizeUploaded}`
+ );
+ },
+ },
+});
+console.log(serveUrl);
+```
+
+## Arguments
+
+An object with the following properties:
+
+### `entryPoint`
+
+An absolute path pointing to the entry point of your Remotion project. [Usually the entry point in your Remotion project is stored at `src/entry.tsx`](/docs/terminology#entry-point).
+
+### `bucketName`
+
+The bucket to where the website will be deployed. The bucket must have been created by Remotion Cloud Run.
+
+### `siteName?`
+
+_optional_
+
+Specify the subfolder in your Cloud Storage bucket that you want the site to deploy to. If you omit this property, a new subfolder with a random name will be created. If a site already exists with the name you passed, it will be overwritten. Can only contain the following characters: `0-9`, `a-z`, `A-Z`, `-`, `!`, `_`, `.`, `*`, `'`, `(`, `)`
+
+### `options?`
+
+_optional_
+
+An object with the following properties:
+
+#### `onBundleProgress`
+
+Callback from Webpack when the bundling has progressed. Passes a number between 0 and 100 to the callback, see example at the top of the page.
+
+#### `onUploadProgress`
+
+Callback function that gets called when uploading of the assets has progressed. Passes an object with the following properties to the callback:
+
+- `totalFiles` (_number_): Total number of files in the bundle.
+- `filesUploaded` (_number_): Number of files that have been fully uploaded so far.
+- `totalSize` (_number_): Total size in bytes of all the files in the bundle.
+- `sizeUploaded` (_number_): Amount of bytes uploaded so far.
+
+#### `webpackOverride`
+
+Allows to pass a custom webpack override. See [`bundle()` -> webpackOverride](/docs/bundle#webpackoverride) for more information.
+
+#### `enableCaching`
+
+Whether webpack caching should be enabled. See [`bundle()` -> enableCaching](/docs/bundle#enablecaching) for more information.
+
+#### `publicDir`
+
+Set the directory in which the files that can be loaded using [`staticFile()`](/docs/staticfile) are located. By default it is the folder `public/` located in the [Remotion Root](/docs/terminology#remotion-root) folder. If you pass a relative path, it will be resolved against the [Remotion Root](/docs/terminology#remotion-root).
+
+#### `rootDir`
+
+The directory in which the Remotion project is rooted in. This should be set to the directory that contains the `package.json` which installs Remotion. By default, it is the current working directory.
+
+:::note
+The current working directory is the directory from which your program gets executed from. It is not the same as the file where bundle() gets called.
+:::
+
+#### `ignoreRegisterRootWarning`
+
+Ignore an error that gets thrown if you pass an entry point file which does not contain `registerRoot`.
+
+## Return value
+
+An object with the following values:
+
+- `serveUrl` _(string)_: An URL such as `https://storage.googleapis.com/remotioncloudrun-123asd321/sites/abcdefgh/index.html`.
+
+ You can use this "Serve URL" to render a video on Remotion Cloud Run using:
+
+ - The [`npx remotion cloudrun render <media | still>`](/docs/cloudrun/cli/render) command
+ - The [`renderMediaOnCloudrun()`](/docs/cloudrun/rendermediaoncloudrun) and [`renderStillOnCloudrun()`](/docs/cloudrun/renderstilloncloudrun) functions.
+ - Locally using the [`renderMedia()`](/docs/renderer/render-media) and [`renderStill()`](/docs/renderer/render-still) functions.
+ - Locally using the [`npx remotion render`](/docs/cli) and [`npx remotion still`](/docs/cli) commands
+
+ If you are rendering on Cloud Run, you can also pass the site name (in this case `abcdefgh`) as an abbreviation.
+
+- `siteName` _(string)_: The identifier of the site that was given. Is either the site name that you have passed into this function, or a random string that was generated if you didn't pass a site name.
+
+- `stats`: An object with 3 entries: `uploadedFiles`, `deletedFiles` and `untouchedFiles`. Each one is a `number`.
+
+## See also
+
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/cloudrun/src/api/deploy-site.ts)
+- [CLI equivalent: `npx remotion cloudrun sites create`](/docs/cloudrun/cli/sites#create)
+- [getSites()](/docs/cloudrun/getsites)
+- [deleteSite()](/docs/cloudrun/deletesite)
diff --git a/packages/docs/docs/cloudrun/getorcreatebucket.md b/packages/docs/docs/cloudrun/getorcreatebucket.md
new file mode 100644
index 0000000000..732002b330
--- /dev/null
+++ b/packages/docs/docs/cloudrun/getorcreatebucket.md
@@ -0,0 +1,59 @@
+---
+image: /generated/articles-docs-cloudrun-getorcreatebucket.png
+id: getorcreatebucket
+title: getOrCreateBucket()
+slug: /cloudrun/getorcreatebucket
+crumb: "Cloud Run API"
+---
+
+Creates a Cloud Storage bucket for Remotion Cloud Run in your GCP project. If one already exists, it will get returned instead.
+
+**Only 1 bucket per region** is necessary for Remotion Cloud Run to function.
+
+```ts twoslash
+// @module: ESNext
+// @target: ESNext
+import { getOrCreateBucket } from "@remotion/cloudrun";
+
+const { bucketName, alreadyExisted } = await getOrCreateBucket({
+ region: "us-east1",
+});
+
+console.log(bucketName); // "remotioncloudrun-32df3p"
+```
+
+## Arguments
+
+An object with the following properties:
+
+### `region`
+
+The [GCP region](/docs/cloudrun/region-selection) which you want to create a bucket in.
+
+### `updateBucketState?`
+
+_optional_
+
+Callback function that returns a state (_string_) of operation. Used by the CLI to provide a progress update. State will be one of the following;
+
+- Checking for existing bucket
+- Creating new bucket
+- Created bucket
+- Using existing bucket
+
+## Return value
+
+A promise resolving to an object with the following properties:
+
+### `bucketName`
+
+The name of your bucket that was found or created.
+
+### `alreadyExisted`
+
+A boolean indicating whether the bucket already existed or was newly created.
+
+## See also
+
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/cloudrun/src/api/get-or-create-bucket.ts)
+- [getServices()](/docs/cloudrun/getservices)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index b96fb7e910..8af63573c3 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -235,6 +235,8 @@ module.exports = {
"cloudrun/deleteservice",
"cloudrun/speculateservicename",
"cloudrun/deploysite",
+ "cloudrun/deletesite",
+ "cloudrun/getorcreatebucket",
"cloudrun/rendermediaoncloudrun",
"cloudrun/renderstilloncloudrun",
],