aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamruddhi Khandale <skhandale@microsoft.com>2023-06-30 01:14:11 +0300
committerGitHub <noreply@github.com>2023-06-30 01:14:11 +0300
commit300814be97eaa5b7780886bd2eb37e96b523b3e7 (patch)
tree9db60abc9475d2f379dc53861d7c8a928bd6e34a
parent8a51aa906676280364df60010575b7dad3162f37 (diff)
Dotnet: Fix Feature failures on ubuntu:jammy (when installing using apt) (#590)feature_dotnet_1.1.4
* fix several bugs * fix test: .NET is now installed from ubuntu feeds * add comment ; use dev containers image * address comments * revert debugging cmd * fix test for bookworm
-rw-r--r--src/dotnet/devcontainer-feature.json2
-rw-r--r--src/dotnet/install.sh32
-rw-r--r--test/dotnet/install_dotnet_6_jammy.sh17
-rw-r--r--test/dotnet/install_dotnet_7_jammy.sh2
-rw-r--r--test/dotnet/install_dotnet_latest.sh2
-rw-r--r--test/dotnet/scenarios.json8
-rwxr-xr-xtest/dotnet/test.sh2
7 files changed, 57 insertions, 8 deletions
diff --git a/src/dotnet/devcontainer-feature.json b/src/dotnet/devcontainer-feature.json
index 4aa264c..4f484cc 100644
--- a/src/dotnet/devcontainer-feature.json
+++ b/src/dotnet/devcontainer-feature.json
@@ -1,6 +1,6 @@
{
"id": "dotnet",
- "version": "1.1.3",
+ "version": "1.1.4",
"name": "Dotnet CLI",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/dotnet",
"description": "Installs the .NET CLI. Provides option of installing sdk or runtime, and option of versions to install. Uses latest version of .NET sdk as defaults to install.",
diff --git a/src/dotnet/install.sh b/src/dotnet/install.sh
index 1c7430a..178994d 100644
--- a/src/dotnet/install.sh
+++ b/src/dotnet/install.sh
@@ -33,6 +33,16 @@ DOTNET_VERSION_CODENAMES_REQUIRE_OLDER_LIBSSL_1="buster bullseye bionic focal hi
# alongside DOTNET_VERSION, but not set as default.
ADDITIONAL_VERSIONS=${ADDITIONALVERSIONS:-""}
+APT_PREFERENCES_CONTENT="$(cat << 'EOF'
+Package: *
+Pin: origin "packages.microsoft.com"
+Pin-Priority: 1001
+EOF
+)"
+
+APT_PREFERENCES_FILE_ADDED="false"
+APT_PREFERENCES_UPDATED="false"
+
set -e
# Clean up
@@ -147,9 +157,9 @@ apt_cache_package_and_version_soft_match() {
. /etc/os-release
local architecture="$(dpkg --print-architecture)"
+ apt-get update -y
major_minor_version="$(echo "${requested_version}" | cut -d "." --field=1,2)"
- package_name="$(apt-cache search "${partial_package_name}-[0-9].[0-9]" | awk -F" - " '{print $1}' | grep -m 1 "${partial_package_name}-${major_minor_version}")"
-
+ package_name="$(apt-cache search "${partial_package_name}-[0-9].[0-9]$" | awk -F" - " '{print $1}' | grep -m 1 "${partial_package_name}-${major_minor_version}")"
dot_escaped="${requested_version//./\\.}"
dot_plus_escaped="${dot_escaped//+/\\+}"
# Regex needs to handle debian package version number format: https://www.systutorials.com/docs/linux/man/5-deb-version/
@@ -193,6 +203,12 @@ install_using_apt() {
# Import key safely and import Microsoft apt repo
curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg
echo "deb [arch=${architecture} signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/repos/microsoft-${ID}-${VERSION_CODENAME}-prod ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/microsoft.list
+
+ [ ! -f /etc/apt/preferences ] && APT_PREFERENCES_FILE_ADDED="true"
+ APT_PREFERENCES_UPDATED="true"
+
+ # See https://github.com/dotnet/core/issues/7699
+ echo "${APT_PREFERENCES_CONTENT}" >> /etc/apt/preferences
apt-get update -y
fi
@@ -233,8 +249,8 @@ install_using_apt() {
mkdir -p "${TARGET_DOTNET_ROOT}"
local dotnet_installed_version="$(dotnet --version)"
# See if its the distro version
- if [[ "$(dotnet --info)" == *"Base Path: /usr/lib/dotnet/dotnet${dotnet_installed_version:0:1}-${dotnet_installed_version}"* ]]; then
- ln -s "/usr/lib/dotnet/dotnet${dotnet_installed_version:0:1}" "${CURRENT_DIR}"
+ if [[ "$(dotnet --info)" == *"Base Path: /usr/lib/dotnet/${DOTNET_SDK_OR_RUNTIME}/${dotnet_installed_version}"* ]]; then
+ ln -s "/usr/lib/dotnet" "${CURRENT_DIR}"
else
# Location used by MS repo versions
ln -s "/usr/share/dotnet" "${CURRENT_DIR}"
@@ -463,6 +479,14 @@ if [ "${CHANGE_OWNERSHIP}" = "true" ]; then
fi
# Clean up
+if [ "${APT_PREFERENCES_UPDATED}" = "true" ]; then
+ if [ "${APT_PREFERENCES_FILE_ADDED}" = "true" ]; then
+ rm -f /etc/apt/preferences
+ else
+ head -n -3 /etc/apt/preferences > /tmp/preferences-temp && mv /tmp/preferences-temp /etc/apt/preferences
+ fi
+fi
+
rm -rf /var/lib/apt/lists/*
echo "Done!"
diff --git a/test/dotnet/install_dotnet_6_jammy.sh b/test/dotnet/install_dotnet_6_jammy.sh
new file mode 100644
index 0000000..fd10634
--- /dev/null
+++ b/test/dotnet/install_dotnet_6_jammy.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+set -e
+
+# Optional: Import test library
+source dev-container-features-test-lib
+
+check "dotnet sdks" dotnet --list-sdks
+check "some major version of dotnet 6 is installed" bash -c "dotnet --list-sdks | grep '6\.[0-9]*\.[0-9]*'"
+check "dotnet version 6 installed" bash -c "ls -l /usr/lib/dotnet/sdk | grep '6\.[0-9]*\.[0-9]*'"
+
+# Verify current symlink exists and works
+check "current link dotnet" /usr/local/dotnet/current/dotnet --info
+check "current link sdk" ls -l /usr/local/dotnet/current/sdk
+
+# Report result
+reportResults
diff --git a/test/dotnet/install_dotnet_7_jammy.sh b/test/dotnet/install_dotnet_7_jammy.sh
index 2c015fc..1392168 100644
--- a/test/dotnet/install_dotnet_7_jammy.sh
+++ b/test/dotnet/install_dotnet_7_jammy.sh
@@ -7,7 +7,7 @@ source dev-container-features-test-lib
check "dotnet sdks" dotnet --list-sdks
check "some major version of dotnet 7 is installed" bash -c "dotnet --list-sdks | grep '7\.[0-9]*\.[0-9]*'"
-check "dotnet version 7 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep '7\.[0-9]*\.[0-9]*'"
+check "dotnet version 7 installed" bash -c "ls -l /usr/lib/dotnet/sdk | grep '7\.[0-9]*\.[0-9]*'"
# Verify current symlink exists and works
check "current link dotnet" /usr/local/dotnet/current/dotnet --info
diff --git a/test/dotnet/install_dotnet_latest.sh b/test/dotnet/install_dotnet_latest.sh
index 2c015fc..1392168 100644
--- a/test/dotnet/install_dotnet_latest.sh
+++ b/test/dotnet/install_dotnet_latest.sh
@@ -7,7 +7,7 @@ source dev-container-features-test-lib
check "dotnet sdks" dotnet --list-sdks
check "some major version of dotnet 7 is installed" bash -c "dotnet --list-sdks | grep '7\.[0-9]*\.[0-9]*'"
-check "dotnet version 7 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep '7\.[0-9]*\.[0-9]*'"
+check "dotnet version 7 installed" bash -c "ls -l /usr/lib/dotnet/sdk | grep '7\.[0-9]*\.[0-9]*'"
# Verify current symlink exists and works
check "current link dotnet" /usr/local/dotnet/current/dotnet --info
diff --git a/test/dotnet/scenarios.json b/test/dotnet/scenarios.json
index 37f83d5..afee26f 100644
--- a/test/dotnet/scenarios.json
+++ b/test/dotnet/scenarios.json
@@ -48,6 +48,14 @@
}
}
},
+ "install_dotnet_6_jammy": {
+ "image": "mcr.microsoft.com/devcontainers/base:jammy",
+ "features": {
+ "dotnet": {
+ "version": "6"
+ }
+ }
+ },
"install_dotnet_latest": {
"image": "ubuntu:jammy",
"features": {
diff --git a/test/dotnet/test.sh b/test/dotnet/test.sh
index 7eb0cf6..f433654 100755
--- a/test/dotnet/test.sh
+++ b/test/dotnet/test.sh
@@ -11,7 +11,7 @@ check "sdks" dotnet --list-sdks
check "version" dotnet --version
echo "Validating expected version present..."
-check "some major version of dotnet 7 is installed" bash -c "dotnet --version | grep '7\.[0-9]*\.[0-9]*'"
+check "some major version of dotnet (7/8) is installed" bash -c "dotnet --version | grep '[7-8]\.[0-9]*\.[0-9]*'"
# Verify current symlink exists and works
check "current link dotnet" /usr/local/dotnet/current/dotnet --info