Setup memory/cpu limits for windows containers

pull/588/head
Andrew Kahr 2023-10-16 21:40:12 -07:00
parent 1f5e83eaf1
commit 2b57efdf8e
6 changed files with 62 additions and 5 deletions

View File

@ -106,6 +106,16 @@ inputs:
default: '' default: ''
description: description:
'User and optionally group (user or user:group or uid:gid) to give ownership of the resulting build artifacts' 'User and optionally group (user or user:group or uid:gid) to give ownership of the resulting build artifacts'
dockerCpuLimit:
required: false
default: ''
description: 'Number of CPU cores to assign the Windows docker container. Defaults to all available cores.'
dockerMemoryLimit:
required: false
default: ''
description:
'Amount of memory to assign the Windows docker container. Defaults to 75% of total system memory rounded down to
the nearest gigabyte.'
allowDirtyBuild: allowDirtyBuild:
required: false required: false
default: '' default: ''

23
dist/index.js vendored
View File

@ -281,6 +281,8 @@ class BuildParameters {
sshPublicKeysDirectoryPath: input_1.default.sshPublicKeysDirectoryPath, sshPublicKeysDirectoryPath: input_1.default.sshPublicKeysDirectoryPath,
gitPrivateToken: input_1.default.gitPrivateToken || (await github_cli_1.GithubCliReader.GetGitHubAuthToken()), gitPrivateToken: input_1.default.gitPrivateToken || (await github_cli_1.GithubCliReader.GetGitHubAuthToken()),
chownFilesTo: input_1.default.chownFilesTo, chownFilesTo: input_1.default.chownFilesTo,
dockerCpuLimit: input_1.default.dockerCpuLimit,
dockerMemoryLimit: input_1.default.dockerMemoryLimit,
providerStrategy: cloud_runner_options_1.default.providerStrategy, providerStrategy: cloud_runner_options_1.default.providerStrategy,
buildPlatform: cloud_runner_options_1.default.buildPlatform, buildPlatform: cloud_runner_options_1.default.buildPlatform,
kubeConfig: cloud_runner_options_1.default.kubeConfig, kubeConfig: cloud_runner_options_1.default.kubeConfig,
@ -5917,7 +5919,7 @@ class Docker {
"${overrideCommands !== '' ? overrideCommands : `/entrypoint.sh`}"`; "${overrideCommands !== '' ? overrideCommands : `/entrypoint.sh`}"`;
} }
static getWindowsCommand(image, parameters) { static getWindowsCommand(image, parameters) {
const { workspace, actionFolder, unitySerial, gitPrivateToken, dockerWorkspacePath } = parameters; const { workspace, actionFolder, unitySerial, gitPrivateToken, dockerWorkspacePath, dockerCpuLimit, dockerMemoryLimit, } = parameters;
return `docker run \ return `docker run \
--workdir c:${dockerWorkspacePath} \ --workdir c:${dockerWorkspacePath} \
--rm \ --rm \
@ -5927,12 +5929,15 @@ class Docker {
${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \ ${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \
--volume "${workspace}":"c:${dockerWorkspacePath}" \ --volume "${workspace}":"c:${dockerWorkspacePath}" \
--volume "c:/regkeys":"c:/regkeys" \ --volume "c:/regkeys":"c:/regkeys" \
--volume "C:/Program Files/Microsoft Visual Studio":"C:/Program Files/Microsoft Visual Studio" \
--volume "C:/Program Files (x86)/Microsoft Visual Studio":"C:/Program Files (x86)/Microsoft Visual Studio" \ --volume "C:/Program Files (x86)/Microsoft Visual Studio":"C:/Program Files (x86)/Microsoft Visual Studio" \
--volume "C:/Program Files (x86)/Windows Kits":"C:/Program Files (x86)/Windows Kits" \ --volume "C:/Program Files (x86)/Windows Kits":"C:/Program Files (x86)/Windows Kits" \
--volume "C:/ProgramData/Microsoft/VisualStudio":"C:/ProgramData/Microsoft/VisualStudio" \ --volume "C:/ProgramData/Microsoft/VisualStudio":"C:/ProgramData/Microsoft/VisualStudio" \
--volume "${actionFolder}/default-build-script":"c:/UnityBuilderAction" \ --volume "${actionFolder}/default-build-script":"c:/UnityBuilderAction" \
--volume "${actionFolder}/platforms/windows":"c:/steps" \ --volume "${actionFolder}/platforms/windows":"c:/steps" \
--volume "${actionFolder}/BlankProject":"c:/BlankProject" \ --volume "${actionFolder}/BlankProject":"c:/BlankProject" \
--cpus=${dockerCpuLimit} \
--memory=${dockerMemoryLimit} \
${image} \ ${image} \
powershell c:/steps/entrypoint.ps1`; powershell c:/steps/entrypoint.ps1`;
} }
@ -6731,6 +6736,7 @@ const cli_1 = __nccwpck_require__(55651);
const cloud_runner_query_override_1 = __importDefault(__nccwpck_require__(52207)); const cloud_runner_query_override_1 = __importDefault(__nccwpck_require__(52207));
const platform_1 = __importDefault(__nccwpck_require__(9707)); const platform_1 = __importDefault(__nccwpck_require__(9707));
const github_1 = __importDefault(__nccwpck_require__(83654)); const github_1 = __importDefault(__nccwpck_require__(83654));
const node_os_1 = __importDefault(__nccwpck_require__(70612));
const core = __importStar(__nccwpck_require__(42186)); const core = __importStar(__nccwpck_require__(42186));
/** /**
* Input variables specified in workflows using "with" prop. * Input variables specified in workflows using "with" prop.
@ -6903,6 +6909,13 @@ class Input {
static get dockerWorkspacePath() { static get dockerWorkspacePath() {
return Input.getInput('dockerWorkspacePath') || '/github/workspace'; return Input.getInput('dockerWorkspacePath') || '/github/workspace';
} }
static get dockerCpuLimit() {
return Input.getInput('dockerCpuLimit') || node_os_1.default.cpus().length.toString();
}
static get dockerMemoryLimit() {
const bytesInGigabyte = 1024 * 1024 * 1024;
return Input.getInput('dockerMemoryLimit') || `${Math.floor((node_os_1.default.totalmem() / bytesInGigabyte) * 0.75)}G`;
}
static ToEnvVarFormat(input) { static ToEnvVarFormat(input) {
if (input.toUpperCase() === input) { if (input.toUpperCase() === input) {
return input; return input;
@ -316402,6 +316415,14 @@ module.exports = require("node:fs");
/***/ }), /***/ }),
/***/ 70612:
/***/ ((module) => {
"use strict";
module.exports = require("node:os");
/***/ }),
/***/ 49411: /***/ 49411:
/***/ ((module) => { /***/ ((module) => {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -116,10 +116,12 @@ class BuildParameters {
if (!Input.unitySerial && GitHub.githubInputEnabled) { if (!Input.unitySerial && GitHub.githubInputEnabled) {
// No serial was present, so it is a personal license that we need to convert // No serial was present, so it is a personal license that we need to convert
if (!Input.unityLicense) { if (!Input.unityLicense) {
throw new Error(`Missing Unity License File and no Serial was found. If this throw new Error(
`Missing Unity License File and no Serial was found. If this
is a personal license, make sure to follow the activation is a personal license, make sure to follow the activation
steps and set the UNITY_LICENSE GitHub secret or enter a Unity steps and set the UNITY_LICENSE GitHub secret or enter a Unity
serial number inside the UNITY_SERIAL GitHub secret.`); serial number inside the UNITY_SERIAL GitHub secret.`,
);
} }
unitySerial = this.getSerialFromLicenseFile(Input.unityLicense); unitySerial = this.getSerialFromLicenseFile(Input.unityLicense);
} else { } else {
@ -156,6 +158,8 @@ class BuildParameters {
sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath, sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath,
gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()), gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()),
chownFilesTo: Input.chownFilesTo, chownFilesTo: Input.chownFilesTo,
dockerCpuLimit: Input.dockerCpuLimit,
dockerMemoryLimit: Input.dockerMemoryLimit,
providerStrategy: CloudRunnerOptions.providerStrategy, providerStrategy: CloudRunnerOptions.providerStrategy,
buildPlatform: CloudRunnerOptions.buildPlatform, buildPlatform: CloudRunnerOptions.buildPlatform,
kubeConfig: CloudRunnerOptions.kubeConfig, kubeConfig: CloudRunnerOptions.kubeConfig,

View File

@ -86,7 +86,15 @@ class Docker {
} }
static getWindowsCommand(image: string, parameters: DockerParameters): string { static getWindowsCommand(image: string, parameters: DockerParameters): string {
const { workspace, actionFolder, unitySerial, gitPrivateToken, dockerWorkspacePath } = parameters; const {
workspace,
actionFolder,
unitySerial,
gitPrivateToken,
dockerWorkspacePath,
dockerCpuLimit,
dockerMemoryLimit,
} = parameters;
return `docker run \ return `docker run \
--workdir c:${dockerWorkspacePath} \ --workdir c:${dockerWorkspacePath} \
@ -97,12 +105,15 @@ class Docker {
${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \ ${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \
--volume "${workspace}":"c:${dockerWorkspacePath}" \ --volume "${workspace}":"c:${dockerWorkspacePath}" \
--volume "c:/regkeys":"c:/regkeys" \ --volume "c:/regkeys":"c:/regkeys" \
--volume "C:/Program Files/Microsoft Visual Studio":"C:/Program Files/Microsoft Visual Studio" \
--volume "C:/Program Files (x86)/Microsoft Visual Studio":"C:/Program Files (x86)/Microsoft Visual Studio" \ --volume "C:/Program Files (x86)/Microsoft Visual Studio":"C:/Program Files (x86)/Microsoft Visual Studio" \
--volume "C:/Program Files (x86)/Windows Kits":"C:/Program Files (x86)/Windows Kits" \ --volume "C:/Program Files (x86)/Windows Kits":"C:/Program Files (x86)/Windows Kits" \
--volume "C:/ProgramData/Microsoft/VisualStudio":"C:/ProgramData/Microsoft/VisualStudio" \ --volume "C:/ProgramData/Microsoft/VisualStudio":"C:/ProgramData/Microsoft/VisualStudio" \
--volume "${actionFolder}/default-build-script":"c:/UnityBuilderAction" \ --volume "${actionFolder}/default-build-script":"c:/UnityBuilderAction" \
--volume "${actionFolder}/platforms/windows":"c:/steps" \ --volume "${actionFolder}/platforms/windows":"c:/steps" \
--volume "${actionFolder}/BlankProject":"c:/BlankProject" \ --volume "${actionFolder}/BlankProject":"c:/BlankProject" \
--cpus=${dockerCpuLimit} \
--memory=${dockerMemoryLimit} \
${image} \ ${image} \
powershell c:/steps/entrypoint.ps1`; powershell c:/steps/entrypoint.ps1`;
} }

View File

@ -4,6 +4,7 @@ import { Cli } from './cli/cli';
import CloudRunnerQueryOverride from './cloud-runner/options/cloud-runner-query-override'; import CloudRunnerQueryOverride from './cloud-runner/options/cloud-runner-query-override';
import Platform from './platform'; import Platform from './platform';
import GitHub from './github'; import GitHub from './github';
import os from 'node:os';
import * as core from '@actions/core'; import * as core from '@actions/core';
@ -226,6 +227,16 @@ class Input {
return Input.getInput('dockerWorkspacePath') || '/github/workspace'; return Input.getInput('dockerWorkspacePath') || '/github/workspace';
} }
static get dockerCpuLimit(): string {
return Input.getInput('dockerCpuLimit') || os.cpus().length.toString();
}
static get dockerMemoryLimit(): string {
const bytesInGigabyte = 1024 * 1024 * 1024;
return Input.getInput('dockerMemoryLimit') || `${Math.floor((os.totalmem() / bytesInGigabyte) * 0.75)}G`;
}
public static ToEnvVarFormat(input: string) { public static ToEnvVarFormat(input: string) {
if (input.toUpperCase() === input) { if (input.toUpperCase() === input) {
return input; return input;