🎥 Make videos programmatically with React
service names parser
Jonny Burger8ab2a13fe1cc
diff --git a/packages/cloudrun/.eslintrc b/packages/cloudrun/.eslintrcindex 1a478661e6..6e9a0dc0ea 100644--- a/packages/cloudrun/.eslintrc+++ b/packages/cloudrun/.eslintrc@@ -11,7 +11,8 @@"@remotion/cli/*/src/*"]}- ]+ ],+ "no-restricted-globals": ["error", "parent"]},"overrides": [{diff --git a/packages/cloudrun/src/api/get-services.ts b/packages/cloudrun/src/api/get-services.tsindex 757cd6fa48..d14217300a 100644--- a/packages/cloudrun/src/api/get-services.ts+++ b/packages/cloudrun/src/api/get-services.ts@@ -4,6 +4,7 @@ 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';+import {getGcpParent, parseServiceName} from './helpers/parse-service-name';export type GetServicesInput = {region: GcpRegion;@@ -23,7 +24,7 @@ export const getServices = async (): Promise<ServiceInfo[]> => {const cloudRunClient = getCloudRunClient();- const parent = `projects/${process.env.REMOTION_GCP_PROJECT_ID}/locations/${params.region}`;+ const parent = getGcpParent(params.region);const [services] = await cloudRunClient.listServices({parent,@@ -46,26 +47,22 @@ export const getServices = async (}return remotionServices.map((service): ServiceInfo => {- const deployedServiceName = service.name?.replace(- parent + '/services/',- ''- ) as string;- const deployedRegion = service.name?.split('/')[3] as string;+ const {consoleUrl, region, remotionVersion, serviceName} = parseServiceName(+ service.name as string,+ params.region+ );return {- serviceName: deployedServiceName,+ consoleUrl,+ region,+ remotionVersion,+ serviceName,timeoutInSeconds: service.template?.timeout?.seconds as number,memoryLimit: service.template?.containers?.[0].resources?.limits?.memory as string,cpuLimit: service.template?.containers?.[0].resources?.limits?.cpu as string,- remotionVersion: service.name- ?.replace(parent + '/services/' + RENDER_SERVICE_PREFIX + '--', '')- .split('--')[0]- .replace(/-/g, '.') as string,uri: service.uri as string,- region: deployedRegion as GcpRegion,- consoleUrl: `https://console.cloud.google.com/run/detail/${deployedRegion}/${deployedServiceName}/logs`,};});};diff --git a/packages/cloudrun/src/api/helpers/parse-service-name.ts b/packages/cloudrun/src/api/helpers/parse-service-name.tsnew file mode 100644index 0000000000..2cb507a31a--- /dev/null+++ b/packages/cloudrun/src/api/helpers/parse-service-name.ts@@ -0,0 +1,26 @@+import {GcpRegion} from '../../pricing/gcp-regions';+import {RENDER_SERVICE_PREFIX} from '../../shared/constants';++export const getGcpParent = (region: GcpRegion) => {+ const parent = `projects/${process.env.REMOTION_GCP_PROJECT_ID}/locations/${region}`;+ return parent;+};++export const parseServiceName = (serviceName: string, region: GcpRegion) => {+ const parent = getGcpParent(region);+ const deployedServiceName = serviceName.replace(+ parent + '/services/',+ ''+ ) as string;+ const deployedRegion = serviceName.split('/')[3] as string;++ return {+ serviceName: deployedServiceName,+ remotionVersion: serviceName+ .replace(parent + '/services/' + RENDER_SERVICE_PREFIX + '--', '')+ .split('--')[0]+ .replace(/-/g, '.') as string,+ region: deployedRegion as GcpRegion,+ consoleUrl: `https://console.cloud.google.com/run/detail/${deployedRegion}/${deployedServiceName}/logs`,+ };+};diff --git a/packages/cloudrun/src/api/test/service-names.test.ts b/packages/cloudrun/src/api/test/service-names.test.tsnew file mode 100644index 0000000000..2897c42ff9--- /dev/null+++ b/packages/cloudrun/src/api/test/service-names.test.ts@@ -0,0 +1,13 @@+import {VERSION} from 'remotion';+import {expect, test} from 'vitest';+import {speculateServiceName} from '../speculate-service-name';++test('Parse service names', () => {+ const serviceName = speculateServiceName({+ cpuLimit: '1.0',+ memoryLimit: '2Gi',+ timeoutSeconds: 120,+ });++ expect(serviceName).toBe(`remotion--${VERSION}--mem2gi--cpu1-0--t-120`);+});