generate_runtime_docker.sh 2.6 KB
Newer Older
W
wangjiawei04 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#!/bin/sh

#abort on error
set -e

function usage
{
    echo "usage: arg_parse_example -a AN_ARG -s SOME_MORE_ARGS [-y YET_MORE_ARGS || -h]"
    echo "   ";
    echo "   --env                 : running env, cpu/cuda10.1/cuda10.2/cuda11";
    echo "   --python              : python version, 2.7/3.6/3.7 ";
    echo "   --serving             : serving version(0.5.0)";
    echo "   --paddle              : paddle version(2.0.1)"
    echo "   --image_name          : image name(default serving_runtime:env-python)"
    echo "  -h | --help            : helper";
}

function parse_args
{
  # positional args
  args=()

  # named args
  while [ "$1" != "" ]; do
      case "$1" in
          --env )               env="$2";             shift;;
          --python )            python="$2";     shift;;
          --serving )           serving="$2";      shift;;
          --paddle )            paddle="$2";      shift;;
      --image_name )          image_name="$2";    shift;;
          -h | --help )         usage;            exit;; # quit and show usage
          * )                 args+=("$1")             # if no match, add it to the positional args
      esac
      shift # move to next kv pair
  done
  # restore positional args
  set -- "${args[@]}"

  # set positionals to vars
  positional_1="${args[0]}"
  positional_2="${args[1]}"

  # validate required args
  if [[ -z "${paddle}" || -z "${env}" || -z "${python}" || -z "${serving}" ]]; then
      echo "Invalid arguments"
      usage
      exit;
  fi

  if [[ -z "${image_name}" ]]; then
      image_name="serving_runtime:$env-$python"
      echo "image_name is not assigned, so it will be set ($image_name)."
  fi

}


function run
{
  parse_args "$@"

  echo "named arg: env: $env"
  if [ $env == "cpu" ]; then
      base_image="ubuntu:16.04"
  elif [ $env == "cuda10.1" ]; then
      base_image="nvidia\/cuda:10.1-cudnn7-runtime-ubuntu16.04"
  elif [ $env == "cuda10.2" ]; then
      base_image="nvidia\/cuda:10.2-cudnn8-runtime-ubuntu16.04"
  fi
  echo "base image: $base_image"
  echo "named arg: python: $python"
  echo "named arg: serving: $serving"
  echo "named arg: paddle: $paddle"
  echo "named arg: image_name: $image_name"
  
  sed -e "s/<<base_image>>/$base_image/g" -e "s/<<python_version>>/$python/g" -e "s/<<run_env>>/$env/g" Dockerfile.runtime_template > Dockerfile.tmp
  docker build --build-arg ftp_proxy=http://172.19.57.45:3128 --build-arg https_proxy=http://172.19.57.45:3128 --build-arg http_proxy=http://172.19.57.45:3128 --build-arg HTTP_PROXY=http://172.19.57.45:3128 --build-arg HTTPS_PROXY=http://172.19.57.45:3128 -t $image_name -f Dockerfile.tmp .
}

run "$@";