mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-07 20:35:33 -04:00
Setup memory/cpu limits for windows containers
This commit is contained in:
parent
1f5e83eaf1
commit
2b57efdf8e
10
action.yml
10
action.yml
@ -106,6 +106,16 @@ inputs:
|
||||
default: ''
|
||||
description:
|
||||
'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:
|
||||
required: false
|
||||
default: ''
|
||||
|
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
@ -116,10 +116,12 @@ class BuildParameters {
|
||||
if (!Input.unitySerial && GitHub.githubInputEnabled) {
|
||||
// No serial was present, so it is a personal license that we need to convert
|
||||
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
|
||||
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);
|
||||
} else {
|
||||
@ -156,6 +158,8 @@ class BuildParameters {
|
||||
sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath,
|
||||
gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()),
|
||||
chownFilesTo: Input.chownFilesTo,
|
||||
dockerCpuLimit: Input.dockerCpuLimit,
|
||||
dockerMemoryLimit: Input.dockerMemoryLimit,
|
||||
providerStrategy: CloudRunnerOptions.providerStrategy,
|
||||
buildPlatform: CloudRunnerOptions.buildPlatform,
|
||||
kubeConfig: CloudRunnerOptions.kubeConfig,
|
||||
|
@ -86,7 +86,15 @@ class Docker {
|
||||
}
|
||||
|
||||
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 \
|
||||
--workdir c:${dockerWorkspacePath} \
|
||||
@ -97,12 +105,15 @@ class Docker {
|
||||
${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \
|
||||
--volume "${workspace}":"c:${dockerWorkspacePath}" \
|
||||
--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)/Windows Kits":"C:/Program Files (x86)/Windows Kits" \
|
||||
--volume "C:/ProgramData/Microsoft/VisualStudio":"C:/ProgramData/Microsoft/VisualStudio" \
|
||||
--volume "${actionFolder}/default-build-script":"c:/UnityBuilderAction" \
|
||||
--volume "${actionFolder}/platforms/windows":"c:/steps" \
|
||||
--volume "${actionFolder}/BlankProject":"c:/BlankProject" \
|
||||
--cpus=${dockerCpuLimit} \
|
||||
--memory=${dockerMemoryLimit} \
|
||||
${image} \
|
||||
powershell c:/steps/entrypoint.ps1`;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import { Cli } from './cli/cli';
|
||||
import CloudRunnerQueryOverride from './cloud-runner/options/cloud-runner-query-override';
|
||||
import Platform from './platform';
|
||||
import GitHub from './github';
|
||||
import os from 'node:os';
|
||||
|
||||
import * as core from '@actions/core';
|
||||
|
||||
@ -226,6 +227,16 @@ class Input {
|
||||
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) {
|
||||
if (input.toUpperCase() === input) {
|
||||
return input;
|
||||
|
Loading…
Reference in New Issue
Block a user