From 7f090b09b55bbb6cc95d9ba7dec9fa63ebb8a875 Mon Sep 17 00:00:00 2001 From: Alexander Smolyakov Date: Tue, 19 Sep 2023 15:42:07 +0400 Subject: [PATCH 1/9] [python] Updated `sudo_if` function - Remove double quotes to avoid issues with string tokenization --- src/python/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/install.sh b/src/python/install.sh index 0e2b1253c..3965eb7b7 100755 --- a/src/python/install.sh +++ b/src/python/install.sh @@ -304,7 +304,7 @@ sudo_if() { if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then su - "$USERNAME" -c "$COMMAND" else - "$COMMAND" + $COMMAND fi } From 9e62a3797a8f5eddf5c24a6b5fd30bd2c4be8c54 Mon Sep 17 00:00:00 2001 From: Alexander Smolyakov Date: Wed, 20 Sep 2023 13:04:26 +0400 Subject: [PATCH 2/9] Add test scenario --- test/python/install_jupyterlab_debian.sh | 19 +++++++++++++++++++ test/python/scenarios.json | 11 ++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/python/install_jupyterlab_debian.sh diff --git a/test/python/install_jupyterlab_debian.sh b/test/python/install_jupyterlab_debian.sh new file mode 100644 index 000000000..903e7a0b2 --- /dev/null +++ b/test/python/install_jupyterlab_debian.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Check for an installation of JupyterLab +check "version" jupyter lab --version + +# Check location of JupyterLab installation +packages="$(python3 -m pip list)" +check "location" grep jupyter <<< "$packages" + +# Check for git extension +check "jupyterlab-git" grep jupyterlab-git <<< "$packages" + +# Report result +reportResults diff --git a/test/python/scenarios.json b/test/python/scenarios.json index c3c1a828b..49832b861 100644 --- a/test/python/scenarios.json +++ b/test/python/scenarios.json @@ -53,5 +53,14 @@ "features": { "python": "3.10" } + }, + "install_jupyterlab_debian": { + "image": "debian:bullseye-slim", + "features": { + "python": { + "version": "3.11", + "installJupyterlab": true + } + } } -} \ No newline at end of file +} From 1f83ebc28c0b7966726151d8712c785c5c5f4f99 Mon Sep 17 00:00:00 2001 From: Alexander Smolyakov Date: Wed, 20 Sep 2023 18:28:13 +0400 Subject: [PATCH 3/9] Revert "Add test scenario" This reverts commit 9e62a3797a8f5eddf5c24a6b5fd30bd2c4be8c54. --- test/python/install_jupyterlab_debian.sh | 19 ------------------- test/python/scenarios.json | 11 +---------- 2 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 test/python/install_jupyterlab_debian.sh diff --git a/test/python/install_jupyterlab_debian.sh b/test/python/install_jupyterlab_debian.sh deleted file mode 100644 index 903e7a0b2..000000000 --- a/test/python/install_jupyterlab_debian.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -# Check for an installation of JupyterLab -check "version" jupyter lab --version - -# Check location of JupyterLab installation -packages="$(python3 -m pip list)" -check "location" grep jupyter <<< "$packages" - -# Check for git extension -check "jupyterlab-git" grep jupyterlab-git <<< "$packages" - -# Report result -reportResults diff --git a/test/python/scenarios.json b/test/python/scenarios.json index 49832b861..c3c1a828b 100644 --- a/test/python/scenarios.json +++ b/test/python/scenarios.json @@ -53,14 +53,5 @@ "features": { "python": "3.10" } - }, - "install_jupyterlab_debian": { - "image": "debian:bullseye-slim", - "features": { - "python": { - "version": "3.11", - "installJupyterlab": true - } - } } -} +} \ No newline at end of file From 51bec72fd3e2c89d825e831c0c12fb3325d47e12 Mon Sep 17 00:00:00 2001 From: Alexander Smolyakov Date: Fri, 22 Sep 2023 15:19:15 +0400 Subject: [PATCH 4/9] Update `jupyterlab git` package name --- test/python/install_additional_jupyterlab.sh | 2 +- test/python/install_jupyterlab.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/python/install_additional_jupyterlab.sh b/test/python/install_additional_jupyterlab.sh index a5658f0d2..58c4f7f54 100755 --- a/test/python/install_additional_jupyterlab.sh +++ b/test/python/install_additional_jupyterlab.sh @@ -17,7 +17,7 @@ packages="$(python3 -m pip list)" check "location" grep jupyter <<< "$packages" # Check for git extension -check "jupyterlab-git" grep jupyterlab-git <<< "$packages" +check "jupyterlab_git" grep jupyterlab_git <<< "$packages" # Check for correct JupyterLab configuration check "config" grep ".*.allow_origin = '*'" /home/vscode/.jupyter/jupyter_server_config.py diff --git a/test/python/install_jupyterlab.sh b/test/python/install_jupyterlab.sh index a5658f0d2..58c4f7f54 100755 --- a/test/python/install_jupyterlab.sh +++ b/test/python/install_jupyterlab.sh @@ -17,7 +17,7 @@ packages="$(python3 -m pip list)" check "location" grep jupyter <<< "$packages" # Check for git extension -check "jupyterlab-git" grep jupyterlab-git <<< "$packages" +check "jupyterlab_git" grep jupyterlab_git <<< "$packages" # Check for correct JupyterLab configuration check "config" grep ".*.allow_origin = '*'" /home/vscode/.jupyter/jupyter_server_config.py From f4ff7f9920ea62151fc90d9342e7a128042da4fd Mon Sep 17 00:00:00 2001 From: Alexander Smolyakov Date: Fri, 22 Sep 2023 16:57:39 +0400 Subject: [PATCH 5/9] Bump feature version --- src/python/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/devcontainer-feature.json b/src/python/devcontainer-feature.json index b4aa21e25..ed06a91a2 100644 --- a/src/python/devcontainer-feature.json +++ b/src/python/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "python", - "version": "1.1.0", + "version": "1.1.1", "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.", From 23814c6a599b534796b01c02a05ed4212a6f7036 Mon Sep 17 00:00:00 2001 From: Alexander Smolyakov Date: Mon, 25 Sep 2023 15:02:14 +0400 Subject: [PATCH 6/9] Test: Install jupyterlab under root user --- src/python/install.sh | 36 +++++++++++++++++++----- test/python/install_jupyterlab_debian.sh | 22 +++++++++++++++ test/python/install_jupyterlab_ubuntu.sh | 22 +++++++++++++++ test/python/scenarios.json | 22 ++++++++++++++- 4 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 test/python/install_jupyterlab_debian.sh create mode 100644 test/python/install_jupyterlab_ubuntu.sh diff --git a/src/python/install.sh b/src/python/install.sh index 3965eb7b7..c765363dd 100755 --- a/src/python/install.sh +++ b/src/python/install.sh @@ -308,21 +308,26 @@ sudo_if() { fi } +install_package() { + PACKAGE="$1" + sudo_if "${PYTHON_SRC}" -m pip install --upgrade --no-cache-dir "$PACKAGE" +} + install_user_package() { PACKAGE="$1" sudo_if "${PYTHON_SRC}" -m pip install --user --upgrade --no-cache-dir "$PACKAGE" } add_user_jupyter_config() { - CONFIG_DIR="/home/$USERNAME/.jupyter" - CONFIG_FILE="$CONFIG_DIR/jupyter_server_config.py" + CONFIG_DIR=$1 + CONFIG_FILE="$2" # Make sure the config file exists or create it with proper permissions test -d "$CONFIG_DIR" || sudo_if mkdir "$CONFIG_DIR" test -f "$CONFIG_FILE" || sudo_if touch "$CONFIG_FILE" # Don't write the same config more than once - grep -q "$1" "$CONFIG_FILE" || echo "$1" >> "$CONFIG_FILE" + grep -q "$3" "$CONFIG_FILE" || echo "$3" >> "$CONFIG_FILE" } install_python() { @@ -461,13 +466,30 @@ if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then exit 1 fi - install_user_package jupyterlab - install_user_package jupyterlab-git + if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then + install_user_package jupyterlab + install_user_package jupyterlab-git + else + install_package jupyterlab + install_package jupyterlab-git + fi # Configure JupyterLab if needed if [ -n "${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}" ]; then - add_user_jupyter_config "c.ServerApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}'" - add_user_jupyter_config "c.NotebookApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}'" + # Resolve config directory and file + CONFIG_DIR="" + CONFIG_FILE="" + + if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then + CONFIG_DIR="/home/$USERNAME/.jupyter" + CONFIG_FILE="$CONFIG_DIR/jupyter_server_config.py" + else + CONFIG_DIR="/root/.jupyter" + CONFIG_FILE="$CONFIG_DIR/jupyter_server_config.py" + fi + + add_user_jupyter_config $CONFIG_DIR $CONFIG_FILE "c.ServerApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}'" + add_user_jupyter_config $CONFIG_DIR $CONFIG_FILE "c.NotebookApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}'" fi fi diff --git a/test/python/install_jupyterlab_debian.sh b/test/python/install_jupyterlab_debian.sh new file mode 100644 index 000000000..3db7fd477 --- /dev/null +++ b/test/python/install_jupyterlab_debian.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Check for an installation of JupyterLab +check "version" jupyter lab --version + +# Check location of JupyterLab installation +packages="$(python3 -m pip list)" +check "location" grep jupyter <<< "$packages" + +# Check for git extension +check "jupyterlab_git" grep jupyterlab_git <<< "$packages" + +# Check for correct JupyterLab configuration +check "config" grep ".*.allow_origin = '*'" /root/.jupyter/jupyter_server_config.py + +# Report result +reportResults diff --git a/test/python/install_jupyterlab_ubuntu.sh b/test/python/install_jupyterlab_ubuntu.sh new file mode 100644 index 000000000..3db7fd477 --- /dev/null +++ b/test/python/install_jupyterlab_ubuntu.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Check for an installation of JupyterLab +check "version" jupyter lab --version + +# Check location of JupyterLab installation +packages="$(python3 -m pip list)" +check "location" grep jupyter <<< "$packages" + +# Check for git extension +check "jupyterlab_git" grep jupyterlab_git <<< "$packages" + +# Check for correct JupyterLab configuration +check "config" grep ".*.allow_origin = '*'" /root/.jupyter/jupyter_server_config.py + +# Report result +reportResults diff --git a/test/python/scenarios.json b/test/python/scenarios.json index c3c1a828b..c3c55d52e 100644 --- a/test/python/scenarios.json +++ b/test/python/scenarios.json @@ -53,5 +53,25 @@ "features": { "python": "3.10" } + }, + "install_jupyterlab_debian": { + "image": "debian:bullseye-slim", + "features": { + "python": { + "version": "3.11", + "installJupyterlab": true, + "configureJupyterlabAllowOrigin": "*" + } + } + }, + "install_jupyterlab_ubuntu": { + "image": "ubuntu:focal", + "features": { + "python": { + "version": "3.11", + "installJupyterlab": true, + "configureJupyterlabAllowOrigin": "*" + } + } } -} \ No newline at end of file +} From bbefeb020423b2ee1a31978abca3ff8d7210afab Mon Sep 17 00:00:00 2001 From: Alexander Smolyakov Date: Mon, 25 Sep 2023 17:01:32 +0400 Subject: [PATCH 7/9] Refactor changes --- src/python/install.sh | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/python/install.sh b/src/python/install.sh index c765363dd..e0b4b3046 100755 --- a/src/python/install.sh +++ b/src/python/install.sh @@ -308,14 +308,15 @@ sudo_if() { fi } -install_package() { - PACKAGE="$1" - sudo_if "${PYTHON_SRC}" -m pip install --upgrade --no-cache-dir "$PACKAGE" -} - install_user_package() { - PACKAGE="$1" - sudo_if "${PYTHON_SRC}" -m pip install --user --upgrade --no-cache-dir "$PACKAGE" + INSTALL_UNDER_ROOT="$1" + PACKAGE="$2" + + if [ "$INSTALL_UNDER_ROOT" = true ]; then + sudo_if "${PYTHON_SRC}" -m pip install --upgrade --no-cache-dir "$PACKAGE" + else + sudo_if "${PYTHON_SRC}" -m pip install --user --upgrade --no-cache-dir "$PACKAGE" + fi } add_user_jupyter_config() { @@ -466,28 +467,24 @@ if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then exit 1 fi + INSTALL_UNDER_ROOT=true; if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then - install_user_package jupyterlab - install_user_package jupyterlab-git - else - install_package jupyterlab - install_package jupyterlab-git + INSTALL_UNDER_ROOT=false fi + install_user_package $INSTALL_UNDER_ROOT jupyterlab + install_user_package $INSTALL_UNDER_ROOT jupyterlab-git + # Configure JupyterLab if needed if [ -n "${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}" ]; then - # Resolve config directory and file - CONFIG_DIR="" - CONFIG_FILE="" - - if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then + # Resolve config directory + CONFIG_DIR="/root/.jupyter" + if [ "$INSTALL_UNDER_ROOT" = false ]; then CONFIG_DIR="/home/$USERNAME/.jupyter" - CONFIG_FILE="$CONFIG_DIR/jupyter_server_config.py" - else - CONFIG_DIR="/root/.jupyter" - CONFIG_FILE="$CONFIG_DIR/jupyter_server_config.py" fi + CONFIG_FILE="$CONFIG_DIR/jupyter_server_config.py" + add_user_jupyter_config $CONFIG_DIR $CONFIG_FILE "c.ServerApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}'" add_user_jupyter_config $CONFIG_DIR $CONFIG_FILE "c.NotebookApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}'" fi From 9decc3d96fe411b80aa433b03a04320085ad5c04 Mon Sep 17 00:00:00 2001 From: Alexander Smolyakov Date: Mon, 25 Sep 2023 17:43:09 +0400 Subject: [PATCH 8/9] Bump patch version --- src/python/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/devcontainer-feature.json b/src/python/devcontainer-feature.json index ed06a91a2..638fa6006 100644 --- a/src/python/devcontainer-feature.json +++ b/src/python/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "python", - "version": "1.1.1", + "version": "1.2.0", "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.", From b39c96402c296ff9d158f61741af84d0b07c0003 Mon Sep 17 00:00:00 2001 From: Alexander Smolyakov Date: Wed, 27 Sep 2023 13:04:23 +0400 Subject: [PATCH 9/9] Address review points --- src/python/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/install.sh b/src/python/install.sh index e0b4b3046..7be5eea8a 100755 --- a/src/python/install.sh +++ b/src/python/install.sh @@ -320,7 +320,7 @@ install_user_package() { } add_user_jupyter_config() { - CONFIG_DIR=$1 + CONFIG_DIR="$1" CONFIG_FILE="$2" # Make sure the config file exists or create it with proper permissions @@ -467,7 +467,7 @@ if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then exit 1 fi - INSTALL_UNDER_ROOT=true; + INSTALL_UNDER_ROOT=true if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then INSTALL_UNDER_ROOT=false fi