Skip to content

Commit

Permalink
Provide a default for linux to allow providing a custom limit on linu…
Browse files Browse the repository at this point in the history
…x containers
  • Loading branch information
AndrewKahr committed Oct 27, 2023
1 parent 9e22e88 commit d47dc75
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
7 changes: 4 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down
20 changes: 17 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/model/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class Docker {
sshPublicKeysDirectoryPath,
gitPrivateToken,
dockerWorkspacePath,
dockerCpuLimit,
dockerMemoryLimit,
} = parameters;

const githubHome = path.join(runnerTempPath, '_github_home');
Expand All @@ -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
Expand Down
19 changes: 17 additions & 2 deletions src/model/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,24 @@ class Input {
}

static get dockerMemoryLimit(): string {
const bytesInGigabyte = 1024 * 1024 * 1024;
const bytesInMegabyte = 1024 * 1024;

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() / bytesInGigabyte) * 0.75)}G`;
return (
Input.getInput('dockerMemoryLimit') || `${Math.floor((os.totalmem() / bytesInMegabyte) * memoryMultiplier)}m`
);
}

public static ToEnvVarFormat(input: string) {
Expand Down

0 comments on commit d47dc75

Please sign in to comment.