Skip to content

Commit 363daaf

Browse files
committed
DockerBuild.ps1 fixes.
1 parent d88a7c8 commit 363daaf

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
lines changed

Build.ps1

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

18-
if ( $env:RUNNING_IN_DOCKER -and $env:START_REMOTE_DEBUGGER )
18+
if ( $VsDebug )
1919
{
2020
$vsmonport = 4024
2121
Write-Host "Starting Visual Studio Remote Debugger, listening at port $vsmonport." -ForegroundColor Cyan
@@ -24,7 +24,17 @@ if ( $env:RUNNING_IN_DOCKER -and $env:START_REMOTE_DEBUGGER )
2424
-NoNewWindow
2525
}
2626

27-
if ( -not $Interactive )
27+
# Change the prompt and window title in Docker.
28+
if ( $env:RUNNING_IN_DOCKER )
2829
{
29-
& dotnet run --project "$PSScriptRoot\$EngPath\src\Build$ProductName.csproj" -- $args
30-
}
30+
function global:prompt {
31+
$host.UI.RawUI.WindowTitle = "[docker] " + (Get-Location).Path
32+
"[docker] $(Get-Location)> "
33+
}
34+
}
35+
36+
37+
if ( -not $Interactive -or $BuildArgs )
38+
{
39+
& dotnet run --project "$PSScriptRoot\$EngPath\src\Build$ProductName.csproj" -- $BuildArgs
40+
}

DockerBuild.ps1

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function New-EnvJson
6767
$envVariables[$envName] = $envValue
6868
}
6969
}
70-
70+
7171
# Convert to JSON and save
7272
$jsonPath = Join-Path $dockerContextDirectory "env.g.json"
7373

@@ -195,14 +195,14 @@ if ( $VsDebug)
195195
Write-Host "Environment variable 'DevEnvDir' is not defined." -ForegroundColor Red
196196
exit 1
197197
}
198-
198+
199199
$remoteDebuggerHostDir = "$($env:DevEnvDir)Remote Debugger\x64"
200200
if ( -not (Test-Path $remoteDebuggerHostDir))
201201
{
202202
Write-Host "Directory '$remoteDebuggerHostDir' does not exist." -ForegroundColor Red
203203
exit 1
204204
}
205-
205+
206206
$remoteDebuggerContainerDir = "C:\msvsmon"
207207
$volumeMappings += @("-v", "${remoteDebuggerHostDir}:${remoteDebuggerContainerDir}:ro")
208208
$MountPoints += $remoteDebuggerContainerDir
@@ -269,26 +269,31 @@ if (-not $BuildImage)
269269
Write-Host "Building the product in the container." -ForegroundColor Green
270270

271271
# Prepare Build.ps1 arguments
272-
$buildCommand = "$SourceDirName\Build.ps1"
273272
if ( $VsDebug )
274273
{
275-
$BuildArgs = @("-VsDebug") + $BuildArgs
274+
$BuildArgs = @("-VsDebug") + $BuildArgs
276275
}
277-
$buildArgsString = $BuildArgs -join " "
278-
$buildCommand += " $buildArgsString"
279-
276+
280277
if ( $Interactive )
281278
{
282279
$pwshArgs = "-NoExit"
280+
$BuildArgs = @("-Interactive") + $BuildArgs
281+
$dockerArgs = @("-it")
283282
}
284283
else
285284
{
286285
$pwshArgs = "-NonInteractive"
286+
$dockerArgs = @()
287287
}
288-
289-
Write-Host "Executing in container: `".\Build.ps1 $buildArgsString`"." -ForegroundColor Cyan
290288

291-
docker run --rm --memory=12g @volumeMappings -w $SourceDirName $ImageName pwsh $pwshArgs -Command $buildCommand
289+
$buildArgsString = $BuildArgs -join " "
290+
$volumeMappingsAsString = $volumeMappings -join " "
291+
$dockerArgsAsString = $dockerArgs -join " "
292+
293+
294+
Write-Host "Executing: ``docker run --rm --memory=12g $volumeMappingsAsString -w $SourceDirName $dockerArgsAsString $ImageName pwsh $pwshArgs -Command `"& .\Build.ps1 $buildArgsString`"``." -ForegroundColor Cyan
295+
296+
docker run --rm --memory=12g @volumeMappings -w $SourceDirName @dockerArgs $ImageName pwsh $pwshArgs -Command "& .\Build.ps1 $buildArgsString"
292297
if ($LASTEXITCODE -ne 0)
293298
{
294299
Write-Host "Docker run (build) failed with exit code $LASTEXITCODE" -ForegroundColor Red

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ RUN c:\ReadEnvironmentVariables.ps1 c:\env.g.json
7070
# Configure NuGet
7171
ENV NUGET_PACKAGES=c:\packages
7272

73+
# Configure .NET SDK
74+
ENV DOTNET_NOLOGO=1
75+
7376
# Configure git
7477
ARG SRC_DIR
75-
RUN echo $env:PATH
7678
RUN git config --global --add safe.directory $env:SRC_DIR/; `
7779
git config --global user.name $env:GIT_USER_NAME; `
7880
git config --global user.email $env:GIT_USER_EMAIL;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,20 +278,22 @@ if (-not $BuildImage)
278278
{
279279
$pwshArgs = "-NoExit"
280280
$BuildArgs = @("-Interactive") + $BuildArgs
281-
$dockerArgs = "-it"
281+
$dockerArgs = @("-it")
282282
}
283283
else
284284
{
285285
$pwshArgs = "-NonInteractive"
286-
$dockerArgs = ""
286+
$dockerArgs = @()
287287
}
288288

289289
$buildArgsString = $BuildArgs -join " "
290+
$volumeMappingsAsString = $volumeMappings -join " "
291+
$dockerArgsAsString = $dockerArgs -join " "
290292

291293

292-
Write-Host "Executing in container: ``pwsh $pwshArgs -Command `"& .\Build.ps1 $buildArgsString`"``." -ForegroundColor Cyan
294+
Write-Host "Executing: ``docker run --rm --memory=12g $volumeMappingsAsString -w $SourceDirName $dockerArgsAsString $ImageName pwsh $pwshArgs -Command `"& .\Build.ps1 $buildArgsString`"``." -ForegroundColor Cyan
293295

294-
docker run --rm --memory=12g @volumeMappings -w $SourceDirName $dockerArgs $ImageName pwsh $pwshArgs -Command "& .\Build.ps1 $buildArgsString"
296+
docker run --rm --memory=12g @volumeMappings -w $SourceDirName @dockerArgs $ImageName pwsh $pwshArgs -Command "& .\Build.ps1 $buildArgsString"
295297
if ($LASTEXITCODE -ne 0)
296298
{
297299
Write-Host "Docker run (build) failed with exit code $LASTEXITCODE" -ForegroundColor Red

0 commit comments

Comments
 (0)