#!/bin/bash # WORKSPACE="/opt/jupyter-ext/install" WORKSPACE=$(pwd) #循环读取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/uninstall.txt -y" # 安装jupyterlab插件 # 安装 jupyterlab 插件 docker exec ${CONTAINER_ID} bash -c " pip install --no-index --find-links=/jupyter-ext -r /jupyter-ext/requirements.txt jupyter_version=$(jupyter lab --version | cut -d. -f1) if pip list | grep -E 'jupyter_ext_model' && \ pip list | grep -E 'jupyter_ext_platform' && \ pip list | grep -E 'jupyterlab-language-pack-zh-CN'; 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