merge devgpu

This commit is contained in:
2024-01-28 19:12:10 +08:00
parent 05c8bf9cdc
commit 8ab4900e81
8 changed files with 160 additions and 108 deletions

View File

@@ -61,18 +61,6 @@ echo "1" | bash <(curl -s https://raw.githubusercontent.com/hotwa/MicroMamba_Ins
mkdir -p /root/workspace/personal /root/workspace/project
EOT
# RUN <<EOT
# #!/bin/bash
# apt install -y texlive-full
# micromamba create -n plot -c conda-forge scienceplots autopep8 python=3 ipykernel pandas numpy matplotlib scipy seaborn orange3 -y
# pip install bamboolib
# EOT
# RUN <<EOT
# #!/bin/bash
# micromamba create -n scardock -c conda-forge -c pylyzeng -c bioconda vinautil -y
# EOT
RUN <<EOT
#!/bin/bash
# 清理和减小镜像大小

View File

@@ -1,80 +1,12 @@
FROM jupyter/scipy-notebook
LABEL base_image="Ubuntu 20.04.3 LTS"
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG JUPYTERHUB_VERSION
FROM quay.io/jupyterhub/jupyterhub:$JUPYTERHUB_VERSION
ARG CREATE_USER="jovyan"
ARG CREATE_USER_PASSWD="password"
ARG ROOT_PASSWD="password"
ARG HOME="/home/${CREATE_USER}"
ARG DEBIAN_FRONTEND="noninteractive"
ENV DEBIAN_FRONTEND=${DEBIAN_FRONTEND}
USER root
RUN <<EOT
#!/bin/bash
# 更新软件源
apt-get update
# 安装时区数据包并设置时区
apt-get install -y tzdata
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
# 安装所需的软件包
apt-get install -y python3 python3-pip gcc g++ build-essential nodejs npm gdebi-core curl wget openssh-server vim lrzsz net-tools sudo git
# 创建新用户
useradd -m -s /bin/bash ${CREATE_USER}
echo "${CREATE_USER}:${CREATE_USER_PASSWD}" | chpasswd
echo "${CREATE_USER} ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers
EOT
RUN <<EOT
#!/bin/bash
# 安装 Jupyter 和相关软件
npm install -g configurable-http-proxy
python3 -m pip install jupyterhub jupyterlab notebook radian pycurl jupyter-rsession-proxy ipykernel jupyterlab-language-pack-zh-CN jupyterlab-git jupyterlab-system-monitor jupyter_nbextensions_configurator jupyter_contrib_nbextensions jupyterlab-unfold jupyterlab_widgets jupyterlab-drawio jupyterlab-spreadsheet-editor jupyterlab-cell-flash jedi-language-server jupyterlab_code_formatter jupyterlab-spellchecker jupyterlab_vim nbresuse ipydrawio jedi ipympl black isort theme-darcula ipywidgets tensorboard jupyterlab_latex jupyter_bokeh autopep8 xeus-python jupyterlab-lsp python-lsp-server nglview dockerspawner jupyterhub-nativeauthenticator lckr_jupyterlab_variableinspector
# 创建 JupyterHub 配置目录
mkdir -p /root/.jupyterhub
EOT
# jupyter-nbextension enable nglview --py --sys-prefix
# jupyter nbextension enable --py --sys-prefix widgetsnbextension
# conda install Rstudio
RUN <<EOT
#!/bin/bash
add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
apt-get update
apt-get install -y r-base
sudo wget https://download2.rstudio.org/server/focal/amd64/rstudio-server-2023.06.0-421-amd64.deb -O /tmp/rstudio-server.deb
sudo chmod +x /tmp/rstudio-server.deb
sudo gdebi -n /tmp/rstudio-server.deb
sudo rm -rf /tmp/rstudio-server.deb
EOT
RUN <<EOT
#!/bin/bash
# 安装micromamba
echo "1" | bash <(curl -s https://raw.githubusercontent.com/hotwa/MicroMamba_Installer/main/install.sh)
mkdir -p /root/workspace/personal /root/workspace/project
EOT
RUN <<EOT
#!/bin/bash
apt install -y texlive-full
micromamba create -n plot -c conda-forge scienceplots autopep8 python=3 ipykernel pandas numpy matplotlib scipy seaborn orange3 -y
pip install bamboolib
EOT
RUN <<EOT
#!/bin/bash
# 清理和减小镜像大小
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/man/?? /usr/share/man/??_*
EOT
RUN <<EOT
#!/bin/bash
micromamba create -n scardock -c conda-forge -c pylyzeng -c bioconda vinautil -y
EOT
# Install dockerspawner, nativeauthenticator
# hadolint ignore=DL3013
RUN python3 -m pip install --no-cache-dir \
dockerspawner \
jupyterhub-nativeauthenticator
CMD ["jupyterhub", "-f", "/srv/jupyterhub/jupyterhub_config.py"]

View File

@@ -64,3 +64,86 @@ docker buildx build -t hotwa/notebook:latest . -f Dockerfile
A tool for building artifacts from source code and injecting them into docker images
- [jupyter-on-openshift/jupyter-notebooks](https://github.com/jupyter-on-openshift/jupyter-notebooks) -
OpenShift compatible S2I builder for basic notebook images
## nvidia-container-toolkit add
参考了 llama [容器部署](https://hub.docker.com/r/ollama/ollama)
```shell
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey \
| sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list \
| sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' \
| sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
```
Configure Docker to use Nvidia driver
```shell
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
```
配置完成之后:
```shell
docker-compose up -d
```
在jupyterhub_config.py中添加这样jupyterhub的容器启动镜像就可以使用宿主机的显卡了
```python
# GPU 和网络配置
c.DockerSpawner.extra_host_config = {
#'network_mode': 'host',
'runtime': 'nvidia'
}
c.DockerSpawner.environment = {
'NVIDIA_DRIVER_CAPABILITIES': 'compute,utility',
'NVIDIA_VISIBLE_DEVICES': 'all'
}
```
## 清除卷
```shell
docker volume ls
docker-compose down
docker rm <container_name_or_id>
docker volume rm basic-example_jupyterhub-data
docker volume rm docker-jupyterhub_jupyterhub-data
docker volume rm jupyterhub-user-admin
```
## 构建
构建基础notebook镜像
```shell
docker buildx build -t hotwa/notebook:latest -f Dockerfile.base-notebook . --load
```
构建jupyterhub镜像
```shell
docker compose build
```
## 推送镜像至阿里云私有仓库
```shell
docker login --username=ze.ga@qq.com registry.cn-hangzhou.aliyuncs.com
# 重命名
docker tag 2ad3860183ce registry.cn-hangzhou.aliyuncs.com/hotwa/jupyterhub:latest
docker tag ddf815cbaa9b registry.cn-hangzhou.aliyuncs.com/hotwa/notebook:latest
# 推送
docker login --username=ze.ga@qq.com registry.cn-hangzhou.aliyuncs.com
docker push registry.cn-hangzhou.aliyuncs.com/hotwa/jupyterhub:latest
docker push registry.cn-hangzhou.aliyuncs.com/hotwa/notebook:latest
# 拉取
docker pull registry.cn-hangzhou.aliyuncs.com/hotwa/jupyterhub:latest
docker pull registry.cn-hangzhou.aliyuncs.com/hotwa/notebook:latest
```

View File

@@ -32,9 +32,20 @@ services:
# All containers will join this network
DOCKER_NETWORK_NAME: jupyterhub-network
# JupyterHub will spawn this Notebook image for users
DOCKER_NOTEBOOK_IMAGE: hotwa/notebook:latest # registry.cn-hangzhou.aliyuncs.com/hotwa/notebook
DOCKER_NOTEBOOK_IMAGE: hotwa/notebook:latest
# Notebook directory inside user image
DOCKER_NOTEBOOK_DIR: /home/jovyan/work
# nginx:
# image: nginx:latest
# volumes:
# - ./nginx.conf:/etc/nginx/nginx.conf:ro
# ports:
# - "18188:80"
# depends_on:
# - hub
# networks:
# - jupyterhub-network
volumes:
jupyterhub-data:
@@ -42,3 +53,5 @@ volumes:
networks:
jupyterhub-network:
name: jupyterhub-network
# use 127.0.0.1:8000 access

26
nginx.conf Normal file
View File

@@ -0,0 +1,26 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
location / {
proxy_pass http://hub:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
}

View File

@@ -97,7 +97,7 @@ echo "${CREATE_USER} ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers
echo "1" | bash <(curl -s https://raw.githubusercontent.com/hotwa/MicroMamba_Installer/main/install.sh)
# 安装 Jupyter 和相关软件
npm install -g configurable-http-proxy
python3 -m pip install --default-timeout=1000 jupyterhub jupyterlab notebook radian pycurl jupyter-rsession-proxy ipykernel jupyterlab-language-pack-zh-CN jupyterlab-git jupyterlab-system-monitor jupyter_nbextensions_configurator jupyter_contrib_nbextensions jupyterlab_widgets jupyterlab-drawio jupyterlab-spreadsheet-editor jupyterlab-cell-flash jedi-language-server jupyterlab_code_formatter jupyterlab-spellchecker jupyterlab_vim nbresuse ipydrawio jedi ipympl black isort theme-darcula ipywidgets tensorboard jupyterlab_latex jupyter_bokeh autopep8 xeus-python jupyterlab-lsp python-lsp-server nglview dockerspawner jupyterhub-nativeauthenticator lckr_jupyterlab_variableinspector
python3 -m pip install jupyterhub jupyterlab notebook radian pycurl jupyter-rsession-proxy ipykernel jupyterlab-language-pack-zh-CN jupyterlab-git jupyterlab-system-monitor jupyter_nbextensions_configurator jupyter_contrib_nbextensions jupyterlab_widgets jupyterlab-drawio jupyterlab-spreadsheet-editor jupyterlab-cell-flash jedi-language-server jupyterlab_code_formatter jupyterlab-spellchecker jupyterlab_vim nbresuse ipydrawio jedi ipympl black isort theme-darcula ipywidgets tensorboard jupyterlab_latex jupyter_bokeh autopep8 xeus-python jupyterlab-lsp python-lsp-server nglview dockerspawner jupyterhub-nativeauthenticator lckr_jupyterlab_variableinspector
EOT
RUN <<EOT
@@ -114,10 +114,6 @@ wget "https://download2.rstudio.org/server/$(lsb_release -cs)/amd64/rstudio-serv
chmod +x /tmp/rstudio-server.deb
gdebi -n /tmp/rstudio-server.deb
rm -rf /tmp/rstudio-server.deb
EOT
RUN <<EOT
#!/bin/bash
chown -R ${CREATE_USER}:users /home/${CREATE_USER}
# 清理和减小镜像大小
apt-get clean
@@ -127,23 +123,24 @@ EOT
# Switch back to jovyan to avoid accidental container runs as root
USER ${NB_UID}
ENV MAMBA_ROOT_PREFIX=/home/${CREATE_USER}/micromamba
ENV PATH="/usr/local/bin/bin:$PATH"
RUN <<EOT
#!/bin/bash
sudo apt update
sudo apt install -y texlive-full
micromamba create -n plot -c conda-forge scienceplots autopep8 python=3 ipykernel pandas numpy matplotlib scipy seaborn orange3 -y
micromamba run -n plot python -m pip install bamboolib
micromamba run -n plot python -m ipykernel install --user --name="sciplot" --display-name="SCIPlot Environment"
EOT
# Install Rust Install evcxr_jupyter for Rust in Jupyter
RUN <<EOT
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
source $HOME/.cargo/env && \
cargo install evcxr_jupyter && \
evcxr_jupyter --install
#!/bin/bash
mamba create -n mixtral_env -c conda-forge ipykernel -y
mamba run -n mixtral_env python -m pip install
mamba run -n mixtral_env python -m ipykernel install --user --name="mixtral" --display-name="mixtral Environment"
EOT
# # new env
# RUN <<EOT
# #!/bin/bash
# EOT
WORKDIR "${HOME}"

View File

@@ -3,6 +3,7 @@
# Distributed under the terms of the Modified BSD License.
import json
import os
import subprocess
from pathlib import Path
import requests
@@ -10,7 +11,19 @@ import requests
# Several operations below deliberately don't check for possible errors
# As this is a healthcheck, it should succeed or raise an exception on error
runtime_dir = Path("/home/") / os.environ["NB_USER"] / ".local/share/jupyter/runtime/"
# Docker runs healtchecks using an exec
# It uses the default user configured when running the image: root for the case of a custom NB_USER or jovyan for the case of the default image user.
# We manually change HOME to make `jupyter --runtime-dir` report a correct path
# More information: <https://github.com/jupyter/docker-stacks/pull/2074#issuecomment-1879778409>
result = subprocess.run(
["jupyter", "--runtime-dir"],
check=True,
capture_output=True,
text=True,
env=dict(os.environ) | {"HOME": "/home/" + os.environ["NB_USER"]},
)
runtime_dir = Path(result.stdout.rstrip())
json_file = next(runtime_dir.glob("*server-*.json"))
url = json.loads(json_file.read_bytes())["url"]