Refactor Python package installer (#1437)
* Remove python-package script * Install JupyterLab with feature script * Install packages using private script * Remove duplicate install * Install Python packages from one script
This commit is contained in:
Родитель
ba0cb7a9db
Коммит
a5358ec894
|
@ -37,7 +37,7 @@ ENV SHELL=/bin/bash \
|
|||
ENV PATH="${NVM_DIR}/current/bin:${NPM_GLOBAL}/bin:${PYTHON_ROOT}/current/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:${GOROOT}/bin:${GOPATH}/bin:${PIPX_BIN_DIR}:/opt/conda/condabin:${JAVA_ROOT}/current/bin:${NODE_ROOT}/current/bin:${PHP_ROOT}/current/bin:${RUBY_ROOT}/current/bin:${MAVEN_ROOT}/current/bin:${HUGO_ROOT}/current/bin:${JUPYTERLAB_PATH}:${ORYX_PATHS}"
|
||||
|
||||
# Install needed utilities and setup non-root user. Use a separate RUN statement to add your own dependencies.
|
||||
COPY library-scripts/* setup-user.sh first-run-notice.txt /tmp/scripts/
|
||||
COPY library-scripts/* setup-user.sh setup-python-tools.sh first-run-notice.txt /tmp/scripts/
|
||||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
# Restore man command
|
||||
&& yes | unminimize 2>&1 \
|
||||
|
@ -72,17 +72,8 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
|||
RUN bash /tmp/scripts/python-debian.sh "none" "/opt/python/latest" "${PIPX_HOME}" "${USERNAME}" "true" \
|
||||
# Install JupyterLab and common machine learning packages
|
||||
&& PYTHON_BINARY="${PYTHON_ROOT}/current/bin/python" \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "jupyterlab" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "numpy" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "pandas" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "scipy" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "matplotlib" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "seaborn" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "scikit-learn" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "tensorflow" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "keras" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "torch" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/python-package-debian.sh "requests" "latest" $PYTHON_BINARY \
|
||||
&& bash /tmp/scripts/jupyterlab-debian.sh "latest" "automatic" ${PYTHON_BINARY} \
|
||||
&& bash /tmp/scripts/setup-python-tools.sh ${PYTHON_BINARY} \
|
||||
# Install rvm, rbenv, any missing base gems
|
||||
&& chown -R ${USERNAME} /opt/ruby/* \
|
||||
&& bash /tmp/scripts/ruby-debian.sh "none" "${USERNAME}" "true" "true" \
|
||||
|
|
|
@ -13,6 +13,7 @@ set -e
|
|||
|
||||
VERSION=${1:-"latest"}
|
||||
USERNAME=${2:-"automatic"}
|
||||
PYTHON=${3:-"python"}
|
||||
|
||||
# If in automatic mode, determine if a user already exists, if not use vscode
|
||||
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
|
||||
|
@ -33,9 +34,8 @@ elif [ "${USERNAME}" = "none" ]; then
|
|||
USER_GID=0
|
||||
fi
|
||||
|
||||
# Use sudo to run as non-root user is not already running
|
||||
sudoUserIf()
|
||||
{
|
||||
# Make sure we run the command as non-root user
|
||||
sudoUserIf() {
|
||||
if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then
|
||||
sudo -u ${USERNAME} "$@"
|
||||
else
|
||||
|
@ -43,18 +43,16 @@ sudoUserIf()
|
|||
fi
|
||||
}
|
||||
|
||||
# If we don't yet have Python, install it now.
|
||||
if ! python --version > /dev/null ; then
|
||||
# Make sure that Python is available
|
||||
if ! ${PYTHON} --version > /dev/null ; then
|
||||
echo "You need to install Python before installing JupyterLab."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If we don't already have JupyterLab installed, install it now.
|
||||
if ! jupyter-lab --version > /dev/null ; then
|
||||
echo "Installing JupyterLab..."
|
||||
if [ "${VERSION}" = "latest" ]; then
|
||||
sudoUserIf pip install jupyterlab
|
||||
else
|
||||
sudoUserIf pip install jupyterlab=="${VERSION}" --no-cache-dir
|
||||
fi
|
||||
# pip skips installation if JupyterLab is already installed
|
||||
echo "Installing JupyterLab..."
|
||||
if [ "${VERSION}" = "latest" ]; then
|
||||
sudoUserIf ${PYTHON} -m pip install jupyterlab --no-cache-dir
|
||||
else
|
||||
sudoUserIf ${PYTHON} -m pip install jupyterlab=="${VERSION}" --no-cache-dir
|
||||
fi
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#-------------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
||||
#-------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/python-package-debian.md
|
||||
# Maintainer: The VS Code and Codespaces Teams
|
||||
#
|
||||
# Syntax: ./python-package-debian.sh
|
||||
|
||||
set -e
|
||||
|
||||
PACKAGE=${1:-""}
|
||||
VERSION=${2:-"latest"}
|
||||
PYTHON=${3:-"python"}
|
||||
USERNAME=${4-"automatic"}
|
||||
|
||||
# If in automatic mode, determine if a user already exists, if not use vscode
|
||||
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
|
||||
USERNAME=""
|
||||
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
|
||||
for CURRENT_USER in ${POSSIBLE_USERS[@]}; do
|
||||
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
|
||||
USERNAME=${CURRENT_USER}
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "${USERNAME}" = "" ]; then
|
||||
USERNAME=vscode
|
||||
fi
|
||||
elif [ "${USERNAME}" = "none" ]; then
|
||||
USERNAME=root
|
||||
USER_UID=0
|
||||
USER_GID=0
|
||||
fi
|
||||
|
||||
# Use sudo to run as non-root user is not already running
|
||||
sudoUserIf()
|
||||
{
|
||||
if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then
|
||||
sudo -u ${USERNAME} "$@"
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Make sure that Python is installed correctly
|
||||
if ! ${PYTHON} --version > /dev/null ; then
|
||||
echo "Python command not found: ${PYTHON}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# pip skips installation when a requirement is already satisfied
|
||||
if [ ${VERSION} = "latest" ]; then
|
||||
sudoUserIf ${PYTHON} -m pip install ${PACKAGE} --no-cache-dir
|
||||
else
|
||||
sudoUserIf ${PYTHON} -m pip install ${PACKAGE}==${VERSION} --no-cache-dir
|
||||
fi
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
PYTHON=${1:-"python"}
|
||||
USERNAME=${2-"automatic"}
|
||||
|
||||
# Make sure we run the command as non-root user
|
||||
sudoUserIf() {
|
||||
if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then
|
||||
sudo -u ${USERNAME} "$@"
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
installPythonPackage() {
|
||||
PACKAGE=${1:-""}
|
||||
VERSION=${2:-"latest"}
|
||||
|
||||
# pip skips installation if the package is already installed
|
||||
echo "Installing $PACKAGE..."
|
||||
if [ "${VERSION}" = "latest" ]; then
|
||||
sudoUserIf ${PYTHON} -m pip install ${PACKAGE} --no-cache-dir
|
||||
else
|
||||
sudoUserIf ${PYTHON} -m pip install ${PACKAGE}=="${VERSION}" --no-cache-dir
|
||||
fi
|
||||
}
|
||||
|
||||
# If in automatic mode, determine if a user already exists, if not use vscode
|
||||
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
|
||||
USERNAME=""
|
||||
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
|
||||
for CURRENT_USER in ${POSSIBLE_USERS[@]}; do
|
||||
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
|
||||
USERNAME=${CURRENT_USER}
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "${USERNAME}" = "" ]; then
|
||||
USERNAME=vscode
|
||||
fi
|
||||
elif [ "${USERNAME}" = "none" ]; then
|
||||
USERNAME=root
|
||||
USER_UID=0
|
||||
USER_GID=0
|
||||
fi
|
||||
|
||||
# Make sure that Python is available
|
||||
if ! ${PYTHON} --version > /dev/null ; then
|
||||
echo "You need to install Python before installing packages"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
installPythonPackage "numpy" "latest"
|
||||
installPythonPackage "pandas" "latest"
|
||||
installPythonPackage "scipy" "latest"
|
||||
installPythonPackage "matplotlib" "latest"
|
||||
installPythonPackage "seaborn" "latest"
|
||||
installPythonPackage "scikit-learn" "latest"
|
||||
installPythonPackage "tensorflow" "latest"
|
||||
installPythonPackage "keras" "latest"
|
||||
installPythonPackage "torch" "latest"
|
||||
installPythonPackage "requests" "latest"
|
|
@ -35,7 +35,6 @@ Some scripts have special installation instructions (like `desktop-lite-debian.s
|
|||
| [Node.js Install Script](docs/node.md) | `node-debian.sh` | VS Code and GitHub Codespaces teams|
|
||||
| [PowerShell Install Script](docs/powershell.md) | `powershell-debian.sh` | VS Code and GitHub Codespaces teams|
|
||||
| [Python Install Script](docs/python.md) | `python-debian.sh` | VS Code and GitHub Codespaces teams|
|
||||
| [Python Package Install Script](docs/python-package.md) | `python-package-debian.sh` | VS Code and GitHub Codespaces teams|
|
||||
| [Ruby Install Script](docs/ruby.md) | `ruby-debian.sh` | VS Code and GitHub Codespaces teams|
|
||||
| [Rust (rustlang) Install Script](docs/rust.md) | `rust-debian.sh` | VS Code and GitHub Codespaces teams|
|
||||
| [SSH Server Install Script](docs/sshd.md) | `sshd-debian.sh` | VS Code and GitHub Codespaces teams|
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
# Python Package Install Script
|
||||
|
||||
*Installs a Python package.*
|
||||
|
||||
**Script status**: Stable
|
||||
|
||||
**OS support**: Debian 9+, Ubuntu 18.04+, and downstream distros.
|
||||
|
||||
**Maintainer**: GitHub Codespaces team
|
||||
|
||||
## Syntax
|
||||
|
||||
```text
|
||||
./python-package-debian.sh PACKAGE [VERSION] [PYTHON_BINARY] [USERNAME]
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Script use
|
||||
|
||||
1. Add [`python-package-debian.sh`](../python-package-debian.sh) to `.devcontainer/library-scripts`
|
||||
|
||||
2. Add the following to your `.devcontainer/Dockerfile`:
|
||||
|
||||
```Dockerfile
|
||||
COPY library-scripts/python-package-debian.sh /tmp/library-scripts/
|
||||
RUN bash /tmp/library-scripts/python-package-debian.sh PACKAGE
|
||||
```
|
||||
|
||||
That's it!
|
|
@ -13,6 +13,7 @@ set -e
|
|||
|
||||
VERSION=${1:-"latest"}
|
||||
USERNAME=${2:-"automatic"}
|
||||
PYTHON=${3:-"python"}
|
||||
|
||||
# If in automatic mode, determine if a user already exists, if not use vscode
|
||||
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
|
||||
|
@ -33,9 +34,8 @@ elif [ "${USERNAME}" = "none" ]; then
|
|||
USER_GID=0
|
||||
fi
|
||||
|
||||
# Use sudo to run as non-root user is not already running
|
||||
sudoUserIf()
|
||||
{
|
||||
# Make sure we run the command as non-root user
|
||||
sudoUserIf() {
|
||||
if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then
|
||||
sudo -u ${USERNAME} "$@"
|
||||
else
|
||||
|
@ -43,18 +43,16 @@ sudoUserIf()
|
|||
fi
|
||||
}
|
||||
|
||||
# If we don't yet have Python, install it now.
|
||||
if ! python --version > /dev/null ; then
|
||||
# Make sure that Python is available
|
||||
if ! ${PYTHON} --version > /dev/null ; then
|
||||
echo "You need to install Python before installing JupyterLab."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If we don't already have JupyterLab installed, install it now.
|
||||
if ! jupyter-lab --version > /dev/null ; then
|
||||
echo "Installing JupyterLab..."
|
||||
if [ "${VERSION}" = "latest" ]; then
|
||||
sudoUserIf pip install jupyterlab
|
||||
else
|
||||
sudoUserIf pip install jupyterlab=="${VERSION}" --no-cache-dir
|
||||
fi
|
||||
# pip skips installation if JupyterLab is already installed
|
||||
echo "Installing JupyterLab..."
|
||||
if [ "${VERSION}" = "latest" ]; then
|
||||
sudoUserIf ${PYTHON} -m pip install jupyterlab --no-cache-dir
|
||||
else
|
||||
sudoUserIf ${PYTHON} -m pip install jupyterlab=="${VERSION}" --no-cache-dir
|
||||
fi
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#-------------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
||||
#-------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/python-package-debian.md
|
||||
# Maintainer: The VS Code and Codespaces Teams
|
||||
#
|
||||
# Syntax: ./python-package-debian.sh
|
||||
|
||||
set -e
|
||||
|
||||
PACKAGE=${1:-""}
|
||||
VERSION=${2:-"latest"}
|
||||
PYTHON=${3:-"python"}
|
||||
USERNAME=${4-"automatic"}
|
||||
|
||||
# If in automatic mode, determine if a user already exists, if not use vscode
|
||||
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
|
||||
USERNAME=""
|
||||
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
|
||||
for CURRENT_USER in ${POSSIBLE_USERS[@]}; do
|
||||
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
|
||||
USERNAME=${CURRENT_USER}
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "${USERNAME}" = "" ]; then
|
||||
USERNAME=vscode
|
||||
fi
|
||||
elif [ "${USERNAME}" = "none" ]; then
|
||||
USERNAME=root
|
||||
USER_UID=0
|
||||
USER_GID=0
|
||||
fi
|
||||
|
||||
# Use sudo to run as non-root user is not already running
|
||||
sudoUserIf()
|
||||
{
|
||||
if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then
|
||||
sudo -u ${USERNAME} "$@"
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Make sure that Python is installed correctly
|
||||
if ! ${PYTHON} --version > /dev/null ; then
|
||||
echo "Python command not found: ${PYTHON}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# pip skips installation when a requirement is already satisfied
|
||||
if [ ${VERSION} = "latest" ]; then
|
||||
sudoUserIf ${PYTHON} -m pip install ${PACKAGE} --no-cache-dir
|
||||
else
|
||||
sudoUserIf ${PYTHON} -m pip install ${PACKAGE}==${VERSION} --no-cache-dir
|
||||
fi
|
Загрузка…
Ссылка в новой задаче