Skip to content

Commit ef87daf

Browse files
authored
update dotnet/oryx features to use recommended install location for dotnet6 (#91)
* use default jammy apt feed to mitigate jammy/oryx install issues * remove old comment * jammy first tries default apt repo * refactoring * glob friendly and tests * test files * better greps * correct path * DEBIAN_FRONTEND global in oryx install script * remove set -e from dotnet script to handle errors ourselves
1 parent ea4eaf2 commit ef87daf

File tree

12 files changed

+165
-92
lines changed

12 files changed

+165
-92
lines changed

.devcontainer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"postCreateCommand": "npm install -g @devcontainers/cli"
3+
}

.github/workflows/test-all.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
test:
1010
runs-on: ubuntu-latest
11-
if: "!contains(github.event.head_commit.message, 'no-ci') && !contains(github.event.head_commit.message, 'CI ignore')"
11+
if: "!contains(github.event.head_commit.message, 'no-ci') && !contains(github.event.head_commit.message, 'CI ignore') && !contains(github.event.head_commit.message, 'Automated documentation update')"
1212
continue-on-error: true
1313
strategy:
1414
matrix:

.github/workflows/test-pr-temp.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/test-pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
jobs:
66
detect-changes:
77
runs-on: ubuntu-latest
8-
if: "!contains(github.event.head_commit.message, 'no-ci') && !contains(github.event.head_commit.message, 'CI ignore')"
8+
if: "!contains(github.event.head_commit.message, 'no-ci') && !contains(github.event.head_commit.message, 'CI ignore') && !contains(github.event.head_commit.message, 'Automated documentation update')"
99
outputs:
1010
features: ${{ steps.filter.outputs.changes }}
1111
steps:

.github/workflows/test-scenarios.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
scenarios:
1111
runs-on: ubuntu-latest
12-
if: "!contains(github.event.head_commit.message, 'no-ci') && !contains(github.event.head_commit.message, 'CI ignore')"
12+
if: "!contains(github.event.head_commit.message, 'no-ci') && !contains(github.event.head_commit.message, 'CI ignore') && !contains(github.event.head_commit.message, 'Automated documentation update')"
1313
steps:
1414
- uses: actions/checkout@v2
1515

src/dotnet/devcontainer-feature.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"type": "string",
99
"proposals": [
1010
"latest",
11-
"6.0",
12-
"5.0",
11+
"6",
12+
"5",
1313
"3.1"
1414
],
1515
"default": "latest",

src/dotnet/install.sh

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ DOTNET_VERSION_CODENAMES_REQUIRE_OLDER_LIBSSL_1="buster bullseye bionic focal hi
3030
# alongside DOTNET_VERSION, but not set as default.
3131
ADDITIONAL_VERSIONS=${ADDITIONALVERSIONS:-""}
3232

33-
# Exit on failure.
34-
set -e
35-
3633
# Setup STDERR.
3734
err() {
3835
echo "(!) $*" >&2
@@ -155,12 +152,12 @@ apt_cache_package_and_version_soft_match() {
155152
local exit_on_no_match="${3:-true}"
156153
local major_minor_version
157154

158-
major_minor_version="$(echo "${requested_version}" | cut -d "." --field=1,2)"
159-
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}")"
160-
161155
# Ensure we've exported useful variables
162156
. /etc/os-release
163157
local architecture="$(dpkg --print-architecture)"
158+
159+
major_minor_version="$(echo "${requested_version}" | cut -d "." --field=1,2)"
160+
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}")"
164161

165162
dot_escaped="${requested_version//./\\.}"
166163
dot_plus_escaped="${dot_escaped//+/\\+}"
@@ -170,14 +167,14 @@ apt_cache_package_and_version_soft_match() {
170167
fuzzy_version="$(apt-cache madison ${package_name} | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "${version_regex}")"
171168
set -e
172169
if [ -z "${fuzzy_version}" ]; then
173-
echo "(!) No full or partial for package \"${package_name}\" match found in apt-cache for \"${requested_version}\" on OS ${ID} ${VERSION_CODENAME} (${architecture})."
170+
echo "(!) No full or partial for package \"${partial_package_name}\" (resolved: \"${package_name}\") match found in apt-cache for \"${requested_version}\" on OS ${ID} ${VERSION_CODENAME} (${architecture})."
174171

175172
if $exit_on_no_match; then
176173
echo "Available versions:"
177174
apt-cache madison ${package_name} | awk -F"|" '{print $2}' | grep -oP '^(.+:)?\K.+'
178175
exit 1 # Fail entire script
179176
else
180-
echo "Continuing to fallback method (if available)"
177+
echo "Continuing to fallback method if available"
181178
return 1;
182179
fi
183180
fi
@@ -194,7 +191,7 @@ apt_cache_package_and_version_soft_match() {
194191
}
195192

196193
# Install .NET CLI using apt-get package installer
197-
install_using_apt() {
194+
install_using_apt_from_microsoft_repo() {
198195
local sdk_or_runtime="$1"
199196
local dotnet_major_minor_version
200197
export DOTNET_PACKAGE="dotnet-${sdk_or_runtime}"
@@ -206,26 +203,46 @@ install_using_apt() {
206203
get_common_setting MICROSOFT_GPG_KEYS_URI
207204
curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg
208205
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
209-
apt-get update
206+
apt-get update -y
210207

211208
if [ "${DOTNET_VERSION}" = "latest" ] || [ "${DOTNET_VERSION}" = "lts" ]; then
212209
DOTNET_VERSION=""
213210
DOTNET_PACKAGE="${DOTNET_PACKAGE}-6.0"
214211
else
215212
# Sets DOTNET_VERSION and DOTNET_PACKAGE if matches found.
216213
apt_cache_package_and_version_soft_match DOTNET_VERSION DOTNET_PACKAGE false
214+
if [ "$?" != 0 ]; then
215+
echo "Failed to find requested version."
216+
return 1
217+
fi
217218

218219
if [[ $(dotnet --version) == *"${DOTNET_VERSION}"* ]] ; then
219220
echo "Dotnet version ${DOTNET_VERSION} is already installed"
220-
exit 1
221-
fi
222-
223-
if [ "$?" != 0 ]; then
224221
return 1
225222
fi
223+
226224
fi
227225

228-
if ! (apt-get install -yq ${DOTNET_PACKAGE}${DOTNET_VERSION}); then
226+
echo "Installing '${DOTNET_PACKAGE}${DOTNET_VERSION}'..."
227+
apt-get install -yq ${DOTNET_PACKAGE}${DOTNET_VERSION}
228+
if [ "$?" != 0 ]; then
229+
echo "Failed to complete apt install of ${DOTNET_PACKAGE}${DOTNET_VERSION}"
230+
return 1
231+
fi
232+
}
233+
234+
install_using_default_apt_repo() {
235+
DOTNET_PACKAGE="dotnet6"
236+
237+
apt_get_update_if_needed
238+
239+
if [[ "${DOTNET_VERSION}" = "latest" ]] || [[ "${DOTNET_VERSION}" = "lts" ]] || [[ ${DOTNET_VERSION} = "6"* ]]; then
240+
if ! (apt-get install -yq ${DOTNET_PACKAGE}); then
241+
echo "Failed to install 'dotnet6' package from default apt repo."
242+
return 1
243+
fi
244+
else
245+
echo "The provided dotnet version is not distributed in this distro's default apt repo."
229246
return 1
230247
fi
231248
}
@@ -379,12 +396,15 @@ install_using_dotnet_releases_url() {
379396

380397
export DEBIAN_FRONTEND=noninteractive
381398

382-
# Dotnet 3.1 and 5.0 are not supported on Ubuntu 22.04 (jammy)+,
399+
. /etc/os-release
400+
architecture="$(dpkg --print-architecture)"
401+
402+
# Dotnet 3.1 and 5 are not supported on Ubuntu 22.04 (jammy)+,
383403
# due to lack of libssl3.0 support.
384404
# See: https://github.com/microsoft/vscode-dev-containers/issues/1458#issuecomment-1135077775
385405
# NOTE: This will only guard against installation of the dotnet versions we propose via 'features'.
386406
# The user can attempt to install any other version at their own risk.
387-
if [[ "${DOTNET_VERSION}" = "3.1" ]] || [[ "${DOTNET_VERSION}" = "5.0" ]]; then
407+
if [[ "${DOTNET_VERSION}" = "3"* ]] || [[ "${DOTNET_VERSION}" = "5"* ]]; then
388408
if [[ ! "${DOTNET_VERSION_CODENAMES_REQUIRE_OLDER_LIBSSL_1}" = *"${VERSION_CODENAME}"* ]]; then
389409
err "Dotnet ${DOTNET_VERSION} is not supported on Ubuntu ${VERSION_CODENAME} due to a change in the 'libssl' dependency across distributions.\n Please upgrade your version of dotnet, or downgrade your OS version."
390410
exit 1
@@ -405,18 +425,20 @@ fi
405425
# Install the .NET CLI
406426
echo "(*) Installing .NET CLI..."
407427

408-
. /etc/os-release
409-
architecture="$(dpkg --print-architecture)"
410-
411428
CHANGE_OWNERSHIP="false"
412429
if [[ "${DOTNET_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${DOTNET_ARCHIVE_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]] && [[ "${INSTALL_USING_APT}" = "true" ]]; then
413430
echo "Detected ${VERSION_CODENAME} on ${architecture}. Attempting to install dotnet from apt"
414-
install_using_apt "${DOTNET_SDK_OR_RUNTIME}"
431+
432+
install_using_default_apt_repo || install_using_apt_from_microsoft_repo "${DOTNET_SDK_OR_RUNTIME}"
433+
if [ "$?" != 0 ]; then
434+
echo "Could not install requested version from apt on current distribution."
435+
exit 1
436+
fi
415437
else
416438
if [[ "${INSTALL_USING_APT}" = "false" ]]; then
417439
echo "Installing dotnet from releases url"
418440
else
419-
echo "Could not install dotnet from apt. Attempting to install dotnet from releases url"
441+
echo "Attempting to install dotnet from releases url"
420442
fi
421443
install_using_dotnet_releases_url "${DOTNET_SDK_OR_RUNTIME}" "${DOTNET_VERSION}"
422444
CHANGE_OWNERSHIP="true"

src/oryx/install.sh

Lines changed: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# Copyright (c) Microsoft Corporation. All rights reserved.
44
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
55
#-------------------------------------------------------------------------------------------------------------
6-
#
7-
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/hugo.md
8-
# Maintainer: The VS Code and Codespaces Teams
6+
97

108
USERNAME=${USERNAME:-"automatic"}
119
UPDATE_RC=${UPDATE_RC:-"true"}
1210

13-
set -eux
11+
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
12+
13+
set -eu
1414

1515
if [ "$(id -u)" -ne 0 ]; then
1616
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
@@ -66,72 +66,89 @@ apt_get_update_if_needed()
6666
check_packages() {
6767
if ! dpkg -s "$@" > /dev/null 2>&1; then
6868
apt_get_update_if_needed
69-
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends "$@"
69+
apt-get -y install --no-install-recommends "$@"
7070
fi
7171
}
7272

7373
install_dotnet_using_apt() {
74-
wget --no-check-certificate https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
75-
sudo dpkg -i packages-microsoft-prod.deb
76-
rm packages-microsoft-prod.deb
77-
78-
rm -rf /var/lib/apt/lists/*
79-
check_packages apt-transport-https dotnet-sdk-6.0
74+
echo "Attempting to auto-install dotnet..."
75+
install_from_microsoft_feed=false
76+
apt_get_update_if_needed
77+
apt-get -yq install dotnet6 || install_from_microsoft_feed="true"
78+
79+
if [ "${install_from_microsoft_feed}" = "true" ]; then
80+
echo "Attempting install from microsoft apt feed..."
81+
curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg
82+
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
83+
apt-get update -y
84+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE="true" apt-get install -yq dotnet-sdk-6.0
85+
fi
86+
87+
echo -e "Finished attempt to install dotnet. Sdks installed:\n"
88+
dotnet --list-sdks
8089
}
8190

91+
# If we don't already have Oryx installed, install it now.
92+
if oryx --version > /dev/null ; then
93+
echo "oryx is already installed. Skipping installation."
94+
exit 0
95+
fi
96+
97+
echo "Installing Oryx..."
98+
99+
# Ensure apt is in non-interactive to avoid prompts
100+
export DEBIAN_FRONTEND=noninteractive
101+
102+
. /etc/os-release
103+
architecture="$(dpkg --print-architecture)"
104+
82105
# Install dependencies
83-
check_packages git sudo wget ca-certificates
106+
check_packages git sudo curl ca-certificates apt-transport-https gnupg2 dirmngr libc-bin
84107

85-
# If we don't already have Oryx installed, install it now.
86-
if ! oryx --version > /dev/null ; then
87-
echo "Installing Oryx..."
108+
if ! cat /etc/group | grep -e "^oryx:" > /dev/null 2>&1; then
109+
groupadd -r oryx
110+
fi
111+
usermod -a -G oryx "${USERNAME}"
88112

89-
if ! cat /etc/group | grep -e "^oryx:" > /dev/null 2>&1; then
90-
groupadd -r oryx
91-
fi
92-
usermod -a -G oryx "${USERNAME}"
113+
# Install dotnet unless available
114+
if ! dotnet --version > /dev/null ; then
115+
echo "'dotnet' was not detected. Attempting to install the latest version of the dotnet sdk to build oryx."
116+
install_dotnet_using_apt
93117

94-
# Install dotnet unless available
95118
if ! dotnet --version > /dev/null ; then
96-
echo "'dotnet' was not detected. Attempting to install the latest version of the dotnet sdk to build oryx."
97-
install_dotnet_using_apt
98-
99-
if ! dotnet --version > /dev/null ; then
100-
echo "Please install Dotnet before installing Oryx"
101-
exit 1
102-
fi
119+
echo "(!) Please install Dotnet before installing Oryx"
120+
exit 1
103121
fi
122+
fi
104123

105-
BUILD_SCRIPT_GENERATOR=/usr/local/buildscriptgen
106-
ORYX=/usr/local/oryx
107-
GIT_ORYX=/opt/tmp
124+
BUILD_SCRIPT_GENERATOR=/usr/local/buildscriptgen
125+
ORYX=/usr/local/oryx
126+
GIT_ORYX=/opt/tmp
108127

109-
mkdir -p ${BUILD_SCRIPT_GENERATOR}
110-
mkdir -p ${ORYX}
128+
mkdir -p ${BUILD_SCRIPT_GENERATOR}
129+
mkdir -p ${ORYX}
111130

112-
git clone --depth=1 https://github.com/microsoft/Oryx $GIT_ORYX
131+
git clone --depth=1 https://github.com/microsoft/Oryx $GIT_ORYX
113132

114-
$GIT_ORYX/build/buildSln.sh
133+
$GIT_ORYX/build/buildSln.sh
115134

116-
dotnet publish -property:ValidateExecutableReferencesMatchSelfContained=false -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildScriptGeneratorCli/BuildScriptGeneratorCli.csproj
117-
118-
dotnet publish -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildServer/BuildServer.csproj
135+
dotnet publish -property:ValidateExecutableReferencesMatchSelfContained=false -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildScriptGeneratorCli/BuildScriptGeneratorCli.csproj
136+
dotnet publish -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildServer/BuildServer.csproj
119137

120-
chmod a+x ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript
138+
chmod a+x ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript
121139

122-
ln -s ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript ${ORYX}/oryx
123-
cp -f $GIT_ORYX/images/build/benv.sh ${ORYX}/benv
140+
ln -s ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript ${ORYX}/oryx
141+
cp -f $GIT_ORYX/images/build/benv.sh ${ORYX}/benv
124142

125-
ORYX_INSTALL_DIR="/opt"
126-
mkdir -p "${ORYX_INSTALL_DIR}"
143+
ORYX_INSTALL_DIR="/opt"
144+
mkdir -p "${ORYX_INSTALL_DIR}"
127145

128-
updaterc "export ORYX_SDK_STORAGE_BASE_URL=https://oryx-cdn.microsoft.io && export ENABLE_DYNAMIC_INSTALL=true && DYNAMIC_INSTALL_ROOT_DIR=$ORYX_INSTALL_DIR && ORYX_PREFER_USER_INSTALLED_SDKS=true && export DEBIAN_FLAVOR=focal-scm"
129-
130-
chown -R "${USERNAME}:oryx" "${ORYX_INSTALL_DIR}" "${BUILD_SCRIPT_GENERATOR}" "${ORYX}"
131-
chmod -R g+r+w "${ORYX_INSTALL_DIR}" "${BUILD_SCRIPT_GENERATOR}" "${ORYX}"
132-
find "${ORYX_INSTALL_DIR}" -type d | xargs -n 1 chmod g+s
133-
find "${BUILD_SCRIPT_GENERATOR}" -type d | xargs -n 1 chmod g+s
134-
find "${ORYX}" -type d | xargs -n 1 chmod g+s
135-
fi
146+
updaterc "export ORYX_SDK_STORAGE_BASE_URL=https://oryx-cdn.microsoft.io && export ENABLE_DYNAMIC_INSTALL=true && DYNAMIC_INSTALL_ROOT_DIR=$ORYX_INSTALL_DIR && ORYX_PREFER_USER_INSTALLED_SDKS=true && export DEBIAN_FLAVOR=focal-scm"
147+
148+
chown -R "${USERNAME}:oryx" "${ORYX_INSTALL_DIR}" "${BUILD_SCRIPT_GENERATOR}" "${ORYX}"
149+
chmod -R g+r+w "${ORYX_INSTALL_DIR}" "${BUILD_SCRIPT_GENERATOR}" "${ORYX}"
150+
find "${ORYX_INSTALL_DIR}" -type d | xargs -n 1 chmod g+s
151+
find "${BUILD_SCRIPT_GENERATOR}" -type d | xargs -n 1 chmod g+s
152+
find "${ORYX}" -type d | xargs -n 1 chmod g+s
136153

137154
echo "Done!"

test-scenarios/install_dotnet_3.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
check "dotnet sdks" dotnet --list-sdks
9+
check "some major version of dotnet 3 is installed" dotnet --list-sdks | grep '3\.[0-9]*\.[0-9]*'
10+
check "dotnet version 3 installed" ls -l /usr/share/dotnet/sdk | grep '3\.[0-9]*\.[0-9]*'
11+
12+
# Report result
13+
reportResults

test-scenarios/install_dotnet_5.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
check "dotnet sdks" dotnet --list-sdks
9+
check "some major version of dotnet 5 is installed" dotnet --list-sdks | grep '5\.[0-9]*\.[0-9]*'
10+
check "dotnet version 5 installed" ls -l /usr/share/dotnet/sdk | grep '5\.[0-9]*\.[0-9]*'
11+
12+
13+
# Report result
14+
reportResults

0 commit comments

Comments
 (0)