Skip to content

Commit dcddbe8

Browse files
gfraiteurclaude
andcommitted
Add -Cpus parameter to DockerBuild.ps1 for CPU limit control
Adds a new parameter to control Docker container CPU allocation, defaulting to the host's processor count. Passes --cpus to docker run commands. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 6914f47 commit dcddbe8

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

DockerBuild.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ param(
1818
[string]$Script = 'Build.ps1', # The build script to be executed inside Docker.
1919
[string]$Isolation = 'process', # Docker isolation mode (process or hyperv).
2020
[string]$Memory = '8g', # Docker memory limit.
21+
[int]$Cpus = [Environment]::ProcessorCount, # Docker CPU limit (defaults to host's CPU count).
2122
[Parameter(ValueFromRemainingArguments)]
2223
[string[]]$BuildArgs # Arguments passed to `Build.ps1` within the container (or Claude prompt if -Claude is specified).
2324
)
@@ -916,8 +917,8 @@ if (-not $BuildImage)
916917
try
917918
{
918919
# Start new container with docker run
919-
Write-Host "Executing: docker run --rm --memory=$Memory --isolation=$Isolation $dockerArgsAsString $VolumeMappingsAsString -e HOME=$containerUserProfile -e USERPROFILE=$containerUserProfile -w $ContainerSourceDir $ImageTag `"$pwshPath`" -Command `"$inlineScript`"" -ForegroundColor Cyan
920-
docker run --rm --memory=$Memory --isolation=$Isolation $dockerArgs @volumeArgs @envArgs -w $ContainerSourceDir $ImageTag $pwshPath -Command $inlineScript
920+
Write-Host "Executing: docker run --rm --memory=$Memory --cpus=$Cpus --isolation=$Isolation $dockerArgsAsString $VolumeMappingsAsString -e HOME=$containerUserProfile -e USERPROFILE=$containerUserProfile -w $ContainerSourceDir $ImageTag `"$pwshPath`" -Command `"$inlineScript`"" -ForegroundColor Cyan
921+
docker run --rm --memory=$Memory --cpus=$Cpus --isolation=$Isolation $dockerArgs @volumeArgs @envArgs -w $ContainerSourceDir $ImageTag $pwshPath -Command $inlineScript
921922
$dockerExitCode = $LASTEXITCODE
922923
}
923924
finally
@@ -1039,8 +1040,8 @@ if (-not $BuildImage)
10391040
else
10401041
{
10411042
# Start new container with docker run
1042-
Write-Host "Executing: ``docker run --rm --memory=$Memory --isolation=$Isolation $dockerArgsAsString $VolumeMappingsAsString -w $ContainerSourceDir $ImageTag `"$pwshPath`" $pwshArgs -Command `"$inlineScript`"" -ForegroundColor Cyan
1043-
docker run --rm --memory=$Memory --isolation=$Isolation $dockerArgs @volumeArgs -w $ContainerSourceDir $ImageTag $pwshPath $pwshArgs -Command $inlineScript
1043+
Write-Host "Executing: ``docker run --rm --memory=$Memory --cpus=$Cpus --isolation=$Isolation $dockerArgsAsString $VolumeMappingsAsString -w $ContainerSourceDir $ImageTag `"$pwshPath`" $pwshArgs -Command `"$inlineScript`"" -ForegroundColor Cyan
1044+
docker run --rm --memory=$Memory --cpus=$Cpus --isolation=$Isolation $dockerArgs @volumeArgs -w $ContainerSourceDir $ImageTag $pwshPath $pwshArgs -Command $inlineScript
10441045
}
10451046

10461047
if ($LASTEXITCODE -ne 0)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ param(
1818
[string]$Script = 'Build.ps1', # The build script to be executed inside Docker.
1919
[string]$Isolation = 'process', # Docker isolation mode (process or hyperv).
2020
[string]$Memory = '8g', # Docker memory limit.
21+
[int]$Cpus = [Environment]::ProcessorCount, # Docker CPU limit (defaults to host's CPU count).
2122
[Parameter(ValueFromRemainingArguments)]
2223
[string[]]$BuildArgs # Arguments passed to `Build.ps1` within the container (or Claude prompt if -Claude is specified).
2324
)
@@ -916,8 +917,8 @@ if (-not $BuildImage)
916917
try
917918
{
918919
# Start new container with docker run
919-
Write-Host "Executing: docker run --rm --memory=$Memory --isolation=$Isolation $dockerArgsAsString $VolumeMappingsAsString -e HOME=$containerUserProfile -e USERPROFILE=$containerUserProfile -w $ContainerSourceDir $ImageTag `"$pwshPath`" -Command `"$inlineScript`"" -ForegroundColor Cyan
920-
docker run --rm --memory=$Memory --isolation=$Isolation $dockerArgs @volumeArgs @envArgs -w $ContainerSourceDir $ImageTag $pwshPath -Command $inlineScript
920+
Write-Host "Executing: docker run --rm --memory=$Memory --cpus=$Cpus --isolation=$Isolation $dockerArgsAsString $VolumeMappingsAsString -e HOME=$containerUserProfile -e USERPROFILE=$containerUserProfile -w $ContainerSourceDir $ImageTag `"$pwshPath`" -Command `"$inlineScript`"" -ForegroundColor Cyan
921+
docker run --rm --memory=$Memory --cpus=$Cpus --isolation=$Isolation $dockerArgs @volumeArgs @envArgs -w $ContainerSourceDir $ImageTag $pwshPath -Command $inlineScript
921922
$dockerExitCode = $LASTEXITCODE
922923
}
923924
finally
@@ -1039,8 +1040,8 @@ if (-not $BuildImage)
10391040
else
10401041
{
10411042
# Start new container with docker run
1042-
Write-Host "Executing: ``docker run --rm --memory=$Memory --isolation=$Isolation $dockerArgsAsString $VolumeMappingsAsString -w $ContainerSourceDir $ImageTag `"$pwshPath`" $pwshArgs -Command `"$inlineScript`"" -ForegroundColor Cyan
1043-
docker run --rm --memory=$Memory --isolation=$Isolation $dockerArgs @volumeArgs -w $ContainerSourceDir $ImageTag $pwshPath $pwshArgs -Command $inlineScript
1043+
Write-Host "Executing: ``docker run --rm --memory=$Memory --cpus=$Cpus --isolation=$Isolation $dockerArgsAsString $VolumeMappingsAsString -w $ContainerSourceDir $ImageTag `"$pwshPath`" $pwshArgs -Command `"$inlineScript`"" -ForegroundColor Cyan
1044+
docker run --rm --memory=$Memory --cpus=$Cpus --isolation=$Isolation $dockerArgs @volumeArgs -w $ContainerSourceDir $ImageTag $pwshPath $pwshArgs -Command $inlineScript
10441045
}
10451046

10461047
if ($LASTEXITCODE -ne 0)

0 commit comments

Comments
 (0)