Skip to content

Commit 778b586

Browse files
DockerBuild.ps1: default Memory and Cpus from BuildAgent environment variables
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9472ae1 commit 778b586

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/PostSharp.Engineering.BuildTools/Resources/DockerBuild.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@
7878
Memory and CPU limits only apply to hyperv isolation.
7979
8080
.PARAMETER Memory
81-
Docker memory limit (e.g., "8g"). Only used with hyperv isolation. Defaults to 24g.
81+
Docker memory limit (e.g., "8g"). Only used with hyperv isolation.
82+
Defaults to $env:BuildAgentMemory (an integer in GB) if set, otherwise 24g.
8283
8384
.PARAMETER Cpus
84-
Docker CPU limit. Defaults to the host processor count. Only used with hyperv isolation.
85+
Docker CPU limit. Only used with hyperv isolation.
86+
Defaults to $env:BuildAgentCpus if set, otherwise the host processor count.
8587
8688
.PARAMETER Mount
8789
Additional directories to mount from the host (readonly by default, append :w for writable).
@@ -143,8 +145,8 @@ param(
143145
[string]$RegistryImage, # Use a pre-built image from a registry, skipping Dockerfile build entirely.
144146
[switch]$NoInit, # Do not generate or call Init.g.ps1 (skips git config, safe.directory, etc).
145147
[string]$Isolation = 'hyperv', # Docker isolation mode (process or hyperv). Memory/CPU limits only apply to hyperv.
146-
[string]$Memory = '24g', # Docker memory limit (e.g., "8g"). Only used with hyperv isolation.
147-
[int]$Cpus = [Environment]::ProcessorCount, # Docker CPU limit. Only used with hyperv isolation.
148+
[string]$Memory = $(if ($env:BuildAgentMemory) { "${env:BuildAgentMemory}g" } else { '24g' }), # Docker memory limit (e.g., "8g"). Only used with hyperv isolation. Defaults to $env:BuildAgentMemory (in GB) or 24g.
149+
[int]$Cpus = $(if ($env:BuildAgentCpus) { [int]$env:BuildAgentCpus } else { [Environment]::ProcessorCount }), # Docker CPU limit. Only used with hyperv isolation. Defaults to $env:BuildAgentCpus or host processor count.
148150
[string[]]$Mount, # Additional directories to mount from host (readonly by default, append :w for writable). Supports * and ** glob patterns.
149151
[string[]]$Env, # Additional environment variables to pass from host to container.
150152
[string[]]$Ports, # Port mappings from host to container (e.g., "8080:80", "3000").

0 commit comments

Comments
 (0)