Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add internalDeployService for cloudrun #2852

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 36 additions & 22 deletions packages/cloudrun/src/api/deploy-service.ts
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
@@ -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