set_up_docker_and_build_py.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. # input
  3. CONTAINER_NAME="${CONTAINER_NAME:-build_fd}"
  4. WITH_GPU="${WITH_GPU:-ON}"
  5. ENABLE_BENCHMARK="${ENABLE_BENCHMARK:-OFF}"
  6. DEBUG="${DEBUG:-OFF}"
  7. PYTHON_VERSION="${PYTHON_VERSION:-3.10.0}"
  8. DOCKER_IMAGE="ccr-2vdh3abv-pub.cnc.bj.baidubce.com/paddlepaddle/paddle_manylinux_devel:cuda11.8-cudnn8.6-trt8.5-gcc8.2"
  9. if [[ -z "$PADDLEINFERENCE_URL" ]]; then
  10. echo "Error: PADDLEINFERENCE_URL is not set."
  11. exit 1
  12. fi
  13. if [[ -z "$PADDLEINFERENCE_VERSION" ]]; then
  14. echo "Error: PADDLEINFERENCE_VERSION is not set."
  15. exit 1
  16. fi
  17. # Set variables
  18. CMAKE_CXX_COMPILER="/usr/local/gcc-8.2/bin/g++"
  19. # Get the current script directory and compute the directory to mount
  20. SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
  21. ULTRAINFER_DIR="$(realpath "$SCRIPT_DIR/../../../")"
  22. # Set the Docker startup command
  23. if [ "$WITH_GPU" = "ON" ]; then
  24. DOCKER_CMD=$(cat << EOF
  25. docker run --gpus all -it --name="${CONTAINER_NAME}" --shm-size=128g --net=host \
  26. -v "${ULTRAINFER_DIR}":/workspace \
  27. -e CMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}" \
  28. -e "http_proxy=${http_proxy}" \
  29. -e "https_proxy=${https_proxy}" \
  30. "${DOCKER_IMAGE}" /bin/bash -c "
  31. cd /workspace && \
  32. ldconfig && \
  33. ./ultra-infer/scripts/linux/_build_py.sh --with-gpu "${WITH_GPU}" --enable-benchmark "${ENABLE_BENCHMARK}" --python "${PYTHON_VERSION}" --paddleinference-url "${PADDLEINFERENCE_URL}" --paddleinference-version "${PADDLEINFERENCE_VERSION}" && \
  34. tail -f /dev/null"
  35. EOF
  36. )
  37. else
  38. DOCKER_CMD=$(cat << EOF
  39. docker run -it --name="${CONTAINER_NAME}" --shm-size=128g --net=host \
  40. -v "${ULTRAINFER_DIR}":/workspace \
  41. -e CMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}" \
  42. -e "http_proxy=${http_proxy}" \
  43. -e "https_proxy=${https_proxy}" \
  44. "${DOCKER_IMAGE}" /bin/bash -c "
  45. cd /workspace && \
  46. ./ultra-infer/scripts/linux/_build_py.sh --with-gpu "${WITH_GPU}" --enable-benchmark "${ENABLE_BENCHMARK}" --python "${PYTHON_VERSION}" --paddleinference-url "${PADDLEINFERENCE_URL}" --paddleinference-version "${PADDLEINFERENCE_VERSION}" && \
  47. tail -f /dev/null"
  48. EOF
  49. )
  50. fi
  51. # If in debug mode, replace --rm with -it and keep the container running
  52. if [ "$DEBUG" = "OFF" ]; then
  53. DOCKER_CMD="${DOCKER_CMD/-it/--rm}"
  54. DOCKER_CMD="${DOCKER_CMD/ && tail -f \/dev\/null/}"
  55. fi
  56. # Check if a Docker container with the same name already exists
  57. if docker ps -a --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then
  58. echo "Error: A Docker container with the name '${CONTAINER_NAME}' already exists."
  59. echo "Please remove the existing container or choose a different container name."
  60. exit 1
  61. fi
  62. echo "Starting Docker container..."
  63. eval "$DOCKER_CMD"