Skip to content

🎥 Make videos programmatically with React

validate image exists for service with remotion version

Matt McGillivray0aec3b4c0b82
diff --git a/packages/cloudrun/package.json b/packages/cloudrun/package.json
index d5c0e38cdc..c140fcf89b 100644
--- a/packages/cloudrun/package.json
+++ b/packages/cloudrun/package.json
@@ -12,25 +12,26 @@
"lint": "eslint src --ext ts,tsx"
},
"dependencies": {
+ "@google-cloud/artifact-registry": "^2.2.2",
"@google-cloud/functions-framework": "^3.1.3",
- "@google-cloud/storage": "^6.9.1",
"@google-cloud/run": "^0.4.0",
- "google-auth-library": "^8.7.0",
+ "@google-cloud/storage": "^6.9.1",
"@remotion/bundler": "workspace:*",
"@remotion/cli": "workspace:*",
"@remotion/renderer": "workspace:*",
- "remotion": "workspace:*",
- "got": "11.8.2"
+ "google-auth-library": "^8.7.0",
+ "got": "11.8.2",
+ "remotion": "workspace:*"
},
"devDependencies": {
- "prettier-plugin-organize-imports": "^3.2.2",
- "typescript": "4.7.2",
- "prettier": "^2.7.1",
+ "@jonny/eslint-config": "3.0.266",
"@remotion/compositor-linux-x64-gnu": "workspace:*",
- "ts-node": "^10.8.0",
"@types/minimist": "1.2.2",
"eslint": "8.25.0",
- "@jonny/eslint-config": "3.0.266",
+ "prettier": "^2.7.1",
+ "prettier-plugin-organize-imports": "^3.2.2",
+ "ts-node": "^10.8.0",
+ "typescript": "4.7.2",
"vitest": "0.24.3"
},
"exports": {
diff --git a/packages/cloudrun/src/api/check-if-service-exists.ts b/packages/cloudrun/src/api/check-if-service-exists.ts
index c0e2ca26a8..9cf500001c 100644
--- a/packages/cloudrun/src/api/check-if-service-exists.ts
+++ b/packages/cloudrun/src/api/check-if-service-exists.ts
@@ -7,6 +7,7 @@ import {validateProjectID} from '../shared/validate-project-id';
import {getCloudRunClient} from './helpers/get-cloud-run-client';
export type CheckIfServiceExistsInput = {
+ remotionVersion: string;
memoryLimit: string;
cpuLimit: string;
timeoutSeconds: number;
@@ -17,23 +18,31 @@ export type CheckIfServiceExistsInput = {
/**
* @description Lists Cloud Run services in the project, and checks for a matching name.
* @link https://remotion.dev/docs/lambda/deployfunction
- * @param options.projectID GCP Project ID to deploy the Cloud Run service to.
- * @param options.serviceNameToCheck The name of the Cloud Run service.
- * @param options.region The region you want to deploy your Cloud Run service to.
+ * @param projectID GCP Project ID to deploy the Cloud Run service to.
+ * @param serviceNameToCheck The name of the Cloud Run service.
+ * @param region The region you want to deploy your Cloud Run service to.
* @returns {Promise<protos.google.cloud.run.v2.IService>} If the service exists, the service object will be returned, otherwise false.
*/
-export const checkIfServiceExists = async (
- options: CheckIfServiceExistsInput
-): Promise<protos.google.cloud.run.v2.IService | undefined> => {
- validateGcpRegion(options.region);
- validateProjectID(options.projectID);
+export const checkIfServiceExists = async ({
+ remotionVersion,
+ memoryLimit,
+ cpuLimit,
+ timeoutSeconds,
+ projectID,
+ region,
+}: CheckIfServiceExistsInput): Promise<
+ protos.google.cloud.run.v2.IService | undefined
+> => {
+ validateGcpRegion(region);
+ validateProjectID(projectID);
- const parent = `projects/${options.projectID}/locations/${options.region}`;
+ const parent = `projects/${projectID}/locations/${region}`;
const serviceName = generateServiceName({
- memoryLimit: options.memoryLimit,
- cpuLimit: options.cpuLimit,
- timeoutSeconds: options.timeoutSeconds,
+ remotionVersion,
+ memoryLimit,
+ cpuLimit,
+ timeoutSeconds,
});
const cloudRunClient = getCloudRunClient();
diff --git a/packages/cloudrun/src/api/deploy-service.ts b/packages/cloudrun/src/api/deploy-service.ts
index a7f88b9596..45c51ca82d 100644
--- a/packages/cloudrun/src/api/deploy-service.ts
+++ b/packages/cloudrun/src/api/deploy-service.ts
@@ -1,13 +1,14 @@
import {generateServiceName} from '../shared/generate-service-name';
import {validateGcpRegion} from '../shared/validate-gcp-region';
+import {validateImageRemotionVersion} from '../shared/validate-image-remotion-version';
import {validateProjectID} from '../shared/validate-project-id';
-import {validateRemotionVersion} from '../shared/validate-remotion-version';
import {checkIfServiceExists} from './check-if-service-exists';
import {constructServiceTemplate} from './helpers/construct-service-deploy-request';
import {getCloudRunClient} from './helpers/get-cloud-run-client';
export type DeployServiceInput = {
remotionVersion: string;
+ performImageVersionValidation?: boolean;
memoryLimit?: string;
cpuLimit?: string;
timeoutSeconds?: number;
@@ -25,51 +26,61 @@ export type DeployServiceOutput = {
/**
* @description Creates a Cloud Run service in your project that will be able to render a video in GCP.
* @link https://remotion.dev/docs/lambda/deployfunction
- * @param options.remotionVersion Which version of Remotion to use within the Cloud Run service.
- * @param options.projectID GCP Project ID to deploy the Cloud Run service to.
- * @param options.region The region you want to deploy your Cloud Run service to.
+ * @param remotionVersion Which version of Remotion to use within the Cloud Run service.
+ * @param projectID GCP Project ID to deploy the Cloud Run service to.
+ * @param region The region you want to deploy your Cloud Run service to.
* @returns {Promise<IService>} An object that contains the `functionName` property
*/
-export const deployService = async (
- options: DeployServiceInput
-): Promise<DeployServiceOutput> => {
- validateGcpRegion(options.region);
- validateProjectID(options.projectID);
- validateRemotionVersion(options.remotionVersion);
+export const deployService = async ({
+ remotionVersion,
+ performImageVersionValidation = true, // default value set here
+ memoryLimit,
+ cpuLimit,
+ timeoutSeconds,
+ projectID,
+ region,
+}: DeployServiceInput): Promise<DeployServiceOutput> => {
+ validateGcpRegion(region);
+ validateProjectID(projectID);
+ if (performImageVersionValidation) {
+ validateImageRemotionVersion(remotionVersion);
+ }
- if (!options.memoryLimit) {
- options.memoryLimit = '512Mi';
+ if (!memoryLimit) {
+ memoryLimit = '512Mi';
}
- if (!options.cpuLimit) {
- options.cpuLimit = '1.0';
+ if (!cpuLimit) {
+ cpuLimit = '1.0';
}
- if (!options.timeoutSeconds) {
- options.timeoutSeconds = 300;
+ if (!timeoutSeconds) {
+ timeoutSeconds = 300;
}
- const parent = `projects/${options.projectID}/locations/${options.region}`;
+ const parent = `projects/${projectID}/locations/${region}`;
const cloudRunClient = getCloudRunClient();
const existingService = await checkIfServiceExists({
- memoryLimit: options.memoryLimit,
- cpuLimit: options.cpuLimit,
- timeoutSeconds: options.timeoutSeconds,
- projectID: options.projectID,
- region: options.region,
+ remotionVersion,
+ memoryLimit,
+ cpuLimit,
+ timeoutSeconds,
+ projectID,
+ region,
});
const serviceName = generateServiceName({
- memoryLimit: options.memoryLimit,
- cpuLimit: options.cpuLimit,
- timeoutSeconds: options.timeoutSeconds,
+ memoryLimit,
+ cpuLimit,
+ timeoutSeconds,
+ remotionVersion,
});
if (existingService) {
return {
- fullName: `projects/remotion-6/locations/${options.region}/services/${serviceName}`,
+ fullName: `projects/remotion-6/locations/${region}/services/${serviceName}`,
shortName: serviceName,
uri: null,
alreadyExists: true,
@@ -81,10 +92,10 @@ export const deployService = async (
service: {
// service structure: https://googleapis.dev/nodejs/run/latest/google.cloud.run.v2.IService.html
template: constructServiceTemplate({
- remotionVersion: options.remotionVersion,
- memoryLimit: options.memoryLimit,
- cpuLimit: options.cpuLimit,
- timeoutSeconds: options.timeoutSeconds,
+ remotionVersion,
+ memoryLimit,
+ cpuLimit,
+ timeoutSeconds,
}),
},
serviceId: serviceName,
diff --git a/packages/cloudrun/src/api/get-services.ts b/packages/cloudrun/src/api/get-services.ts
index 4ff09e7b3e..6955ee5b31 100644
--- a/packages/cloudrun/src/api/get-services.ts
+++ b/packages/cloudrun/src/api/get-services.ts
@@ -1,7 +1,8 @@
import {JWT} from 'google-auth-library';
+import {VERSION} from 'remotion/version';
import type {GcpRegion} from '../pricing/gcp-regions';
import {RENDER_SERVICE_PREFIX} from '../shared/constants';
-import {SERVICE_VERSION_STRING} from '../shared/service-version-string';
+import {serviceVersionString} from '../shared/service-version-string';
import type {ServiceInfo} from './get-service-info';
import {getCloudRunClient} from './helpers/get-cloud-run-client';
import type {IService} from './helpers/IService';
@@ -95,7 +96,9 @@ export const getServices = async (
if (options.compatibleOnly) {
remotionServices = services.filter((s) => {
return s.name?.startsWith(
- `${parent}/services/${RENDER_SERVICE_PREFIX}--${SERVICE_VERSION_STRING}--`
+ `${parent}/services/${RENDER_SERVICE_PREFIX}--${serviceVersionString(
+ VERSION
+ )}--`
);
});
} else {
diff --git a/packages/cloudrun/src/cli/commands/services/deploy.ts b/packages/cloudrun/src/cli/commands/services/deploy.ts
index 22c7b18bde..99a17132a2 100644
--- a/packages/cloudrun/src/cli/commands/services/deploy.ts
+++ b/packages/cloudrun/src/cli/commands/services/deploy.ts
@@ -4,7 +4,7 @@ import {allowUnauthenticatedAccess} from '../../../api/cloud-run-allow-unauthent
import {deployService} from '../../../api/deploy-service';
import {generateServiceName} from '../../../shared/generate-service-name';
import {validateGcpRegion} from '../../../shared/validate-gcp-region';
-import {validateRemotionVersion} from '../../../shared/validate-remotion-version';
+import {validateImageRemotionVersion} from '../../../shared/validate-image-remotion-version';
import {parsedCloudrunCli} from '../../args';
import {getGcpRegion} from '../../get-gcp-region';
import {quit} from '../../helpers/quit';
@@ -15,7 +15,7 @@ export const CLOUD_RUN_DEPLOY_SUBCOMMAND = 'deploy';
export const cloudRunDeploySubcommand = async () => {
const region = getGcpRegion();
const projectID = process.env.REMOTION_GCP_PROJECT_ID as string;
- const remotionVersion = VERSION;
+ const remotionVersion = parsedCloudrunCli['remotion-version'] ?? VERSION;
const allowUnauthenticated =
parsedCloudrunCli['allow-unauthenticated'] ?? false;
let memoryLimit = parsedCloudrunCli.memoryLimit ?? '512Mi';
@@ -46,7 +46,7 @@ Validating Deployment of Cloud Run Service:
}
validateGcpRegion(region);
- validateRemotionVersion(remotionVersion);
+ await validateImageRemotionVersion(remotionVersion);
if (projectID === undefined) {
Log.error(`REMOTION_GCP_PROJECT_ID not found in the .env file.`);
@@ -62,6 +62,7 @@ Validating Deployment of Cloud Run Service:
try {
const deployResult = await deployService({
remotionVersion,
+ performImageVersionValidation: false, // this is already performed above
memoryLimit,
cpuLimit,
timeoutSeconds,
@@ -133,6 +134,7 @@ Service Already Deployed! Check GCP Console for Cloud Run URL.
memoryLimit,
cpuLimit,
timeoutSeconds,
+ remotionVersion,
})}.`
)
);
diff --git a/packages/cloudrun/src/shared/generate-service-name.ts b/packages/cloudrun/src/shared/generate-service-name.ts
index a73431a54d..0009a4de71 100644
--- a/packages/cloudrun/src/shared/generate-service-name.ts
+++ b/packages/cloudrun/src/shared/generate-service-name.ts
@@ -1,14 +1,16 @@
import {RENDER_SERVICE_PREFIX} from './constants';
-import {SERVICE_VERSION_STRING} from './service-version-string';
+import {serviceVersionString} from './service-version-string';
export const generateServiceName = ({
memoryLimit,
cpuLimit,
timeoutSeconds,
+ remotionVersion,
}: {
memoryLimit: string;
cpuLimit: string;
timeoutSeconds: number;
+ remotionVersion: string;
}): string => {
const sanitisedCPU = cpuLimit.replace(/\./g, '-').substring(0, 10);
@@ -19,7 +21,7 @@ export const generateServiceName = ({
return [
RENDER_SERVICE_PREFIX,
- SERVICE_VERSION_STRING,
+ serviceVersionString(remotionVersion),
`mem${sanitisedMem}`,
`cpu${sanitisedCPU}`,
`t-${String(timeoutSeconds)}`,
diff --git a/packages/cloudrun/src/shared/service-version-string.ts b/packages/cloudrun/src/shared/service-version-string.ts
index 446999f06c..a79c969763 100644
--- a/packages/cloudrun/src/shared/service-version-string.ts
+++ b/packages/cloudrun/src/shared/service-version-string.ts
@@ -1,5 +1,3 @@
-import {VERSION} from 'remotion/version';
-
-export const SERVICE_VERSION_STRING = VERSION.replace(/\./g, '-')
- .replace(/\+/g, '-')
- .substring(0, 10);
+export const serviceVersionString = (version: string) => {
+ return version.replace(/\./g, '-').replace(/\+/g, '-').substring(0, 10);
+};
diff --git a/packages/cloudrun/src/shared/validate-image-remotion-version.ts b/packages/cloudrun/src/shared/validate-image-remotion-version.ts
new file mode 100644
index 0000000000..744e47f0a4
--- /dev/null
+++ b/packages/cloudrun/src/shared/validate-image-remotion-version.ts
@@ -0,0 +1,20 @@
+import {ArtifactRegistryClient} from '@google-cloud/artifact-registry';
+
+export const validateImageRemotionVersion = async (remotionVersion: string) => {
+ const client = new ArtifactRegistryClient();
+ const listedTags = await client.listTags({
+ parent:
+ 'projects/remotion-dev/locations/us/repositories/cloud-run/packages/render',
+ });
+
+ for (const tag of listedTags[0]) {
+ if (remotionVersion === tag.name?.split('/').pop()) {
+ // if match is found, exit the function
+ return;
+ }
+ }
+
+ throw new Error(
+ `The tag for Remotion version ${remotionVersion} was not found in the cloud run registry image.`
+ );
+};
diff --git a/packages/cloudrun/src/shared/validate-remotion-version.ts b/packages/cloudrun/src/shared/validate-remotion-version.ts
deleted file mode 100644
index fc06f823d6..0000000000
--- a/packages/cloudrun/src/shared/validate-remotion-version.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export const validateRemotionVersion = (remotionVersion: unknown) => {
- // TODO - ensure the image exists at us-docker.pkg.dev/remotion-dev/cloud-run/render:${remotionVersion}
-};
diff --git a/packages/docs/docs/cloudrun.md b/packages/docs/docs/cloudrun.md
index dc04b363b4..1957ed8f78 100644
--- a/packages/docs/docs/cloudrun.md
+++ b/packages/docs/docs/cloudrun.md
@@ -1,5 +1,5 @@
---
-image: /generated/articles-docs-lambda.png
+image: /generated/articles-docs-cloudrun.png
id: cloudrun
sidebar_label: Overview
title: "@remotion/cloudrun"
diff --git a/packages/docs/docs/cloudrun/region-selection.md b/packages/docs/docs/cloudrun/region-selection.md
index 8c1a170c3c..48e9861d4b 100644
--- a/packages/docs/docs/cloudrun/region-selection.md
+++ b/packages/docs/docs/cloudrun/region-selection.md
@@ -8,7 +8,7 @@ crumb: "Cloudrun"
import {GcpRegionList} from '../../components/cloudrun/regions.tsx';
-Before going live with Remotion Cloud Run, you need to think about into which GCP region you are deploying your service and bucket.
+Before going live with Remotion Cloud Run, you need to think about into which GCP region you are deploying your service and bucket (which will hold your sites and renders).
This document explains how to select a region and which considerations you need to make.
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 480e42bc2b..5392ae01f5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -206,6 +206,7 @@ importers:
packages/cloudrun:
specifiers:
+ '@google-cloud/artifact-registry': ^2.2.2
'@google-cloud/functions-framework': ^3.1.3
'@google-cloud/run': ^0.4.0
'@google-cloud/storage': ^6.9.1
@@ -225,6 +226,7 @@ importers:
typescript: 4.7.2
vitest: 0.24.3
dependencies:
+ '@google-cloud/artifact-registry': 2.2.2
'@google-cloud/functions-framework': 3.2.0
'@google-cloud/run': 0.4.2
'@google-cloud/storage': 6.10.1
@@ -7510,6 +7512,16 @@ packages:
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dev: true
+ /@google-cloud/artifact-registry/2.2.2:
+ resolution: {integrity: sha512-Y00m9sYpTdHuW8miR9B/mdG6sK8aTKZMQ7ATUf4ixr5hrq85vokF9IRE/MzGWpGozjYqVFRJpGkiTs+Lx4lKyw==}
+ engines: {node: '>=12.0.0'}
+ dependencies:
+ google-gax: 3.6.0
+ transitivePeerDependencies:
+ - encoding
+ - supports-color
+ dev: false
+
/@google-cloud/functions-framework/3.2.0:
resolution: {integrity: sha512-eFafD4xocXmt3KM1z2X3lARvT2zLuXcw1V+T6xGoOAPfXQDduK77bKpkJx44QCAXh2c8qHYIT6dlSJWu5n5Lmg==}
engines: {node: '>=10.0.0'}
@@ -21161,6 +21173,7 @@ packages:
/source-map/0.6.1:
resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==}
engines: {node: '>=0.10.0'}
+ requiresBuild: true
/source-map/0.7.3:
resolution: {integrity: sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==}