build-docker.sh 3.3 KB

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