🎥 Make videos programmatically with React
calls are authenticated, now using .env keys
Matt McGillivrayb2118671b0e5
diff --git a/.gitignore b/.gitignoreindex d14d1832a6..5b9b4bc471 100644--- a/.gitignore+++ b/.gitignore@@ -14,4 +14,3 @@ packages/example/out.vercelpackages/renderer/targetpackages/gcp/src/remotion-lambda-gcp.code-workspace-sa-key*.jsondiff --git a/packages/example/sa-key.json b/packages/example/sa-key.jsonnew file mode 100644index 0000000000..75fe7b757a--- /dev/null+++ b/packages/example/sa-key.json@@ -0,0 +1,12 @@+{+ "type": "service_account",+ "project_id": "new-remotion-project",+ "private_key_id": "f06e06b0933a468ccacbe8f29c9f50b03299ff17",+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC4K1M4IOWiRVcR\nsENC5ESTrRKdmVjE5Spea7vBC1aHeyDaxQeEupEZqhqWgGktQK+EgPagfrrVrhF9\nqJ9beReI0FI/nfuNXp5VdeZF2ZPAn5Oo8TtUqYNuhokZ02GwuE30ZZW9YK6XwlOb\nPVbdM8UV3Ewc4Cb2oPI5Nx/8SYReIAsFToVgIqR5OfQo2kgjnzg0H9fu0pT07l5X\namFeH3q2JH46DqRcGYACqRFKAD9bOqsCW7QMpwvkeCbSzXTduSu/0RHXYWpsVkTS\nBPvN+G+Nmp94b5nCwnVvydtqBsAJfedtUnS2b3ElTnW7OstZ91ycCiAn7/1ng8T+\ngfZ28CgtAgMBAAECggEAN9KGBG7QO8nJtOZY1NcsxBhDGrrm0bNmjr0X6VD+9szG\n7hiniT8liQJq0bB1cM55BPA0EPyos+jxi0WHm+nNzN3b+EVyAG0sD9pPJF/pLYsQ\n7jXEVoqU+HTV7JqKM08B7fC2nPLHqN8xiU3j3ON6uwANn/j/RmUNVnNTghxkf0Sy\nUDul0myCnHF/S562S2XNXYr0DrRCBDFzIg9rIrgy51mWK6pCqC8KLsVYpqeFmkxZ\nSSyml+asIF5C+sFXAcgCTu0aaADydJ2V1GXQmlbhHUaB2J3r0YxP8+XCPdxEDPao\npszxBkLt54UR/8AzRVB0ne4pRfYPGpgEiNp33lCzfwKBgQDlJQjnoet8LOKtqZ+e\ndcZPlUV0JMOuTM3vjWfYV2vKf8usvqw5+e76cOAg1l7/meCbTMtkWXlV4MNT++nm\nsezLMC4BxV2NH8gE5Ece14a+hD6ounlMmHQaxbcPXdunEo230hXtasuftrhlhOo5\n3OuEJGTjzsEAmWno6HdeDy3uWwKBgQDNwOeb5jNUVbIaIYM04uwlYt1vtUEHoSsA\nqrmsoCc8ABXFk8mWVHU5ixBWApfRk9jqodPenpm9EDVeuyAg+AlIDoOBACEgKFkl\n9FuAL1eBUBb1CGpEy5vBXfibtk55bftoybT2cid8UYGcZW2cDk187H9gaxsC577F\nQgTw/teaFwKBgFO2Eei9KJA2vaD/5MY49HfCapshizMz78/h8twAI+rYgQncpoKP\nohRwBBE6/32VM47IoU1Jup/6+qDF2Q9kVMNuGIChH6ocwC+5TZog1qLnIRT2+rVW\nxKO7M0Mz4LjKeGd9InGXoEf6sqazxfXZlVizCwCGWc/kO+LQejsshHUdAoGAa9Hl\nzP1x8oTBww3CuukbRHAtiAdcn4nmhf/xMrPuO3Pz9MiAP+XcVB46nkfXlPy8FCBf\nbW6BM+EVhqHasUwpWPg6E1SlBzv9k3UcqeylF1+H2Dnjrk9gPJFo4PhE4T8wGvZw\nfSDO7ker+u/v43JfStKH4VffHMOiZa419rAk/VsCgYB9KvX0Zh9zK0Fn5NM4aVXS\nrW+oQvc2GZr0gawU5Vy52XBguhIr/J/gbdP45K742sm7W3M5yxXJaJr3wBgvzLjc\ngS2lMmGLOmUJa3XJWlwHX7MXL0aJHeqKyKGYuKQCQn5qIvMm4C6BMKvTcHf19vTn\nWAEIB4izGy2alJ5CLAZEPw==\n-----END PRIVATE KEY-----\n",+ "client_email": "[email protected]",+ "client_id": "115224721668347071070",+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",+ "token_uri": "https://oauth2.googleapis.com/token",+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/remotionsa%40new-remotion-project.iam.gserviceaccount.com"+}\ No newline at end of filediff --git a/packages/gcp/package.json b/packages/gcp/package.jsonindex 9270c15c22..ed5b82046a 100644--- a/packages/gcp/package.json+++ b/packages/gcp/package.json@@ -10,9 +10,6 @@"watch": "tsc -w","lint": "eslint src --ext ts,tsx"},- "bin": {- "remotion-gcp": "remotion-gcp-cli.mjs"- },"dependencies": {"@google-cloud/functions-framework": "^3.1.3","@google-cloud/storage": "^6.9.1",diff --git a/packages/gcp/readme.md b/packages/gcp/readme.mdindex 3131191351..cd2a03dc38 100644--- a/packages/gcp/readme.md+++ b/packages/gcp/readme.md@@ -38,15 +38,17 @@ Navigate to the [Service Accounts](https://console.cloud.google.com/projectselec- Click Done to finish creating the service account.-### 3. Save a key for the Service Account+### 3. Save Service Account credentials- Navigate to the [Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) screen in Google Cloud Console, within IAM.- Select the Cloud project created in the previous step.- Click on the ellipsis under 'Actions', in the final column, and click 'Manage keys'.- On the next screen, click ADD KEY, and then Create new key.- select JSON, and click Create.-- Save the JSON file to your computer, with the filename `sa-key.json`.-- Place the key in the root of the Remotion project you wish to deploy to GCP. For now, this will have to be somewhere that `npx remotion gcp ...` is able to run, as this package is not deploy to npm yet.+- Save the JSON file to your computer, and open it.+- Create/edit a .env file in the root of your Remotion project.+ - Create a REMOTION_GCP_CLIENT_EMAIL key, and copy over the client_email value, _including the quotation marks_.+ - Create a REMOTION_GCP_PRIVATE_KEY key, and copy over the private_key value, _including the quotation marks_.### 3. Enable required APIs in the projectdiff --git a/packages/gcp/remotion-gcp-cli.mjs b/packages/gcp/remotion-gcp-cli.mjsdeleted file mode 100755index 71dc30c22c..0000000000--- a/packages/gcp/remotion-gcp-cli.mjs+++ /dev/null@@ -1,155 +0,0 @@-#!/usr/bin/env node-import {Storage} from '@google-cloud/storage';-import fs from 'fs';--// npx remotion-gcp --project=remotion-lambda --service-name=hello --region=australia-southeast1--// const { ServicesClient } = v2;--const sa_data = fs.readFileSync('./sa-key.json', 'utf8');-const sa_json = JSON.parse(sa_data);--// const runClient = new ServicesClient({-// credentials: sa_json-// });--// const newService = await createService()--// // TODO: Check input for whether to allow unauthenticated access-// allowUnauthenticatedAccess(newService)--// async function createService() {-// const project = 'remotion-lambda' // TODO: get from args-// const location = 'australia-southeast1' // TODO: get from args--// const parent = `projects/${project}/locations/${location}`-// const serviceId = 'remotionCloudRun' // TODO: get from args, or use a default name--// // service structure: https://googleapis.dev/nodejs/run/latest/google.cloud.run.v2.IService.html-// const service = {-// template: {-// containers: [-// { image: 'us-docker.pkg.dev/remotion-dev/cloud-run/render:3.3.51-alpha' }-// ]-// }-// }-// // Construct request-// const request = {-// parent,-// service,-// serviceId,-// };--// // Run request-// const [operation] = await runClient.createService(request);-// const [response] = await operation.promise();-// return response.name-// }--// async function allowUnauthenticatedAccess(newService) {-// await runClient.setIamPolicy(-// {-// resource: newService,-// policy: {-// bindings: [-// {-// role: 'roles/run.invoker',-// members: ['allUsers']-// }-// ]-// }-// });-// }--const cloudStorageClient = new Storage({- credentials: sa_json,-});--// cloudStorageClient.bucket('remotionlambda-testy').get()--// const result = await cloudStorageClient.bucket('remotionlambda-testc').get();-const bucketName = 'remotionlambda-test';-const prefix = 'sites/xmycbufjs3/';-// const [files] = await cloudStorageClient.bucket(bucketName).getFiles({ prefix });-// // const [files, nextContinuationToken] = await cloudStorageClient.bucket('gcp-public-data-landsat').getFiles({ prefix: 'LC08/01/001' });--// const dir = [-// 'bundle.js', 'bundle.js.map'-// ]--// const filesOnStorageButNotLocal = files.filter((fileOnStorage) => {-// const key = fileOnStorage.name?.substring(prefix.length);-// return !dir[key];-// });-// filesOnStorageButNotLocal.map((d) => [-// console.log('d', d.name)-// ])--// const key = 'sites/xmycbufjs3/LibraryMock.png'-// await cloudStorageClient.bucket(bucketName).file(key).delete();-// https://storage.googleapis.com/remotionlambda-test/sites/xmycbufjs3/LibraryMock.png-const firstFilePath = 'haloInf.mp4';-const secondFilePath = 'zoomJump.mp4';--// const transferManager = new TransferManager(cloudStorageClient.bucket(bucketName));-// await transferManager.uploadManyFiles([firstFilePath, secondFilePath], { prefix });--// for (const filePath of [firstFilePath, secondFilePath]) {-// console.log(`${filePath} uploaded to ${bucketName}.`);-// }--const bucket = cloudStorageClient.bucket(bucketName);-const remote_file = bucket.file('new/haloInf.mp4');--console.log('test message');--const uploadPromises = [];-const paths = [firstFilePath, secondFilePath];--async function uploadInParallel() {- for (const index in paths) {- const path = paths[index];- const fileSizeInBytes = fs.statSync(path).size;- uploadPromises.push(- fs- .createReadStream(path)- .pipe(bucket.file(`new/${path}`).createWriteStream())- .on('error', (err) => {})- .on('progress', (p) => {- console.log(- path,- `${Math.floor((p.bytesWritten / fileSizeInBytes) * 100)}%`- );- })- .on('finish', () => {- console.log(path, ' completed');- })- );- }-}-// const promise = Promise.all(uploadPromises).catch(console.error);--// uploadInParallel()-// console.log('before')-// await promise-// console.log('after')--const uploads = paths.map(async (path) => {- const fileSizeInBytes = fs.statSync(path).size;- return new Promise((resolve, reject) => {- fs.createReadStream(path)- .pipe(bucket.file(`new/${path}`).createWriteStream())- .on('error', (error) => reject(error))- .on('progress', (p) => {- console.log(- path,- `${Math.floor((p.bytesWritten / fileSizeInBytes) * 100)}%`- );- })- .on('finish', () => resolve('done'));- });-});-console.log('before');-const promise = Promise.all(uploads);-await promise;-console.log('after');diff --git a/packages/gcp/src/api/check-if-service-exists.ts b/packages/gcp/src/api/check-if-service-exists.tsindex 42ea8d4475..734f5ccb7a 100644--- a/packages/gcp/src/api/check-if-service-exists.ts+++ b/packages/gcp/src/api/check-if-service-exists.ts@@ -1,11 +1,10 @@import type {protos} from '@google-cloud/run';-import {v2} from '@google-cloud/run';import {CliInternals} from '@remotion/cli';-import fs from 'fs';import {Log} from '../cli/log';import {validateGcpRegion} from '../shared/validate-gcp-region';import {validateProjectID} from '../shared/validate-project-id';import {validateServiceName} from '../shared/validate-service-name';+import {getCloudRunClient} from './helpers/get-cloud-run-client';export type CheckIfServiceExistsInput = {serviceNameToCheck: string;@@ -30,14 +29,8 @@ export const checkIfServiceExists = async (const parent = `projects/${options.projectID}/locations/${options.region}`;- const {ServicesClient} = v2;+ const cloudRunClient = getCloudRunClient();- const sa_data = fs.readFileSync('./sa-key.json', 'utf8');- const sa_json = JSON.parse(sa_data);-- const runClient = new ServicesClient({- credentials: sa_json,- });// Construct requestconst request = {parent,@@ -45,7 +38,7 @@ export const checkIfServiceExists = async (// Run requesttry {- const iterable = runClient.listServicesAsync(request);+ const iterable = cloudRunClient.listServicesAsync(request);for await (const response of iterable) {if (response.name === `${parent}/services/${options.serviceNameToCheck}`diff --git a/packages/gcp/src/api/helpers/get-cloud-run-client.ts b/packages/gcp/src/api/helpers/get-cloud-run-client.tsindex a4ea32fc9b..2872110098 100644--- a/packages/gcp/src/api/helpers/get-cloud-run-client.ts+++ b/packages/gcp/src/api/helpers/get-cloud-run-client.ts@@ -1,13 +1,12 @@import {v2} from '@google-cloud/run';-import fs from 'fs';const {ServicesClient} = v2;-const sa_data = fs.readFileSync('./sa-key.json', 'utf8');-const sa_json = JSON.parse(sa_data);-export const getCloudRunClient = () => {return new ServicesClient({- credentials: sa_json,+ credentials: {+ client_email: process.env.REMOTION_GCP_CLIENT_EMAIL,+ private_key: process.env.REMOTION_GCP_PRIVATE_KEY,+ },});};diff --git a/packages/gcp/src/api/helpers/get-cloud-storage-client.ts b/packages/gcp/src/api/helpers/get-cloud-storage-client.tsindex aa5dfe13a6..c5ec485f12 100644--- a/packages/gcp/src/api/helpers/get-cloud-storage-client.ts+++ b/packages/gcp/src/api/helpers/get-cloud-storage-client.ts@@ -1,11 +1,10 @@import {Storage} from '@google-cloud/storage';-import fs from 'fs';--const sa_data = fs.readFileSync('./sa-key.json', 'utf8');-const sa_json = JSON.parse(sa_data);export const getCloudStorageClient = () => {return new Storage({- credentials: sa_json,+ credentials: {+ client_email: process.env.REMOTION_GCP_CLIENT_EMAIL,+ private_key: process.env.REMOTION_GCP_PRIVATE_KEY,+ },});};diff --git a/packages/gcp/src/api/testCall.ts b/packages/gcp/src/api/testCall.tsdeleted file mode 100644index 70ad01b6f1..0000000000--- a/packages/gcp/src/api/testCall.ts+++ /dev/null@@ -1,51 +0,0 @@-import {CliInternals} from '@remotion/cli';-import fs from 'fs';-import {GoogleAuth} from 'google-auth-library';--export type TestInput = {- cloudRunUrl: string;-};--export const testAuth = async ({cloudRunUrl}: TestInput): Promise<any> => {- const composition = 'still-zoom';- const outputBucket = 'remotioncloudrun-n8x4pc7dz3';- const outName = 'out.png';- const serveUrl =- 'https://storage.googleapis.com/remotioncloudrun-n8x4pc7dz3/sites/axp52acnh2/index.html';- const inputProps = {};- const outputFile = outName;-- CliInternals.Log.info(- CliInternals.chalk.gray(- `-Sending request to Cloud Run:-- Cloud Run Service URL = ${cloudRunUrl}- Type = still- Composition = ${composition}- Output Bucket = ${outputBucket}- Output File = ${outName}- `.trim()- )- );-- const data = {- type: 'still',- composition,- serveUrl,- inputProps,- outputBucket,- outputFile,- };- const sa_data = fs.readFileSync('./sa-key.json', 'utf8');- const credentials = JSON.parse(sa_data);-- const auth = new GoogleAuth({credentials});- const client = await auth.getIdTokenClient(cloudRunUrl);- const res = await client.request({- url: cloudRunUrl,- method: 'POST',- data,- });- console.info(res.data);-};diff --git a/packages/gcp/src/cli/commands/render/index.ts b/packages/gcp/src/cli/commands/render/index.tsindex 092b95f918..e554f02282 100644--- a/packages/gcp/src/cli/commands/render/index.ts+++ b/packages/gcp/src/cli/commands/render/index.ts@@ -4,7 +4,6 @@ import {BINARY_NAME} from '../../../shared/constants';import {quit} from '../../helpers/quit';import {renderMediaSubcommand, RENDER_MEDIA_SUBCOMMAND} from './renderMedia';import {renderStillSubcommand, RENDER_STILL_SUBCOMMAND} from './renderStill';-import {testAuthSubcommand, TEST_AUTH_SUBCOMMAND} from './testAuth';export const RENDER_COMMAND = 'render';@@ -31,11 +30,6 @@ export const renderCommand = (args: string[], remotionRoot: string) => {return renderStillSubcommand(args.slice(1), remotionRoot);}- if (args[0] === TEST_AUTH_SUBCOMMAND) {- Log.info(`yo`);- return testAuthSubcommand(args.slice(1));- }-if (args[0]) {Log.error(`Subcommand ${args[0]} not found.`);printCloudRunHelp();diff --git a/packages/gcp/src/cli/commands/render/testAuth.ts b/packages/gcp/src/cli/commands/render/testAuth.tsdeleted file mode 100644index 56404d64d0..0000000000--- a/packages/gcp/src/cli/commands/render/testAuth.ts+++ /dev/null@@ -1,21 +0,0 @@-import {testAuth} from '../../../api/testCall';-import {quit} from '../../helpers/quit';-import {Log} from '../../log';--export const TEST_AUTH_SUBCOMMAND = 'test';--export const testAuthSubcommand = async (args: string[]) => {- const cloudRunUrl = args[0];-- if (!cloudRunUrl) {- Log.error('No Cloud Run Service URL passed.');- Log.info(- 'Pass an additional argument specifying the endpoint of your Cloud Run Service.'- );- quit(1);- }-- await testAuth({- cloudRunUrl,- });-};