Provide a default for linux to allow providing a custom limit on linux containers

This commit is contained in:
Andrew Kahr 2023-10-27 16:52:55 -07:00
parent 9e22e88260
commit d47dc754af
5 changed files with 25 additions and 5 deletions

View File

@ -109,13 +109,14 @@ inputs:
dockerCpuLimit:
required: false
default: ''
description: 'Number of CPU cores to assign the Windows docker container. Defaults to all available cores.'
description: 'Number of CPU cores to assign the docker container. Defaults to all available cores on all platforms.'
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.'
'Amount of memory to assign the docker container. Defaults to 95% of total system memory rounded down to the
nearest megabyte on Linux and 80% on Windows. On unrecognized platforms, defaults to 75% of total system memory.
To manually specify a value, use the format <number><unit>, where unit is either m or g. ie: 512m = 512 megabytes'
allowDirtyBuild:
required: false
default: ''

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -48,6 +48,8 @@ class Docker {
sshPublicKeysDirectoryPath,
gitPrivateToken,
dockerWorkspacePath,
dockerCpuLimit,
dockerMemoryLimit,
} = parameters;
const githubHome = path.join(runnerTempPath, '_github_home');
@ -72,6 +74,8 @@ class Docker {
--volume "${actionFolder}/platforms/ubuntu/steps:/steps:z" \
--volume "${actionFolder}/platforms/ubuntu/entrypoint.sh:/entrypoint.sh:z" \
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
--cpus=${dockerCpuLimit} \
--memory=${dockerMemoryLimit} \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${
sshAgent && !sshPublicKeysDirectoryPath

View File

@ -232,9 +232,24 @@ class Input {
}
static get dockerMemoryLimit(): string {
const bytesInGigabyte = 1024 * 1024 * 1024;
const bytesInMegabyte = 1024 * 1024;
return Input.getInput('dockerMemoryLimit') || `${Math.floor((os.totalmem() / bytesInGigabyte) * 0.75)}G`;
let memoryMultiplier;
switch (os.platform()) {
case 'linux':
memoryMultiplier = 0.95;
break;
case 'win32':
memoryMultiplier = 0.8;
break;
default:
memoryMultiplier = 0.75;
break;
}
return (
Input.getInput('dockerMemoryLimit') || `${Math.floor((os.totalmem() / bytesInMegabyte) * memoryMultiplier)}m`
);
}
public static ToEnvVarFormat(input: string) {