build-docker.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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-1.4.0-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.0-cudnn8-devel-ubuntu18.04"
  17. ;;
  18. --no-cache-build)
  19. NO_CACHE="--no-cache"
  20. ;;
  21. --build-development-image)
  22. BUILD_DEV=YES
  23. ;;
  24. --build-examples)
  25. BUILD_EXAMPLES=YES
  26. ;;
  27. --shas-only)
  28. # output the SHA sum of each build. This is useful for scripting tests,
  29. # especially when builds of different versions are running on the same machine.
  30. # It also can facilitate cleanup.
  31. OUTPUT_SHA=YES
  32. ;;
  33. --wheel-to-use)
  34. # Which wheel to use. This defaults to the latest nightly on python 3.7
  35. echo "not implemented, just hardcode me :'("
  36. exit 1
  37. ;;
  38. --python-version)
  39. # Python version to install. e.g. 3.7.7.
  40. # Changing python versions may require a different wheel.
  41. # If not provided defaults to 3.7.7
  42. shift
  43. PYTHON_VERSION=$1
  44. ;;
  45. *)
  46. echo "Usage: build-docker.sh [ --no-cache-build ] [ --shas-only ] [ --build-development-image ] [ --build-examples ] [ --wheel-to-use ] [ --python-version ]"
  47. exit 1
  48. esac
  49. shift
  50. done
  51. WHEEL_DIR=$(mktemp -d)
  52. wget --quiet "$WHEEL_URL" -P "$WHEEL_DIR"
  53. WHEEL="$WHEEL_DIR/$(basename "$WHEEL_DIR"/*.whl)"
  54. # Build base-deps, ray-deps, and ray.
  55. for IMAGE in "base-deps" "ray-deps" "ray"
  56. do
  57. cp "$WHEEL" "docker/$IMAGE/$(basename "$WHEEL")"
  58. if [ $OUTPUT_SHA ]; then
  59. 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)
  60. echo "rayproject/$IMAGE:nightly$GPU SHA:$IMAGE_SHA"
  61. else
  62. 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
  63. fi
  64. rm "docker/$IMAGE/$(basename "$WHEEL")"
  65. done
  66. # Build the current Ray source
  67. if [ $BUILD_DEV ]; then
  68. git rev-parse HEAD > ./docker/development/git-rev
  69. git archive -o ./docker/development/ray.tar "$(git rev-parse HEAD)"
  70. if [ $OUTPUT_SHA ]; then
  71. IMAGE_SHA=$(docker build --no-cache -q -t rayproject/development docker/development)
  72. echo "rayproject/development:latest SHA:$IMAGE_SHA"
  73. else
  74. docker build --no-cache -t rayproject/development docker/development
  75. fi
  76. rm ./docker/development/ray.tar ./docker/development/git-rev
  77. fi
  78. if [ $BUILD_EXAMPLES ]; then
  79. if [ $OUTPUT_SHA ]; then
  80. IMAGE_SHA=$(docker build $NO_CACHE -q -t rayproject/examples docker/examples)
  81. echo "rayproject/examples:latest SHA:$IMAGE_SHA"
  82. else
  83. docker build $NO_CACHE -t rayproject/examples docker/examples
  84. fi
  85. fi
  86. rm -rf "$WHEEL_DIR"