Skip to content

Commit

Permalink
add internalDeployService for cloudrun
Browse files Browse the repository at this point in the history
  • Loading branch information
UmungoBungo committed Sep 5, 2023
1 parent 13cf6c6 commit 632fb3f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
58 changes: 36 additions & 22 deletions packages/cloudrun/src/api/deploy-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ import {checkIfServiceExists} from './check-if-service-exists';
import {constructServiceTemplate} from './helpers/construct-service-deploy-request';
import {getCloudRunClient} from './helpers/get-cloud-run-client';

type InternalDeployServiceInput = {
performImageVersionValidation: boolean;
memoryLimit: string;
cpuLimit: string;
timeoutSeconds: number;
minInstances: number;
maxInstances: number;
projectID: string;
region: string;
};
export type DeployServiceInput = {
performImageVersionValidation?: boolean;
memoryLimit?: string;
Expand Down Expand Up @@ -39,33 +49,13 @@ const deployServiceRaw = async ({
maxInstances,
projectID,
region,
}: DeployServiceInput): Promise<DeployServiceOutput> => {
}: InternalDeployServiceInput): Promise<DeployServiceOutput> => {
validateGcpRegion(region);
validateProjectID(projectID);
if (performImageVersionValidation) {
validateImageRemotionVersion();
}

if (!memoryLimit) {
memoryLimit = '2Gi';
}

if (!cpuLimit) {
cpuLimit = '1.0';
}

if (!timeoutSeconds) {
timeoutSeconds = DEFAULT_TIMEOUT;
}

if (!minInstances) {
minInstances = DEFAULT_MIN_INSTANCES;
}

if (!maxInstances) {
maxInstances = DEFAULT_MAX_INSTANCES;
}

const parent = `projects/${projectID}/locations/${region}`;

const cloudRunClient = getCloudRunClient();
Expand Down Expand Up @@ -120,6 +110,9 @@ const deployServiceRaw = async ({
};
};

export const internalDeployService =
PureJSAPIs.wrapWithErrorHandling(deployServiceRaw);

/**
* @description Creates a Cloud Run service in your project that will be able to render a video in GCP.
* @link https://remotion.dev/docs/cloudrun/deployservice
Expand All @@ -131,4 +124,25 @@ const deployServiceRaw = async ({
* @param params.region GCP region to deploy the Cloud Run service to.
* @returns {Promise<DeployServiceOutput>} See documentation for detailed structure
*/
export const deployService = PureJSAPIs.wrapWithErrorHandling(deployServiceRaw);

export const deployService = ({
performImageVersionValidation = true,
memoryLimit,
cpuLimit,
timeoutSeconds,
minInstances,
maxInstances,
projectID,
region,
}: DeployServiceInput): Promise<DeployServiceOutput> => {
return internalDeployService({
performImageVersionValidation,
memoryLimit: memoryLimit ?? '2Gi',
cpuLimit: cpuLimit ?? '1.0',
timeoutSeconds: timeoutSeconds ?? DEFAULT_TIMEOUT,
minInstances: minInstances ?? DEFAULT_MIN_INSTANCES,
maxInstances: maxInstances ?? DEFAULT_MAX_INSTANCES,
projectID,
region,
});
};
12 changes: 7 additions & 5 deletions packages/cloudrun/src/cli/commands/services/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CliInternals} from '@remotion/cli';
import {VERSION} from 'remotion/version';
import {displayServiceInfo, LEFT_COL} from '.';
import {deployService} from '../../../api/deploy-service';
import {internalDeployService} from '../../../api/deploy-service';
import {
DEFAULT_MAX_INSTANCES,
DEFAULT_MIN_INSTANCES,
Expand Down Expand Up @@ -68,11 +68,13 @@ ${[
}

try {
const deployResult = await deployService({
const deployResult = await internalDeployService({
performImageVersionValidation: false, // this is already performed above
memoryLimit,
cpuLimit,
timeoutSeconds,
memoryLimit: memoryLimit ?? '2Gi',
cpuLimit: cpuLimit ?? '1.0',
timeoutSeconds: timeoutSeconds ?? DEFAULT_TIMEOUT,
minInstances: Number(minInstances) ?? DEFAULT_MIN_INSTANCES,
maxInstances: Number(maxInstances) ?? DEFAULT_MAX_INSTANCES,
projectID,
region,
});
Expand Down

0 comments on commit 632fb3f

Please sign in to comment.