install.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env bash
  2. # Set error handling
  3. set -o errexit
  4. set -o nounset
  5. set -o pipefail
  6. # Get the root directory and third_party directory
  7. ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
  8. # Include the common functions
  9. source "${ROOT_DIR}/hack/lib/init.sh"
  10. function download_deps() {
  11. if ! command -v uv &> /dev/null; then
  12. pip install uv
  13. fi
  14. # uv sync --all-extras to install all dependencies
  15. uv sync --locked
  16. if [[ "${DEPS_ONLY:-false}" == "false" ]]; then
  17. uv pip install pre-commit==3.7.1
  18. uv run pre-commit install
  19. fi
  20. }
  21. function download_ui() {
  22. local default_tag="latest"
  23. local ui_path="${ROOT_DIR}/gpustack/ui"
  24. local tmp_ui_path="${ui_path}/tmp"
  25. local tag="latest"
  26. if [[ "${GIT_VERSION}" != "v0.0.0" ]]; then
  27. tag="${GIT_VERSION}"
  28. fi
  29. rm -rf "${ui_path}"
  30. mkdir -p "${tmp_ui_path}/ui"
  31. gpustack::log::info "downloading '${tag}' UI assets"
  32. if ! curl --retry 3 --retry-connrefused --retry-delay 3 -sSfL "https://gpustack-ui-1303613262.cos.accelerate.myqcloud.com/releases/${tag}.tar.gz" 2>/dev/null |
  33. tar -xzf - --directory "${tmp_ui_path}/ui" 2>/dev/null; then
  34. if [[ "${tag:-}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
  35. gpustack::log::fatal "failed to download '${tag}' ui archive"
  36. fi
  37. gpustack::log::warn "failed to download '${tag}' ui archive, fallback to '${default_tag}' ui archive"
  38. if ! curl --retry 3 --retry-connrefused --retry-delay 3 -sSfL "https://gpustack-ui-1303613262.cos.accelerate.myqcloud.com/releases/${default_tag}.tar.gz" |
  39. tar -xzf - --directory "${tmp_ui_path}/ui" 2>/dev/null; then
  40. gpustack::log::fatal "failed to download '${default_tag}' ui archive"
  41. fi
  42. fi
  43. cp -a "${tmp_ui_path}/ui/dist/." "${ui_path}"
  44. rm -rf "${tmp_ui_path}"
  45. }
  46. # Copy extra static files to ui including catalog icons
  47. function copy_extra_static() {
  48. local extra_static_path="${ROOT_DIR}/static"
  49. local ui_static_path="${ROOT_DIR}/gpustack/ui/static"
  50. if [ -d "${extra_static_path}" ]; then
  51. cp -a "${extra_static_path}/." "${ui_static_path}"
  52. fi
  53. }
  54. # Update community backends
  55. function make_community_backends() {
  56. local tmp_dir
  57. tmp_dir=$(mktemp -d -t gpustack-community-backends.XXXXXX)
  58. # shellcheck disable=SC2064
  59. trap "rm -rf \"${tmp_dir}\"" EXIT
  60. local target_dir="${ROOT_DIR}/gpustack/assets/"
  61. gpustack::log::info "pulling community backends"
  62. # Clone the repository
  63. git clone https://github.com/gpustack/community-inference-backends "${tmp_dir}"
  64. # Build the community backends
  65. (
  66. cd "${tmp_dir}"
  67. if [[ "${UV_SYSTEM_PYTHON:-}" == "1" ]]; then
  68. # In Docker build, use system Python directly
  69. uv pip install PyYAML && uv run make
  70. else
  71. # For local development, use virtual environment
  72. uv venv && source .venv/bin/activate && uv pip install PyYAML && uv run make
  73. fi
  74. )
  75. # Create target directory and copy the yaml file
  76. mkdir -p "${target_dir}"
  77. cp "${tmp_dir}/dist/community-inference-backends.yaml" "${target_dir}/community-inference-backends.yaml"
  78. gpustack::log::info "community backends updated successfully"
  79. }
  80. #
  81. # main
  82. #
  83. gpustack::log::info "+++ DEPENDENCIES +++"
  84. download_deps
  85. download_ui
  86. copy_extra_static
  87. make_community_backends
  88. gpustack::log::info "--- DEPENDENCIES ---"