You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

build_image.sh 5.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/bin/bash
  2. # default values.
  3. BASE_CPU_IMAGE=reg.docker.alibaba-inc.com/modelscope/ubuntu:20.04
  4. BASE_GPU_IMAGE=reg.docker.alibaba-inc.com/modelscope/ubuntu:20.04-cuda11.3.0-cudnn8-devel
  5. MODELSCOPE_REPO_ADDRESS=reg.docker.alibaba-inc.com/modelscope/modelscope
  6. python_version=3.7.13
  7. torch_version=1.11.0
  8. cudatoolkit_version=11.3
  9. tensorflow_version=1.15.5
  10. modelscope_version=None
  11. is_ci_test=False
  12. is_dsw=False
  13. is_cpu=False
  14. run_ci_test=False
  15. function usage(){
  16. echo "usage: build.sh "
  17. echo " --python=python_version set python version, default: $python_version"
  18. echo " --torch=torch_version set pytorch version, fefault: $torch_version"
  19. echo " --cudatoolkit=cudatoolkit_version set cudatoolkit version used for pytorch, default: $cudatoolkit_version"
  20. echo " --tensorflow=tensorflow_version set tensorflow version, default: $tensorflow_version"
  21. echo " --modelscope=modelscope_version set modelscope version, default: $modelscope_version"
  22. echo " --test option for run test before push image, only push on ci test pass"
  23. echo " --cpu option for build cpu version"
  24. echo " --dsw option for build dsw version"
  25. echo " --ci option for build ci version"
  26. echo " --push option for push image to remote repo"
  27. }
  28. for i in "$@"; do
  29. case $i in
  30. --python=*)
  31. python_version="${i#*=}"
  32. shift
  33. ;;
  34. --torch=*)
  35. torch_version="${i#*=}"
  36. shift # pytorch version
  37. ;;
  38. --tensorflow=*)
  39. tensorflow_version="${i#*=}"
  40. shift # tensorflow version
  41. ;;
  42. --cudatoolkit=*)
  43. cudatoolkit_version="${i#*=}"
  44. shift # cudatoolkit for pytorch
  45. ;;
  46. --modelscope=*)
  47. modelscope_version="${i#*=}"
  48. shift # cudatoolkit for pytorch
  49. ;;
  50. --test)
  51. run_ci_test=True
  52. shift # will run ci test
  53. ;;
  54. --cpu)
  55. is_cpu=True
  56. shift # is cpu image
  57. ;;
  58. --ci)
  59. is_ci_test=True
  60. shift # is ci, will not install modelscope
  61. ;;
  62. --dsw)
  63. is_dsw=True
  64. shift # is dsw, will set dsw cache location
  65. ;;
  66. --push)
  67. is_push=True
  68. shift # is dsw, will set dsw cache location
  69. ;;
  70. --help)
  71. usage
  72. exit 0
  73. ;;
  74. -*|--*)
  75. echo "Unknown option $i"
  76. usage
  77. exit 1
  78. ;;
  79. *)
  80. ;;
  81. esac
  82. done
  83. if [ "$modelscope_version" == "None" ]; then
  84. echo "ModelScope version must specify!"
  85. exit 1
  86. fi
  87. if [ "$is_cpu" == "True" ]; then
  88. export BASE_IMAGE=$BASE_CPU_IMAGE
  89. base_tag=ubuntu20.04
  90. export USE_GPU=False
  91. else
  92. export BASE_IMAGE=$BASE_GPU_IMAGE
  93. base_tag=ubuntu20.04-cuda11.3.0
  94. export USE_GPU=True
  95. fi
  96. if [[ $python_version == 3.7* ]]; then
  97. base_tag=$base_tag-py37
  98. elif [[ $python_version == z* ]]; then
  99. base_tag=$base_tag-py38
  100. elif [[ $python_version == z* ]]; then
  101. base_tag=$base_tag-py39
  102. else
  103. echo "Unsupport python version: $python_version"
  104. exit 1
  105. fi
  106. target_image_tag=$base_tag-torch$torch_version-tf$tensorflow_version
  107. if [ "$is_ci_test" == "True" ]; then
  108. target_image_tag=$target_image_tag-$modelscope_version-ci
  109. else
  110. target_image_tag=$target_image_tag-$modelscope_version-test
  111. fi
  112. export IMAGE_TO_BUILD=$MODELSCOPE_REPO_ADDRESS:$target_image_tag
  113. export PYTHON_VERSION=$python_version
  114. export TORCH_VERSION=$torch_version
  115. export CUDATOOLKIT_VERSION=$cudatoolkit_version
  116. export TENSORFLOW_VERSION=$tensorflow_version
  117. echo -e "Building image with:\npython$python_version\npytorch$torch_version\ntensorflow:$tensorflow_version\ncudatoolkit:$cudatoolkit_version\ncpu:$is_cpu\nis_ci:$is_ci_test\nis_dsw:$is_dsw\n"
  118. docker_file_content=`cat docker/Dockerfile.ubuntu`
  119. if [ "$is_ci_test" != "True" ]; then
  120. echo "Building ModelScope lib, will install ModelScope lib to image"
  121. docker_file_content="${docker_file_content} \nRUN pip install --no-cache-dir modelscope==$modelscope_version -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html"
  122. fi
  123. echo "$is_dsw"
  124. if [ "$is_dsw" == "False" ]; then
  125. echo "Not DSW image"
  126. else
  127. echo "Building dsw image well need set ModelScope lib cache location."
  128. docker_file_content="${docker_file_content} \nENV MODELSCOPE_CACHE=/mnt/workspace/.cache/modelscope"
  129. fi
  130. printf "$docker_file_content" > Dockerfile
  131. docker build -t $IMAGE_TO_BUILD \
  132. --build-arg USE_GPU \
  133. --build-arg BASE_IMAGE \
  134. --build-arg PYTHON_VERSION \
  135. --build-arg TORCH_VERSION \
  136. --build-arg CUDATOOLKIT_VERSION \
  137. --build-arg TENSORFLOW_VERSION \
  138. -f Dockerfile .
  139. if [ $? -ne 0 ]; then
  140. echo "Running docker build command error, please check the log!"
  141. exit -1
  142. fi
  143. if [ "$run_ci_test" == "True" ]; then
  144. echo "Running ci case."
  145. export MODELSCOPE_CACHE=/home/mulin.lyh/model_scope_cache
  146. export MODELSCOPE_HOME_CACHE=/home/mulin.lyh/ci_case_home # for credential
  147. export IMAGE_NAME=$MODELSCOPE_REPO_ADDRESS
  148. export IMAGE_VERSION=$target_image_tag
  149. export MODELSCOPE_DOMAIN=www.modelscope.cn
  150. export HUB_DATASET_ENDPOINT=http://www.modelscope.cn
  151. export CI_TEST=True
  152. export TEST_LEVEL=1
  153. if [ "$is_ci_test" != "True" ]; then
  154. echo "Testing for dsw image or MaaS-lib image"
  155. export CI_COMMAND="python tests/run.py"
  156. fi
  157. bash .dev_scripts/dockerci.sh
  158. if [ $? -ne 0 ]; then
  159. echo "Running unittest failed, please check the log!"
  160. exit -1
  161. fi
  162. fi
  163. if [ "$is_push" == "True" ]; then
  164. echo "Pushing image: $IMAGE_TO_BUILD"
  165. docker push $IMAGE_TO_BUILD
  166. fi