Skip to content

Commit 72c61ee

Browse files
committed
Use same template for installing .NET on windows and linux
1 parent aa9ad57 commit 72c61ee

File tree

68 files changed

+840
-668
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+840
-668
lines changed

eng/dockerfile-templates/Dockerfile.linux.download-dotnet renamed to eng/dockerfile-templates/Dockerfile.download-dotnet

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
{{
2-
_ ARGS:
2+
_
3+
ARGS:
34
product : Product name, e.g. "dotnet", "aspnet", "sdk"
45
extract-to : Directory where .NET will be extracted
56
extract-paths : (optional) Paths within the .NET tarball to extract
67
^
78

89
set product to ARGS["product"] ^
910

11+
set isWindows to find(OS_VERSION, "server") >= 0 ^
1012
set isAlpine to find(OS_VERSION, "alpine") >= 0 ^
11-
set platform to when(isAlpine, "linux-musl", "linux") ^
13+
14+
set templatePlatform to when(isWindows, "windows", "linux") ^
15+
set lineEnd to when(isWindows, "; `", " \") ^
16+
set lineContinue to when(isWindows, "`", "\") ^
17+
set continue to when(isWindows, "", "&& ") ^
18+
19+
set useFileVariables to isWindows ^
20+
set useExtraLines to isWindows ^
21+
set extraLine to when(useExtraLines, cat("
22+
", lineContinue), "") ^
23+
24+
set platform to
25+
when(isAlpine,
26+
"linux-musl",
27+
when(isWindows,
28+
"win",
29+
"linux"))^
1230

1331
set dotnetVersion to join(slice(split(PRODUCT_VERSION, "."), 0, 2), ".") ^
1432
set productVersion to VARIABLES[cat("dotnet|", dotnetVersion, "|product-version")] ^
@@ -37,6 +55,9 @@
3755
"dotnet_version")) ^
3856
set versionVariableRef to cat("$", versionVariable) ^
3957
set versionVariableValue to buildVersion ^
58+
set assignVersionVariable to when(isWindows,
59+
cat("$", versionVariable, " = ", versionVariableValue),
60+
cat(versionVariable, "=", versionVariableValue)) ^
4061

4162
set shaFunction to "512" ^
4263
set urlParts to split(downloadUrl, "/") ^
@@ -81,32 +102,67 @@
81102
set fileName to replace(fileName, runtimeVersionVariableValue, runtimeVersionVariableRef)
82103
}}^
83104

105+
set assign(variable, value) to:{{
106+
if (isWindows):{{
107+
return cat("$", variable, " = \@"", value, "\@"")
108+
}}^else:{{
109+
return cat(variable, "=", value)
110+
}}^_
111+
}}^
112+
84113
set filesToDownload to [
85114
["url": downloadUrl],
86115
["url": shaUrl]
87-
]
116+
]^
117+
118+
if (useFileVariables):{{
119+
set fileVariable to when(product = "aspnet", "aspnetcore_file", "dotnet_file") ^
120+
set fileVariableRef to cat("$", fileVariable) ^
121+
set fileVariableValue to fileName ^
122+
set fileName to fileVariableRef ^
123+
124+
set shaVariable to when(shaUrlIsAggregate, "dotnet_checksums_file", "dotnet_sha512_file") ^
125+
set shaVariableRef to cat("$", shaVariable) ^
126+
set shaVariableValue to shaFileName ^
127+
set shaFileName to shaVariableRef ^
128+
129+
set downloadUrl to replace(downloadUrl, fileVariableValue, fileVariableRef) ^
130+
set shaUrl to replace(shaUrl, fileVariableValue, fileVariableRef) ^
131+
set shaUrl to replace(shaUrl, shaVariableValue, shaVariableRef) ^
132+
133+
set filesToDownload to [
134+
["out-file": fileName, "url": downloadUrl],
135+
["out-file": shaFileName, "url": shaUrl]
136+
]
137+
}}^
138+
139+
set remove to when(isWindows, "Remove-Item -Force", "rm") ^
140+
set downloadFiles to cat("Dockerfile.", templatePlatform, ".download-files") ^
141+
set validateChecksum to cat("Dockerfile.", templatePlatform, ".validate-checksum") ^
142+
set extractFile to cat("Dockerfile.", templatePlatform, ".extract-file")
88143

89-
}}{{versionVariable}}={{versionVariableValue}}{{if product = "sdk" && shaUrlIsAggregate: \
90-
&& {{runtimeVersionVariable}}={{runtimeVersionVariableValue}}}} \
91-
&& {{InsertTemplate("Dockerfile.linux.download-files", [
144+
}}{{assign(versionVariable, versionVariableValue)}}{{if product = "sdk" && shaUrlIsAggregate:{{lineEnd}}
145+
{{continue}}{{assign(runtimeVersionVariable, runtimeVersionVariableValue)}}}}{{if useFileVariables:{{lineEnd}}
146+
{{continue}}{{assign(fileVariable, fileVariableValue)}}{{lineEnd}}
147+
{{continue}}{{assign(shaVariable, shaVariableValue)}}}}{{lineEnd}}{{extraLine}}
148+
{{continue}}{{InsertTemplate(downloadFiles, [
92149
"files": filesToDownload
93-
])}} \
94-
&& {{InsertTemplate("Dockerfile.linux.validate-checksum", [
150+
])}}{{lineEnd}}{{extraLine}}
151+
{{continue}}{{InsertTemplate(validateChecksum, [
95152
"file": fileName,
96153
"sha-function": shaFunction,
97154
"sha-file": shaFileName,
98155
"sha-file-is-bare": shaUrlIsBare,
99156
"sha-file-is-aggregate": shaUrlIsAggregate
100-
])}}{{
101-
if ARGS["extract-to"]: \
102-
&& mkdir --parents {{ARGS["extract-to"]}} \
103-
&& {{
104-
InsertTemplate("Dockerfile.linux.extract-file", [
157+
])}}{{if ARGS["extract-to"]:{{lineEnd}}{{extraLine}}
158+
{{continue}}mkdir {{if !isWindows:--parents }}{{ARGS["extract-to"]}}{{lineEnd}}
159+
{{continue}}{{
160+
InsertTemplate(extractFile, [
105161
"file": fileName,
106162
"dest-dir": ARGS["extract-to"],
107163
"extract-paths": ARGS["extract-paths"]
108164
])
109-
}}}} \
110-
&& rm \
111-
{{fileName}} \
165+
}}}}{{lineEnd}}
166+
{{continue}}{{remove}} {{lineContinue}}
167+
{{fileName}} {{lineContinue}}
112168
{{shaFileName}}

eng/dockerfile-templates/Dockerfile.windows.download-file

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{{
2+
_ Downloads one or more files using PowerShell
3+
4+
ARGS:
5+
files: array of files to download, with the following format:
6+
[
7+
url: URL to download the file from
8+
out-file: (optional) name of the output file
9+
]
10+
^
11+
12+
_ Documentation for using Managed Identity/OAuth tokens to access Azure storage accounts:
13+
https://learn.microsoft.com/en-us/rest/api/storageservices/authorize-with-azure-active-directory#call-storage-operations-with-oauth-tokens ^
14+
15+
set isInternal(url) to:{{
16+
return find(url, "dotnetstage") >= 0
17+
}}^
18+
19+
for i, file in ARGS["files"]:{{
20+
if (!isAnyInternal):{{
21+
set isAnyInternal to isInternal(file["url"])
22+
}}^_
23+
}}^_
24+
25+
}}{{if isAnyInternal:$Headers = @@{ `
26+
Authorization = \"Bearer $env:ACCESSTOKEN\"; `
27+
'x-ms-version' = '2017-11-09'; `
28+
}; `}}{{
29+
for i, file in ARGS["files"]:Invoke-WebRequest -OutFile {{file["out-file"]}} \"{{file["url"]}}\"{{
30+
if (isInternal(file["url"])): -Headers $Headers^
31+
set isLastFile to (i = len(ARGS["files"]) - 1)^
32+
if (!isLastFile):; `
33+
}}}}

eng/dockerfile-templates/Dockerfile.windows.install-dotnet

Lines changed: 0 additions & 66 deletions
This file was deleted.

eng/dockerfile-templates/aspnet/Dockerfile.linux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ RUN {{InsertTemplate("../Dockerfile.linux.install-pkgs",
5151
])}}
5252
}}
5353
# Retrieve ASP.NET Core
54-
RUN {{InsertTemplate("../Dockerfile.linux.download-dotnet", [
54+
RUN {{InsertTemplate("../Dockerfile.download-dotnet", [
5555
"product": "aspnet",
5656
"extract-to": "/dotnet",
5757
"extract-paths": ["./shared/Microsoft.AspNetCore.App"],

eng/dockerfile-templates/aspnet/Dockerfile.linux-composite

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ RUN {{InsertTemplate("../Dockerfile.linux.install-pkgs",
4242
])}}
4343
}}
4444
# Retrieve ASP.NET Composite Runtime
45-
RUN {{InsertTemplate("../Dockerfile.linux.download-dotnet", [
45+
RUN {{InsertTemplate("../Dockerfile.download-dotnet", [
4646
"product": "aspnet-composite",
4747
"extract-to": when(isDistroless, "/usr/share/dotnet", "/dotnet")
4848
], " ")}}

eng/dockerfile-templates/aspnet/Dockerfile.windows

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ RUN powershell -Command " `
2626
$ErrorActionPreference = 'Stop'; `
2727
$ProgressPreference = 'SilentlyContinue'; `
2828
`
29-
{{InsertTemplate("../Dockerfile.windows.install-dotnet", [
30-
"download-path": cat("/aspnetcore/Runtime/", buildVersion, "/aspnetcore-runtime-", buildVersion, "-win-x64.zip"),
31-
"extract-paths": ["./shared/Microsoft.AspNetCore.App"],
32-
"extract-dir": "dotnet",
33-
"mkdir": "dotnet/shared/Microsoft.AspNetCore.App"
29+
{{InsertTemplate("../Dockerfile.download-dotnet", [
30+
"product": "aspnet",
31+
"extract-to": "dotnet",
32+
"extract-paths": ["./shared/Microsoft.AspNetCore.App"]
3433
], " ")}}"
3534

3635

eng/dockerfile-templates/runtime/Dockerfile.linux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ RUN {{InsertTemplate("../Dockerfile.linux.install-pkgs",
5151
])}}
5252
}}
5353
# Retrieve .NET Runtime
54-
RUN {{InsertTemplate("../Dockerfile.linux.download-dotnet", [
54+
RUN {{InsertTemplate("../Dockerfile.download-dotnet", [
5555
"product": "runtime",
5656
"extract-to": when(isDistroless, "/usr/share/dotnet", "/dotnet")
5757
], " ")}}{{

eng/dockerfile-templates/runtime/Dockerfile.windows

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ RUN powershell -Command " `
2929
$ErrorActionPreference = 'Stop'; `
3030
$ProgressPreference = 'SilentlyContinue'; `
3131
`
32-
{{InsertTemplate("../Dockerfile.windows.install-dotnet", [
33-
"download-path": cat("/Runtime/", buildVersion, "/", "dotnet-runtime-", buildVersion, "-win-x64.zip"),
34-
"extract-dir": "dotnet",
35-
"mkdir": "dotnet"
32+
{{InsertTemplate("../Dockerfile.download-dotnet", [
33+
"product": "runtime",
34+
"extract-to": "dotnet"
3635
], " ")}}"
3736

3837

0 commit comments

Comments
 (0)