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

Dotnet: Fix Feature failures on ubuntu:jammy (when installing using apt) #590

Merged
merged 6 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion src/dotnet/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
16 changes: 12 additions & 4 deletions src/dotnet/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,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 -v "source-built-artifacts" | grep -m 1 "${partial_package_name}-${major_minor_version}")"
samruddhikhandale marked this conversation as resolved.
Show resolved Hide resolved
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/
Expand Down Expand Up @@ -193,6 +193,14 @@ 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

# See https://github.com/dotnet/core/issues/7699
samruddhikhandale marked this conversation as resolved.
Show resolved Hide resolved
cat << 'EOF' >> /etc/apt/preferences
Package: *
Pin: origin "packages.microsoft.com"
Pin-Priority: 1001
EOF

apt-get update -y
fi

Expand Down Expand Up @@ -233,8 +241,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}"
Expand Down
17 changes: 17 additions & 0 deletions test/dotnet/install_dotnet_6_jammy.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/dotnet/install_dotnet_7_jammy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/dotnet/install_dotnet_latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/dotnet/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down