Skip to content

Commit 78b89a4

Browse files
authored
Clean up more Dockerfile templates and optimize removing/extracting multiple files (#6506)
1 parent 469f2db commit 78b89a4

File tree

70 files changed

+281
-245
lines changed

Some content is hidden

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

70 files changed

+281
-245
lines changed

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

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,67 @@
55
extract-paths : (optional) Paths within the tarball to extract
66
out-file : (optional) Name of the output file
77

8-
The following arguments are mutually exclusive:
9-
sha : (optional) The checksum of the downloaded file
10-
sha-url : (optional) URL to download checksum file
11-
sha-url-aggregate : (optional) URL to download aggregate checksum file
8+
The following arguments groups are mutually exclusive:
9+
10+
sha : (optional) The checksum of the downloaded file
11+
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
1215
^
1316

17+
set shaFunction to "512" ^
1418
set urlParts to split(ARGS["download-url"], "/") ^
1519
set fileName to
1620
when(ARGS["out-file"],
1721
ARGS["out-file"],
1822
urlParts[len(urlParts) - 1]) ^
23+
1924
set fileNameParts to split(fileName, ".") ^
20-
set fileExtension to fileNameParts[len(fileNameParts) - 1]
21-
22-
}}{{InsertTemplate("Dockerfile.linux.download-validate-file", [
23-
"url": ARGS["download-url"],
24-
"out-file": ARGS["out-file"],
25-
"sha": ARGS["sha"],
26-
"sha-url": ARGS["sha-url"],
27-
"sha-url-aggregate": ARGS["sha-url-aggregate"],
28-
"sha-var-name": ARGS["sha-var-name"]
29-
])}}{{
25+
set fileExtension to fileNameParts[len(fileNameParts) - 1] ^
26+
27+
set shaUrlParts to split(ARGS["sha-url"], "/") ^
28+
set shaFileName to shaUrlParts[len(shaUrlParts) - 1] ^
29+
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+
}}}}{{
3057
if ARGS["extract-to"]: \
3158
&& mkdir --parents {{ARGS["extract-to"]}} \
32-
&& {{if (fileExtension = "zip"):{{
33-
InsertTemplate("Dockerfile.linux.extract-zip", [
34-
"file": fileName,
35-
"dest-dir": ARGS["extract-to"],
36-
"extract-paths": ARGS["extract-paths"]
37-
])}}^else:{{
38-
InsertTemplate("Dockerfile.linux.extract-tarball", [
59+
&& {{
60+
InsertTemplate("Dockerfile.linux.extract-file", [
3961
"file": fileName,
4062
"dest-dir": ARGS["extract-to"],
4163
"extract-paths": ARGS["extract-paths"]
42-
])}}}}}}
64+
])
65+
}}}}{{
66+
if (ARGS["sha-url"]): \
67+
&& rm \
68+
{{fileName}} \
69+
{{shaFileName}}^
70+
else: \
71+
&& rm {{fileName}}}}

eng/dockerfile-templates/Dockerfile.linux.download-files

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
set numFiles to len(ARGS["files"]) ^
5555
set indent to when(numFiles > 1, " ", "")
5656

57-
}}{{downloadCommand}} {{if (numFiles > 1): \
57+
}}{{downloadCommand}} {{if (numFiles > 1):\
5858
}}{{
5959
for i, file in ARGS["files"]:{{indent}}{{
6060
set isLastFile to (i = len(ARGS["files"]) - 1)

eng/dockerfile-templates/Dockerfile.linux.download-validate-file

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{
2+
_ Extracts a file (zip or tarball) based on its extension
3+
4+
ARGS:
5+
file: File to extract
6+
dest-dir: Destination directory
7+
extract-paths: (optional) Paths within the archive to extract
8+
^
9+
10+
set fileNameParts to split(ARGS["file"], ".") ^
11+
set fileExtension to fileNameParts[len(fileNameParts) - 1]
12+
13+
14+
}}{{
15+
if (fileExtension = "zip")
16+
:unzip {{ARGS["file"]}}{{if ARGS["dest-dir"]: -d {{ARGS["dest-dir"]}}}}{{if ARGS["extract-paths"]: {{join(ARGS["extract-paths"], " ")}}}}^
17+
else
18+
:tar --gzip --extract --no-same-owner --file {{ARGS["file"]}}{{if ARGS["dest-dir"]: --directory {{ARGS["dest-dir"]}}}}{{if ARGS["extract-paths"]: {{join(ARGS["extract-paths"], " ")}}}}}}

eng/dockerfile-templates/Dockerfile.linux.extract-tarball

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

eng/dockerfile-templates/Dockerfile.linux.extract-zip

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

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33

44
ARGS:
55
Required by all option groups:
6-
sha-function : SHA function to use (e.g. 256, 384, 512), not optional.
6+
sha-function : SHA function to use (e.g. 256, 384, 512), not optional.
77

88
The following argument groups are mutually exclusive:
99

10-
file : Path to the file to validate.
11-
sha : Expected checksum of the downloaded file.
12-
sha-var-name : (optional) Name of variable to store the checksum in. If not provided,
13-
the checksum will be written inline with the call to the sha*sum check
14-
tool.
15-
16-
sha-file : Checksum file to validate against. The file should contain a single
17-
line with the expected checksum and the file name to validate,
18-
separated by one or two spaces. See `man cksum` or `man sha512sum` for
19-
details.
20-
21-
sha-file-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.
10+
file : Path to the file to validate.
11+
sha : Expected checksum of the downloaded file.
12+
sha-var-name : (optional) Name of variable to store the checksum in. If not provided,
13+
the checksum will be written inline with the call to the sha*sum check
14+
tool.
15+
16+
sha-file : Checksum file to validate against. The file should contain a single
17+
line with the expected checksum and the file name to validate,
18+
separated by one or two spaces. See `man cksum` or `man sha512sum` for
19+
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.
2525
^
2626

2727
set isAlpine to find(OS_VERSION, "alpine") >= 0 ^
@@ -31,12 +31,14 @@
3131
ARGS["sha"])
3232

3333
}}{{
34-
if ARGS["sha"]:{{if ARGS["sha-var-name"]:{{ARGS["sha-var-name"]}}='{{ARGS["sha"]}}' \
34+
if ARGS["sha"]:{{
35+
if ARGS["sha-var-name"]:{{ARGS["sha-var-name"]}}='{{ARGS["sha"]}}' \
3536
&& }}echo "{{shaValue}} {{ARGS["file"]}}" | sha{{ARGS["sha-function"]}}sum -c -^
36-
elif (ARGS["sha-file"])
37-
:sha{{ARGS["sha-function"]}}sum -c {{ARGS["sha-file"]}}^
38-
elif (ARGS["sha-file-aggregate"])
39-
:if (isAlpine)
40-
:awk -v file="{{ARGS["file"]}}" '{gsub(/\r/, "")} $2 == file' ${{ARGS["sha-file-aggregate"]}} | sha512sum -c^
37+
elif (ARGS["file"]):{{
38+
if (ARGS["sha-file-is-aggregate"]):{{
39+
if (isAlpine)
40+
:awk -v file="{{ARGS["file"]}}" '{gsub(/\r/, "")} $2 == file' {{ARGS["sha-file"]}} | sha{{ARGS["sha-function"]}}sum -c^
41+
else
42+
:sha{{ARGS["sha-function"]}}sum -c {{ARGS["sha-file"]}} --ignore-missing}}^
4143
else
42-
:sha512sum --ignore-missing --check {{ARGS["sha-file"]}}}}
44+
:sha{{ARGS["sha-function"]}}sum -c {{ARGS["sha-file"]}}}}}}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@
3737
"sha-function": "512"
3838
], " ")}} \
3939
&& mkdir --parents {{installDir}} \
40-
&& {{InsertTemplate("../Dockerfile.linux.extract-tarball", [
40+
&& {{InsertTemplate("../Dockerfile.linux.extract-file", [
4141
"file": azBlobFileName,
4242
"dest-dir": installDir,
4343
"extract-paths": ARGS["extract-paths"]
4444
], " ")}} \
45-
&& {{InsertTemplate("../Dockerfile.linux.extract-tarball", [
45+
&& {{InsertTemplate("../Dockerfile.linux.extract-file", [
4646
"file": s3FileName,
4747
"dest-dir": installDir,
4848
"extract-paths": ARGS["extract-paths"]
49-
], " ")}}
49+
], " ")}} \
50+
&& rm \
51+
{{azBlobFileName}} \
52+
{{s3FileName}}

eng/dockerfile-templates/runtime-deps/Dockerfile.chiseled-ubuntu

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
set osVersionNumber to split(OS_ARCH_HYPHENATED, "-")[1] ^
99

1010
set chiselUrl to VARIABLES[cat("chisel|", dotnetVersion, "|", ARCH_SHORT, "|url")] ^
11+
set chiselFileName to "chisel.tar.gz" ^
1112
set shaFunction to "384" ^
1213
set chiselSha to VARIABLES[cat("chisel|", dotnetVersion, "|", ARCH_SHORT, "|sha", shaFunction)] ^
13-
set rocksToolboxUrl to VARIABLES[cat("rocks-toolbox|", dotnetVersion, "|url")] ^
14+
set rocksToolboxBaseUrl to VARIABLES[cat("rocks-toolbox|", dotnetVersion, "|url")] ^
1415
set rocksToolboxRef to VARIABLES[cat("rocks-toolbox|", dotnetVersion, "|version")] ^
16+
set rocksToolboxUrl to cat(rocksToolboxBaseUrl, "/", rocksToolboxRef, "/chisel-wrapper") ^
1517

1618
set installerImageTag to cat(ARCH_VERSIONED, "/buildpack-deps:", osVersionBase, "-curl") ^
1719

@@ -62,20 +64,25 @@
6264

6365
RUN apt-get update && apt-get install -y file
6466

65-
RUN {{InsertTemplate("../Dockerfile.linux.download-validate-file",
66-
[
67-
"out-file": "chisel.tar.gz",
67+
RUN {{InsertTemplate("../Dockerfile.linux.download-files", ["files": [[
6868
"url": chiselUrl,
69-
"sha": chiselSha,
70-
"sha-var-name": cat("chisel_sha", shaFunction),
69+
"out-file": chiselFileName
70+
]]], " ")}} \
71+
&& {{InsertTemplate("../Dockerfile.linux.validate-checksum", [
72+
"file": chiselFileName,
7173
"sha-function": shaFunction,
74+
"sha": chiselSha,
75+
"sha-var-name": cat("chisel_sha", shaFunction)
7276
], " ")}} \
73-
&& tar -xzf chisel.tar.gz -C /usr/bin/ chisel \
74-
&& {{InsertTemplate("../Dockerfile.linux.download-validate-file",
75-
[
76-
"out-file": "/usr/bin/chisel-wrapper",
77-
"url": cat(rocksToolboxUrl, "/", rocksToolboxRef, "/chisel-wrapper")
77+
&& {{InsertTemplate("../Dockerfile.linux.extract-file", [
78+
"file": chiselFileName,
79+
"dest-dir": "/usr/bin/"
7880
], " ")}} \
81+
&& rm {{chiselFileName}} \
82+
&& {{InsertTemplate("../Dockerfile.linux.download-files", ["files": [[
83+
"url": rocksToolboxUrl,
84+
"out-file": "/usr/bin/chisel-wrapper"
85+
]]], " ")}} \
7986
&& chmod 755 /usr/bin/chisel-wrapper
8087

8188
RUN {{InsertTemplate("Dockerfile.linux.non-root-user-staged", [

eng/dockerfile-templates/sdk/Dockerfile.linux.install-powershell

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
set url to cat("https://powershellinfraartifacts-gkhedzdeaghdezhr.z01.azurefd.net/tool/$powershell_version/", nupkgName)
88
}}# Install PowerShell global tool
99
RUN powershell_version={{VARIABLES[cat("powershell|", dotnetVersion, "|build-version")]}} \
10-
&& {{InsertTemplate("../Dockerfile.linux.download-validate-file",
11-
[
12-
"out-file": nupkgName,
13-
"url": url,
14-
"sha": VARIABLES[join(["powershell", dotnetVersion, shaPlatform, "sha"], "|")],
15-
"sha-var-name": "powershell_sha512"
16-
], " ")}} \
10+
&& {{InsertTemplate("../Dockerfile.linux.download-files", ["files": [[
11+
"url": url,
12+
"out-file": nupkgName
13+
]]], " ")}} \
14+
&& {{InsertTemplate("../Dockerfile.linux.validate-checksum", [
15+
"file": nupkgName,
16+
"sha-function": "512",
17+
"sha-var-name": "powershell_sha512",
18+
"sha": VARIABLES[join(["powershell", dotnetVersion, shaPlatform, "sha"], "|")]
19+
], " ")}} \
1720
&& mkdir --parents /usr/share/powershell \
1821
&& dotnet tool install --add-source / --tool-path /usr/share/powershell --version $powershell_version PowerShell.{{nupkgPlatform}} \
1922
&& dotnet nuget locals all --clear \

0 commit comments

Comments
 (0)