-
Notifications
You must be signed in to change notification settings - Fork 20
/
build-container.ps1
57 lines (49 loc) · 2.17 KB
/
build-container.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
param(
[Parameter(Mandatory = $false)][string] $Arch = "x64",
[Parameter(Mandatory = $false)][string] $Tag = $null,
[Parameter(Mandatory = $false)][switch] $Cache
)
$ErrorActionPreference = "Stop"
. .\windows\versions.ps1
$BaseTable = @{
1809 = "mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019";
1909 = "mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-1909";
2004 = "mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-2004";
## 20H2 reports itself as 2009 in the registry
2009 = "mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-20H2"
2022 = "mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2022"
}
$kernelver = [int](get-itemproperty -path "hklm:software\microsoft\windows nt\currentversion" -name releaseid).releaseid
$build = [System.Environment]::OSVersion.version.build
$productname = (get-itemproperty -path "hklm:software\microsoft\windows nt\currentversion" -n productname).productname
Write-Host -ForegroundColor Green "Detected kernel version $kernelver, build $build and product name $productname"
# Windows Server 2022 still reports 2009 as releaseid
if ($build -ge 20348) {
$kernelver = 2022
}
Write-Host -ForegroundColor Green "Using base image $($BaseTable[$kernelver])"
$arglist = @()
if($Tag -eq $null -or $Tag -eq ""){
$Tag ="builder_$($kernelver)_$Arch"
}
$arglist += "build"
# Read arguments from go.env file
$lines = Get-Content -Path 'go.env'
foreach ($line in $lines) {
$arglist += "--build-arg"
$arglist += "$line"
}
foreach ($h in $SoftwareTable.GetEnumerator()){
if( -not ($($h.Key) -like "*SHA256")){
$arglist += "--build-arg"
$arglist += "$($h.Key)=$($h.Value)"
}
}
if( -not $Cache) {
$arglist += "--no-cache"
}
$arglist += -split "-m 4096M --build-arg BASE_IMAGE=$($BaseTable[$kernelver]) --build-arg DD_TARGET_ARCH=$Arch --build-arg WINDOWS_VERSION=$kernelver -t $Tag --file .\windows\Dockerfile ."
# Write-Host -ForegroundColor Green "Building with the following command:"
# Write-Host -ForegroundColor Green "$buildcommand `n"
filter timestamp {"$(Get-Date -Format o): $_"}
& docker $arglist | timestamp