build_deployment_image.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env bash
  2. # TODO: Allow building multiple variants in a single run?
  3. set -e
  4. device_type='gpu'
  5. env_type='prod'
  6. docker_image_tag='latest'
  7. pip_index_url=''
  8. while getopts 'k:dt:p:' opt; do
  9. case "${opt}" in
  10. k)
  11. # "k" for "kind"
  12. if [ "${OPTARG}" != 'cpu' ] && [ "${OPTARG}" != 'gpu' ]; then
  13. echo "Invalid device type: ${OPTARG}" >&2
  14. exit 2
  15. fi
  16. device_type="${OPTARG}"
  17. ;;
  18. d) env_type='dev' ;;
  19. t) docker_image_tag="${OPTARG}" ;;
  20. p) pip_index_url="${OPTARG}" ;; # 新增的-p
  21. *)
  22. echo "Usage: $0 [-k <device-type>] [-d] [-t <docker-image-tag>] [-p <pip-index-url>]" >&2
  23. exit 2
  24. ;;
  25. esac
  26. done
  27. shift "$((OPTIND - 1))"
  28. if [ $# -ne 0 ]; then
  29. echo "Positional parameters will not be used." >&2
  30. fi
  31. args=(
  32. -f Dockerfile
  33. -t "ccr-2vdh3abv-pub.cnc.bj.baidubce.com/paddlex/hps:${docker_image_tag}"
  34. --target deployment
  35. --build-arg DEVICE_TYPE="${device_type}"
  36. --build-arg ENV_TYPE="${env_type}"
  37. --build-arg http_proxy="${http_proxy}"
  38. --build-arg https_proxy="${https_proxy}"
  39. )
  40. [[ -n $pip_index_url ]] && args+=( --build-arg PIP_INDEX_URL="${pip_index_url}" )
  41. DOCKER_BUILDKIT=1 docker build "${args[@]}" ../../..