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

@remotion/cloudrun: New onlyAllocateCpuDuringRequestProcessing flag and apply correct service account #4387

Merged
merged 3 commits into from
Oct 10, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/src/parsed-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const BooleanFlags = [
'repro',
'compatible-only',
'force-path-style',
'onlyAllocateCpuDuringRequestProcessing',
];

export const parsedCli = minimist<CommandLineOptions>(process.argv.slice(2), {
Expand Down
7 changes: 7 additions & 0 deletions packages/cloudrun/src/api/deploy-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type InternalDeployServiceInput = {
region: string;
logLevel: LogLevel;
indent: boolean;
onlyAllocateCpuDuringRequestProcessing: boolean;
};
export type DeployServiceInput = {
performImageVersionValidation?: boolean;
Expand All @@ -36,6 +37,7 @@ export type DeployServiceInput = {
logLevel?: LogLevel;
projectID: string;
region: string;
onlyAllocateCpuDuringRequestProcessing?: boolean;
};

export type DeployServiceOutput = {
Expand All @@ -55,6 +57,7 @@ const deployServiceRaw = async ({
projectID,
region,
logLevel,
onlyAllocateCpuDuringRequestProcessing,
}: InternalDeployServiceInput): Promise<DeployServiceOutput> => {
validateGcpRegion(region);
validateProjectID(projectID);
Expand Down Expand Up @@ -99,6 +102,7 @@ const deployServiceRaw = async ({
timeoutSeconds,
minInstances,
maxInstances,
onlyAllocateCpuDuringRequestProcessing,
}),
},
serviceId: serviceName,
Expand Down Expand Up @@ -141,6 +145,7 @@ export const deployService = ({
projectID,
region,
logLevel,
onlyAllocateCpuDuringRequestProcessing,
}: DeployServiceInput): Promise<DeployServiceOutput> => {
return internalDeployService({
performImageVersionValidation,
Expand All @@ -153,5 +158,7 @@ export const deployService = ({
region,
logLevel: logLevel ?? 'info',
indent: false,
onlyAllocateCpuDuringRequestProcessing:
onlyAllocateCpuDuringRequestProcessing ?? false,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export const constructServiceTemplate = ({
timeoutSeconds,
minInstances,
maxInstances,
onlyAllocateCpuDuringRequestProcessing,
}: {
memoryLimit: string;
cpuLimit: string;
timeoutSeconds: number;
minInstances: number;
maxInstances: number;
onlyAllocateCpuDuringRequestProcessing: boolean;
}): google.cloud.run.v2.IRevisionTemplate => {
return {
scaling: {
Expand All @@ -39,10 +41,12 @@ export const constructServiceTemplate = ({
memory: memoryLimit,
cpu: cpuLimit,
},
cpuIdle: onlyAllocateCpuDuringRequestProcessing,
},
},
],
maxInstanceRequestConcurrency: 1,
executionEnvironment: ExecutionEnvironment.EXECUTION_ENVIRONMENT_GEN1,
serviceAccount: process.env.REMOTION_GCP_CLIENT_EMAIL,
};
};
1 change: 1 addition & 0 deletions packages/cloudrun/src/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type servicesCommandLineOptions = {
y: boolean;
yes: boolean;
force: boolean;
['onlyAllocateCpuDuringRequestProcessing']: boolean;
f: boolean;

['max-retries']: number;
Expand Down
3 changes: 3 additions & 0 deletions packages/cloudrun/src/cli/commands/services/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const cloudRunDeploySubcommand = async (logLevel: LogLevel) => {
const maxInstances = String(
parsedCloudrunCli.maxInstances ?? DEFAULT_MAX_INSTANCES,
);
const onlyAllocateCpuDuringRequestProcessing =
parsedCloudrunCli.onlyAllocateCpuDuringRequestProcessing ?? false;
const timeoutSeconds = parsedCloudrunCli.timeoutSeconds ?? DEFAULT_TIMEOUT;

if (!CliInternals.quietFlagProvided()) {
Expand Down Expand Up @@ -88,6 +90,7 @@ ${[
region,
logLevel,
indent: false,
onlyAllocateCpuDuringRequestProcessing,
});

if (!deployResult.fullName) {
Expand Down
225 changes: 152 additions & 73 deletions packages/docs/docs/cloudrun/cli/services.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
image: /generated/articles-docs-cloudrun-cli-services.png
id: services
sidebar_label: services
title: "npx remotion cloudrun services"
title: 'npx remotion cloudrun services'
slug: /cloudrun/cli/services
crumb: "Cloud Run CLI Reference"
crumb: 'Cloud Run CLI Reference'
---

<ExperimentalBadge>
<p>Cloud Run is in <a href="/docs/cloudrun-alpha">Alpha</a>, which means APIs may change in any version and documentation is not yet finished. See the <a href="https://remotion.dev/changelog">changelog to stay up to date with breaking changes</a>.</p>
<p>
Cloud Run is in <a href="/docs/cloudrun-alpha">Alpha</a>, which means APIs
may change in any version and documentation is not yet finished. See the{' '}
<a href="https://remotion.dev/changelog">
changelog to stay up to date with breaking changes
</a>
.
</p>
</ExperimentalBadge>

The `npx remotion cloudrun services` command allows you to deploy, view and delete GCP Cloud Run services that can render videos and stills.
Expand All @@ -29,28 +36,50 @@ npx remotion cloudrun services deploy
Creates a new service in your GCP project. If a service exists in the same region, with the same Remotion version, with the same amount of memory, disk space and timeout duration, the name of the already deployed service will be returned instead.

<details>
<summary>
Example output
</summary>
<pre>
Validating Deployment of Cloud Run Service:<br/><br/>
Remotion Version: 3.3.95<br/>
Memory Limit: 2Gi<br/>
CPU Limit: 1.0<br/>
Timeout: 300<br/>
Project Name: remotion-example<br/>
Region: us-east1<br/><br/>
Deploying Cloud Run Service...<br/><br/><br/>
Cloud Run Deployed!<br/><br/>
Service name: remotion--3-3-95--mem512mi--cpu2--t-1200<br/>
Version: 3.3.95<br/>
CPU Limit: 2<br/>
Memory Limit: 512Mi<br/>
Timeout: 1200sec<br/>
Region: us-east1<br/>
Service URL: https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app<br/>
GCP Console URL: https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs<br/><br/>
</pre>
<summary>Example output</summary>
<pre>
Validating Deployment of Cloud Run Service:
<br />
<br />
Remotion Version: 3.3.95
<br />
Memory Limit: 2Gi
<br />
CPU Limit: 1.0
<br />
Timeout: 300
<br />
Project Name: remotion-example
<br />
Region: us-east1
<br />
<br />
Deploying Cloud Run Service...
<br />
<br />
<br />
Cloud Run Deployed!
<br />
<br />
Service name: remotion--3-3-95--mem512mi--cpu2--t-1200
<br />
Version: 3.3.95
<br />
CPU Limit: 2<br />
Memory Limit: 512Mi
<br />
Timeout: 1200sec
<br />
Region: us-east1
<br />
Service URL:
https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app
<br />
GCP Console URL:
https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs
<br />
<br />
</pre>
</details>

### `--region`
Expand Down Expand Up @@ -85,6 +114,11 @@ Timeout of the Cloud Run service. Default: 300 seconds.
Not to be confused with the [`--timeout` flag when rendering which defines the timeout for `delayRender()`](/docs/cli/render#--timeout).
:::

### `--onlyAllocateCpuDuringRequestProcessing`<AvailableFrom v="4.0.221" />

If this is set to true, `cpu_idle` will be set to `true` in the service manifest.
CPU alloction will be disabled while no request is being processed, which can lead to significant cost savings.

### `--quiet`, `-q`

Only logs the service name, and 'Authenticated access granted'.
Expand All @@ -98,28 +132,49 @@ npx remotion cloudrun services ls
Lists the services that you have deployed to GCP in the [selected region](/docs/cloudrun/region-selection).

<details>
<summary>
Example output
</summary>
<pre>
2 services in us-east1<br/><br/>
Service name: remotion--3-3-95--mem512mi--cpu2--t-1200<br/>
Version: 3.3.95<br/>
CPU Limit: 2<br/>
Memory Limit: 512Mi<br/>
Timeout: 1200sec<br/>
Region: us-east1<br/>
Service URL: https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app<br/>
GCP Console URL: https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs<br/><br/>
Service name: remotion--3-3-82--mem512mi--cpu1-0--t-800<br/>
Version: 3.3.82<br/>
CPU Limit: 1.0<br/>
Memory Limit: 512Mi<br/>
Timeout: 800sec<br/>
Region: us-east1<br/>
Service URL: https://remotion--3-3-82--mem512mi--cpu1-0--t-800-1a2b3c4d5e-ue.a.run.app<br/>
GCP Console URL: https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-82--mem512mi--cpu1-0--t-800/logs<br/><br/>
</pre>
<summary>Example output</summary>
<pre>
2 services in us-east1
<br />
<br />
Service name: remotion--3-3-95--mem512mi--cpu2--t-1200
<br />
Version: 3.3.95
<br />
CPU Limit: 2<br />
Memory Limit: 512Mi
<br />
Timeout: 1200sec
<br />
Region: us-east1
<br />
Service URL:
https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app
<br />
GCP Console URL:
https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs
<br />
<br />
Service name: remotion--3-3-82--mem512mi--cpu1-0--t-800
<br />
Version: 3.3.82
<br />
CPU Limit: 1.0
<br />
Memory Limit: 512Mi
<br />
Timeout: 800sec
<br />
Region: us-east1
<br />
Service URL:
https://remotion--3-3-82--mem512mi--cpu1-0--t-800-1a2b3c4d5e-ue.a.run.app
<br />
GCP Console URL:
https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-82--mem512mi--cpu1-0--t-800/logs
<br />
<br />
</pre>
</details>

### `--region`
Expand Down Expand Up @@ -176,32 +231,56 @@ npx remotion cloudrun services rmall
Removes all services from your GCP project for a certain region.

<details>
<summary>
Example output
</summary>
<pre>
2 services in us-east1<br/><br/>
Service name: remotion--3-3-95--mem512mi--cpu2--t-1200<br/>
Version: 3.3.95<br/>
CPU Limit: 2<br/>
Memory Limit: 512Mi<br/>
Timeout: 1200sec<br/>
Region: us-east1<br/>
Service URL: https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app<br/>
GCP Console URL: https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs<br/><br/>
Delete? (Y/n) n<br/>
Skipping service - remotion--3-3-95--mem512mi--cpu2--t-1200.<br/><br/>
Service name: remotion--3-3-82--mem512mi--cpu1-0--t-800<br/>
Version: 3.3.82<br/>
CPU Limit: 1.0<br/>
Memory Limit: 512Mi<br/>
Timeout: 800sec<br/>
Region: us-east1<br/>
Service URL: https://remotion--3-3-82--mem512mi--cpu1-0--t-800-1a2b3c4d5e-ue.a.run.app<br/>
GCP Console URL: https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-82--mem512mi--cpu1-0--t-800/logs<br/><br/>
Delete? (Y/n) n<br/>
Skipping service - remotion--3-3-82--mem512mi--cpu1-0--t-800.<br/>
</pre>
<summary>Example output</summary>
<pre>
2 services in us-east1
<br />
<br />
Service name: remotion--3-3-95--mem512mi--cpu2--t-1200
<br />
Version: 3.3.95
<br />
CPU Limit: 2<br />
Memory Limit: 512Mi
<br />
Timeout: 1200sec
<br />
Region: us-east1
<br />
Service URL:
https://remotion--3-3-95--mem512mi--cpu2--t-1200-1a2b3c4d5e-ue.a.run.app
<br />
GCP Console URL:
https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-95--mem512mi--cpu2--t-1200/logs
<br />
<br />
Delete? (Y/n) n<br />
Skipping service - remotion--3-3-95--mem512mi--cpu2--t-1200.
<br />
<br />
Service name: remotion--3-3-82--mem512mi--cpu1-0--t-800
<br />
Version: 3.3.82
<br />
CPU Limit: 1.0
<br />
Memory Limit: 512Mi
<br />
Timeout: 800sec
<br />
Region: us-east1
<br />
Service URL:
https://remotion--3-3-82--mem512mi--cpu1-0--t-800-1a2b3c4d5e-ue.a.run.app
<br />
GCP Console URL:
https://console.cloud.google.com/run/detail/us-east1/remotion--3-3-82--mem512mi--cpu1-0--t-800/logs
<br />
<br />
Delete? (Y/n) n<br />
Skipping service - remotion--3-3-82--mem512mi--cpu1-0--t-800.
<br />
</pre>
</details>

### `--region`
Expand Down
Loading
Loading