Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit d555ec8

Browse files
authored
Add JupyterLab as a feature (#1335)
* Add JupyterLab as a feature If Python is not installed, error out and tell the user that it's missing. * Use --no-cache-dir when installing jupyterlab with pip. * Updates to JupyterLab feature. * Rename JUPYTER_LAB_VERSION to just VERSION. * Only install JupyterLab if it's not yet installed. * Update README * Add ms-toolsai.jupyter extension. * [python-3-anaconda] Copy all library scripts. * Install JupyterLab as non-root user. * [codespaces] Don't install JupyterLab with pip, use the feature instead. * Add .local/bin to PATH so smoke test will find jupyter-lab.
1 parent 73ebc9d commit d555ec8

File tree

8 files changed

+210
-3
lines changed

8 files changed

+210
-3
lines changed

containers/codespaces-linux/.devcontainer/base.Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ ENV SHELL=/bin/bash \
3333
CARGO_HOME="/usr/local/cargo" \
3434
RUSTUP_HOME="/usr/local/rustup" \
3535
SDKMAN_DIR="/usr/local/sdkman" \
36+
JUPYTERLAB_PATH="${HOMEDIR}/.local/bin" \
3637
DOCKER_BUILDKIT=1
3738

38-
ENV PATH="${NVM_DIR}/current/bin:${NPM_GLOBAL}/bin:${ORIGINAL_PATH}:${DOTNET_ROOT}:${DOTNET_ROOT}/tools:${SDKMAN_DIR}/bin:${SDKMAN_DIR}/candidates/gradle/current/bin:${SDKMAN_DIR}/candidates/java/current/bin:/opt/maven/lts:${CARGO_HOME}/bin:${GOROOT}/bin:${GOPATH}/bin:${PIPX_BIN_DIR}:/opt/conda/condabin:${JAVA_ROOT}/current/bin:${NODE_ROOT}/current/bin:${PHP_ROOT}/current/bin:${PYTHON_ROOT}/current/bin:${RUBY_ROOT}/current/bin:${MAVEN_ROOT}/current/bin:${HUGO_ROOT}/current/bin:${ORYX_PATHS}"
39+
ENV PATH="${NVM_DIR}/current/bin:${NPM_GLOBAL}/bin:${ORIGINAL_PATH}:${DOTNET_ROOT}:${DOTNET_ROOT}/tools:${SDKMAN_DIR}/bin:${SDKMAN_DIR}/candidates/gradle/current/bin:${SDKMAN_DIR}/candidates/java/current/bin:/opt/maven/lts:${CARGO_HOME}/bin:${GOROOT}/bin:${GOPATH}/bin:${PIPX_BIN_DIR}:/opt/conda/condabin:${JAVA_ROOT}/current/bin:${NODE_ROOT}/current/bin:${PHP_ROOT}/current/bin:${PYTHON_ROOT}/current/bin:${RUBY_ROOT}/current/bin:${MAVEN_ROOT}/current/bin:${HUGO_ROOT}/current/bin:${JUPYTERLAB_PATH}:${ORYX_PATHS}"
3940

4041
# Install needed utilities and setup non-root user. Use a separate RUN statement to add your own dependencies.
4142
COPY library-scripts/* setup-user.sh first-run-notice.txt /tmp/scripts/
@@ -72,12 +73,12 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
7273

7374
# Install Python, PHP, Ruby utilities, and JupyterLab
7475
RUN bash /tmp/scripts/python-debian.sh "none" "/opt/python/latest" "${PIPX_HOME}" "${USERNAME}" "true" \
76+
&& bash /tmp/scripts/jupyterlab-debian.sh \
7577
# Install rvm, rbenv, any missing base gems
7678
&& chown -R ${USERNAME} /opt/ruby/* \
7779
&& bash /tmp/scripts/ruby-debian.sh "none" "${USERNAME}" "true" "true" \
7880
# Link composer
7981
&& ln -s $(which composer.phar) /usr/local/bin/composer \
80-
&& pip install jupyterlab \
8182
&& apt-get clean -y
8283

8384
# Install PowerShell
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
#-------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+
#-------------------------------------------------------------------------------------------------------------
6+
#
7+
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/jupyterlab.md
8+
# Maintainer: The VS Code and Codespaces Teams
9+
#
10+
# Syntax: ./jupyter-debian.sh
11+
12+
set -e
13+
14+
VERSION=${1:-"latest"}
15+
USERNAME=${2:-"automatic"}
16+
17+
# If in automatic mode, determine if a user already exists, if not use vscode
18+
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
19+
USERNAME=""
20+
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
21+
for CURRENT_USER in ${POSSIBLE_USERS[@]}; do
22+
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
23+
USERNAME=${CURRENT_USER}
24+
break
25+
fi
26+
done
27+
if [ "${USERNAME}" = "" ]; then
28+
USERNAME=vscode
29+
fi
30+
elif [ "${USERNAME}" = "none" ]; then
31+
USERNAME=root
32+
USER_UID=0
33+
USER_GID=0
34+
fi
35+
36+
# Use sudo to run as non-root user is not already running
37+
sudoUserIf()
38+
{
39+
if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then
40+
sudo -u ${USERNAME} "$@"
41+
else
42+
"$@"
43+
fi
44+
}
45+
46+
# If we don't yet have Python, install it now.
47+
if ! python --version > /dev/null ; then
48+
echo "You need to install Python before installing JupyterLab."
49+
exit 1
50+
fi
51+
52+
# If we don't already have JupyterLab installed, install it now.
53+
if ! jupyter-lab --version > /dev/null ; then
54+
echo "Installing JupyterLab..."
55+
if [ "${VERSION}" = "latest" ]; then
56+
sudoUserIf pip install jupyterlab
57+
else
58+
sudoUserIf pip install jupyterlab=="${VERSION}" --no-cache-dir
59+
fi
60+
fi

containers/python-3-anaconda/.devcontainer/base.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/base:0-bullseye
1414
COPY --from=upstream /opt /opt/
1515

1616
# Copy library scripts to execute
17-
COPY .devcontainer/library-scripts/node-debian.sh .devcontainer/add-notice.sh .devcontainer/library-scripts/*.env /tmp/library-scripts/
17+
COPY .devcontainer/library-scripts/*.sh .devcontainer/add-notice.sh .devcontainer/library-scripts/*.env /tmp/library-scripts/
1818

1919
# Setup conda to mirror contents from https://github.com/ContinuumIO/docker-images/blob/master/anaconda3/debian/Dockerfile
2020
ENV LANG=C.UTF-8 \

script-library/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Some scripts have special installation instructions (like `desktop-lite-debian.s
2929
| [Gradle Install Script](docs/gradle.md) | `gradle-debian.sh` | VS Code and GitHub Codespaces teams|
3030
| [Homebrew Install Script](docs/homebrew.md) | `homebrew-debian.sh` (Community) | [@andreiborisov](https://github.com/andreiborisov) |
3131
| [Java Install Script](docs/java.md) | `java-debian.sh` | VS Code and GitHub Codespaces teams|
32+
| [JupyterLab Install Script](docs/jupyterlab.md) | `jupyterlab-debian.sh` | VS Code and GitHub Codespaces teams|
3233
| [Kubectl and Helm Install Script](docs/kubectl-helm.md) | `kubectl-helm-debian.sh` | VS Code and GitHub Codespaces teams|
3334
| [Maven Install Script](docs/maven.md) | `maven-debian.sh` | VS Code and GitHub Codespaces teams|
3435
| [Node.js Install Script](docs/node.md) | `node-debian.sh` | VS Code and GitHub Codespaces teams|

script-library/container-features/src/devcontainer-features.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,33 @@
11701170
"ruby-rails-postgres",
11711171
"python-3-postgres"
11721172
]
1173+
},
1174+
{
1175+
"id": "jupyterlab",
1176+
"name": "Jupyter Lab",
1177+
"documentationURL": "https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/jupyterlab.md",
1178+
"options": {
1179+
"version": {
1180+
"type": "string",
1181+
"proposals": ["latest", "3.6.2"],
1182+
"default": "latest",
1183+
"description": "Select or enter a jupyterlab version."
1184+
}
1185+
},
1186+
"buildArg": "_VSC_INSTALL_JUPYTERLAB",
1187+
"extensions": [
1188+
"ms-python.python",
1189+
"ms-python.vscode-pylance",
1190+
"ms-toolsai.jupyter"
1191+
],
1192+
"include": [
1193+
"codespaces-linux",
1194+
"python-3",
1195+
"python-3-anaconda",
1196+
"python-3-miniconda",
1197+
"ubuntu",
1198+
"debian"
1199+
]
11731200
}
11741201
]
11751202
}

script-library/container-features/src/feature-scripts.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ _VSC_INSTALL_RUST="rust-debian.sh /usr/local/cargo /usr/local/rustup automatic t
2121
_VSC_INSTALL_POWERSHELL="powershell-debian.sh ${_BUILD_ARG_POWERSHELL_VERSION:-latest}"
2222
_VSC_INSTALL_DESKTOP_LITE="desktop-lite-debian.sh automatic ${_BUILD_ARG_DESKTOP_LITE_PASSWORD:-vscode} true ${_BUILD_ARG_DESKTOP_LITE_VNCPORT:-5901} ${_BUILD_ARG_DESKTOP_LITE_WEBPORT:-6080}"
2323
_VSC_INSTALL_DOTNET="dotnet-debian.sh ${_BUILD_ARG_DOTNET_VERSION:-latest} ${_BUILD_ARG_DOTNET_RUNTIMEONLY:-false} automatic true /usr/local/dotnet dotnet"
24+
_VSC_INSTALL_JUPYTERLAB="jupyterlab-debian.sh ${_BUILD_ARG_JUPYTERLAB_VERSION:-latest}"

script-library/docs/jupyterlab.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# JupyterLab Install Script
2+
3+
*Installs JupyterLab.*
4+
5+
**Script status**: Stable
6+
7+
**OS support**: Debian 9+, Ubuntu 18.04+, and downstream distros.
8+
9+
**Maintainer**: GitHub Codespaces team
10+
11+
## Syntax
12+
13+
```text
14+
./jupyterlab-debian.sh
15+
```
16+
17+
Or as a feature:
18+
19+
```json
20+
"features": {
21+
"jupyterlab": {
22+
"version": "latest"
23+
}
24+
}
25+
```
26+
27+
## Usage
28+
29+
### Feature use
30+
31+
To install this feature in your primary dev container, reference it in `devcontainer.json` as follows:
32+
33+
```json
34+
"features": {
35+
"jupyterlab": {
36+
"version": "latest"
37+
}
38+
}
39+
```
40+
41+
If you have already built your development container, run the **Rebuild Container** command from the command
42+
palette (<kdb>Ctrl/Cmd</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd> or <kbd>F1</kbd>) to pick up the change.
43+
44+
You must have Python already installed in order to use this feature.
45+
46+
### Script use
47+
48+
1. Add [`jupyterlab-debian.sh`](../jupyterlab-debian.sh) to `.devcontainer/library-scripts`
49+
50+
2. Add the following to your `.devcontainer/Dockerfile`:
51+
52+
```Dockerfile
53+
COPY library-scripts/jupyterlab-debian.sh /tmp/library-scripts/
54+
RUN bash /tmp/library-scripts/jupyterlab-debian.sh
55+
```
56+
57+
That's it!
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
#-------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+
#-------------------------------------------------------------------------------------------------------------
6+
#
7+
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/jupyterlab.md
8+
# Maintainer: The VS Code and Codespaces Teams
9+
#
10+
# Syntax: ./jupyter-debian.sh
11+
12+
set -e
13+
14+
VERSION=${1:-"latest"}
15+
USERNAME=${2:-"automatic"}
16+
17+
# If in automatic mode, determine if a user already exists, if not use vscode
18+
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
19+
USERNAME=""
20+
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
21+
for CURRENT_USER in ${POSSIBLE_USERS[@]}; do
22+
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
23+
USERNAME=${CURRENT_USER}
24+
break
25+
fi
26+
done
27+
if [ "${USERNAME}" = "" ]; then
28+
USERNAME=vscode
29+
fi
30+
elif [ "${USERNAME}" = "none" ]; then
31+
USERNAME=root
32+
USER_UID=0
33+
USER_GID=0
34+
fi
35+
36+
# Use sudo to run as non-root user is not already running
37+
sudoUserIf()
38+
{
39+
if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then
40+
sudo -u ${USERNAME} "$@"
41+
else
42+
"$@"
43+
fi
44+
}
45+
46+
# If we don't yet have Python, install it now.
47+
if ! python --version > /dev/null ; then
48+
echo "You need to install Python before installing JupyterLab."
49+
exit 1
50+
fi
51+
52+
# If we don't already have JupyterLab installed, install it now.
53+
if ! jupyter-lab --version > /dev/null ; then
54+
echo "Installing JupyterLab..."
55+
if [ "${VERSION}" = "latest" ]; then
56+
sudoUserIf pip install jupyterlab
57+
else
58+
sudoUserIf pip install jupyterlab=="${VERSION}" --no-cache-dir
59+
fi
60+
fi

0 commit comments

Comments
 (0)