@@ -53,7 +53,8 @@ function New-EnvJson
5353 {
5454 $moduleName = " Az.KeyVault"
5555
56- if (-not (Get-Module - ListAvailable - Name $moduleName )) {
56+ if (-not (Get-Module - ListAvailable - Name $moduleName ))
57+ {
5758 Write-Error " The required module '$moduleName ' is not installed. Please install it with: Install-Module -Name $moduleName "
5859 exit 1
5960 }
@@ -158,18 +159,16 @@ if (-not (Test-Path $dockerContextDirectory))
158159
159160
160161# Prepare volume mappings
161- $volumeMappings = @ (" -v" , " ${SourceDirName} :${SourceDirName} " )
162- $MountPoints = @ ($SourceDirName )
163-
164- # We must add a MountPoint anyway so the directory is created in the container.
165- $MountPoints += " c:\packages"
162+ $VolumeMappings = @ (" -v" , " ${SourceDirName} :${SourceDirName} " )
163+ $MountPoints = @ ($SourceDirName , " c:\packages" )
164+ $GitDirectories = @ ($SourceDirName )
166165
167- # Define static Git system directory for mapping
166+ # Define static Git system directory for mapping. This used by Teamcity as an LFS parent repo.
168167$gitSystemDir = " $BuildAgentPath \system\git"
169168
170169if (Test-Path $gitSystemDir )
171170{
172- $volumeMappings += @ (" -v" , " ${gitSystemDir} :${gitSystemDir} :ro" )
171+ $VolumeMappings += @ (" -v" , " ${gitSystemDir} :${gitSystemDir} :ro" )
173172 $MountPoints += $gitSystemDir
174173}
175174
@@ -184,27 +183,27 @@ if (-not $NoNuGetCache)
184183 New-Item - ItemType Directory - Force - Path $nugetCacheDir | Out-Null
185184 }
186185
187- $volumeMappings += @ (" -v" , " ${nugetCacheDir} :c:\packages" )
186+ $VolumeMappings += @ (" -v" , " ${nugetCacheDir} :c:\packages" )
188187}
189188
190189# Mount VS Remote Debugger
191- if ( $VsDebug )
190+ if ($VsDebug )
192191{
193- if ( -not $env: DevEnvDir )
192+ if (-not $env: DevEnvDir )
194193 {
195194 Write-Host " Environment variable 'DevEnvDir' is not defined." - ForegroundColor Red
196195 exit 1
197196 }
198197
199- $remoteDebuggerHostDir = " $ ( $env: DevEnvDir ) Remote Debugger\x64"
200- if ( -not (Test-Path $remoteDebuggerHostDir ))
198+ $remoteDebuggerHostDir = " $ ( $env: DevEnvDir ) Remote Debugger\x64"
199+ if (-not (Test-Path $remoteDebuggerHostDir ))
201200 {
202201 Write-Host " Directory '$remoteDebuggerHostDir ' does not exist." - ForegroundColor Red
203202 exit 1
204203 }
205204
206205 $remoteDebuggerContainerDir = " C:\msvsmon"
207- $volumeMappings += @ (" -v" , " ${remoteDebuggerHostDir} :${remoteDebuggerContainerDir} :ro" )
206+ $VolumeMappings += @ (" -v" , " ${remoteDebuggerHostDir} :${remoteDebuggerContainerDir} :ro" )
208207 $MountPoints += $remoteDebuggerContainerDir
209208
210209}
@@ -221,14 +220,21 @@ if (Test-Path $sourceDependenciesDir)
221220 if (-not [string ]::IsNullOrEmpty($targetPath ) -and (Test-Path $targetPath ))
222221 {
223222 Write-Host " Found symbolic link '$ ( $link.Name ) ' -> '$targetPath '" - ForegroundColor Cyan
224- $volumeMappings += @ (" -v" , " ${targetPath} :${targetPath} :ro" )
223+ $VolumeMappings += @ (" -v" , " ${targetPath} :${targetPath} :ro" )
225224 $MountPoints += $targetPath
225+ $GitDirectories += $targetPath
226226 }
227227 else
228228 {
229229 Write-Host " Warning: Symbolic link '$ ( $link.Name ) ' target '$targetPath ' does not exist or is invalid" - ForegroundColor Yellow
230230 }
231231 }
232+
233+ $sourceDirectories = Get-ChildItem - Path $sourceDependenciesDir - Force | Where-Object { $_.LinkType -eq $null }
234+ foreach ($sourceDirectory in $sourceDirectories )
235+ {
236+ $GitDirectories += $sourceDirectory
237+ }
232238}
233239
234240# Execute auto-generated DockerMounts.g.ps1 script to add more directory mounts.
@@ -239,16 +245,18 @@ if (Test-Path $dockerMountsScript)
239245 . $dockerMountsScript
240246}
241247
242- $mountPointsArg = $MountPoints -Join " ;"
248+ $mountPointsAsString = $MountPoints -Join " ;"
249+ $gitDirectoriesAsString = $GitDirectories -Join " ;"
243250
244- Write-Host " Volume mappings: " @volumeMappings - ForegroundColor Gray
245- Write-Host " Mount points: " $mountPointsArg - ForegroundColor Gray
251+ Write-Host " Volume mappings: " @VolumeMappings - ForegroundColor Gray
252+ Write-Host " Mount points: " $mountPointsAsString - ForegroundColor Gray
253+ Write-Host " Git directories: " $gitDirectoriesAsString - ForegroundColor Gray
246254
247255# Building the image.
248256if (-not $NoBuildImage )
249257{
250258 Write-Host " Building the image." - ForegroundColor Green
251- Get-Content - Raw Dockerfile | docker build - t $ImageName -- build-arg SRC_DIR = " $SourceDirName " -- build-arg MOUNTPOINTS= " $mountPointsArg " -f - $dockerContextDirectory
259+ Get-Content - Raw Dockerfile | docker build - t $ImageName -- build-arg GITDIRS = " $gitDirectoriesAsString " -- build-arg MOUNTPOINTS= " $mountPointsAsString " -f - $dockerContextDirectory
252260 if ($LASTEXITCODE -ne 0 )
253261 {
254262 Write-Host " Docker build failed with exit code $LASTEXITCODE " - ForegroundColor Red
@@ -269,12 +277,12 @@ if (-not $BuildImage)
269277 Write-Host " Building the product in the container." - ForegroundColor Green
270278
271279 # Prepare Build.ps1 arguments
272- if ( $VsDebug )
280+ if ($VsDebug )
273281 {
274282 $BuildArgs = @ (" -VsDebug" ) + $BuildArgs
275283 }
276284
277- if ( $Interactive )
285+ if ($Interactive )
278286 {
279287 $pwshArgs = " -NoExit"
280288 $BuildArgs = @ (" -Interactive" ) + $BuildArgs
@@ -287,13 +295,13 @@ if (-not $BuildImage)
287295 }
288296
289297 $buildArgsString = $BuildArgs -join " "
290- $volumeMappingsAsString = $volumeMappings -join " "
298+ $VolumeMappingsAsString = $VolumeMappings -join " "
291299 $dockerArgsAsString = $dockerArgs -join " "
292300
293301
294- Write-Host " Executing: `` docker run --rm --memory=12g $volumeMappingsAsString -w $SourceDirName $dockerArgsAsString $ImageName pwsh $pwshArgs -Command `" & .\Build.ps1 $buildArgsString `"`` ." - ForegroundColor Cyan
302+ Write-Host " Executing: `` docker run --rm --memory=12g $VolumeMappingsAsString -w $SourceDirName $dockerArgsAsString $ImageName pwsh $pwshArgs -Command `" & .\Build.ps1 $buildArgsString `"`` ." - ForegroundColor Cyan
295303
296- docker run -- rm -- memory= 12g @volumeMappings - w $SourceDirName @dockerArgs $ImageName pwsh $pwshArgs - Command " & .\Build.ps1 $buildArgsString "
304+ docker run -- rm -- memory= 12g @VolumeMappings - w $SourceDirName @dockerArgs $ImageName pwsh $pwshArgs - Command " & .\Build.ps1 $buildArgsString "
297305 if ($LASTEXITCODE -ne 0 )
298306 {
299307 Write-Host " Docker run (build) failed with exit code $LASTEXITCODE " - ForegroundColor Red
0 commit comments