set_up_docker_and_build_cpp.sh 2.5 KB

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