Skip to content

Commit eeedad0

Browse files
authored
Use online checksums for Linux .NET images (#6508)
1 parent 4a175e3 commit eeedad0

File tree

561 files changed

+4914
-3024
lines changed

Some content is hidden

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

561 files changed

+4914
-3024
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{
2+
_ Download, verify, extract, and clean up an "appliance" product
3+
4+
ARGS:
5+
product : Product name, e.g. "yarp", "aspire-dashboard", etc.
6+
productVersion : Version of the product that will be downloaded
7+
download-url : URL to download the product from
8+
sha : SHA512 checksum of the product archive
9+
file-name : Name of the file to download, e.g. "yarp.zip"
10+
extract-to : Directory where the product will be extracted to
11+
12+
}}{{InsertTemplate("Dockerfile.linux.download-files", [
13+
"files": [
14+
["url": ARGS["download-url"], "out-file": ARGS["file-name"]]
15+
]
16+
])}} \
17+
&& {{InsertTemplate("Dockerfile.linux.validate-checksum", [
18+
"file": ARGS["file-name"],
19+
"sha-function": "512",
20+
"sha": ARGS["sha"],
21+
"sha-var-name": cat(ARGS["product"], "_sha512")
22+
])}} \
23+
&& mkdir --parents {{ARGS["extract-to"]}} \
24+
&& {{InsertTemplate("Dockerfile.linux.extract-file", [
25+
"file": ARGS["file-name"],
26+
"dest-dir": ARGS["extract-to"]
27+
])}} \
28+
&& rm {{ARGS["file-name"]}}
Lines changed: 88 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,103 @@
11
{{
22
_ ARGS:
3-
download-url : URL to download .NET from
3+
product : Product name, e.g. "dotnet", "aspnet", "sdk"
44
extract-to : Directory where .NET will be extracted
5-
extract-paths : (optional) Paths within the tarball to extract
6-
out-file : (optional) Name of the output file
5+
extract-paths : (optional) Paths within the .NET tarball to extract
6+
^
77

8-
The following arguments groups are mutually exclusive:
8+
set product to ARGS["product"] ^
99

10-
sha : (optional) The checksum of the downloaded file
10+
set isAlpine to find(OS_VERSION, "alpine") >= 0 ^
11+
set platform to when(isAlpine, "linux-musl", "linux") ^
1112

12-
sha-url : (optional) URL to download checksum file
13-
sha-url-is-aggregate : (optional) True if the checksum file contains more than one checksum,
14-
but we only want to validate the checksum of the file we downloaded
15-
^
13+
set dotnetVersion to join(slice(split(PRODUCT_VERSION, "."), 0, 2), ".") ^
14+
set productVersion to VARIABLES[cat("dotnet|", dotnetVersion, "|product-version")] ^
15+
set buildVersion to VARIABLES[cat(product, "|", dotnetVersion, "|build-version")] ^
16+
17+
set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^
18+
set checksumsBaseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|checksums|", VARIABLES["branch"])] ^
19+
set isInternal to find(baseUrl, "dotnetstage") >= 0 ^
20+
21+
if (product = "runtime"):{{
22+
set downloadPath to cat("/Runtime/", buildVersion, "/dotnet-runtime-", buildVersion, "-", platform, "-", ARCH_SHORT, ".tar.gz")
23+
}}^elif (product = "aspnet"):{{
24+
set downloadPath to cat("/aspnetcore/Runtime/", buildVersion, "/aspnetcore-runtime-", buildVersion, "-", platform, "-", ARCH_SHORT, ".tar.gz")
25+
}}^elif (product = "aspnet-composite"):{{
26+
set downloadPath to cat("/aspnetcore/Runtime/", buildVersion, "/aspnetcore-runtime-composite-", buildVersion, "-", platform, "-", ARCH_SHORT, ".tar.gz")
27+
}}^elif (product = "sdk"):{{
28+
set downloadPath to cat("/Sdk/", buildVersion, "/dotnet-sdk-", buildVersion, "-", platform, "-", ARCH_SHORT, ".tar.gz")
29+
}}^
30+
set downloadUrl to cat(baseUrl, downloadPath) ^
31+
32+
set versionVariable to
33+
when(product = "aspnet" || product = "aspnet-composite",
34+
"aspnetcore_version",
35+
when(product = "sdk",
36+
"dotnet_sdk_version",
37+
"dotnet_version")) ^
38+
set versionVariableRef to cat("$", versionVariable) ^
39+
set versionVariableValue to buildVersion ^
1640

1741
set shaFunction to "512" ^
18-
set urlParts to split(ARGS["download-url"], "/") ^
19-
set fileName to
20-
when(ARGS["out-file"],
21-
ARGS["out-file"],
22-
urlParts[len(urlParts) - 1]) ^
42+
set urlParts to split(downloadUrl, "/") ^
43+
set fileName to urlParts[len(urlParts) - 1] ^
2344

2445
set fileNameParts to split(fileName, ".") ^
2546
set fileExtension to fileNameParts[len(fileNameParts) - 1] ^
2647

27-
set shaUrlParts to split(ARGS["sha-url"], "/") ^
48+
_ For now the aggregate and bare checksum files are mutually exclusive, but
49+
in the future we expect .NET 10 to have non-aggregate, non-bare checksum
50+
files before the other .NET versions, so it's necessary to have a
51+
separate condition for bare checksum files. ^
52+
_ Aggregate checksum files are also not available for internal builds. ^
53+
set shaUrlIsAggregate to (!isInternal && (dotnetVersion = "8.0" || dotnetVersion = "9.0")) ^
54+
set shaUrlIsBare to (isInternal || dotnetVersion = "10.0") ^
55+
56+
set shaUrlPath to when(shaUrlIsAggregate,
57+
VARIABLES[cat("dotnet|", dotnetVersion, "|aggregate-checksums")],
58+
cat(downloadPath, ".sha512")) ^
59+
set shaUrl to cat(checksumsBaseUrl, shaUrlPath) ^
60+
61+
set shaUrlParts to split(shaUrl, "/") ^
2862
set shaFileName to shaUrlParts[len(shaUrlParts) - 1] ^
2963

30-
set filesToDownload to
31-
when(ARGS["sha-url"],
32-
[
33-
["url": ARGS["download-url"]],
34-
["url": ARGS["sha-url"]]
35-
],
36-
[
37-
["url": ARGS["download-url"], "out-file": ARGS["out-file"]]
38-
]
39-
)
40-
41-
}}{{
42-
InsertTemplate("Dockerfile.linux.download-files", [
43-
"files": filesToDownload
44-
])
45-
}}{{
46-
if (ARGS["sha"] || ARGS["sha-url"]): \
47-
&& {{
48-
InsertTemplate("Dockerfile.linux.validate-checksum", [
49-
"file": fileName,
50-
"sha-function": shaFunction,
51-
"sha": ARGS["sha"],
52-
"sha-var-name": ARGS["sha-var-name"],
53-
"sha-file": shaFileName,
54-
"sha-file-is-aggregate": ARGS["sha-url-is-aggregate"]
55-
])
56-
}}}}{{
64+
_ Replace occurrences of versions with references to the version variable ^
65+
set downloadUrl to replace(downloadUrl, versionVariableValue, versionVariableRef) ^
66+
set shaUrl to replace(shaUrl, versionVariableValue, versionVariableRef) ^
67+
set shaFileName to replace(shaFileName, versionVariableValue, versionVariableRef) ^
68+
set fileName to replace(fileName, versionVariableValue, versionVariableRef) ^
69+
70+
_ The .NET SDK has two versions associated with it - SDK version and Runtime version.
71+
Aggregate checksum files are associated with the .NET runtime version, so if we're
72+
installing the SDK we need to have a separate variable for the runtime version. ^
73+
if (product = "sdk" && shaUrlIsAggregate):{{
74+
set runtimeVersionVariable to "dotnet_version" ^
75+
set runtimeVersionVariableRef to cat("$", runtimeVersionVariable) ^
76+
set runtimeVersionVariableValue to VARIABLES[cat("runtime|", dotnetVersion, "|build-version")] ^
77+
78+
set downloadUrl to replace(downloadUrl, runtimeVersionVariableValue, runtimeVersionVariableRef) ^
79+
set shaUrl to replace(shaUrl, runtimeVersionVariableValue, runtimeVersionVariableRef) ^
80+
set shaFileName to replace(shaFileName, runtimeVersionVariableValue, runtimeVersionVariableRef) ^
81+
set fileName to replace(fileName, runtimeVersionVariableValue, runtimeVersionVariableRef)
82+
}}^
83+
84+
set filesToDownload to [
85+
["url": downloadUrl],
86+
["url": shaUrl]
87+
]
88+
89+
}}{{versionVariable}}={{versionVariableValue}}{{if product = "sdk" && shaUrlIsAggregate: \
90+
&& {{runtimeVersionVariable}}={{runtimeVersionVariableValue}}}} \
91+
&& {{InsertTemplate("Dockerfile.linux.download-files", [
92+
"files": filesToDownload
93+
])}} \
94+
&& {{InsertTemplate("Dockerfile.linux.validate-checksum", [
95+
"file": fileName,
96+
"sha-function": shaFunction,
97+
"sha-file": shaFileName,
98+
"sha-file-is-bare": shaUrlIsBare,
99+
"sha-file-is-aggregate": shaUrlIsAggregate
100+
])}}{{
57101
if ARGS["extract-to"]: \
58102
&& mkdir --parents {{ARGS["extract-to"]}} \
59103
&& {{
@@ -62,10 +106,7 @@ if ARGS["extract-to"]: \
62106
"dest-dir": ARGS["extract-to"],
63107
"extract-paths": ARGS["extract-paths"]
64108
])
65-
}}}}{{
66-
if (ARGS["sha-url"]): \
109+
}}}} \
67110
&& rm \
68111
{{fileName}} \
69-
{{shaFileName}}^
70-
else: \
71-
&& rm {{fileName}}}}
112+
{{shaFileName}}

eng/dockerfile-templates/Dockerfile.linux.validate-checksum

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,35 @@
1717
line with the expected checksum and the file name to validate,
1818
separated by one or two spaces. See `man cksum` or `man sha512sum` for
1919
details.
20-
21-
sha-file-is-aggregate : File containing a list of checksums. The file may contain one or more
22-
lines with expected checksums and file names separated by one or two
23-
spaces. One line must have a filename matching the file you wish to
24-
validate. See `man cksum` or `man sha512sum` for details.
20+
sha-file-is-bare : Whether the checksum file does not contain the file name.
21+
sha-file-is-aggregate : Whether the checksum file contains more than one checksum. The file
22+
should contain one or more lines with expected checksums and file
23+
names separated by one or two spaces. One line must have a filename
24+
matching the file you wish to validate. See `man cksum` or
25+
`man sha512sum` for details.
2526
^
2627

2728
set isAlpine to find(OS_VERSION, "alpine") >= 0 ^
2829

29-
set shaValue to when(ARGS["sha-var-name"],
30-
cat("$", ARGS["sha-var-name"]),
31-
ARGS["sha"])
30+
set shaValue to
31+
when(ARGS["sha-file"] && ARGS["sha-file-is-bare"],
32+
cat("$(cat ", ARGS["sha-file"],")"),
33+
when(ARGS["sha-var-name"],
34+
cat("$", ARGS["sha-var-name"]),
35+
ARGS["sha"]))
3236

3337
}}{{
34-
if ARGS["sha"]:{{
38+
if (ARGS["sha"] || (ARGS["sha-file"] && ARGS["sha-file-is-bare"])):{{
3539
if ARGS["sha-var-name"]:{{ARGS["sha-var-name"]}}='{{ARGS["sha"]}}' \
3640
&& }}echo "{{shaValue}} {{ARGS["file"]}}" | sha{{ARGS["sha-function"]}}sum -c -^
3741
elif (ARGS["file"]):{{
3842
if (ARGS["sha-file-is-aggregate"]):{{
43+
_ As a temporary workaround, these commands need to normalize line endings in the checksum files.
44+
Remove the `sed` and `gsub` calls when https://github.com/dotnet/core/issues/9958 is fixed. ^
3945
if (isAlpine)
4046
:awk -v file="{{ARGS["file"]}}" '{gsub(/\r/, "")} $2 == file' {{ARGS["sha-file"]}} | sha{{ARGS["sha-function"]}}sum -c^
4147
else
42-
:sha{{ARGS["sha-function"]}}sum -c {{ARGS["sha-file"]}} --ignore-missing}}^
48+
:sed -i 's/\r$//' {{ARGS["sha-file"]}} \
49+
&& sha{{ARGS["sha-function"]}}sum -c {{ARGS["sha-file"]}} --ignore-missing}}^
4350
else
4451
:sha{{ARGS["sha-function"]}}sum -c {{ARGS["sha-file"]}}}}}}

eng/dockerfile-templates/aspire-dashboard/Dockerfile.linux

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
set aspireBaseUrl to cat(VARIABLES[cat("aspire-dashboard|", aspireMajorMinor, "|base-url|", VARIABLES["branch"])], "/aspire/", versionFolder, "/") ^
2424

2525
set downloadUrl to cat(aspireBaseUrl, "aspire-dashboard-linux-", ARCH_SHORT, ".zip") ^
26+
set outFile to "aspire_dashboard.zip" ^
27+
set appDir to "/app" ^
2628
set sha to VARIABLES[join(["aspire-dashboard", aspireMajorMinor, "linux", ARCH_SHORT, "sha"], "|")]
2729

2830
}}ARG REPO=mcr.microsoft.com/dotnet/aspnet
@@ -35,21 +37,22 @@ ARG ACCESSTOKEN}}
3537
}}
3638
# Retrieve Aspire Dashboard
3739
RUN dotnet_aspire_version={{aspireVersion}} \
38-
&& {{InsertTemplate("../Dockerfile.linux.download-dotnet", [
40+
&& {{InsertTemplate("../Dockerfile.linux.download-appliance", [
41+
"product": "aspire_dashboard",
42+
"productVersion": aspireVersion,
3943
"download-url": downloadUrl,
40-
"out-file": "aspire_dashboard.zip",
41-
"extract-to": "/app",
42-
"sha-var-name": "aspire_dashboard_sha512",
43-
"sha": sha
44+
"sha": sha,
45+
"file-name": outFile,
46+
"extract-to": appDir
4447
], " ")}}
4548

4649

4750
# Aspire Dashboard image
4851
FROM {{aspnetBaseTag}}
4952

50-
WORKDIR /app
51-
COPY --from=installer /app .
53+
WORKDIR {{appDir}}
54+
COPY --from=installer {{appDir}} .
5255

5356
{{InsertTemplate("Dockerfile.envs")}}
5457

55-
ENTRYPOINT [ "dotnet", "/app/Aspire.Dashboard.dll" ]
58+
ENTRYPOINT [ "dotnet", "{{appDir}}/Aspire.Dashboard.dll" ]

eng/dockerfile-templates/aspnet/Dockerfile.linux

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

5660

5761
# ASP.NET Core image

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ RUN {{InsertTemplate("../Dockerfile.linux.install-pkgs",
4242
])}}
4343
}}
4444
# Retrieve ASP.NET Composite Runtime
45-
{{InsertTemplate("../runtime/Dockerfile.linux.install-runtime", [ "is-composite-runtime": "true", ])}}
45+
RUN {{InsertTemplate("../Dockerfile.linux.download-dotnet", [
46+
"product": "aspnet-composite",
47+
"extract-to": when(isDistroless, "/usr/share/dotnet", "/dotnet")
48+
], " ")}}
4649
{{ if isDistroless:
4750
RUN mkdir /dotnet-symlink \
4851
&& ln -s /usr/share/dotnet/dotnet /dotnet-symlink/dotnet

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

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

eng/dockerfile-templates/monitor-base/Dockerfile.linux.install-monitor-base

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
set monitorBaseUrl to cat(VARIABLES[cat("monitor|", monitorMajorMinor, "|base-url|", VARIABLES["branch"])], "/diagnostics/monitor/", versionFolder, "/")
88

99
}}RUN dotnet_monitor_version={{monitorVersion}} \
10-
&& {{InsertTemplate("../Dockerfile.linux.download-dotnet", [
10+
&& {{InsertTemplate("../Dockerfile.linux.download-appliance", [
11+
"product": "dotnet_monitor_base",
1112
"download-url": cat(monitorBaseUrl, "dotnet-monitor-base-$dotnet_monitor_version-linux-", ARCH_SHORT, ".tar.gz"),
12-
"out-file": "dotnet-monitor-base.tar.gz",
13-
"extract-to": "/app",
14-
"sha-var-name": "dotnet_monitor_base_sha512",
15-
"sha": VARIABLES[join(["monitor-base", monitorMajorMinor, "linux", ARCH_SHORT, "sha"], "|")]
13+
"file-name": "dotnet-monitor-base.tar.gz",
14+
"extract-to": "/app"
15+
"sha": VARIABLES[join(["monitor-base", monitorMajorMinor, "linux", ARCH_SHORT, "sha"], "|")],
1616
], " ")}}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{{
22
_ ARGS:
3-
is-internal (optional): Whether the Dockerfile is targeting an internal build of the product ^
3+
is-internal (optional): Whether the Dockerfile is targeting an internal build of the product
4+
is-standalone (optional): Whether the ENV instruction should be included ^
45

56
set dotnetVersion to join(slice(split(PRODUCT_VERSION, "."), 0, 2), ".") ^
67
set isStableBranding to (find(VARIABLES[cat("sdk|", dotnetVersion, "|build-version")], "-servicing") >= 0 ||
78
find(VARIABLES[cat("sdk|", dotnetVersion, "|build-version")], "-rtm") >= 0) ^
89
set runtimeVersion to when(isStableBranding && ARGS["is-internal"],
910
VARIABLES[cat("dotnet|", dotnetVersion, "|product-version")],
1011
VARIABLES[cat("runtime|", dotnetVersion, "|build-version")])
12+
1113
}}# .NET Runtime version
12-
{{if INDENT ="":ENV }}DOTNET_VERSION={{runtimeVersion}}
14+
{{if ARGS["is-standalone"]:ENV }}DOTNET_VERSION={{runtimeVersion}}

eng/dockerfile-templates/runtime/Dockerfile.linux

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ RUN {{InsertTemplate("../Dockerfile.linux.install-pkgs",
5151
])}}
5252
}}
5353
# Retrieve .NET Runtime
54-
{{InsertTemplate("Dockerfile.linux.install-runtime")}}{{
54+
RUN {{InsertTemplate("../Dockerfile.linux.download-dotnet", [
55+
"product": "runtime",
56+
"extract-to": when(isDistroless, "/usr/share/dotnet", "/dotnet")
57+
], " ")}}{{
5558
if isDistroless:
5659

5760
RUN mkdir /dotnet-symlink \
@@ -61,7 +64,10 @@ RUN mkdir /dotnet-symlink \
6164
# .NET runtime image
6265
FROM {{runtimeDepsBaseTag}}
6366

64-
{{InsertTemplate("Dockerfile.envs", ["is-internal": isInternal])}}
67+
{{InsertTemplate("Dockerfile.envs", [
68+
"is-internal": isInternal,
69+
"is-standalone": "true"
70+
])}}
6571
{{ if isDistroless:
6672
COPY --from=installer ["/usr/share/dotnet", "/usr/share/dotnet"]
6773
COPY --from=installer ["/dotnet-symlink", "/usr/bin"]

0 commit comments

Comments
 (0)