Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new CDN for dotnet builds #1230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dotnet/scripts/dotnet-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fetch_latest_version_in_channel() {
local channel="$1"
local runtime="$2"
if [ "$runtime" = "dotnet" ]; then
wget -qO- "https://dotnetcli.azureedge.net/dotnet/Runtime/$channel/latest.version"
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Runtime/$channel/latest.version"
elif [ "$runtime" = "aspnetcore" ]; then
wget -qO- "https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$channel/latest.version"
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/aspnetcore/Runtime/$channel/latest.version"
else
wget -qO- "https://dotnetcli.azureedge.net/dotnet/Sdk/$channel/latest.version"
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Sdk/$channel/latest.version"
fi
}

Expand Down
123 changes: 107 additions & 16 deletions src/dotnet/scripts/vendor/dotnet-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,17 @@ get_normalized_architecture_for_specific_sdk_version() {
# args:
# version or channel - $1
is_arm64_supported() {
#any channel or version that starts with the specified versions
case "$1" in
( "1"* | "2"* | "3"* | "4"* | "5"*)
echo false
return 0
# Extract the major version by splitting on the dot
major_version="${1%%.*}"

# Check if the major version is a valid number and less than 6
case "$major_version" in
[0-9]*)
if [ "$major_version" -lt 6 ]; then
echo false
return 0
fi
;;
esac

echo true
Expand Down Expand Up @@ -950,6 +956,37 @@ get_absolute_path() {
return 0
}

# args:
# override - $1 (boolean, true or false)
get_cp_options() {
eval $invocation

local override="$1"
local override_switch=""

if [ "$override" = false ]; then
override_switch="-n"

# create temporary files to check if 'cp -u' is supported
tmp_dir="$(mktemp -d)"
tmp_file="$tmp_dir/testfile"
tmp_file2="$tmp_dir/testfile2"

touch "$tmp_file"

# use -u instead of -n if it's available
if cp -u "$tmp_file" "$tmp_file2" 2>/dev/null; then
override_switch="-u"
fi

# clean up
rm -f "$tmp_file" "$tmp_file2"
rm -rf "$tmp_dir"
fi

echo "$override_switch"
}

# args:
# input_files - stdin
# root_path - $1
Expand All @@ -961,15 +998,7 @@ copy_files_or_dirs_from_list() {
local root_path="$(remove_trailing_slash "$1")"
local out_path="$(remove_trailing_slash "$2")"
local override="$3"
local osname="$(get_current_os_name)"
local override_switch=$(
if [ "$override" = false ]; then
if [ "$osname" = "linux-musl" ]; then
printf -- "-u";
else
printf -- "-n";
fi
fi)
local override_switch="$(get_cp_options "$override")"

cat | uniq | while read -r file_path; do
local path="$(remove_beginning_slash "${file_path#$root_path}")"
Expand Down Expand Up @@ -1243,6 +1272,61 @@ downloadwget() {
return 0
}

extract_stem() {
local url="$1"
# extract the protocol
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
# remove the protocol
url="${1/$proto/}"
# extract the path (if any) - since we know all of our feeds have a first path segment, we can skip the first one. otherwise we'd use -f2- to get the full path
full_path="$(echo $url | grep / | cut -d/ -f2-)"
path="$(echo $full_path | cut -d/ -f2-)"
echo $path
}

check_url_exists() {
eval $invocation
local url="$1"

local code=""
if machine_has "curl"
then
code=$(curl --head -o /dev/null -w "%{http_code}" -s --fail "$url");
elif machine_has "wget"
then
# get the http response, grab the status code
server_response=$(wget -qO- --method=HEAD --server-response "$url" 2>&1)
code=$(echo "$server_response" | grep "HTTP/" | awk '{print $2}')
fi
if [ $code = "200" ]; then
return 0
else
return 1
fi
}

sanitize_redirect_url() {
eval $invocation

local url_stem
url_stem=$(extract_stem "$1")
say_verbose "Checking configured feeds for the asset at ${yellow:-}$url_stem${normal:-}"

for feed in "${feeds[@]}"
do
local trial_url="$feed/$url_stem"
say_verbose "Checking ${yellow:-}$trial_url${normal:-}"
if check_url_exists "$trial_url"; then
say_verbose "Found a match at ${yellow:-}$trial_url${normal:-}"
echo "$trial_url"
return 0
else
say_verbose "No match at ${yellow:-}$trial_url${normal:-}"
fi
done
return 1
}

get_download_link_from_aka_ms() {
eval $invocation

Expand Down Expand Up @@ -1295,6 +1379,11 @@ get_download_link_from_aka_ms() {
return 1
fi

sanitized_redirect_url=$(sanitize_redirect_url "$aka_ms_download_link")
if [[ -n "$sanitized_redirect_url" ]]; then
aka_ms_download_link="$sanitized_redirect_url"
fi

say_verbose "The redirect location retrieved: '$aka_ms_download_link'."
return 0
else
Expand All @@ -1306,7 +1395,9 @@ get_download_link_from_aka_ms() {
get_feeds_to_use()
{
feeds=(
"https://builds.dotnet.microsoft.com/dotnet"
"https://dotnetcli.azureedge.net/dotnet"
"https://ci.dot.net/public"
"https://dotnetbuilds.azureedge.net/public"
)

Expand Down Expand Up @@ -1735,7 +1826,7 @@ do
zip_path="$1"
;;
-?|--?|-h|--help|-[Hh]elp)
script_name="$(basename "$0")"
script_name="dotnet-install.sh"
echo ".NET Tools Installer"
echo "Usage:"
echo " # Install a .NET SDK of a given Quality from a given Channel"
Expand Down Expand Up @@ -1865,4 +1956,4 @@ fi

say "Note that the script does not resolve dependencies during installation."
say "To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the \"Dependencies\" section."
say "Installation finished successfully."
say "Installation finished successfully."
123 changes: 107 additions & 16 deletions src/oryx/scripts/vendor/dotnet-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,17 @@ get_normalized_architecture_for_specific_sdk_version() {
# args:
# version or channel - $1
is_arm64_supported() {
#any channel or version that starts with the specified versions
case "$1" in
( "1"* | "2"* | "3"* | "4"* | "5"*)
echo false
return 0
# Extract the major version by splitting on the dot
major_version="${1%%.*}"

# Check if the major version is a valid number and less than 6
case "$major_version" in
[0-9]*)
if [ "$major_version" -lt 6 ]; then
echo false
return 0
fi
;;
esac

echo true
Expand Down Expand Up @@ -950,6 +956,37 @@ get_absolute_path() {
return 0
}

# args:
# override - $1 (boolean, true or false)
get_cp_options() {
eval $invocation

local override="$1"
local override_switch=""

if [ "$override" = false ]; then
override_switch="-n"

# create temporary files to check if 'cp -u' is supported
tmp_dir="$(mktemp -d)"
tmp_file="$tmp_dir/testfile"
tmp_file2="$tmp_dir/testfile2"

touch "$tmp_file"

# use -u instead of -n if it's available
if cp -u "$tmp_file" "$tmp_file2" 2>/dev/null; then
override_switch="-u"
fi

# clean up
rm -f "$tmp_file" "$tmp_file2"
rm -rf "$tmp_dir"
fi

echo "$override_switch"
}

# args:
# input_files - stdin
# root_path - $1
Expand All @@ -961,15 +998,7 @@ copy_files_or_dirs_from_list() {
local root_path="$(remove_trailing_slash "$1")"
local out_path="$(remove_trailing_slash "$2")"
local override="$3"
local osname="$(get_current_os_name)"
local override_switch=$(
if [ "$override" = false ]; then
if [ "$osname" = "linux-musl" ]; then
printf -- "-u";
else
printf -- "-n";
fi
fi)
local override_switch="$(get_cp_options "$override")"

cat | uniq | while read -r file_path; do
local path="$(remove_beginning_slash "${file_path#$root_path}")"
Expand Down Expand Up @@ -1243,6 +1272,61 @@ downloadwget() {
return 0
}

extract_stem() {
local url="$1"
# extract the protocol
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
# remove the protocol
url="${1/$proto/}"
# extract the path (if any) - since we know all of our feeds have a first path segment, we can skip the first one. otherwise we'd use -f2- to get the full path
full_path="$(echo $url | grep / | cut -d/ -f2-)"
path="$(echo $full_path | cut -d/ -f2-)"
echo $path
}

check_url_exists() {
eval $invocation
local url="$1"

local code=""
if machine_has "curl"
then
code=$(curl --head -o /dev/null -w "%{http_code}" -s --fail "$url");
elif machine_has "wget"
then
# get the http response, grab the status code
server_response=$(wget -qO- --method=HEAD --server-response "$url" 2>&1)
code=$(echo "$server_response" | grep "HTTP/" | awk '{print $2}')
fi
if [ $code = "200" ]; then
return 0
else
return 1
fi
}

sanitize_redirect_url() {
eval $invocation

local url_stem
url_stem=$(extract_stem "$1")
say_verbose "Checking configured feeds for the asset at ${yellow:-}$url_stem${normal:-}"

for feed in "${feeds[@]}"
do
local trial_url="$feed/$url_stem"
say_verbose "Checking ${yellow:-}$trial_url${normal:-}"
if check_url_exists "$trial_url"; then
say_verbose "Found a match at ${yellow:-}$trial_url${normal:-}"
echo "$trial_url"
return 0
else
say_verbose "No match at ${yellow:-}$trial_url${normal:-}"
fi
done
return 1
}

get_download_link_from_aka_ms() {
eval $invocation

Expand Down Expand Up @@ -1295,6 +1379,11 @@ get_download_link_from_aka_ms() {
return 1
fi

sanitized_redirect_url=$(sanitize_redirect_url "$aka_ms_download_link")
if [[ -n "$sanitized_redirect_url" ]]; then
aka_ms_download_link="$sanitized_redirect_url"
fi

say_verbose "The redirect location retrieved: '$aka_ms_download_link'."
return 0
else
Expand All @@ -1306,7 +1395,9 @@ get_download_link_from_aka_ms() {
get_feeds_to_use()
{
feeds=(
"https://builds.dotnet.microsoft.com/dotnet"
"https://dotnetcli.azureedge.net/dotnet"
"https://ci.dot.net/public"
"https://dotnetbuilds.azureedge.net/public"
)

Expand Down Expand Up @@ -1735,7 +1826,7 @@ do
zip_path="$1"
;;
-?|--?|-h|--help|-[Hh]elp)
script_name="$(basename "$0")"
script_name="dotnet-install.sh"
echo ".NET Tools Installer"
echo "Usage:"
echo " # Install a .NET SDK of a given Quality from a given Channel"
Expand Down Expand Up @@ -1865,4 +1956,4 @@ fi

say "Note that the script does not resolve dependencies during installation."
say "To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the \"Dependencies\" section."
say "Installation finished successfully."
say "Installation finished successfully."
6 changes: 3 additions & 3 deletions test/dotnet/dotnet_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ fetch_latest_version_in_channel() {
local channel="$1"
local runtime="$2"
if [ "$runtime" = "dotnet" ]; then
wget -qO- "https://dotnetcli.azureedge.net/dotnet/Runtime/$channel/latest.version"
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Runtime/$channel/latest.version"
elif [ "$runtime" = "aspnetcore" ]; then
wget -qO- "https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$channel/latest.version"
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/aspnetcore/Runtime/$channel/latest.version"
else
wget -qO- "https://dotnetcli.azureedge.net/dotnet/Sdk/$channel/latest.version"
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Sdk/$channel/latest.version"
fi
}

Expand Down