Skip to content

🎥 Make videos programmatically with React

fix(cloudrun): check for missing credentials

Jonny Burger1b80bbd4ae07
diff --git a/packages/cloudrun/src/api/deploy-service.ts b/packages/cloudrun/src/api/deploy-service.ts
index 11dfe02e1e..a9c832bf87 100644
--- a/packages/cloudrun/src/api/deploy-service.ts
+++ b/packages/cloudrun/src/api/deploy-service.ts
@@ -62,7 +62,7 @@ const deployServiceRaw = async ({
validateGcpRegion(region);
validateProjectID(projectID);
if (performImageVersionValidation) {
- validateImageRemotionVersion();
+ await validateImageRemotionVersion();
}
const parent = `projects/${projectID}/locations/${region}`;
diff --git a/packages/cloudrun/src/api/helpers/get-auth-client-for-url.ts b/packages/cloudrun/src/api/helpers/get-auth-client-for-url.ts
index 31f31c2686..c79e615ece 100644
--- a/packages/cloudrun/src/api/helpers/get-auth-client-for-url.ts
+++ b/packages/cloudrun/src/api/helpers/get-auth-client-for-url.ts
@@ -3,8 +3,11 @@ import {
getProjectId,
isInCloudTask,
} from '../../functions/helpers/is-in-cloud-task';
+import {checkCredentials} from '../../shared/check-credentials';
export const getAuthClientForUrl = async (url: string) => {
+ checkCredentials();
+
let auth = new GoogleAuth();
if (isInCloudTask()) {
auth = new GoogleAuth({
diff --git a/packages/cloudrun/src/api/helpers/get-cloud-logging-client.ts b/packages/cloudrun/src/api/helpers/get-cloud-logging-client.ts
index 33f9402195..ade358bff5 100644
--- a/packages/cloudrun/src/api/helpers/get-cloud-logging-client.ts
+++ b/packages/cloudrun/src/api/helpers/get-cloud-logging-client.ts
@@ -3,10 +3,13 @@ import {
getProjectId,
isInCloudTask,
} from '../../functions/helpers/is-in-cloud-task';
+import {checkCredentials} from '../../shared/check-credentials';
const {LoggingServiceV2Client} = v2;
export const getCloudLoggingClient = () => {
+ checkCredentials();
+
if (isInCloudTask()) {
return new LoggingServiceV2Client({
projectId: getProjectId(),
diff --git a/packages/cloudrun/src/api/helpers/get-cloud-run-client.ts b/packages/cloudrun/src/api/helpers/get-cloud-run-client.ts
index 0caaada0d1..db1feda270 100644
--- a/packages/cloudrun/src/api/helpers/get-cloud-run-client.ts
+++ b/packages/cloudrun/src/api/helpers/get-cloud-run-client.ts
@@ -3,10 +3,13 @@ import {
getProjectId,
isInCloudTask,
} from '../../functions/helpers/is-in-cloud-task';
+import {checkCredentials} from '../../shared/check-credentials';
const {ServicesClient} = v2;
export const getCloudRunClient = () => {
+ checkCredentials();
+
if (isInCloudTask()) {
return new ServicesClient({
projectId: getProjectId(),
diff --git a/packages/cloudrun/src/api/helpers/get-cloud-storage-client.ts b/packages/cloudrun/src/api/helpers/get-cloud-storage-client.ts
index 7a26bbd2f0..256b8b8c4e 100644
--- a/packages/cloudrun/src/api/helpers/get-cloud-storage-client.ts
+++ b/packages/cloudrun/src/api/helpers/get-cloud-storage-client.ts
@@ -3,8 +3,11 @@ import {
getProjectId,
isInCloudTask,
} from '../../functions/helpers/is-in-cloud-task';
+import {checkCredentials} from '../../shared/check-credentials';
export const getCloudStorageClient = () => {
+ checkCredentials();
+
if (isInCloudTask()) {
return new Storage({
projectId: getProjectId(),
diff --git a/packages/cloudrun/src/api/helpers/get-resource-manager-client.ts b/packages/cloudrun/src/api/helpers/get-resource-manager-client.ts
index af02259aa3..2081ec0c18 100644
--- a/packages/cloudrun/src/api/helpers/get-resource-manager-client.ts
+++ b/packages/cloudrun/src/api/helpers/get-resource-manager-client.ts
@@ -3,9 +3,12 @@ import {
getProjectId,
isInCloudTask,
} from '../../functions/helpers/is-in-cloud-task';
+import {checkCredentials} from '../../shared/check-credentials';
const {ProjectsClient} = v3;
export const getResourceManagerClient = () => {
+ checkCredentials();
+
if (isInCloudTask()) {
return new ProjectsClient({
projectId: getProjectId(),
diff --git a/packages/cloudrun/src/cli/index.ts b/packages/cloudrun/src/cli/index.ts
index ef02743490..896f2de394 100644
--- a/packages/cloudrun/src/cli/index.ts
+++ b/packages/cloudrun/src/cli/index.ts
@@ -1,6 +1,8 @@
import {CliInternals} from '@remotion/cli';
import type {LogLevel} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
+import {checkCredentials} from '../shared/check-credentials';
+import {setIsCli} from '../shared/is-cli';
import {parsedCloudrunCli} from './args';
import {PERMISSIONS_COMMAND, permissionsCommand} from './commands/permissions';
import {REGIONS_COMMAND, regionsCommand} from './commands/regions';
@@ -22,6 +24,10 @@ const matchCommand = (
quit(0);
}
+ if (args[0] !== REGIONS_COMMAND) {
+ checkCredentials();
+ }
+
if (args[0] === RENDER_COMMAND) {
return renderCommand(args.slice(1), remotionRoot, logLevel);
}
@@ -61,6 +67,8 @@ export const executeCommand = async (
remotionRoot: string,
logLevel: LogLevel,
) => {
+ setIsCli(true);
+
try {
await matchCommand(args, remotionRoot, logLevel);
} catch (err) {
diff --git a/packages/cloudrun/src/shared/check-credentials.ts b/packages/cloudrun/src/shared/check-credentials.ts
new file mode 100644
index 0000000000..f4b67cce70
--- /dev/null
+++ b/packages/cloudrun/src/shared/check-credentials.ts
@@ -0,0 +1,30 @@
+import {isInCloudTask} from '../functions/helpers/is-in-cloud-task';
+import {DOCS_URL} from './docs-url';
+import {getIsCli} from './is-cli';
+
+export const checkCredentials = () => {
+ if (isInCloudTask()) {
+ return;
+ }
+
+ for (const variable of [
+ 'REMOTION_GCP_PROJECT_ID',
+ 'REMOTION_GCP_CLIENT_EMAIL',
+ 'REMOTION_GCP_PRIVATE_KEY',
+ ]) {
+ if (!process.env[variable]) {
+ throw new Error(
+ [
+ `You have tried to call a Remotion Cloud Run function, but have not set the environment variable ${variable}.`,
+ getIsCli()
+ ? null
+ : `- Environment variables from a '.env' file are not automatically read if you are calling the Node.JS APIs, in that case you need to load the file yourself or set the environment variables manually.`,
+ `- Please refer to the Remotion Cloud Run docs (${DOCS_URL}/docs/cloudrun/setup) to see how to generate the credentials for your GCP account and then set the environment variables.`,
+ `- To generate a new '.env' file, see: ${DOCS_URL}/docs/cloudrun/generate-env`,
+ ]
+ .filter(Boolean)
+ .join('\n'),
+ );
+ }
+ }
+};
diff --git a/packages/cloudrun/src/shared/is-cli.ts b/packages/cloudrun/src/shared/is-cli.ts
new file mode 100644
index 0000000000..d62d3ff01b
--- /dev/null
+++ b/packages/cloudrun/src/shared/is-cli.ts
@@ -0,0 +1,7 @@
+let isCli = false;
+
+export const getIsCli = () => isCli;
+
+export const setIsCli = (cli: boolean) => {
+ isCli = cli;
+};
diff --git a/packages/cloudrun/src/shared/validate-image-remotion-version.ts b/packages/cloudrun/src/shared/validate-image-remotion-version.ts
index e2159f49aa..2e6dcd9f97 100644
--- a/packages/cloudrun/src/shared/validate-image-remotion-version.ts
+++ b/packages/cloudrun/src/shared/validate-image-remotion-version.ts
@@ -1,7 +1,10 @@
import {ArtifactRegistryClient} from '@google-cloud/artifact-registry';
import {VERSION} from 'remotion/version';
+import {checkCredentials} from './check-credentials';
export const validateImageRemotionVersion = async () => {
+ checkCredentials();
+
const client = new ArtifactRegistryClient({
projectId: process.env.REMOTION_GCP_PROJECT_ID,
credentials: {