From 8ab4900e81c79ba5771f4762b0e172cdaae5cfb0 Mon Sep 17 00:00:00 2001 From: hotwa Date: Sun, 28 Jan 2024 19:12:10 +0800 Subject: [PATCH] merge devgpu --- Dockerfile.jupyterhub | 12 --- Dockerfile.jupyterhub.bak | 86 +++------------------- README.md | 85 ++++++++++++++++++++- docker-compose.yml | 15 +++- nginx.conf | 26 +++++++ spawnerdockerfile/Dockerfile | 2 +- spawnerdockerfile/Dockerfile.base-notebook | 25 +++---- spawnerdockerfile/docker_healthcheck.py | 17 ++++- 8 files changed, 160 insertions(+), 108 deletions(-) create mode 100644 nginx.conf diff --git a/Dockerfile.jupyterhub b/Dockerfile.jupyterhub index 09b5841..0cfd894 100644 --- a/Dockerfile.jupyterhub +++ b/Dockerfile.jupyterhub @@ -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 < /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 < +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 +``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1415f61..f8d400f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..9bc4ad3 --- /dev/null +++ b/nginx.conf @@ -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; + } + } +} diff --git a/spawnerdockerfile/Dockerfile b/spawnerdockerfile/Dockerfile index 545e2db..aabd396 100644 --- a/spawnerdockerfile/Dockerfile +++ b/spawnerdockerfile/Dockerfile @@ -72,4 +72,4 @@ HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \ # Switch back to jovyan to avoid accidental container runs as root USER ${NB_UID} -WORKDIR "${HOME}" +WORKDIR "${HOME}" \ No newline at end of file diff --git a/spawnerdockerfile/Dockerfile.base-notebook b/spawnerdockerfile/Dockerfile.base-notebook index db0d263..1f43664 100644 --- a/spawnerdockerfile/Dockerfile.base-notebook +++ b/spawnerdockerfile/Dockerfile.base-notebook @@ -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 < +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"] @@ -23,4 +36,4 @@ proxies = { r = requests.get(url, proxies=proxies, verify=False) # request without SSL verification r.raise_for_status() -print(r.content) +print(r.content) \ No newline at end of file