build-docker.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. # shellcheck disable=SC2086
  3. # This script is for users to build docker images locally. It is most useful for users wishing to edit the
  4. # base-deps, ray-deps, or ray images. This script is *not* tested, so please look at the
  5. # ci/build/build-docker-images.py if there are problems with using this script.
  6. set -x
  7. GPU=""
  8. BASE_IMAGE="ubuntu:focal"
  9. WHEEL_URL="https://s3-us-west-2.amazonaws.com/ray-wheels/latest/ray-3.0.0.dev0-cp37-cp37m-manylinux2014_x86_64.whl"
  10. PYTHON_VERSION="3.7.16"
  11. while [[ $# -gt 0 ]]
  12. do
  13. key="$1"
  14. case $key in
  15. --gpu)
  16. GPU="-gpu"
  17. BASE_IMAGE="nvidia/cuda:11.2.0-cudnn8-devel-ubuntu18.04"
  18. ;;
  19. --base-image)
  20. # Override for the base image.
  21. shift
  22. BASE_IMAGE=$1
  23. ;;
  24. --no-cache-build)
  25. NO_CACHE="--no-cache"
  26. ;;
  27. --build-development-image)
  28. BUILD_DEV=YES
  29. ;;
  30. --build-examples)
  31. BUILD_EXAMPLES=YES
  32. ;;
  33. --shas-only)
  34. # output the SHA sum of each build. This is useful for scripting tests,
  35. # especially when builds of different versions are running on the same machine.
  36. # It also can facilitate cleanup.
  37. OUTPUT_SHA=YES
  38. ;;
  39. --wheel-to-use)
  40. # Which wheel to use. This defaults to the latest nightly on python 3.7
  41. echo "not implemented, just hardcode me :'("
  42. exit 1
  43. ;;
  44. --python-version)
  45. # Python version to install. e.g. 3.7.7.
  46. # Changing python versions may require a different wheel.
  47. # If not provided defaults to 3.7.7
  48. shift
  49. PYTHON_VERSION=$1
  50. ;;
  51. *)
  52. echo "Usage: build-docker.sh [ --gpu ] [ --base-image ] [ --no-cache-build ] [ --shas-only ] [ --build-development-image ] [ --build-examples ] [ --wheel-to-use ] [ --python-version ]"
  53. exit 1
  54. esac
  55. shift
  56. done
  57. WHEEL_DIR=$(mktemp -d)
  58. wget --quiet "$WHEEL_URL" -P "$WHEEL_DIR"
  59. WHEEL="$WHEEL_DIR/$(basename "$WHEEL_DIR"/*.whl)"
  60. # Build base-deps, ray-deps, and ray.
  61. for IMAGE in "base-deps" "ray-deps" "ray"
  62. do
  63. cp "$WHEEL" "docker/$IMAGE/$(basename "$WHEEL")"
  64. if [ "$OUTPUT_SHA" ]; then
  65. IMAGE_SHA=$(docker build $NO_CACHE --build-arg GPU="$GPU" --build-arg BASE_IMAGE="$BASE_IMAGE" --build-arg WHEEL_PATH="$(basename "$WHEEL")" --build-arg PYTHON_VERSION="$PYTHON_VERSION" -q -t "rayproject/$IMAGE:nightly$GPU" "docker/$IMAGE")
  66. echo "rayproject/$IMAGE:nightly$GPU SHA:$IMAGE_SHA"
  67. else
  68. docker build $NO_CACHE --build-arg GPU="$GPU" --build-arg BASE_IMAGE="$BASE_IMAGE" --build-arg WHEEL_PATH="$(basename "$WHEEL")" --build-arg PYTHON_VERSION="$PYTHON_VERSION" -t "rayproject/$IMAGE:nightly$GPU" "docker/$IMAGE"
  69. fi
  70. rm "docker/$IMAGE/$(basename "$WHEEL")"
  71. done
  72. # Build the current Ray source
  73. if [ $BUILD_DEV ]; then
  74. git rev-parse HEAD > ./docker/development/git-rev
  75. git archive -o ./docker/development/ray.tar "$(git rev-parse HEAD)"
  76. if [ $OUTPUT_SHA ]; then
  77. IMAGE_SHA=$(docker build $NO_CACHE -q -t rayproject/development docker/development)
  78. echo "rayproject/development:latest SHA:$IMAGE_SHA"
  79. else
  80. docker build $NO_CACHE -t rayproject/development docker/development
  81. fi
  82. rm ./docker/development/ray.tar ./docker/development/git-rev
  83. fi
  84. if [ $BUILD_EXAMPLES ]; then
  85. if [ $OUTPUT_SHA ]; then
  86. IMAGE_SHA=$(docker build $NO_CACHE -q -t rayproject/examples docker/examples)
  87. echo "rayproject/examples:latest SHA:$IMAGE_SHA"
  88. else
  89. docker build $NO_CACHE -t rayproject/examples docker/examples
  90. fi
  91. fi
  92. rm -rf "$WHEEL_DIR"