|
1 | 1 | # The original of this file is in the PostSharp.Engineering repo. |
2 | 2 | # You can generate this file using `./Build.ps1 generate-scripts`. |
| 3 | + |
3 | 4 | [CmdletBinding(PositionalBinding = $false)] |
4 | 5 | param( |
5 | | - [switch]$Interactive, |
6 | | - [switch]$BuildImage, |
7 | | - [switch]$NoBuildImage, |
8 | | - [switch]$NoClean, |
9 | | - [string]$ImageName, |
| 6 | + [switch]$Interactive, # Opens an interactive PowerShell session |
| 7 | + [switch]$BuildImage, # Only builds the image, but does not build the product. |
| 8 | + [switch]$NoBuildImage, # Does not build the image. |
| 9 | + [switch]$NoClean, # Does not clean up. |
| 10 | + [switch]$NoNuGetCache, # Does not mount the host nuget cache in the container. |
| 11 | + [switch]$KeepSecrets, # Does not override the secrets.g.json file. |
| 12 | + [string]$ImageName, # Image name (defaults to a name based on the directory). |
10 | 13 | [string]$BuildAgentPath = 'C:\BuildAgent', |
11 | 14 | [Parameter(ValueFromRemainingArguments)] |
12 | | - [string[]]$BuildArgs |
| 15 | + [string[]]$BuildArgs # Arguments passed to `Build.ps1` within the container. |
13 | 16 | ) |
14 | 17 |
|
15 | 18 | # This setting is replaced by the generate-scripts command. |
@@ -87,57 +90,67 @@ if (-not $env:IS_TEAMCITY_AGENT -and -not $NoClean) |
87 | 90 | Get-ChildItem @("bin", "obj") -Recurse | Remove-Item -Force -Recurse -ProgressAction SilentlyContinue |
88 | 91 | } |
89 | 92 |
|
90 | | -# Create secrets JSON file (after cleanup) |
91 | | -$secretsJsonPath = New-SecretsJson -EnvironmentVariableList $EnvironmentVariables |
| 93 | +# Create secrets JSON file. |
| 94 | +if ( -not $KeepSecrets ) |
| 95 | +{ |
| 96 | + New-SecretsJson -EnvironmentVariableList $EnvironmentVariables |
| 97 | +} |
92 | 98 |
|
93 | 99 | # Get the source directory name from $PSScriptRoot |
94 | 100 | $SourceDirName = $PSScriptRoot |
95 | 101 |
|
96 | 102 | # Start timing the entire process except cleaning |
97 | 103 | $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() |
98 | 104 |
|
99 | | - |
100 | | - |
101 | 105 | # Ensure docker context directory exists and contains at least one file |
102 | 106 | if (-not (Test-Path $dockerContextDirectory)) |
103 | 107 | { |
104 | 108 | Write-Error "Docker context directory '$dockerContextDirectory' does not exist." |
105 | 109 | exit 1 |
106 | 110 | } |
107 | 111 |
|
108 | | -# Create local NuGet cache directory if it doesn't exist |
109 | | -$nugetCacheDir = Join-Path $env:USERPROFILE ".nuget\packages" |
110 | | -Write-Host "NuGet cache directory: $nugetCacheDir" -ForegroundColor Cyan |
111 | | -if (-not (Test-Path $nugetCacheDir)) |
112 | | -{ |
113 | | - Write-Host "Creating NuGet cache directory on host: $nugetCacheDir" |
114 | | - New-Item -ItemType Directory -Force -Path $nugetCacheDir | Out-Null |
115 | | -} |
| 112 | + |
| 113 | +# Prepare volume mappings |
| 114 | +$volumeMappings = @("-v", "${SourceDirName}:${SourceDirName}") |
| 115 | +$MountPoints = @($SourceDirName) |
| 116 | + |
116 | 117 | # Define static Git system directory for mapping |
117 | 118 | $gitSystemDir = "$BuildAgentPath\system\git" |
118 | 119 |
|
119 | | -# Prepare volume mappings |
120 | | -$volumeMappings = @("-v", "${SourceDirName}:${SourceDirName}", "-v", "${nugetCacheDir}:c:\packages") |
121 | | -$MountPoints = @($SourceDirName, "c:\packages") |
122 | 120 | if (Test-Path $gitSystemDir) |
123 | 121 | { |
124 | 122 | $volumeMappings += @("-v", "${gitSystemDir}:${gitSystemDir}:ro") |
125 | 123 | $MountPoints += $gitSystemDir |
126 | 124 | } |
127 | 125 |
|
| 126 | +# Mount the host NuGet cache in the container. |
| 127 | +if ( -not $NoNuGetCache ) |
| 128 | +{ |
| 129 | + $nugetCacheDir = Join-Path $env:USERPROFILE ".nuget\packages" |
| 130 | + Write-Host "NuGet cache directory: $nugetCacheDir" -ForegroundColor Cyan |
| 131 | + if (-not (Test-Path $nugetCacheDir)) |
| 132 | + { |
| 133 | + Write-Host "Creating NuGet cache directory on host: $nugetCacheDir" |
| 134 | + New-Item -ItemType Directory -Force -Path $nugetCacheDir | Out-Null |
| 135 | + } |
| 136 | + |
| 137 | + $volumeMappings += @("-v", "${nugetCacheDir}:c:\packages") |
| 138 | +} |
| 139 | + |
| 140 | +# We must add a MountPoint anyway so the directory is created in the container. |
| 141 | +$MountPoints += "c:\packages" |
| 142 | + |
128 | 143 |
|
129 | | -# Execute auto-generated DockerMounts script in current context |
| 144 | +# Execute auto-generated DockerMounts.g.ps1 script to add more directory mounts. |
130 | 145 | $dockerMountsScript = Join-Path $EngPath 'DockerMounts.g.ps1' |
131 | 146 | if (Test-Path $dockerMountsScript) |
132 | 147 | { |
133 | 148 | Write-Host "Importing Docker mount points from $dockerMountsScript" -ForegroundColor Cyan |
134 | 149 | . $dockerMountsScript |
135 | 150 | } |
136 | 151 |
|
137 | | - |
138 | 152 | $mountPointsArg = $MountPoints -Join ";" |
139 | 153 |
|
140 | | - |
141 | 154 | Write-Host "Volume mappings: " @volumeMappings -ForegroundColor Gray |
142 | 155 | Write-Host "Mount points: " $mountPointsArg -ForegroundColor Gray |
143 | 156 |
|
|
0 commit comments