🎥 Make videos programmatically with React
deploy service with memory limit
Matt McGillivray00be3f901a58
diff --git a/packages/gcp/src/api/deploy-new-cloud-run.ts b/packages/gcp/src/api/deploy-new-cloud-run.tsindex 8ce36b318d..a8305521a8 100644--- a/packages/gcp/src/api/deploy-new-cloud-run.ts+++ b/packages/gcp/src/api/deploy-new-cloud-run.ts@@ -1,6 +1,7 @@import {validateGcpRegion} from '../shared/validate-gcp-region';import {validateProjectID} from '../shared/validate-project-id';import {validateRemotionVersion} from '../shared/validate-remotion-version';+import {validateServiceMemory} from '../shared/validate-service-memory';import {validateServiceName} from '../shared/validate-service-name';import {getCloudRunClient} from './helpers/get-cloud-run-client';import type {IService} from './helpers/IService';@@ -8,6 +9,7 @@ import type {IService} from './helpers/IService';export type DeployCloudRunInput = {remotionVersion: string;serviceName: string;+ memory: string;projectID: string;region: string;overwriteService: boolean;@@ -27,6 +29,7 @@ export const deployNewCloudRun = async (): Promise<IService> => {validateGcpRegion(options.region);validateServiceName(options.serviceName);+ validateServiceMemory(options.memory);validateProjectID(options.projectID);validateRemotionVersion(options.remotionVersion);@@ -43,6 +46,11 @@ export const deployNewCloudRun = async (containers: [{image: `us-docker.pkg.dev/remotion-dev/cloud-run/render:${options.remotionVersion}`,+ resources: {+ limits: {+ memory: options.memory,+ },+ },},],},diff --git a/packages/gcp/src/cli/commands/cloud-run/deploy.ts b/packages/gcp/src/cli/commands/cloud-run/deploy.tsindex 683d2f0a1e..96d52e5032 100644--- a/packages/gcp/src/cli/commands/cloud-run/deploy.ts+++ b/packages/gcp/src/cli/commands/cloud-run/deploy.ts@@ -9,6 +9,7 @@ import {validateGcpRegion} from '../../../shared/validate-gcp-region';import {validateOverwrite} from '../../../shared/validate-overwrite';import {validateProjectID} from '../../../shared/validate-project-id';import {validateRemotionVersion} from '../../../shared/validate-remotion-version';+import {validateServiceMemory} from '../../../shared/validate-service-memory';import {validateServiceName} from '../../../shared/validate-service-name';import {parsedGcpCli} from '../../args';import {getGcpRegion} from '../../get-gcp-region';@@ -24,9 +25,11 @@ export const cloudRunDeploySubcommand = async () => {const remotionVersion = parsedGcpCli['remotion-version'] ?? VERSION;const allowUnauthenticated = parsedGcpCli['allow-unauthenticated'] ?? false;const overwriteService = parsedGcpCli['overwrite-service'] ?? false;+ const memory = parsedGcpCli.memory ?? '512Mi';validateGcpRegion(region);validateServiceName(serviceName);+ validateServiceMemory(memory);validateProjectID(projectID);validateRemotionVersion(remotionVersion);validateOverwrite(overwriteService);@@ -92,7 +95,7 @@ GCP Console URL = https://console.cloud.google.com/run/detail/${region}/${servic}} else {Log.info(CliInternals.chalk.gray('deploy cancelled'));- quit(1); // TODO: Check with Jonny what to pass to quit+ quit(1); // TODO: Check with Jonny what to pass to quit - 0 or 1?}} else {// if no existing service, deploy new service@@ -101,6 +104,7 @@ GCP Console URL = https://console.cloud.google.com/run/detail/${region}/${servicconst deployResult = await deployNewCloudRun({remotionVersion,serviceName,+ memory,projectID,region,overwriteService,diff --git a/packages/gcp/src/shared/validate-service-memory.ts b/packages/gcp/src/shared/validate-service-memory.tsnew file mode 100644index 0000000000..c3ce6bcb67--- /dev/null+++ b/packages/gcp/src/shared/validate-service-memory.ts@@ -0,0 +1,18 @@+export const validateServiceMemory = (serviceMemory: unknown) => {+ if (typeof serviceMemory !== 'string') {+ throw new TypeError(+ `The 'memory' argument must be a string, but is ${JSON.stringify(+ serviceMemory+ )}`+ );+ }++ // Check if the service memory is a valid value for a GCP CLoud Run service+ if (!serviceMemory.match(/^(128Mi|256Mi|512Mi|1Gi|2Gi|4Gi|8Gi|16Gi|32Gi)$/)) {+ throw new Error(+ 'The `serviceMemory` must match the RegExp `/^(128Mi|256Mi|512Mi|1Gi|2Gi|4Gi|8Gi|16Gi|32Gi)$/`. This means it may only be a valid GCP Cloud Run memory value. You passed: ' ++ serviceMemory ++ '. Check for invalid characters.'+ );+ }+};