Skip to content

πŸŽ₯ Make videos programmatically with React

doesn't recreate service, just returns service name

Matt McGillivray783224140732
diff --git a/packages/cloudrun/gcpInstaller/gcpInstaller.tar b/packages/cloudrun/gcpInstaller/gcpInstaller.tar
index 1f4e9ee53b..427eb7ac4b 100644
Binary files a/packages/cloudrun/gcpInstaller/gcpInstaller.tar and b/packages/cloudrun/gcpInstaller/gcpInstaller.tar differ
diff --git a/packages/cloudrun/src/api/deploy-service.ts b/packages/cloudrun/src/api/deploy-service.ts
index 697cf65c7f..5d680c714a 100644
--- a/packages/cloudrun/src/api/deploy-service.ts
+++ b/packages/cloudrun/src/api/deploy-service.ts
@@ -2,9 +2,9 @@ import {generateServiceName} from '../shared/generate-service-name';
import {validateGcpRegion} from '../shared/validate-gcp-region';
import {validateProjectID} from '../shared/validate-project-id';
import {validateRemotionVersion} from '../shared/validate-remotion-version';
+import {checkIfServiceExists} from './check-if-service-exists';
import {constructServiceTemplate} from './helpers/construct-service-deploy-request';
import {getCloudRunClient} from './helpers/get-cloud-run-client';
-import type {IService} from './helpers/IService';
export type DeployServiceInput = {
remotionVersion: string;
@@ -12,6 +12,13 @@ export type DeployServiceInput = {
cpu: string;
projectID: string;
region: string;
+ redeploy: boolean;
+};
+
+export type DeployServiceOutput = {
+ name: string | null | undefined;
+ uri: string | null | undefined;
+ alreadyExists: boolean;
};
/**
@@ -24,7 +31,7 @@ export type DeployServiceInput = {
*/
export const deployService = async (
options: DeployServiceInput
-): Promise<IService> => {
+): Promise<DeployServiceOutput> => {
// ToDo: This needs to allow for defaults for use of the node API without CLI
validateGcpRegion(options.region);
validateProjectID(options.projectID);
@@ -34,11 +41,26 @@ export const deployService = async (
const cloudRunClient = getCloudRunClient();
+ const existingService = await checkIfServiceExists({
+ memory: options.memory,
+ cpu: options.cpu,
+ projectID: options.projectID,
+ region: options.region,
+ });
+
const serviceName = generateServiceName({
memory: options.memory,
cpu: options.cpu,
});
+ if (existingService) {
+ return {
+ name: serviceName,
+ uri: null,
+ alreadyExists: true,
+ };
+ }
+
const request = {
parent,
service: {
@@ -56,5 +78,9 @@ export const deployService = async (
const [operation] = await cloudRunClient.createService(request);
const [response] = await operation.promise();
- return response;
+ return {
+ name: response.name,
+ uri: response.uri,
+ alreadyExists: false,
+ };
};
diff --git a/packages/cloudrun/src/cli/commands/services/deploy.ts b/packages/cloudrun/src/cli/commands/services/deploy.ts
index 2d4eabf157..3a83893409 100644
--- a/packages/cloudrun/src/cli/commands/services/deploy.ts
+++ b/packages/cloudrun/src/cli/commands/services/deploy.ts
@@ -1,6 +1,5 @@
import {CliInternals} from '@remotion/cli';
import {VERSION} from 'remotion/version';
-import {checkIfServiceExists} from '../../../api/check-if-service-exists';
import {allowUnauthenticatedAccess} from '../../../api/cloud-run-allow-unauthenticated-access';
import {deployService} from '../../../api/deploy-service';
import {generateServiceName} from '../../../shared/generate-service-name';
@@ -8,7 +7,6 @@ import {validateGcpRegion} from '../../../shared/validate-gcp-region';
import {validateRemotionVersion} from '../../../shared/validate-remotion-version';
import {parsedCloudrunCli} from '../../args';
import {getGcpRegion} from '../../get-gcp-region';
-import {confirmCli} from '../../helpers/confirm';
import {quit} from '../../helpers/quit';
import {Log} from '../../log';
@@ -50,26 +48,6 @@ Validating Deployment of Cloud Run Service:
quit(0);
}
- const existingService = await checkIfServiceExists({
- memory,
- cpu,
- projectID,
- region,
- });
-
- if (existingService) {
- const answer = await confirmCli({
- delMessage:
- 'A Cloud Run service with the same Remotion Version, Memory, and CPU already exists. Do you want to re-deploy? (Y/n)',
- allowForceFlag: true,
- });
-
- if (answer === false) {
- Log.info(CliInternals.chalk.white('\nService deployment cancelled.'));
- quit(1);
- }
- }
-
// if no existing service, deploy new service
Log.info(CliInternals.chalk.white('\nDeploying Cloud Run Service...'));
try {
@@ -79,6 +57,7 @@ Validating Deployment of Cloud Run Service:
cpu,
projectID,
region,
+ redeploy: true,
});
if (!deployResult.name) {
@@ -86,25 +65,40 @@ Validating Deployment of Cloud Run Service:
throw new Error(JSON.stringify(deployResult));
}
- if (!deployResult.uri) {
+ if (!deployResult.alreadyExists && !deployResult.uri) {
Log.error('service uri not returned from Cloud Run API.');
- throw new Error(JSON.stringify(deployResult));
}
- Log.info();
+ if (deployResult.alreadyExists) {
+ Log.info();
- Log.info(
- CliInternals.chalk.blueBright(
- `
-πŸŽ‰ Cloud Run Deployed! πŸŽ‰
+ Log.info(
+ CliInternals.chalk.blueBright(
+ `
+ Service Already Deployed! Check GCP Console for Cloud Run URL.
+
+ Full Service Name = ${deployResult.name}
+ Project = ${projectID}
+ GCP Console URL = https://console.cloud.google.com/run/detail/${region}/${deployResult.name}/revisions
+ `.trim()
+ )
+ );
+ } else {
+ Log.info();
+ Log.info(
+ CliInternals.chalk.blueBright(
+ `
+ πŸŽ‰ Cloud Run Deployed! πŸŽ‰
+
Full Service Name = ${deployResult.name}
Cloud Run URL = ${deployResult.uri}
Project = ${projectID}
GCP Console URL = https://console.cloud.google.com/run/detail/${region}/${deployResult.name}/revisions
- `.trim()
- )
- );
+ `.trim()
+ )
+ );
+ }
await allowUnauthenticatedAccessToService(
deployResult.name,