|
| 1 | +{{ |
| 2 | + _ Downloads, validate, and extracts the .NET Runtime, ASP.NET Core Runtime, or .NET SDK |
| 3 | + |
| 4 | + ARGS: |
| 5 | + product : Product name, e.g. "dotnet", "aspnet", "sdk" |
| 6 | + extract-to : Directory where .NET will be extracted |
| 7 | + extract-paths : (optional) Paths within the .NET tarball to extract |
| 8 | + ^ |
| 9 | + |
| 10 | + set product to ARGS["product"] ^ |
| 11 | + |
| 12 | + set isWindows to find(OS_VERSION, "server") >= 0 ^ |
| 13 | + set isAlpine to find(OS_VERSION, "alpine") >= 0 ^ |
| 14 | + |
| 15 | + set platform to when(isWindows, "win", when(isAlpine, "linux-musl", "linux"))^ |
| 16 | + set templatePlatform to when(isWindows, "windows", "linux") ^ |
| 17 | + set lineEnd to when(isWindows, "; `", " \") ^ |
| 18 | + set lineContinue to when(isWindows, "`", "\") ^ |
| 19 | + set continue to when(isWindows, "", "&& ") ^ |
| 20 | + set remove to when(isWindows, "Remove-Item -Force", "rm") ^ |
| 21 | + |
| 22 | + set useFileVariables to isWindows ^ |
| 23 | + set useExtraLines to isWindows ^ |
| 24 | + set extraLine to when(useExtraLines, cat(" |
| 25 | +", lineContinue), "") ^ |
| 26 | + |
| 27 | + set dotnetVersion to join(slice(split(PRODUCT_VERSION, "."), 0, 2), ".") ^ |
| 28 | + set productVersion to VARIABLES[cat("dotnet|", dotnetVersion, "|product-version")] ^ |
| 29 | + set buildVersion to VARIABLES[cat(product, "|", dotnetVersion, "|build-version")] ^ |
| 30 | + |
| 31 | + set baseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|", VARIABLES["branch"])] ^ |
| 32 | + set checksumsBaseUrl to VARIABLES[cat("dotnet|", dotnetVersion, "|base-url|checksums|", VARIABLES["branch"])] ^ |
| 33 | + set isInternal to find(baseUrl, "dotnetstage") >= 0 ^ |
| 34 | + |
| 35 | + set archiveExtension to when(isWindows, ".zip", ".tar.gz") ^ |
| 36 | + |
| 37 | + if (product = "runtime"):{{ |
| 38 | + set downloadPath to cat("/Runtime/", buildVersion, "/dotnet-runtime-", buildVersion, "-", platform, "-", ARCH_SHORT, archiveExtension) |
| 39 | + }}^elif (product = "aspnet"):{{ |
| 40 | + set downloadPath to cat("/aspnetcore/Runtime/", buildVersion, "/aspnetcore-runtime-", buildVersion, "-", platform, "-", ARCH_SHORT, archiveExtension) |
| 41 | + }}^elif (product = "aspnet-composite"):{{ |
| 42 | + set downloadPath to cat("/aspnetcore/Runtime/", buildVersion, "/aspnetcore-runtime-composite-", buildVersion, "-", platform, "-", ARCH_SHORT, archiveExtension) |
| 43 | + }}^elif (product = "sdk"):{{ |
| 44 | + set downloadPath to cat("/Sdk/", buildVersion, "/dotnet-sdk-", buildVersion, "-", platform, "-", ARCH_SHORT, archiveExtension) |
| 45 | + }}^ |
| 46 | + set downloadUrl to cat(baseUrl, downloadPath) ^ |
| 47 | + |
| 48 | + set shaFunction to "512" ^ |
| 49 | + set urlParts to split(downloadUrl, "/") ^ |
| 50 | + set fileName to urlParts[len(urlParts) - 1] ^ |
| 51 | + |
| 52 | + _ For now the aggregate and bare checksum files are mutually exclusive, but |
| 53 | + in the future we expect .NET 10 to have non-aggregate, non-bare checksum |
| 54 | + files before the other .NET versions, so it's necessary to have a |
| 55 | + separate condition for bare checksum files. ^ |
| 56 | + _ Aggregate checksum files are also not available for internal builds. ^ |
| 57 | + set shaUrlIsAggregate to (!isInternal && (dotnetVersion = "8.0" || dotnetVersion = "9.0")) ^ |
| 58 | + set shaUrlIsBare to (isInternal || dotnetVersion = "10.0") ^ |
| 59 | + |
| 60 | + set shaUrlPath to when(shaUrlIsAggregate, |
| 61 | + VARIABLES[cat("dotnet|", dotnetVersion, "|aggregate-checksums")], |
| 62 | + cat(downloadPath, ".sha512")) ^ |
| 63 | + set shaUrl to cat(checksumsBaseUrl, shaUrlPath) ^ |
| 64 | + |
| 65 | + set shaUrlParts to split(shaUrl, "/") ^ |
| 66 | + set shaFileName to shaUrlParts[len(shaUrlParts) - 1] ^ |
| 67 | + |
| 68 | + _ The .NET SDK has two versions associated with it - SDK version and Runtime version. |
| 69 | + Aggregate checksum files are associated with the .NET runtime version, so if we're |
| 70 | + installing the SDK we need to have a separate variable for the runtime version. ^ |
| 71 | + if (product = "sdk" && shaUrlIsAggregate):{{ |
| 72 | + set runtimeVersion to VARIABLES[cat("runtime|", dotnetVersion, "|build-version")] |
| 73 | + }}^ |
| 74 | + |
| 75 | + set downloadFiles to cat("Dockerfile.", templatePlatform, ".download-files") ^ |
| 76 | + set validateChecksum to cat("Dockerfile.", templatePlatform, ".validate-checksum") ^ |
| 77 | + set extractFile to cat("Dockerfile.", templatePlatform, ".extract-file") ^ |
| 78 | + |
| 79 | + set variableAssignments to [] ^ |
| 80 | + |
| 81 | + _ Replace variables in a string with their values ^ |
| 82 | + set replaceVariables(string) to:{{ |
| 83 | + for variable, value in variableAssignments:{{ |
| 84 | + set string to replace(string, value, cat("$", variable)) |
| 85 | + }}^ |
| 86 | + return string |
| 87 | + }}^ |
| 88 | + |
| 89 | + _ Replace variables in a string, format specifically for the purpose of |
| 90 | + assigning to a variable in PowerShell. ^ |
| 91 | + set replaceVariablesPwshString(string) to:{{ |
| 92 | + for variable, value in variableAssignments:{{ |
| 93 | + set found to find(string, value)^ |
| 94 | + if (found = 0):{{ |
| 95 | + _ variable at beginning of string ^ |
| 96 | + return cat(replace(string, value, cat("$", variable, " + '")), "'") |
| 97 | + }}^elif (found > 0):{{ |
| 98 | + _ variable somewhere in the middle of the string ^ |
| 99 | + set parts to split(string, value)^ |
| 100 | + return cat("'", parts[0], "' + $", variable, " + '", parts[1], "'") |
| 101 | + }}^_ |
| 102 | + }}^ |
| 103 | + return cat("'", string, "'") |
| 104 | + }}^ |
| 105 | + |
| 106 | + set assign(variable, value, isPwshString) to:{{ |
| 107 | + _ Add variable to collection, return a string that assigns the variable ^ |
| 108 | + set rhs to when(isWindows, |
| 109 | + replaceVariablesPwshString(value), |
| 110 | + replaceVariables(value))^ |
| 111 | + set out to when(isWindows, |
| 112 | + cat("$", variable, " = ", rhs), |
| 113 | + cat(variable, "=", rhs))^ |
| 114 | + set variableAssignments to union([variable: value], variableAssignments) ^ |
| 115 | + return out |
| 116 | + }} |
| 117 | + |
| 118 | +}}{{ |
| 119 | + assign( |
| 120 | + when(product = "aspnet" || product = "aspnet-composite", |
| 121 | + "aspnetcore_version", |
| 122 | + when(product = "sdk", |
| 123 | + "dotnet_sdk_version", |
| 124 | + "dotnet_version")), |
| 125 | + buildVersion |
| 126 | + ) |
| 127 | +}}{{if runtimeVersion:{{lineEnd}} |
| 128 | +{{continue}}{{ |
| 129 | + assign("dotnet_version", runtimeVersion) |
| 130 | +}}}}{{if useFileVariables:{{lineEnd}} |
| 131 | +{{continue}}{{ |
| 132 | + set fileNameVar to when(product = "aspnet", "aspnetcore_file", "dotnet_file")^ |
| 133 | + assign(fileNameVar, fileName)^ |
| 134 | + set fileName to replaceVariables(fileName) |
| 135 | +}}{{lineEnd}} |
| 136 | +{{continue}}{{ |
| 137 | + set shaFileVar to when(shaUrlIsAggregate, "dotnet_checksums_file", "dotnet_sha512_file")^ |
| 138 | + assign(shaFileVar, shaFileName)^ |
| 139 | + set shaFileName to replaceVariables(shaFileName) |
| 140 | +}}}}{{lineEnd}}{{extraLine}} |
| 141 | +{{continue}}{{ |
| 142 | + set downloadUrl to replaceVariables(downloadUrl) ^ |
| 143 | + set shaUrl to replaceVariables(shaUrl) ^ |
| 144 | + set filesToDownload to when(useFileVariables, |
| 145 | + [ |
| 146 | + ["out-file": fileName, "url": downloadUrl], |
| 147 | + ["out-file": shaFileName, "url": shaUrl] |
| 148 | + ], |
| 149 | + [ |
| 150 | + ["url": downloadUrl], |
| 151 | + ["url": shaUrl] |
| 152 | + ] |
| 153 | + )^ |
| 154 | + InsertTemplate(downloadFiles, [ |
| 155 | + "files": filesToDownload |
| 156 | + ]) |
| 157 | +}}{{lineEnd}}{{extraLine}} |
| 158 | +{{continue}}{{ |
| 159 | + InsertTemplate(validateChecksum, [ |
| 160 | + "file": replaceVariables(fileName), |
| 161 | + "sha-function": shaFunction, |
| 162 | + "sha-file": replaceVariables(shaFileName), |
| 163 | + "sha-file-is-bare": shaUrlIsBare, |
| 164 | + "sha-file-is-aggregate": shaUrlIsAggregate, |
| 165 | + "use-cmd-escape": isWindows && product = "sdk" |
| 166 | + ]) |
| 167 | +}}{{if ARGS["extract-to"]:{{lineEnd}}{{extraLine}} |
| 168 | +{{continue}}mkdir {{if !isWindows:--parents }}{{ARGS["extract-to"]}}{{lineEnd}} |
| 169 | +{{continue}}{{ |
| 170 | + InsertTemplate(extractFile, [ |
| 171 | + "file": replaceVariables(fileName), |
| 172 | + "dest-dir": ARGS["extract-to"], |
| 173 | + "extract-paths": ARGS["extract-paths"] |
| 174 | + ]) |
| 175 | +}}}}{{lineEnd}} |
| 176 | +{{continue}}{{remove}} {{lineContinue}} |
| 177 | + {{replaceVariables(fileName)}}{{if isWindows:,}} {{lineContinue}} |
| 178 | + {{replaceVariables(shaFileName)}} |
0 commit comments