🎥 Make videos programmatically with React
rm and rmall for service, docs + code, Added service delete permission
Matt McGillivrayfba3a5523d8c
diff --git a/.vscode/settings.json b/.vscode/settings.jsonindex 0715ae71d9..d3a69f555a 100644--- a/.vscode/settings.json+++ b/.vscode/settings.json@@ -3,5 +3,8 @@"editor.codeActionsOnSave": {"source.organizeImports": false,"source.fixAll": true- }+ },+ "cSpell.words": [+ "rmall"+ ]}diff --git a/packages/cloudrun/gcpInstaller/gcpInstaller.tar b/packages/cloudrun/gcpInstaller/gcpInstaller.tarindex c48ed2d069..d572528ccb 100644Binary files a/packages/cloudrun/gcpInstaller/gcpInstaller.tar and b/packages/cloudrun/gcpInstaller/gcpInstaller.tar differdiff --git a/packages/cloudrun/sa-permissions.json b/packages/cloudrun/sa-permissions.jsonindex f84faacc32..adc5694e85 100644--- a/packages/cloudrun/sa-permissions.json+++ b/packages/cloudrun/sa-permissions.json@@ -5,6 +5,7 @@"run.routes.invoke","run.services.create","run.services.get",+ "run.services.delete","run.services.list","run.services.update","storage.buckets.create",diff --git a/packages/cloudrun/src/api/delete-service.ts b/packages/cloudrun/src/api/delete-service.tsnew file mode 100644index 0000000000..809cc34a3d--- /dev/null+++ b/packages/cloudrun/src/api/delete-service.ts@@ -0,0 +1,23 @@+import {getCloudRunClient} from './helpers/get-cloud-run-client';++export type DeleteServiceInput = {+ serviceName: string;+ region: string;+};++/**+ * @description Deletes a service from GCP Cloud Run+ * @see [Documentation](https://remotion.dev/docs/cloudrun/deleteservice)+ * @param options.serviceName The name of the service.+ * @returns {Promise<void>} Nothing. Throws if the service failed to delete.+ */+export const deleteService = async (+ options: DeleteServiceInput+): Promise<void> => {+ const cloudRunClient = getCloudRunClient();++ // Run request+ await cloudRunClient.deleteService({+ name: `projects/${process.env.REMOTION_GCP_PROJECT_ID}/locations/${options.region}/services/${options.serviceName}`,+ });+};diff --git a/packages/cloudrun/src/cli/commands/services/index.ts b/packages/cloudrun/src/cli/commands/services/index.tsindex ed929f451a..b0d13a604b 100644--- a/packages/cloudrun/src/cli/commands/services/index.ts+++ b/packages/cloudrun/src/cli/commands/services/index.ts@@ -4,6 +4,8 @@ import {quit} from '../../helpers/quit';import {Log} from '../../log';import {cloudRunDeploySubcommand, CLOUD_RUN_DEPLOY_SUBCOMMAND} from './deploy';import {servicesLsCommand, SERVICES_LS_SUBCOMMAND} from './ls';+import {servicesRmCommand, SERVICES_RM_SUBCOMMAND} from './rm';+import {servicesRmallCommand, SERVICES_RMALL_SUBCOMMAND} from './rmall';export const SERVICES_COMMAND = 'services';@@ -21,15 +23,33 @@ const printCloudRunHelp = () => {Log.info('');Log.info(`${BINARY_NAME} ${SERVICES_COMMAND} ${CLOUD_RUN_DEPLOY_SUBCOMMAND}`);Log.info(CliInternals.chalk.gray('Deploy a new Cloud Run service'));+ CliInternals.Log.info('');+ CliInternals.Log.info(+ `${BINARY_NAME} ${SERVICES_COMMAND} ${SERVICES_RM_SUBCOMMAND} <service-name>`+ );+ CliInternals.Log.info(CliInternals.chalk.gray('Delete a Cloud Run service'));+ CliInternals.Log.info('');+ CliInternals.Log.info(+ `${BINARY_NAME} ${SERVICES_COMMAND} ${SERVICES_RMALL_SUBCOMMAND}`+ );+ CliInternals.Log.info(+ CliInternals.chalk.gray('Delete all services in selected region')+ );};-// TODO: Add RM, RMALL subcommands-export const servicesCommand = (args: string[]) => {if (args[0] === SERVICES_LS_SUBCOMMAND) {return servicesLsCommand();}+ if (args[0] === SERVICES_RM_SUBCOMMAND) {+ return servicesRmCommand(args.slice(1));+ }++ if (args[0] === SERVICES_RMALL_SUBCOMMAND) {+ return servicesRmallCommand();+ }+if (args[0] === CLOUD_RUN_DEPLOY_SUBCOMMAND) {return cloudRunDeploySubcommand();}diff --git a/packages/cloudrun/src/cli/commands/services/rm.ts b/packages/cloudrun/src/cli/commands/services/rm.tsnew file mode 100644index 0000000000..3beb55c6a4--- /dev/null+++ b/packages/cloudrun/src/cli/commands/services/rm.ts@@ -0,0 +1,77 @@+import {CliInternals} from '@remotion/cli';+import {deleteService} from '../../../api/delete-service';+import {getServiceInfo} from '../../../api/get-service-info';+import {BINARY_NAME} from '../../../shared/constants';+import {getGcpRegion} from '../../get-gcp-region';+import {confirmCli} from '../../helpers/confirm';+import {quit} from '../../helpers/quit';+import {Log} from '../../log';+import {SERVICES_COMMAND} from './index';+import {SERVICES_LS_SUBCOMMAND} from './ls';++export const SERVICES_RM_SUBCOMMAND = 'rm';+const LEFT_COL = 16;++export const servicesRmCommand = async (args: string[]) => {+ if (args.length === 0) {+ Log.error('No service name passed.');+ Log.error(+ 'Pass another argument which is the name of the service you would like to remove.'+ );+ Log.info(+ `You can run \`${BINARY_NAME} ${SERVICES_COMMAND} ${SERVICES_LS_SUBCOMMAND}\` to see a list of deployed Cloud Run services.`+ );+ quit(1);+ }++ if (args[0] === '()') {+ Log.info('No services to remove.');+ return;+ }++ const region = getGcpRegion();++ for (const serviceName of args) {+ const infoOutput = CliInternals.createOverwriteableCliOutput({+ quiet: CliInternals.quietFlagProvided(),+ cancelSignal: null,+ });+ infoOutput.update('Getting service info...');+ const info = await getServiceInfo({+ region,+ serviceName,+ });++ infoOutput.update(+ [+ 'Service name: '.padEnd(LEFT_COL, ' ') + ' ' + info.serviceName,+ 'Version: '.padEnd(LEFT_COL, ' ') + ' ' + info.remotionVersion,+ 'CPU Limit: '.padEnd(LEFT_COL, ' ') + ' ' + info.cpuLimit,+ 'Memory Limit: '.padEnd(LEFT_COL, ' ') + ' ' + info.memoryLimit,+ 'Timeout: '.padEnd(LEFT_COL, ' ') + ' ' + info.timeoutInSeconds + 'sec',+ ].join('\n')+ );+ Log.info();++ const confirmDelete = await confirmCli({+ delMessage: 'Delete? (Y/n)',+ allowForceFlag: true,+ });++ if (!confirmDelete) {+ Log.info(`Skipping service - ${info.serviceName}.`);+ continue;+ }++ const output = CliInternals.createOverwriteableCliOutput({+ quiet: CliInternals.quietFlagProvided(),+ cancelSignal: null,+ });+ output.update('Deleting...');+ await deleteService({+ serviceName,+ region,+ });+ output.update('Deleted!\n');+ }+};diff --git a/packages/cloudrun/src/cli/commands/services/rmall.ts b/packages/cloudrun/src/cli/commands/services/rmall.tsnew file mode 100644index 0000000000..2ce9c2194d--- /dev/null+++ b/packages/cloudrun/src/cli/commands/services/rmall.ts@@ -0,0 +1,59 @@+import {CliInternals} from '@remotion/cli';+import {deleteService} from '../../../api/delete-service';+import {getServiceInfo} from '../../../api/get-service-info';+import {getServices} from '../../../api/get-services';+import {getGcpRegion} from '../../get-gcp-region';+import {confirmCli} from '../../helpers/confirm';+import {Log} from '../../log';++export const SERVICES_RMALL_SUBCOMMAND = 'rmall';+const LEFT_COL = 16;++export const servicesRmallCommand = async () => {+ const region = getGcpRegion();+ const services = await getServices({+ region,+ compatibleOnly: false,+ });++ for (const serv of services) {+ const infoOutput = CliInternals.createOverwriteableCliOutput({+ quiet: CliInternals.quietFlagProvided(),+ cancelSignal: null,+ });+ infoOutput.update('Getting service info...');+ const info = await getServiceInfo({+ region,+ serviceName: serv.serviceName,+ });++ infoOutput.update(+ [+ 'Service name: '.padEnd(LEFT_COL, ' ') + ' ' + info.serviceName,+ 'Version: '.padEnd(LEFT_COL, ' ') + ' ' + info.remotionVersion,+ 'CPU Limit: '.padEnd(LEFT_COL, ' ') + ' ' + info.cpuLimit,+ 'Memory Limit: '.padEnd(LEFT_COL, ' ') + ' ' + info.memoryLimit,+ 'Timeout: '.padEnd(LEFT_COL, ' ') + ' ' + info.timeoutInSeconds + 'sec',+ ].join('\n')+ );+ Log.info();++ const confirmDelete = await confirmCli({+ delMessage: 'Delete? (Y/n)',+ allowForceFlag: true,+ });++ if (!confirmDelete) {+ Log.info(`Skipping service - ${info.serviceName}.`);+ continue;+ }++ const output = CliInternals.createOverwriteableCliOutput({+ quiet: CliInternals.quietFlagProvided(),+ cancelSignal: null,+ });+ output.update('Deleting...');+ await deleteService({region, serviceName: serv.serviceName});+ output.update('Deleted!\n');+ }+};diff --git a/packages/docs/docs/cloudrun/cli/services.md b/packages/docs/docs/cloudrun/cli/services.mdindex cc3e64c741..5b8ab1910b 100644--- a/packages/docs/docs/cloudrun/cli/services.md+++ b/packages/docs/docs/cloudrun/cli/services.md@@ -108,7 +108,7 @@ Prints only the service names in a space-separated list. If no services exist, p## rm```-npx remotion cloudrun services rm remotion-render-2021-12-16-2048mb-240sec+npx remotion cloudrun services rm remotion--3-3-82--mem512mi--cpu1-0--t-800```Removes one or more services from your GCP project. Pass a space-separated list of services you'd like to delete.@@ -119,10 +119,11 @@ Example output</summary><pre><br/>-Function name: remotion-render-2021-12-16-2048mb-240sec<br/>-Memory: 2048MB<br/>-Timeout: 120sec<br/>-Version: 2021-12-16<br/>+Service name: remotion--3-3-82--mem2gi--cpu1-0--t-800<br/>+Version: 3.3.82<br/>+CPU Limit: 1.0<br/>+Memory Limit: 2Gi<br/>+Timeout: 300sec<br/>Delete? (Y/n): Y<br/>Deleted!<br/>@@ -152,17 +153,19 @@ Example output</summary><pre><br/>-Function name: remotion-render-2021-12-16-2048mb-240sec<br/>-Memory: 2048MB<br/>-Timeout: 120sec<br/>-Version: 2021-12-16<br/>+Service name: remotion--3-3-82--mem2gi--cpu1-0--t-800<br/>+Version: 3.3.82<br/>+CPU Limit: 1.0<br/>+Memory Limit: 2Gi<br/>+Timeout: 300sec<br/>Delete? (Y/n): Y<br/>Deleted!<br/>-Function name: remotion-render-2021-12-18-2048mb-240sec<br/>-Memory: 2048MB<br/>-Timeout: 120sec<br/>-Version: 2021-12-16<br/>+Service name: remotion--3-3-82--mem4gi--cpu2-0--t-1200<br/>+Version: 3.3.82<br/>+CPU Limit: 1.0<br/>+Memory Limit: 2Gi<br/>+Timeout: 300sec<br/>Delete? (Y/n): Y<br/>Deleted!<br/>