Commit 91a85f26 authored by chenpangpang's avatar chenpangpang
Browse files

feat: 更新插件

parent 54ccc164
...@@ -21,11 +21,11 @@ if [ ! -d "./tmp" ];then ...@@ -21,11 +21,11 @@ if [ ! -d "./tmp" ];then
mkdir tmp mkdir tmp
fi fi
if [ "${framework}" == "jupyterlab" ];then if [ "${framework}" == "jupyterlab" ];then
cp ./jupyter-extension-install-v3/*.whl ./tmp/ cp ./jupyter-extension-install-v4/*.whl ./tmp/
cp ./jupyter-extension-install-v3/requirements.txt ./tmp/ cp ./jupyter-extension-install-v4/requirements.txt ./tmp/
cp ./extension.sh ./tmp/ cp ./extension.sh ./tmp/
cp ./jupyter_lab_config.py ./tmp/ cp ./jupyter_lab_config.py ./tmp/
cp -r ./jupyter-extension-install-v3/static ./tmp/ cp -r ./jupyter-extension-install-v4/static ./tmp/
fi fi
if [ "${framework}" == "codeserver" ];then if [ "${framework}" == "codeserver" ];then
cp ./code-server_4.7.0_amd64.deb ./tmp/ cp ./code-server_4.7.0_amd64.deb ./tmp/
......
# Jupyterlab插件部署手册
# Jupyterlab版本
期望后续新镜像Jupyterlab版本≥4.0.0 (python ≥ 3.8)
```bash
pip install jupyterlab=4.0.0
```
# 插件更新
## 单个镜像插件安装
```bash
# 提供whl插件包,每个功能一种插件,容器内执行
pip install jupyter_ext_dataset-0.1.0-py3-none-any.whl
# 批量安装
pip install --no-index --find-links=. -r requirements.txt
```
## 批量镜像插件安装
使用updateJupyterImage_script脚本
## 功能验证
Jupyterlab插件功能验证
```bash
# 确认三个插件及jupyterlab都有
pip list
```
在Sothisai中启动后
汉化、scnet图标、数据集插件左边菜单
\ No newline at end of file
#!/bin/bash
# 框架
framework=$1
# 输出镜像tag
image_tag=$2
# 基础镜像
base_image=$3
build_args=" --build-arg BASE_IMAGE=$base_image"
if [ ${base_image%%:*} = "pytorch/pytorch" ]; then
build_args="$build_args --build-arg BASE_IMAGE_IS_TORCH=1 "
fi
for arg in ${*:4}
do
build_args="$build_args --build-arg $arg "
done
tmp_dockerfile="Dockerfile.${RANDOM}"
if [ ! -d "./tmp" ];then
mkdir tmp
fi
if [ "${framework}" == "jupyterlab" ];then
cp ./jupyter-extension-install-v3/*.whl ./tmp/
cp ./jupyter-extension-install-v3/requirements.txt ./tmp/
cp ./extension.sh ./tmp/
cp ./jupyter_lab_config.py ./tmp/
cp -r ./jupyter-extension-install-v3/static ./tmp/
fi
if [ "${framework}" == "codeserver" ];then
cp ./code-server_4.7.0_amd64.deb ./tmp/
fi
cp ./python-requirements.txt ./tmp/
cp -f ./Dockerfile.${framework}_ubuntu ./tmp/${tmp_dockerfile}
echo "docker build -f ./tmp/${tmp_dockerfile} -t ${image_tag} $build_args ./tmp/"
docker build -f ./tmp/${tmp_dockerfile} -t ${image_tag} $build_args ./tmp/
rm -r ./tmp
if [[ $? -eq 0 ]];then
echo -e "\033[32mBuild Image Successfully !\033[0m"
else
echo -e "\033[32mBuild Image fail!\033[0m"
exit 1
fi
\ No newline at end of file
image.sourcefind.cn:5000/cpu/admin/base/jupyterlab:3.4.7-multi.python
\ No newline at end of file
jupyterlab-language-pack-zh-CN
jupyter_ext_platform==1.0.11
jupyter_ext_model==1.0.7
git_lfs==1.6
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>JupyterLab</title><meta name="viewport" content="width=device-width,initial-scale=1">{# Copy so we do not modify the page_config with updates. #} {% set page_config_full = page_config.copy() %} {# Set a dummy variable - we just want the side effect of the update. #} {% set _ = page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %}<script id="jupyter-config-data" type="application/json">{{ page_config_full | tojson }}</script>{% block favicon %}<link rel="icon" type="image/x-icon" href="{{ base_url | escape }}static/favicons/favicon.ico" class="idle favicon"><link rel="" type="image/x-icon" href="{{ base_url | escape }}static/favicons/favicon-busy-1.ico" class="busy favicon">{% endblock %}<script defer="defer" src="mainJsParam"></script></head>
<script>/* Remove token from URL. */
(function () {
var location = window.location;
var search = location.search;
// If there is no query string, bail.
if (search.length <= 1) {
return;
}
// Rebuild the query string without the `token`.
var query = '?' + search.slice(1).split('&')
.filter(function (param) { return param.split('=')[0] !== 'token'; })
.join('&');
// Rebuild the URL with the new query string.
var url = location.origin + location.pathname +
(query !== '?' ? query : '') + location.hash;
if (url === location.href) {
return;
}
window.history.replaceState({ }, '', url);
})();</script>
<div id="sugon-logo-wrap">
<img src="{{page_config.fullStaticUrl}}/scnet-loading.gif" />
<div class="waiting-text">加载服务中,请稍候</div>
<span class="time-limit time-limited">
当前实例任务单次运行最大时长
<span class="time" id="sugon-time-limit"></span>
,请注意及时保存重要文件
</span>
<span class="time-limit time-unlimited">当前实例任务不会自动关停并将持续产生费用,请注意按需手动关停。</span>
</div>
</body>
<style>
#sugon-logo-wrap {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 100;
text-align: center;
}
#sugon-logo-wrap img {
width: 50px;
}
#sugon-logo-wrap .waiting-text {
font-size: 20px;
font-weight: 500;
color: #3b4048;
line-height: 30px;
margin: 18px 0 26px;
text-align: center;
}
#sugon-logo-wrap .time-limit {
font-size: 14px;
font-weight: 400;
color: #3B4048;
line-height: 14px;
display: none;
}
#sugon-logo-wrap .time-limit .time {
font-weight: 700;
font-size: 18px;
color: #FFB333;
}
</style>
<script>
var sugonLoadInterval = setInterval(() => {
var sugonMenu = document.getElementById('jp-menu-panel')
if (sugonMenu) {
clearInterval(sugonLoadInterval)
document.body.removeChild(document.getElementById('sugon-logo-wrap'))
}
}, 100)
const query = new URLSearchParams(window.location.search);
if (query.get('limit')) {
const limit = query.get('limit')
if (limit === 'unlimited') {
document.querySelector('.time-limit.time-unlimited').style.display = 'block'
} else {
const timeText = Number(limit.split(':')[0]) + '小时'
document.querySelector('.time-limit.time-limited').style.display = 'block'
document.getElementById('sugon-time-limit').innerText = timeText
}
}
</script>
</html>
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>JupyterLab</title><meta name="viewport" content="width=device-width,initial-scale=1">{# Copy so we do not modify the page_config with updates. #} {% set page_config_full = page_config.copy() %} {# Set a dummy variable - we just want the side effect of the update. #} {% set _ = page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %}<script id="jupyter-config-data" type="application/json">{{ page_config_full | tojson }}</script>{% block favicon %}<link rel="icon" type="image/x-icon" href="{{ base_url | escape }}static/favicons/favicon.ico" class="idle favicon"><link rel="" type="image/x-icon" href="{{ base_url | escape }}static/favicons/favicon-busy-1.ico" class="busy favicon">{% endblock %}<script defer="defer" src="{{page_config.fullStaticUrl}}/main.dd06365fd804e00186dc.js?v=dd06365fd804e00186dc"></script></head>
<script>/* Remove token from URL. */
(function () {
var location = window.location;
var search = location.search;
// If there is no query string, bail.
if (search.length <= 1) {
return;
}
// Rebuild the query string without the `token`.
var query = '?' + search.slice(1).split('&')
.filter(function (param) { return param.split('=')[0] !== 'token'; })
.join('&');
// Rebuild the URL with the new query string.
var url = location.origin + location.pathname +
(query !== '?' ? query : '') + location.hash;
if (url === location.href) {
return;
}
window.history.replaceState({ }, '', url);
})();</script>
<div id="sugon-logo-wrap">
<img src="{{page_config.fullStaticUrl}}/scnet-loading.gif" />
<div class="waiting-text">加载服务中,请稍候</div>
<span class="time-limit time-limited">
当前实例任务单次运行最大时长
<span class="time" id="sugon-time-limit"></span>
,请注意及时保存重要文件
</span>
<span class="time-limit time-unlimited">当前实例任务不会自动关停并将持续产生费用,请注意按需手动关停。</span>
</div>
</body>
<style>
#sugon-logo-wrap {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 100;
text-align: center;
}
#sugon-logo-wrap img {
width: 50px;
}
#sugon-logo-wrap .waiting-text {
font-size: 20px;
font-weight: 500;
color: #3b4048;
line-height: 30px;
margin: 18px 0 26px;
text-align: center;
}
#sugon-logo-wrap .time-limit {
font-size: 14px;
font-weight: 400;
color: #3B4048;
line-height: 14px;
display: none;
}
#sugon-logo-wrap .time-limit .time {
font-weight: 700;
font-size: 18px;
color: #FFB333;
}
</style>
<script>
var sugonLoadInterval = setInterval(() => {
var sugonMenu = document.getElementById('jp-menu-panel')
if (sugonMenu) {
clearInterval(sugonLoadInterval)
document.body.removeChild(document.getElementById('sugon-logo-wrap'))
}
}, 100)
const query = new URLSearchParams(window.location.search);
if (query.get('limit')) {
const limit = query.get('limit')
if (limit === 'unlimited') {
document.querySelector('.time-limit.time-unlimited').style.display = 'block'
} else {
const timeText = Number(limit.split(':')[0]) + '小时'
document.querySelector('.time-limit.time-limited').style.display = 'block'
document.getElementById('sugon-time-limit').innerText = timeText
}
}
</script>
</html>
#!/bin/bash
WORKSPACE="/opt/jupyter-ext/install"
#循环读取images.txt,并存入list中
n=0
fail_image_array=()
for line in $(cat images.txt | grep ^[^#])
do
list[$n]=$line
((n+=1))
done
echo "需推送的镜像地址如下:"
for variable in ${list[@]}
do
echo ${variable}
done
for variable in ${list[@]}
do
#下载镜像
echo "准备拉取镜像: $variable"
docker pull $variable
# #获取拉取的镜像ID
imageId=`docker images -q $variable`
echo "[$variable]拉取完成后的镜像ID: $imageId"
#启动容器
CONTAINER_ID=$(docker run -v $WORKSPACE:/jupyter-ext -itd $variable)
echo "容器ID:${CONTAINER_ID},启动jupyter 检查文件中..."
content=$(docker exec ${CONTAINER_ID} bash -c 'nohup jupyter lab --allow-root --ip=0.0.0.0 --port=8888 > /tmp/start.log 2>&1 & sleep 20s; cat /tmp/start.log| grep "JupyterLab application directory"')
echo $content
if [ -z "$content" ]; then
echo "image jupyter sourcecode path check failed!please retry! imageId:$imageId,containerId:${CONTAINER_ID}"
docker stop ${CONTAINER_ID}
fail_image_array+=("${variable}")
continue
else
jupyter_file_path=$(echo "$content" | grep -oP '(?<=is\s)(\/[^ ]+)')
fi
echo "jupyter sourcecode path is :${jupyter_file_path}/static"
file_check=$(docker exec ${CONTAINER_ID} bash -c 'if [ -d "'${jupyter_file_path}'/static" ]; then echo "success"; else echo "failed"; fi')
echo $file_check
if [ "failed" == "$file_check" ]; then
echo "image jupyter sourcecode path check failed!please retry! image:$variable"
docker stop ${CONTAINER_ID}
fail_image_array+=("${variable}")
continue
fi
# 获取index的内容 那去js名 替换
js_content=$(docker exec ${CONTAINER_ID} bash -c "cat '${jupyter_file_path}'/static/index.html ")
echo $js_content
js_path=$(echo "$js_content" | grep -oP '{{page_config\.fullStaticUrl}}/main\.[^"]+\.js\?v=[^"]+' )
js_path2=$(echo "$js_content" | grep -oP '{{page_config\.fullStaticUrl}}/vendors~main\.[^"]+\.js\?v=[^"]+' )
js_path3=$(echo "$js_content" | grep -oP '{{page_config\.fullStaticUrl}}/vendors~main\.[^"]+\.js' )
echo "jupyter js source path is: $js_path"
if [ -z "$js_path" ];then
if [ -z "$js_path2" ];then
if [ -z "$js_path3" ];then
echo "image jupyter sourcecode main js path check failed!please retry! imageId:$imageId,containerId:${CONTAINER_ID}"
docker stop ${CONTAINER_ID}
fail_image_array+=("${variable}")
continue
else
js_path=$js_path3
fi
else
js_path=$js_path2
fi
fi
cat $WORKSPACE/static/index-base.html > $WORKSPACE/static/index.html
sed -i "s#mainJsParam#${js_path}#g" $WORKSPACE/static/index.html
docker cp -a $WORKSPACE/static/index.html ${CONTAINER_ID}:${jupyter_file_path}/static/index.html
docker cp -a $WORKSPACE/static/scnet-loading.gif ${CONTAINER_ID}:${jupyter_file_path}/static/scnet-loading.gif
jupyter_dir=$(docker exec ${CONTAINER_ID} bash -c "whereis jupyter | cat|awk -F':' '{print \$2}'")
echo "image env jupyter cmd path :${jupyter_dir}"
# docker exec ${CONTAINER_ID} bash -c "mkdir -p '/opt/conda/bin/';ln -s ${jupyter_dir} /opt/conda/bin/"
# 卸载之前jupyterlab插件
docker exec ${CONTAINER_ID} bash -c "pip uninstall -r /jupyter-ext/requirements.txt"
# 安装jupyterlab插件
docker exec ${CONTAINER_ID} bash -c "pip install --no-index --find-links=/jupyter-ext -r /jupyter-ext/requirements.txt;if pip list | grep -E 'jupyter_ext_dataset' && pip list | grep -E 'jupyter_ext_logo' && pip list | grep -E 'jupyterlab-language-pack-zh-CN' && [ "$(jupyter lab --version | cut -d. -f1)" -gt 2 ];then echo "安装成功";else echo \"安装失败!! $variable\" | tee /jupyter-ext/errorImages.txt; fi"
# 禁用splash插件
docker exec ${CONTAINER_ID} bash -c "jupyter labextension disable @jupyterlab/apputils-extension:splash"
# 打镜像
docker commit ${CONTAINER_ID} $variable
#重新打镜像标签
# docker tag $imageId $registryAddr$repository:$imageNewTag
# #推送镜像
# docker push $registryAddr$repository:$imageNewTag
# 删除容器及镜像
# docker stop ${CONTAINER_ID}
# docker rm ${CONTAINER_ID}
# docker rmi ${imageId}
# 验证命令
# docker run -it -p8080:8080 --env JUPYTERLAB_WORKSPACES_DIR=/tmp/111 --entrypoint='' f7fa3a053830 /bin/bash
# mkidr -p /opt/conda/bin/;ln -n /usr/bin/jupyter /opt/conda/bin/jupyter ;/opt/conda/bin/jupyter lab --allow-root --ip=0.0.0.0 --port=8080
done
echo "jupyter source code update failed:"
echo $fail_image_array
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment