build_ubuntu.sh 1.59 KB
Newer Older
chenpangpang's avatar
chenpangpang committed
1
2
#!/bin/bash
# 框架
chenpangpang's avatar
chenpangpang committed
3
framework=$1
chenpangpang's avatar
chenpangpang committed
4
5
6
7
8
9
10
11
12
13
14
15
16
# 输出镜像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

chenpangpang's avatar
chenpangpang committed
17
18
19
20
21
22
tmp_dockerfile="Dockerfile.${RANDOM}"

if [ ! -d "./tmp" ];then
mkdir tmp
fi
if [ "${framework}" == "jupyterlab" ];then
chenpangpang's avatar
chenpangpang committed
23
24
  cp ./jupyter-extension-install-v3/*.whl ./tmp/
  cp ./jupyter-extension-install-v3/requirements.txt ./tmp/
chenpangpang's avatar
chenpangpang committed
25
26
  cp ./extension.sh ./tmp/
  cp ./jupyter_lab_config.py ./tmp/
chenpangpang's avatar
chenpangpang committed
27
  cp -r ./jupyter-extension-install-v3/static ./tmp/
chenpangpang's avatar
chenpangpang committed
28
29
30
31
32
33
34
35
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}
# temp_image="$(grep -n '^FROM' ./tmp/${tmp_dockerfile} | tac | head -1 | awk '{print $2}')"
# sed -i "s?${temp_image}?${base_tag}?g" ./tmp/${tmp_dockerfile}
chenpangpang's avatar
chenpangpang committed
36
37
38
39
# docker build --build-arg BASE_IMAGE_IS_TORCH=1 --build-arg IMAGE="pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime" -f ./tmp/${tmp_dockerfile} -t ${newtag} ./tmp/
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/
#echo "docker build -f ./tmp/${tmp_dockerfile} -t ${image_tag} $build_args ./tmp/"
40
build_status=$?
chenpangpang's avatar
chenpangpang committed
41
rm -r ./tmp
42
if [[ build_status -eq 0 ]];then
chenpangpang's avatar
chenpangpang committed
43
44
        echo -e "\033[32mBuild Image Successfully !\033[0m"
else
chenpangpang's avatar
chenpangpang committed
45
        echo -e "\033[32mBuild Image fail!\033[0m"
chenpangpang's avatar
chenpangpang committed
46
        exit 1
47
fi