Skip to content

Commit 68ce7e3

Browse files
committed
Fixed DockerBuild.ps1.
1 parent 8c4af1e commit 68ce7e3

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

Build.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $EngPath = 'eng'
1515
$ProductName = 'PostSharpEngineering'
1616
####
1717

18-
if ( $StartVsmon )
18+
if ($StartVsmon)
1919
{
2020
$vsmonport = 4024
2121
Write-Host "Starting Visual Studio Remote Debugger, listening at port $vsmonport." -ForegroundColor Cyan
@@ -25,22 +25,23 @@ if ( $StartVsmon )
2525
}
2626

2727
# Change the prompt and window title in Docker.
28-
if ( $env:RUNNING_IN_DOCKER )
28+
if ($env:RUNNING_IN_DOCKER)
2929
{
30-
function global:prompt {
30+
function global:prompt
31+
{
3132
$host.UI.RawUI.WindowTitle = "[docker] " + (Get-Location).Path
32-
"[docker] $(Get-Location)> "
33+
"[docker] $( Get-Location )> "
3334
}
3435
}
3536

3637

37-
if ( -not $Interactive -or $BuildArgs )
38+
if (-not $Interactive -or $BuildArgs)
3839
{
3940
# Change the working directory so we can use a global.json that is specific to eng.
4041
$previousLocation = Get-Location
41-
42+
4243
Set-Location $PSScriptRoot\$EngPath\src
43-
44+
4445
try
4546
{
4647

DockerBuild.ps1

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ Write-Host "Volume mappings: " @VolumeMappings -ForegroundColor Gray
254254
Write-Host "Mount points: " $mountPointsAsString -ForegroundColor Gray
255255
Write-Host "Git directories: " $gitDirectoriesAsString -ForegroundColor Gray
256256

257+
# Kill all containers
258+
docker ps -q --filter "ancestor=$ImageName" | ForEach-Object {
259+
Write-Host "Killing container $_"
260+
docker kill $_
261+
}
262+
257263
# Building the image.
258264
if (-not $NoBuildImage)
259265
{
@@ -287,23 +293,23 @@ if (-not $BuildImage)
287293
if ($Interactive)
288294
{
289295
$pwshArgs = "-NoExit"
290-
$BuildArgs = @("-Interactive") + $BuildArgs
291-
$dockerArgs = @("-it")
296+
$BuildArgs = @("-Interactive") + $BuildArgs
297+
$dockerArgs = @("-it")
292298
}
293299
else
294300
{
295301
$pwshArgs = "-NonInteractive"
296-
$dockerArgs = @()
302+
$dockerArgs = @()
297303
}
298304

299305
$buildArgsString = $BuildArgs -join " "
300-
$VolumeMappingsAsString = $VolumeMappings -join " "
301-
$dockerArgsAsString = $dockerArgs -join " "
306+
$VolumeMappingsAsString = $VolumeMappings -join " "
307+
$dockerArgsAsString = $dockerArgs -join " "
302308

303309

304-
Write-Host "Executing: ``docker run --rm --memory=12g $VolumeMappingsAsString -w $SourceDirName $dockerArgsAsString $ImageName pwsh $pwshArgs -Command `"& .\Build.ps1 $buildArgsString`; exit `$LASTEXITCODE`"``." -ForegroundColor Cyan
310+
Write-Host "Executing: ``docker run --rm --memory= 12g $VolumeMappingsAsString -w $SourceDirName $dockerArgsAsString $ImageName pwsh $pwshArgs -Command `"& .\Build.ps1 $buildArgsString`; exit `$LASTEXITCODE`"``." -ForegroundColor Cyan
305311

306-
docker run --rm --memory=12g @VolumeMappings -w $SourceDirName @dockerArgs $ImageName pwsh $pwshArgs -Command "& .\Build.ps1 $buildArgsString`; exit `$LASTEXITCODE;"
312+
docker run --rm --memory=12g @VolumeMappings -w $SourceDirName @dockerArgs $ImageName pwsh $pwshArgs -Command "& .\Build.ps1 $buildArgsString`; exit `$LASTEXITCODE; "
307313
if ($LASTEXITCODE -ne 0)
308314
{
309315
Write-Host "Docker run (build) failed with exit code $LASTEXITCODE" -ForegroundColor Red

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ param(
1313
[string]$BuildAgentPath = 'C:\BuildAgent',
1414
[switch]$LoadEnvFromKeyVault, # Forces loading environment variables form the key vault.
1515
[switch]$StartVsmon, # Enable the remote debugger.
16-
[switch]$KillAll, # Kill all containers before building the image.
1716
[Parameter(ValueFromRemainingArguments)]
1817
[string[]]$BuildArgs # Arguments passed to `Build.ps1` within the container.
1918
)
@@ -256,9 +255,9 @@ Write-Host "Mount points: " $mountPointsAsString -ForegroundColor Gray
256255
Write-Host "Git directories: " $gitDirectoriesAsString -ForegroundColor Gray
257256

258257
# Kill all containers
259-
docker ps -q | ForEach-Object {
260-
Write-Host "Killing container
261-
docker rm -f $_
258+
docker ps -q --filter "ancestor=$ImageName" | ForEach-Object {
259+
Write-Host "Killing container $_"
260+
docker kill $_
262261
}
263262

264263
# Building the image.

0 commit comments

Comments
 (0)