-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathDockerfile
More file actions
103 lines (93 loc) · 4.89 KB
/
Dockerfile
File metadata and controls
103 lines (93 loc) · 4.89 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# escape=`
ARG REPO=mcr.microsoft.com/dotnet/aspnet
# Installer image
FROM mcr.microsoft.com/windows/servercore:1809-amd64 AS installer
# Download MinGit
RUN powershell -Command " `
$ErrorActionPreference = 'Stop'; `
$ProgressPreference = 'SilentlyContinue'; `
`
Invoke-WebRequest -OutFile mingit.zip https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.1/MinGit-2.53.0-64-bit.zip; `
$mingit_sha256 = '82b562c918ec87b2ef5316ed79bb199e3a25719bb871a0f10294acf21ebd08cd'; `
if ((Get-FileHash mingit.zip -Algorithm sha256).Hash -ne $mingit_sha256) { `
Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
exit 1; `
}; `
mkdir MinGit; `
tar --gzip --extract --no-same-owner --file mingit.zip --directory MinGit; `
Remove-Item -Force mingit.zip"
RUN powershell -Command " `
$ErrorActionPreference = 'Stop'; `
$ProgressPreference = 'SilentlyContinue'; `
`
# Retrieve .NET SDK
$dotnet_sdk_version = '9.0.312'; `
$dotnet_version = '9.0.14'; `
$dotnet_file = 'dotnet-sdk-' + $dotnet_sdk_version + '-win-x64.zip'; `
$dotnet_checksums_file = $dotnet_version + '-sha.txt'; `
`
Invoke-WebRequest -OutFile $dotnet_file https://builds.dotnet.microsoft.com/dotnet/Sdk/$dotnet_sdk_version/$dotnet_file; `
Invoke-WebRequest -OutFile $dotnet_checksums_file https://builds.dotnet.microsoft.com/dotnet/checksums/$dotnet_checksums_file; `
`
$dotnet_sha512 = ( `
(Get-Content $dotnet_checksums_file | Where-Object { `
$_ -match ([regex]::Escape($dotnet_file))` + '$'; `
}) -split '\s+' `
)[0].ToUpper(); `
$actual_hash = (Get-FileHash $dotnet_file -Algorithm SHA512).Hash.ToUpper(); `
`
if ($dotnet_sha512 -ne $actual_hash) { `
Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
Write-Host 'Expected: ' + $dotnet_sha512; `
Write-Host 'Actual: ' + $actual_hash; `
exit 1; `
}; `
`
mkdir dotnet; `
tar --gzip --extract --no-same-owner --file $dotnet_file --directory dotnet; `
Remove-Item -Force `
$dotnet_file, `
$dotnet_checksums_file; `
`
# Install PowerShell global tool
$powershell_version = '7.5.4'; `
Invoke-WebRequest -OutFile PowerShell.Windows.x64.$powershell_version.nupkg https://powershellinfraartifacts-gkhedzdeaghdezhr.z01.azurefd.net/tool/$powershell_version/PowerShell.Windows.x64.$powershell_version.nupkg; `
$powershell_sha512 = '060aa45fa4c9d92fb6c5f2ab60e2265cf048a4bf67c8b7da1fc3c5c1e7ab1ead8fcf1302d05133e3308a10535c5e299d1f76ba0e1ccee0ff56a4fcaa556f9b7d'; `
if ((Get-FileHash PowerShell.Windows.x64.$powershell_version.nupkg -Algorithm sha512).Hash -ne $powershell_sha512) { `
Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
exit 1; `
}; `
& \dotnet\dotnet tool install --add-source . --tool-path \powershell --version $powershell_version PowerShell.Windows.x64; `
& \dotnet\dotnet nuget locals all --clear; `
Remove-Item -Force PowerShell.Windows.x64.$powershell_version.nupkg; `
Remove-Item -Path \powershell\.store\powershell.windows.x64\$powershell_version\powershell.windows.x64\$powershell_version\powershell.windows.x64.$powershell_version.nupkg -Force; `
`
# Delete everything in the dotnet folder that's not needed in the SDK layer but will instead be derived from base layers
Get-ChildItem -Exclude 'LICENSE.txt','ThirdPartyNotices.txt','packs','sdk','sdk-manifests','templates','shared' -Path dotnet `
| Remove-Item -Force -Recurse; `
Get-ChildItem -Exclude 'Microsoft.WindowsDesktop.App' -Path dotnet\shared `
| Remove-Item -Force -Recurse"
# SDK image
FROM $REPO:9.0.14-nanoserver-1809
ENV `
# Do not generate certificate
DOTNET_GENERATE_ASPNET_CERTIFICATE=false `
# Do not show first run text
DOTNET_NOLOGO=true `
# SDK version
DOTNET_SDK_VERSION=9.0.312 `
# Enable correct mode for dotnet watch (only mode supported in a container)
DOTNET_USE_POLLING_FILE_WATCHER=true `
# Skip extraction of XML docs - generally not useful within an image/container - helps performance
NUGET_XMLDOC_MODE=skip `
# PowerShell telemetry for docker image usage
POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-DotnetSDK-NanoServer-1809
# In order to set system PATH, ContainerAdministrator must be used
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;C:\Program Files\powershell;C:\Program Files\MinGit\cmd"
USER ContainerUser
COPY --from=installer ["/dotnet", "/Program Files/dotnet"]
COPY --from=installer ["/powershell", "/Program Files/powershell"]
COPY --from=installer ["/MinGit", "/Program Files/MinGit"]
# Trigger first run experience by running arbitrary cmd
RUN dotnet help