From d38f1ff2741aab922e8fc6fc2c2128d40c08ab13 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Thu, 17 Nov 2022 17:02:07 +0000 Subject: [PATCH 1/6] Oryx: Install dotnet 3.1 runtime --- src/oryx/devcontainer-feature.json | 2 +- src/oryx/install.sh | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/oryx/devcontainer-feature.json b/src/oryx/devcontainer-feature.json index 2596bd9f9..5c643445b 100644 --- a/src/oryx/devcontainer-feature.json +++ b/src/oryx/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "oryx", - "version": "1.0.11", + "version": "1.0.12", "name": "Oryx", "description": "Installs the oryx CLI", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/oryx", diff --git a/src/oryx/install.sh b/src/oryx/install.sh index 054983adb..23f41aa35 100755 --- a/src/oryx/install.sh +++ b/src/oryx/install.sh @@ -139,6 +139,10 @@ if ! dotnet --version > /dev/null ; then fi fi +# Additionally install dotnet3.1 runtime as the oryx tool is made with it +apt_get_update +apt-get -yq install dotnet-runtime-3.1 + BUILD_SCRIPT_GENERATOR=/usr/local/buildscriptgen ORYX=/usr/local/oryx GIT_ORYX=/opt/tmp/oryx-repo From 52d64104995682a5da079e5a58df0818dd9b58e4 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Thu, 17 Nov 2022 17:26:49 +0000 Subject: [PATCH 2/6] fix tests --- src/oryx/install.sh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/oryx/install.sh b/src/oryx/install.sh index 23f41aa35..050626980 100755 --- a/src/oryx/install.sh +++ b/src/oryx/install.sh @@ -71,24 +71,20 @@ check_packages() { } install_dotnet_using_apt() { - echo "Attempting to auto-install dotnet..." + local dotnet_installation_package="$1" + echo "Attempting to install dotnet ${dotnet_installation_package}..." install_from_microsoft_feed=false apt_get_update - DOTNET_INSTALLATION_PACKAGE="dotnet6" - apt-get -yq install $DOTNET_INSTALLATION_PACKAGE || install_from_microsoft_feed="true" + apt-get -yq install $dotnet_installation_package || install_from_microsoft_feed="true" if [ "${install_from_microsoft_feed}" = "true" ]; then echo "Attempting install from microsoft apt feed..." 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 apt-get update -y - DOTNET_INSTALLATION_PACKAGE="dotnet-sdk-6.0" - DOTNET_SKIP_FIRST_TIME_EXPERIENCE="true" apt-get install -yq $DOTNET_INSTALLATION_PACKAGE + DOTNET_SKIP_FIRST_TIME_EXPERIENCE="true" apt-get install -yq $dotnet_installation_package fi - echo -e "Finished attempt to install dotnet. Sdks installed:\n" - dotnet --list-sdks - # Clean up apt-get clean -y rm -rf /var/lib/apt/lists/* @@ -131,18 +127,18 @@ DOTNET_INSTALLATION_PACKAGE="" # Install dotnet unless available if ! dotnet --version > /dev/null ; then echo "'dotnet' was not detected. Attempting to install the latest version of the dotnet sdk to build oryx." - install_dotnet_using_apt + DOTNET_INSTALLATION_PACKAGE="dotnet-sdk-3.1" + install_dotnet_using_apt "${DOTNET_INSTALLATION_PACKAGE}" if ! dotnet --version > /dev/null ; then echo "(!) Please install Dotnet before installing Oryx" exit 1 fi +else + # Additionally install dotnet3.1 runtime as the oryx tool is built with it + install_dotnet_using_apt "dotnet-runtime-3.1" fi -# Additionally install dotnet3.1 runtime as the oryx tool is made with it -apt_get_update -apt-get -yq install dotnet-runtime-3.1 - BUILD_SCRIPT_GENERATOR=/usr/local/buildscriptgen ORYX=/usr/local/oryx GIT_ORYX=/opt/tmp/oryx-repo From 7686d3cafac6878ad40c11c358a231f8a5bf4b3e Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Thu, 17 Nov 2022 18:45:28 +0000 Subject: [PATCH 3/6] build with .NET 6 + add tests --- src/oryx/install.sh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/oryx/install.sh b/src/oryx/install.sh index 050626980..cf0ea14dd 100755 --- a/src/oryx/install.sh +++ b/src/oryx/install.sh @@ -71,20 +71,24 @@ check_packages() { } install_dotnet_using_apt() { - local dotnet_installation_package="$1" - echo "Attempting to install dotnet ${dotnet_installation_package}..." + echo "Attempting to auto-install dotnet..." install_from_microsoft_feed=false apt_get_update - apt-get -yq install $dotnet_installation_package || install_from_microsoft_feed="true" + DOTNET_INSTALLATION_PACKAGE="dotnet6" + apt-get -yq install $DOTNET_INSTALLATION_PACKAGE || install_from_microsoft_feed="true" if [ "${install_from_microsoft_feed}" = "true" ]; then echo "Attempting install from microsoft apt feed..." 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 apt-get update -y - DOTNET_SKIP_FIRST_TIME_EXPERIENCE="true" apt-get install -yq $dotnet_installation_package + DOTNET_INSTALLATION_PACKAGE="dotnet-sdk-6.0" + DOTNET_SKIP_FIRST_TIME_EXPERIENCE="true" apt-get install -yq $DOTNET_INSTALLATION_PACKAGE fi + echo -e "Finished attempt to install dotnet. Sdks installed:\n" + dotnet --list-sdks + # Clean up apt-get clean -y rm -rf /var/lib/apt/lists/* @@ -123,20 +127,21 @@ usermod -a -G oryx "${USERNAME}" # Required to decide if we want to clean up dotnet later. DOTNET_INSTALLATION_PACKAGE="" +DOTNET="" -# Install dotnet unless available -if ! dotnet --version > /dev/null ; then - echo "'dotnet' was not detected. Attempting to install the latest version of the dotnet sdk to build oryx." - DOTNET_INSTALLATION_PACKAGE="dotnet-sdk-3.1" - install_dotnet_using_apt "${DOTNET_INSTALLATION_PACKAGE}" +# Oryx needs to be built with .NET 6 +if type dotnet > /dev/null 2>&1 && [[ "$(dotnet --version)" != *"6"* ]] ; then + echo "'dotnet 6' was not detected. Attempting to install the latest version of the dotnet sdk to build oryx." + install_dotnet_using_apt if ! dotnet --version > /dev/null ; then echo "(!) Please install Dotnet before installing Oryx" exit 1 fi + + DOTNET="/usr/bin/dotnet" else - # Additionally install dotnet3.1 runtime as the oryx tool is built with it - install_dotnet_using_apt "dotnet-runtime-3.1" + DOTNET=$(which dotnet) fi BUILD_SCRIPT_GENERATOR=/usr/local/buildscriptgen @@ -150,8 +155,8 @@ git clone --depth=1 https://github.com/microsoft/Oryx $GIT_ORYX $GIT_ORYX/build/buildSln.sh -dotnet publish -property:ValidateExecutableReferencesMatchSelfContained=false -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildScriptGeneratorCli/BuildScriptGeneratorCli.csproj -dotnet publish -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildServer/BuildServer.csproj +${DOTNET} publish -property:ValidateExecutableReferencesMatchSelfContained=false -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildScriptGeneratorCli/BuildScriptGeneratorCli.csproj +${DOTNET} publish -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildServer/BuildServer.csproj chmod a+x ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript From 4ed560f743d7d7fb62cbce9cdcb87dbcab1ca573 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Thu, 17 Nov 2022 18:45:48 +0000 Subject: [PATCH 4/6] add tests --- src/oryx/install.sh | 2 +- src/python/devcontainer-feature.json | 2 +- src/python/install.sh | 2 +- test/oryx/sample-python/requirements.txt | 2 ++ test/oryx/sample-python/src/solve.py | 12 +++++++++ test/oryx/scenarios.json | 15 +++++++++++ test/oryx/test_python_project.sh | 32 ++++++++++++++++++++++++ 7 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 test/oryx/sample-python/requirements.txt create mode 100644 test/oryx/sample-python/src/solve.py create mode 100644 test/oryx/test_python_project.sh diff --git a/src/oryx/install.sh b/src/oryx/install.sh index cf0ea14dd..0d196f2cd 100755 --- a/src/oryx/install.sh +++ b/src/oryx/install.sh @@ -118,7 +118,7 @@ export DEBIAN_FRONTEND=noninteractive # Install dependencies -check_packages git sudo curl ca-certificates apt-transport-https gnupg2 dirmngr libc-bin +check_packages git sudo curl ca-certificates apt-transport-https gnupg2 dirmngr libc-bin moreutils if ! cat /etc/group | grep -e "^oryx:" > /dev/null 2>&1; then groupadd -r oryx diff --git a/src/python/devcontainer-feature.json b/src/python/devcontainer-feature.json index fbbf62c60..b96511b9f 100644 --- a/src/python/devcontainer-feature.json +++ b/src/python/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "python", - "version": "1.0.14", + "version": "1.0.15", "name": "Python", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/python", "description": "Installs the provided version of Python, as well as PIPX, and other common Python utilities. JupyterLab is conditionally installed with the python feature. Note: May require source code compilation.", diff --git a/src/python/install.sh b/src/python/install.sh index 79ab7de1c..d823cc99e 100755 --- a/src/python/install.sh +++ b/src/python/install.sh @@ -17,7 +17,7 @@ export PIPX_HOME=${PIPX_HOME:-"/usr/local/py-utils"} USERNAME=${USERNAME:-"automatic"} UPDATE_RC=${UPDATE_RC:-"true"} -USE_ORYX_IF_AVAILABLE=${USE_ORYX_IF_AVAILABLE:-"true"} +USE_ORYX_IF_AVAILABLE=${USEORYXIFAVAILABLE:-"true"} INSTALL_JUPYTERLAB=${INSTALLJUPYTERLAB:-"false"} CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN=${CONFIGUREJUPYTERLABALLOWORIGIN:-""} diff --git a/test/oryx/sample-python/requirements.txt b/test/oryx/sample-python/requirements.txt new file mode 100644 index 000000000..c8a04f68a --- /dev/null +++ b/test/oryx/sample-python/requirements.txt @@ -0,0 +1,2 @@ +mpmath==1.2.1 +sympy==1.11.1 diff --git a/test/oryx/sample-python/src/solve.py b/test/oryx/sample-python/src/solve.py new file mode 100644 index 000000000..141a99646 --- /dev/null +++ b/test/oryx/sample-python/src/solve.py @@ -0,0 +1,12 @@ +from sympy import Symbol, Eq, solve + +x = Symbol("x") +y = Symbol("y") + +equation_1 = Eq((x + y), 2) +equation_2 = Eq((x - y), 4) +print("Equation 1:", equation_1) +print("Equation 2:", equation_2) + +solution = solve((equation_1, equation_2), (x, y)) +print("Solution:", solution) diff --git a/test/oryx/scenarios.json b/test/oryx/scenarios.json index 4b9fa90e9..bbfc277a9 100644 --- a/test/oryx/scenarios.json +++ b/test/oryx/scenarios.json @@ -8,5 +8,20 @@ }, "oryx": {} } + }, + "test_python_project": { + "image": "ubuntu:focal", + "features": { + "python": { + "version": "3.10.4", + "additionalVersions": "3.9.7", + "useOryxIfAvailable": "false" + }, + "dotnet": { + "version": "7", + "installUsingApt": "false" + }, + "oryx": {} + } } } \ No newline at end of file diff --git a/test/oryx/test_python_project.sh b/test/oryx/test_python_project.sh new file mode 100644 index 000000000..a0d5eef08 --- /dev/null +++ b/test/oryx/test_python_project.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +cd sample-python + +# Replicates Oryx's behavior for universal image +DEBIAN_FLAVOR="focal-scm" +mkdir -p /opt/oryx && echo "vso-focal" > /opt/oryx/.imagetype +echo "DEBIAN|${DEBIAN_FLAVOR}" | tr '[a-z]' '[A-Z]' > /opt/oryx/.ostype + +ln -snf /usr/local/oryx/* /opt/oryx + +PYTHON_PATH="/home/codespace/.python/current" +mkdir -p /home/codespace/.python +ln -snf /usr/local/python/current $PYTHON_PATH +ln -snf /usr/local/python /opt/python + +export PATH="/home/codespace/.python/current/bin:${PATH}" +which python + +pythonVersion=$(python -V 2>&1 | grep -Po '(?<=Python )(.+)') +pythonSite=`python -m site --user-site` +check "oryx-build-python" oryx build --property python_version="${pythonVersion}" --property packagedir="${pythonSite}" ./ +check "oryx-build-python-installed" python3 -m pip list | grep mpmath +check "oryx-build-python-result" python3 ./src/solve.py + +# Report result +reportResults From a0e734345f69d75cb83d9c8d7760a342510449e2 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Thu, 17 Nov 2022 19:01:08 +0000 Subject: [PATCH 5/6] fix tests --- src/oryx/install.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/oryx/install.sh b/src/oryx/install.sh index 0d196f2cd..d14eacb2d 100755 --- a/src/oryx/install.sh +++ b/src/oryx/install.sh @@ -116,7 +116,6 @@ echo "Installing Oryx..." # Ensure apt is in non-interactive to avoid prompts export DEBIAN_FRONTEND=noninteractive - # Install dependencies check_packages git sudo curl ca-certificates apt-transport-https gnupg2 dirmngr libc-bin moreutils @@ -127,11 +126,15 @@ usermod -a -G oryx "${USERNAME}" # Required to decide if we want to clean up dotnet later. DOTNET_INSTALLATION_PACKAGE="" -DOTNET="" +DOTNET_BINARY="" + +if dotnet --version > /dev/null ; then + DOTNET_BINARY=$(which dotnet) +fi # Oryx needs to be built with .NET 6 -if type dotnet > /dev/null 2>&1 && [[ "$(dotnet --version)" != *"6"* ]] ; then - echo "'dotnet 6' was not detected. Attempting to install the latest version of the dotnet sdk to build oryx." +if [["${DOTNET_BINARY}" = "" ]] || [[ "$(dotnet --version)" != *"6"* ]] ; then + echo "'dotnet 6' was not detected. Attempting to install .NET 6 to build oryx." install_dotnet_using_apt if ! dotnet --version > /dev/null ; then @@ -139,9 +142,7 @@ if type dotnet > /dev/null 2>&1 && [[ "$(dotnet --version)" != *"6"* ]] ; then exit 1 fi - DOTNET="/usr/bin/dotnet" -else - DOTNET=$(which dotnet) + DOTNET_BINARY="/usr/bin/dotnet" fi BUILD_SCRIPT_GENERATOR=/usr/local/buildscriptgen @@ -155,8 +156,8 @@ git clone --depth=1 https://github.com/microsoft/Oryx $GIT_ORYX $GIT_ORYX/build/buildSln.sh -${DOTNET} publish -property:ValidateExecutableReferencesMatchSelfContained=false -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildScriptGeneratorCli/BuildScriptGeneratorCli.csproj -${DOTNET} publish -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildServer/BuildServer.csproj +${DOTNET_BINARY} publish -property:ValidateExecutableReferencesMatchSelfContained=false -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildScriptGeneratorCli/BuildScriptGeneratorCli.csproj +${DOTNET_BINARY} publish -r linux-x64 -o ${BUILD_SCRIPT_GENERATOR} -c Release $GIT_ORYX/src/BuildServer/BuildServer.csproj chmod a+x ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript From 264e7c26259bcc78d9bd9ea3edce19486fc7ba4b Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Thu, 17 Nov 2022 19:05:30 +0000 Subject: [PATCH 6/6] shellcheck: nit --- src/oryx/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oryx/install.sh b/src/oryx/install.sh index d14eacb2d..aa4af2c8c 100755 --- a/src/oryx/install.sh +++ b/src/oryx/install.sh @@ -133,7 +133,7 @@ if dotnet --version > /dev/null ; then fi # Oryx needs to be built with .NET 6 -if [["${DOTNET_BINARY}" = "" ]] || [[ "$(dotnet --version)" != *"6"* ]] ; then +if [[ "${DOTNET_BINARY}" = "" ]] || [[ "$(dotnet --version)" != *"6"* ]] ; then echo "'dotnet 6' was not detected. Attempting to install .NET 6 to build oryx." install_dotnet_using_apt