Skip to content

🎥 Make videos programmatically with React

align

Jonny Burger5754c42bf4d9
diff --git a/packages/cloudrun/package.json b/packages/cloudrun/package.json
index af2f76344d..d1f084dc78 100644
--- a/packages/cloudrun/package.json
+++ b/packages/cloudrun/package.json
@@ -10,6 +10,7 @@
"start": "functions-framework --target=TypescriptFunction",
"watch": "tsc -w",
"lint": "eslint src --ext ts,tsx",
+ "test": "vitest --run",
"publish": "node container/submit.mjs"
},
"dependencies": {
@@ -54,4 +55,4 @@
]
}
}
-}
\ No newline at end of file
+}
diff --git a/packages/cloudrun/src/api/get-service-info.ts b/packages/cloudrun/src/api/get-service-info.ts
index 5a0a4c6578..dc7a362eca 100644
--- a/packages/cloudrun/src/api/get-service-info.ts
+++ b/packages/cloudrun/src/api/get-service-info.ts
@@ -1,6 +1,6 @@
import type {GcpRegion} from '../pricing/gcp-regions';
-import {RENDER_SERVICE_PREFIX} from '../shared/constants';
import {getCloudRunClient} from './helpers/get-cloud-run-client';
+import {parseServiceName} from './helpers/parse-service-name';
export type ServiceInfo = {
serviceName: string;
@@ -39,12 +39,11 @@ export const getServiceInfo = async ({
throw new Error(`Service ${serviceName} not found`);
}
- const parent = `projects/${process.env.REMOTION_GCP_PROJECT_ID}/locations/${region}`;
- const deployedRegion = service.name?.split('/')[3] as string;
- const deployedServiceName = service.name?.replace(
- parent + '/services/',
- ''
- ) as string;
+ const {
+ region: deployedRegion,
+ remotionVersion,
+ serviceName: deployedServiceName,
+ } = parseServiceName(service.name as string, region);
return {
serviceName: deployedServiceName,
@@ -53,12 +52,9 @@ export const getServiceInfo = async ({
?.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,
+ remotionVersion,
uri: service.uri as string,
- region: deployedRegion as GcpRegion,
+ region: deployedRegion,
consoleUrl: `https://console.cloud.google.com/run/detail/${deployedRegion}/${deployedServiceName}/logs`,
};
};
diff --git a/packages/cloudrun/src/api/get-services.ts b/packages/cloudrun/src/api/get-services.ts
index d14217300a..86f2a55d84 100644
--- a/packages/cloudrun/src/api/get-services.ts
+++ b/packages/cloudrun/src/api/get-services.ts
@@ -35,14 +35,12 @@ export const getServices = async (
if (params.compatibleOnly) {
remotionServices = services.filter((s) => {
return s.name?.startsWith(
- `${parent}/services/${RENDER_SERVICE_PREFIX}--${serviceVersionString()}--`
+ `${parent}/services/${RENDER_SERVICE_PREFIX}-${serviceVersionString()}-`
);
});
} else {
remotionServices = services.filter((s) => {
- return s.name?.startsWith(
- `${parent}/services/${RENDER_SERVICE_PREFIX}--`
- );
+ return s.name?.startsWith(`${parent}/services/${RENDER_SERVICE_PREFIX}-`);
});
}
diff --git a/packages/cloudrun/src/api/helpers/parse-service-name.ts b/packages/cloudrun/src/api/helpers/parse-service-name.ts
index 2cb507a31a..5159ce759f 100644
--- a/packages/cloudrun/src/api/helpers/parse-service-name.ts
+++ b/packages/cloudrun/src/api/helpers/parse-service-name.ts
@@ -1,26 +1,28 @@
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) => {
+export const parseServiceName = (
+ fullServiceName: string,
+ region: GcpRegion
+) => {
const parent = getGcpParent(region);
- const deployedServiceName = serviceName.replace(
- parent + '/services/',
- ''
- ) as string;
- const deployedRegion = serviceName.split('/')[3] as string;
+ const shortServiceName = fullServiceName.replace(parent + '/services/', '');
+ const deployedRegion = fullServiceName.split('/')[3] as string;
+
+ const matched = shortServiceName.match(/remotion\-(.*)\-mem([0-9])/);
+
+ if (!matched) {
+ throw new Error(`Could not parse service name ${shortServiceName}`);
+ }
return {
- serviceName: deployedServiceName,
- remotionVersion: serviceName
- .replace(parent + '/services/' + RENDER_SERVICE_PREFIX + '--', '')
- .split('--')[0]
- .replace(/-/g, '.') as string,
+ serviceName: shortServiceName,
+ remotionVersion: matched[1],
region: deployedRegion as GcpRegion,
- consoleUrl: `https://console.cloud.google.com/run/detail/${deployedRegion}/${deployedServiceName}/logs`,
+ consoleUrl: `https://console.cloud.google.com/run/detail/${deployedRegion}/${shortServiceName}/logs`,
};
};
diff --git a/packages/cloudrun/src/api/test/service-names.test.ts b/packages/cloudrun/src/api/test/service-names.test.ts
index 2897c42ff9..a7fa2b8611 100644
--- a/packages/cloudrun/src/api/test/service-names.test.ts
+++ b/packages/cloudrun/src/api/test/service-names.test.ts
@@ -1,13 +1,36 @@
import {VERSION} from 'remotion';
import {expect, test} from 'vitest';
+import {GcpRegion} from '../../pricing/gcp-regions';
+import {getGcpParent, parseServiceName} from '../helpers/parse-service-name';
import {speculateServiceName} from '../speculate-service-name';
+const dashedVersion = VERSION.replace(/\./g, '-');
+const region: GcpRegion = 'asia-east1';
+
+process.env.REMOTION_GCP_PROJECT_ID = 'remotion-test-project';
+
test('Parse service names', () => {
- const serviceName = speculateServiceName({
- cpuLimit: '1.0',
- memoryLimit: '2Gi',
- timeoutSeconds: 120,
+ const shortServiceName = speculateServiceName({
+ cpuLimit: '8.0',
+ memoryLimit: '100000k',
+ // max timeout
+ timeoutSeconds: 3600,
});
- expect(serviceName).toBe(`remotion--${VERSION}--mem2gi--cpu1-0--t-120`);
+ expect(shortServiceName).toBe(
+ `remotion-${VERSION.replace(/\./g, '-')}-mem100000k-cpu8-0-t3600`
+ );
+
+ const fullServiceName = `${getGcpParent(
+ region
+ )}/services/${shortServiceName}`;
+
+ const parsed = parseServiceName(fullServiceName, region);
+ expect(parsed).toEqual({
+ consoleUrl: `https://console.cloud.google.com/run/detail/asia-east1/remotion-${dashedVersion}-mem100000k-cpu8-0-t3600/logs`,
+ region: 'asia-east1',
+ remotionVersion: '4-1-0-alpha2',
+ serviceName: `remotion-${dashedVersion}-mem100000k-cpu8-0-t3600`,
+ });
+ expect(shortServiceName.length).toBeLessThanOrEqual(49);
});
diff --git a/packages/cloudrun/src/shared/generate-service-name.ts b/packages/cloudrun/src/shared/generate-service-name.ts
index dcf305eda8..e9b307b7b2 100644
--- a/packages/cloudrun/src/shared/generate-service-name.ts
+++ b/packages/cloudrun/src/shared/generate-service-name.ts
@@ -22,6 +22,6 @@ export const generateServiceName = ({
serviceVersionString(),
`mem${sanitisedMem}`,
`cpu${sanitisedCPU}`,
- `t-${String(timeoutSeconds)}`,
- ].join('--');
+ `t${String(timeoutSeconds)}`,
+ ].join('-');
};
diff --git a/packages/cloudrun/src/shared/service-version-string.ts b/packages/cloudrun/src/shared/service-version-string.ts
index e4640656c5..d40b588f2b 100644
--- a/packages/cloudrun/src/shared/service-version-string.ts
+++ b/packages/cloudrun/src/shared/service-version-string.ts
@@ -1,5 +1,5 @@
import {VERSION} from 'remotion/version';
export const serviceVersionString = () => {
- return VERSION.replace(/\./g, '-').replace(/\+/g, '-').substring(0, 10);
+ return VERSION.replace(/\./g, '-').replace(/\+/g, '-');
};