You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gpustack/hack/install.sh

92 lines
2.8 KiB

#!/usr/bin/env bash
# Set error handling
set -o errexit
set -o nounset
set -o pipefail
# Get the root directory and third_party directory
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
# Include the common functions
source "${ROOT_DIR}/hack/lib/init.sh"
function download_deps() {
pip install poetry==1.8.3
poetry install
if [[ "${POETRY_ONLY:-false}" == "false" ]]; then
pip install pre-commit==3.7.1
pre-commit install
fi
}
function download_ui() {
local default_tag="latest"
local ui_path="${ROOT_DIR}/gpustack/ui"
local tmp_ui_path="${ui_path}/tmp"
local tag="latest"
local local_ui_dir="/home/gpustack-ui/dist" # 本地 UI 构建目录
if [[ "${GIT_VERSION}" != "v0.0.0" ]]; then
tag="${GIT_VERSION}"
fi
# 删除旧的 ui 目录
rm -rf "${ui_path}"
mkdir -p "${ui_path}"
gpustack::log::info "Checking for local UI build at ${local_ui_dir}"
# 优先检查本地构建目录是否存在且非空
if [[ -d "${local_ui_dir}" ]] && [[ -n "$(ls -A ${local_ui_dir} 2>/dev/null)" ]]; then
gpustack::log::info "Local UI found at ${local_ui_dir}, copying..."
cp -a "${local_ui_dir}/." "${ui_path}"
gpustack::log::info "Local UI copied successfully."
return 0
else
gpustack::log::info "No valid local UI found at ${local_ui_dir}, proceeding with download..."
fi
# 如果本地没有,则下载远程 UI
mkdir -p "${tmp_ui_path}/ui"
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 |
tar -xzf - --directory "${tmp_ui_path}/ui" 2>/dev/null; then
if [[ "${tag:-}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
gpustack::log::fatal "failed to download '${tag}' ui archive"
fi
gpustack::log::warn "failed to download '${tag}' ui archive, fallback to '${default_tag}' ui archive"
if ! curl --retry 3 --retry-connrefused --retry-delay 3 -sSfL "https://gpustack-ui-1303613262.cos.accelerate.myqcloud.com/releases/${default_tag}.tar.gz" |
tar -xzf - --directory "${tmp_ui_path}/ui" 2>/dev/null; then
gpustack::log::fatal "failed to download '${default_tag}' ui archive"
fi
fi
# 复制解压后的内容
cp -a "${tmp_ui_path}/ui/dist/." "${ui_path}"
# 清理临时目录
rm -rf "${tmp_ui_path}"
}
# Copy extra static files to ui including catalog icons
function copy_extra_static() {
local extra_static_path="${ROOT_DIR}/static"
local ui_static_path="${ROOT_DIR}/gpustack/ui/static"
if [ -d "${extra_static_path}" ]; then
cp -a "${extra_static_path}/." "${ui_static_path}"
fi
}
#
# main
#
gpustack::log::info "+++ DEPENDENCIES +++"
download_deps
download_ui
copy_extra_static
gpustack::log::info "--- DEPENDENCIES ---"