Skip to content

Commit 652bbae

Browse files
authored
Update internal Dockerfile templates to support managed identity OAuth token (#6472)
1 parent 354e446 commit 652bbae

399 files changed

Lines changed: 783 additions & 722 deletions

File tree

Some content is hidden

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

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
sha-var-name: Name of variable that stores the checksum
99
sha-function: SHA function to use ^
1010

11-
set isInternal to find(ARGS["url"], "artifacts.visualstudio.com") >= 0 ^
12-
set alpineSetTokenCmd to 'token=$(echo "${ACCESSTOKEN}:${ACCESSTOKEN}" | base64 -w 0)' ^
13-
set additionalWgetArgs to when(isInternal, '--header="Authorization: Basic $token" ', '') ^
14-
set additionalCurlArgs to when(isInternal, '-u :$ACCESSTOKEN --basic ', '') ^
11+
_ Documentation for using Managed Identity/OAuth tokens to access Azure storage accounts:
12+
https://learn.microsoft.com/en-us/rest/api/storageservices/authorize-with-azure-active-directory#call-storage-operations-with-oauth-tokens ^
13+
14+
set isInternal to find(ARGS["url"], "dotnetstage") >= 0 ^
15+
set headerArgs to when(isInternal, '--header "Authorization: Bearer $ACCESSTOKEN" --header "x-ms-version: 2017-11-09" ', '') ^
1516
set isAlpine to find(OS_VERSION, "alpine") >= 0 ^
1617
set shaFunction to ARGS["sha-function"] ^
1718
set shaFunction to when(shaFunction, shaFunction, "512")
18-
}}{{if isAlpine:{{if isInternal:{{alpineSetTokenCmd}} \
19-
&& }}wget {{additionalWgetArgs}}-O^else:curl {{additionalCurlArgs}}-fSL --output}} {{ARGS["out-file"]}} {{if isInternal:"{{ARGS["url"]}}"^else:{{ARGS["url"]}}}}{{if ARGS["sha"]: \
19+
}}{{if isAlpine:wget {{headerArgs}}-O^else:curl {{headerArgs}}-fSL --output}} {{ARGS["out-file"]}} {{if isInternal:"{{ARGS["url"]}}"^else:{{ARGS["url"]}}}}{{if ARGS["sha"]: \
2020
&& {{ARGS["sha-var-name"]}}='{{ARGS["sha"]}}' \
2121
&& echo "${{ARGS["sha-var-name"]}} {{ARGS["out-file"]}}" | sha{{shaFunction}}sum -c -}}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88
sha-var-name: Name of variable that stores the checksum
99
hash-algorithm: Algorithm type to use to get the checksum. Defaults to sha512 ^
1010

11-
set isInternal to find(ARGS["url"], "artifacts.visualstudio.com") >= 0 ^
11+
_ Documentation for using Managed Identity/OAuth tokens to access Azure storage accounts:
12+
https://learn.microsoft.com/en-us/rest/api/storageservices/authorize-with-azure-active-directory#call-storage-operations-with-oauth-tokens ^
13+
14+
set isInternal to find(ARGS["url"], "dotnetstage") >= 0 ^
1215
set hashAlgorithm to when(ARGS["hash-algorithm"], ARGS["hash-algorithm"], "sha512")
1316
}}{{if isInternal:`
14-
$Base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(\":$($Env:ACCESSTOKEN)\")); `
15-
$Headers = @@{Authorization = \"Basic $Base64AuthInfo\"}; `
17+
$Headers = @@{ `
18+
Authorization = \"Bearer $env:ACCESSTOKEN\"; `
19+
'x-ms-version' = '2017-11-09'; `
20+
}; `
1621
Invoke-WebRequest -OutFile {{ARGS["out-file"]}} \"{{ARGS["url"]}}\" -Headers $Headers; `
1722
`^else:Invoke-WebRequest -OutFile {{ARGS["out-file"]}} {{ARGS["url"]}}; `}}
1823
${{ARGS["sha-var-name"]}} = '{{ARGS["sha"]}}'; `

eng/dockerfile-templates/aspnet/Dockerfile.linux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
set isFullAzureLinux to isAzureLinux && !isDistroless ^
1111
set isDistrolessAzureLinux to isAzureLinux && isDistroless ^
1212
set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^
13-
set isInternal to find(baseUrl, "artifacts.visualstudio.com") >= 0 ^
13+
set isInternal to find(baseUrl, "dotnetstage") >= 0 ^
1414
set runtimeDepsVariant to when(ARGS["is-extra"], "-extra", "") ^
1515
set tagVersion to when(dotnetVersion = "8.0",
1616
VARIABLES[cat("dotnet|", dotnetVersion, "|product-version")],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
set isFullAzureLinux to isAzureLinux && !isDistroless ^
77
set isDistrolessAzureLinux to isAzureLinux && isDistroless ^
88
set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^
9-
set isInternal to find(baseUrl, "artifacts.visualstudio.com") >= 0 ^
9+
set isInternal to find(baseUrl, "dotnetstage") >= 0 ^
1010
set isSingleStage to isAlpine && !isInternal ^
1111
set runtimeDepsVariant to when(ARGS["is-extra"], "-extra", "") ^
1212
set tagVersion to when(dotnetVersion = "8.0",

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

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,50 @@
77
- installer-stage (optional): Name of the Dockerfile stage responsible for installation ^
88

99
set dotnetVersion to join(slice(split(PRODUCT_VERSION, "."), 0, 2), ".") ^
10+
set productVersion to VARIABLES[cat("dotnet|", dotnetVersion, "|product-version")] ^
11+
set buildVersion to VARIABLES[cat("aspnet|", dotnetVersion, "|build-version")] ^
12+
1013
set isFullAzureLinux to defined(match(OS_VERSION, "^cbl-mariner\d+\.\d+$")) ^
1114
set isDistroless to find(OS_VERSION, "distroless") >= 0 || find(OS_VERSION, "chiseled") >= 0 ^
1215
set isAlpine to find(OS_VERSION, "alpine") >= 0 ^
1316
set platform to when(isAlpine, "linux-musl", "linux") ^
1417
set destDir to "/dotnet" ^
15-
set aspnetVersionDir to when(ARGS["use-local-version-var"],
16-
"$aspnetcore_version",
17-
when(ARGS["is-internal"],
18-
VARIABLES[cat("aspnet|", dotnetVersion, "|build-version")],
19-
"$ASPNET_VERSION")) ^
20-
set isStableBranding to (find(VARIABLES[cat("sdk|", dotnetVersion, "|build-version")], "-servicing") >= 0 ||
21-
find(VARIABLES[cat("sdk|", dotnetVersion, "|build-version")], "-rtm") >= 0) ^
22-
set aspnetVersionFile to when(isStableBranding,
23-
VARIABLES[cat("dotnet|", dotnetVersion, "|product-version")],
24-
aspnetVersionDir) ^
25-
set url to cat(
26-
VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])],
27-
"/aspnetcore/Runtime/", aspnetVersionDir, "/aspnetcore-runtime-", aspnetVersionFile,
28-
"-", platform, "-", ARCH_SHORT, ".tar.gz") ^
18+
19+
set sdkBuildVersion to VARIABLES[cat("sdk|", dotnetVersion, "|build-version")] ^
20+
set isStableBranding to find(sdkBuildVersion, "-servicing") >= 0 || find(sdkBuildVersion, "-rtm") >= 0 ^
21+
22+
_ Set versions explicitly, and dynamically replace them based on whether they match the env/local variables. ^
23+
_ For preview (non-stable) versions, the full build version is always in the file name. ^
24+
set fileVersion to when(isStableBranding, productVersion, buildVersion) ^
25+
set versionDir to buildVersion ^
26+
27+
set versionVariable to
28+
when(ARGS["use-local-version-var"],
29+
"aspnetcore_version",
30+
"ASPNET_VERSION") ^
31+
32+
set versionVariableValue to buildVersion ^
33+
if (versionDir = versionVariableValue):{{
34+
set versionDir to cat("$", versionVariable)
35+
}}^
36+
if (fileVersion = versionVariableValue):{{
37+
set fileVersion to cat("$", versionVariable)
38+
}}^
39+
40+
set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^
41+
set downloadUrl to cat(baseUrl, "/aspnetcore/Runtime/", versionDir, "/aspnetcore-runtime-", fileVersion, "-", platform, "-", ARCH_SHORT, ".tar.gz") ^
42+
set sha to VARIABLES[join(["aspnet", dotnetVersion, platform, ARCH_SHORT, "sha"], "|")] ^
43+
2944
set files to [
3045
[
3146
"filename": "aspnetcore.tar.gz",
32-
"url": url,
33-
"sha": VARIABLES[join(["aspnet", dotnetVersion, platform, ARCH_SHORT, "sha"], "|")],
47+
"url": downloadUrl,
48+
"sha": sha,
3449
"sha-var-name": "aspnetcore_sha512",
3550
"extract-paths": ["./shared/Microsoft.AspNetCore.App"]
3651
]
3752
] ^
53+
3854
set copyEnabled to ARGS["install-method"] = "copy-and-install" ^
3955
set downloadEnabled to ARGS["install-method"] = "download" || ARGS["install-method"] = "download-and-install" ^
4056
set installEnabled to ARGS["install-method"] = "download-and-install" || ARGS["install-method"] = "copy-and-install"
@@ -46,7 +62,7 @@ if copyEnabled:{{InsertTemplate("../Dockerfile.linux.copy-files",
4662
"destination": ""
4763
])
4864
}}
49-
}}RUN {{if ARGS["use-local-version-var"]:aspnetcore_version={{VARIABLES[cat("aspnet|", dotnetVersion, "|build-version")]}} \
65+
}}RUN {{if ARGS["use-local-version-var"]:{{versionVariable}}={{versionVariableValue}} \
5066
&& }}{{InsertTemplate("../Dockerfile.linux.download-and-install",
5167
[
5268
"files": files,

eng/dockerfile-templates/aspnet/Dockerfile.windows

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set isServerCore to find(OS_VERSION, "windowsservercore") >= 0 ^
44

55
set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^
6-
set isInternal to find(baseUrl, "artifacts.visualstudio.com") >= 0 ^
6+
set isInternal to find(baseUrl, "dotnetstage") >= 0 ^
77

88
set installerStageFromImage to cat("mcr.microsoft.com/windows/servercore:", OS_VERSION_NUMBER, "-amd64") ^
99

eng/dockerfile-templates/runtime-deps/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
set isAzureLinux to isCblMariner || defined(match(OS_VERSION, "^azurelinux\d+\.\d+$")) ^
1313

1414
set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^
15-
set isInternal to find(baseUrl, "artifacts.visualstudio.com") >= 0 ^
15+
set isInternal to find(baseUrl, "dotnetstage") >= 0 ^
1616

1717
set baseImageRepo to when(isAlpine,
1818
cat(ARCH_VERSIONED, "/alpine"),

eng/dockerfile-templates/runtime/Dockerfile.linux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
set isFullAzureLinux to isAzureLinux && !isDistroless ^
1111
set isDistrolessAzureLinux to isAzureLinux && isDistroless ^
1212
set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^
13-
set isInternal to find(baseUrl, "artifacts.visualstudio.com") >= 0 ^
13+
set isInternal to find(baseUrl, "dotnetstage") >= 0 ^
1414
set runtimeDepsVariant to when(ARGS["is-extra"], "-extra", "") ^
1515
set tagVersion to VARIABLES[cat("dotnet|", dotnetVersion, "|fixed-tag")] ^
1616
set runtimeDepsBaseTag to cat(

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

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,60 @@
1010
is-composite-runtime (optional): Whether to install aspnetcore composite version ^
1111

1212
set dotnetVersion to join(slice(split(PRODUCT_VERSION, "."), 0, 2), ".") ^
13-
set isAlpine to find(OS_VERSION, "alpine") >= 0 ^
14-
set varPlatform to when(isAlpine, "linux-musl", "linux") ^
15-
set runtimeVersionDir to when(ARGS["use-local-version-var"],
16-
"$dotnet_version",
17-
when(ARGS["is-internal"],
18-
VARIABLES[cat("runtime|", dotnetVersion, "|build-version")],
19-
"$DOTNET_VERSION")) ^
20-
set aspnetCompositeVersionDir to when(ARGS["use-local-version-var"],
21-
"$aspnetcore_version",
22-
when(ARGS["is-internal"],
13+
set productVersion to VARIABLES[cat("dotnet|", dotnetVersion, "|product-version")] ^
14+
set buildVersion to
15+
when(ARGS["is-composite-runtime"],
2316
VARIABLES[cat("aspnet|", dotnetVersion, "|build-version")],
24-
"$ASPNET_VERSION")) ^
25-
set isStableBranding to (find(VARIABLES[cat("sdk|", dotnetVersion, "|build-version")], "-servicing") >= 0 ||
26-
find(VARIABLES[cat("sdk|", dotnetVersion, "|build-version")], "-rtm") >= 0) ^
27-
set runtimeVersionFile to when(isStableBranding,
28-
VARIABLES[cat("dotnet|", dotnetVersion, "|product-version")],
29-
runtimeVersionDir) ^
30-
set aspnetCompositeVersionFile to when(isStableBranding,
31-
VARIABLES[cat("dotnet|", dotnetVersion, "|product-version")],
32-
aspnetCompositeVersionDir) ^
33-
set filePlatform to when(isAlpine, "-linux-musl", "-linux") ^
17+
VARIABLES[cat("runtime|", dotnetVersion, "|build-version")]) ^
18+
19+
set isAlpine to find(OS_VERSION, "alpine") >= 0 ^
20+
set platform to when(isAlpine, "linux-musl", "linux") ^
21+
22+
set sdkBuildVersion to VARIABLES[cat("sdk|", dotnetVersion, "|build-version")] ^
23+
set isStableBranding to find(sdkBuildVersion, "-servicing") >= 0 || find(sdkBuildVersion, "-rtm") >= 0 ^
24+
25+
_ Set versions explicitly, and dynamically replace them based on whether they match the env/local variables. ^
26+
_ For preview (non-stable) versions, the full build version is always in the file name. ^
27+
set fileVersion to when(isStableBranding, productVersion, buildVersion) ^
28+
set versionDir to buildVersion ^
29+
30+
set versionVariable to
31+
when(ARGS["is-composite-runtime"],
32+
when(ARGS["use-local-version-var"],
33+
"aspnetcore_version",
34+
"ASPNET_VERSION"),
35+
when(ARGS["use-local-version-var"],
36+
"dotnet_version",
37+
"DOTNET_VERSION")) ^
38+
39+
set versionVariableValue to buildVersion ^
40+
if (versionDir = versionVariableValue):{{
41+
set versionDir to cat("$", versionVariable)
42+
}}^
43+
if (fileVersion = versionVariableValue):{{
44+
set fileVersion to cat("$", versionVariable)
45+
}}^
46+
3447
set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^
35-
set runtimeBaseUrl to cat(baseUrl, "/Runtime/", runtimeVersionDir, "/") ^
36-
set aspnetCompositeUrl to cat(baseUrl, "/aspnetcore/Runtime/", aspnetCompositeVersionDir, "/aspnetcore-runtime-composite-", aspnetCompositeVersionFile,
37-
filePlatform, "-", ARCH_SHORT, ".tar.gz") ^
38-
set files to when(ARGS["is-composite-runtime"],
39-
[
40-
[
41-
"filename": "dotnet.tar.gz",
42-
"url": aspnetCompositeUrl,
43-
"sha": VARIABLES[join(["aspnet-composite", dotnetVersion, varPlatform, ARCH_SHORT, "sha"], "|")],
44-
"sha-var-name": "dotnet_sha512"
45-
]
46-
],
48+
set downloadUrl to
49+
when(ARGS["is-composite-runtime"],
50+
cat(baseUrl, "/aspnetcore/Runtime/", versionDir, "/aspnetcore-runtime-composite-", fileVersion, "-", platform, "-", ARCH_SHORT, ".tar.gz"),
51+
cat(baseUrl, "/Runtime/", versionDir, "/dotnet-runtime-", fileVersion, "-", platform, "-", ARCH_SHORT, ".tar.gz")) ^
52+
set sha to
53+
when(ARGS["is-composite-runtime"],
54+
VARIABLES[join(["aspnet-composite", dotnetVersion, platform, ARCH_SHORT, "sha"], "|")],
55+
VARIABLES[join(["runtime", dotnetVersion, platform, ARCH_SHORT, "sha"], "|")]) ^
56+
57+
set files to
4758
[
4859
[
4960
"filename": "dotnet.tar.gz",
50-
"url": cat(runtimeBaseUrl, "dotnet-runtime-", runtimeVersionFile, "-", varPlatform, "-", ARCH_SHORT, ".tar.gz"),
51-
"sha": VARIABLES[join(["runtime", dotnetVersion, varPlatform, ARCH_SHORT, "sha"], "|")],
61+
"url": downloadUrl,
62+
"sha": sha,
5263
"sha-var-name": "dotnet_sha512"
5364
]
54-
]) ^
65+
] ^
66+
5567
set copyEnabled to ARGS["install-method"] = "copy-and-install" ^
5668
set downloadEnabled to ARGS["install-method"] = "download" || ARGS["install-method"] = "download-and-install" ^
5769
set installEnabled to ARGS["install-method"] = "download-and-install" || ARGS["install-method"] = "copy-and-install"
@@ -63,8 +75,7 @@ if copyEnabled:{{InsertTemplate("../Dockerfile.linux.copy-files",
6375
"destination": ""
6476
])
6577
}}
66-
}}RUN {{if ARGS["use-local-version-var"]:{{ if ARGS["is-composite-runtime"]:aspnetcore_version={{VARIABLES[cat("aspnet|", dotnetVersion, "|build-version")]}} ^
67-
else:dotnet_version={{VARIABLES[cat("runtime|", dotnetVersion, "|build-version")]}}}} \
78+
}}RUN {{if ARGS["use-local-version-var"]:{{versionVariable}}={{versionVariableValue}} \
6879
&& }}{{InsertTemplate("../Dockerfile.linux.download-and-install",
6980
[
7081
"files": files,

eng/dockerfile-templates/runtime/Dockerfile.windows

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set isServer2025 to find(OS_VERSION_NUMBER, "2025") >= 0 ^
55

66
set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^
7-
set isInternal to find(baseUrl, "artifacts.visualstudio.com") >= 0 ^
7+
set isInternal to find(baseUrl, "dotnetstage") >= 0 ^
88

99
set installerStageRepo to cat("mcr.microsoft.com/windows/", "servercore") ^
1010
set runtimeStageRepo to cat("mcr.microsoft.com/windows/", when(isServerCore, "servercore", "nanoserver")) ^

0 commit comments

Comments
 (0)