mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-06-30 20:31:50 +08:00
feat(deps): add uv-backed package installer (#5987)
* feat(deps): add uv-backed package installer * feat(deps): support package cache root
This commit is contained in:
@@ -27,6 +27,23 @@ export PATH="${VENV_PATH}/bin:$PATH"
|
||||
# 校正设置目录
|
||||
CONFIG_DIR="${CONFIG_DIR:-/config}"
|
||||
|
||||
function apply_package_cache_env() {
|
||||
PACKAGE_CACHE_ROOT="${PACKAGE_CACHE_ROOT:-${CONFIG_DIR}/.cache}"
|
||||
export PACKAGE_CACHE_ROOT
|
||||
export PIP_CACHE_DIR="${PIP_CACHE_DIR:-${PACKAGE_CACHE_ROOT}/pip}"
|
||||
export UV_CACHE_DIR="${UV_CACHE_DIR:-${PACKAGE_CACHE_ROOT}/uv}"
|
||||
mkdir -p "${PIP_CACHE_DIR}" "${UV_CACHE_DIR}"
|
||||
}
|
||||
|
||||
function apply_package_proxy_env() {
|
||||
if [ -n "${PROXY_HOST}" ]; then
|
||||
export HTTP_PROXY="${PROXY_HOST}"
|
||||
export HTTPS_PROXY="${PROXY_HOST}"
|
||||
export http_proxy="${PROXY_HOST}"
|
||||
export https_proxy="${PROXY_HOST}"
|
||||
fi
|
||||
}
|
||||
|
||||
# 环境变量补全
|
||||
# 优先级: 系统环境变量 -> .env 文件 (即使为空字符串) -> 预设默认值
|
||||
# 精准适配 Python 端 set_key (quote_mode="always", 单引号包裹, \' 转义)
|
||||
@@ -39,6 +56,7 @@ function load_config_from_app_env() {
|
||||
declare -A vars_and_default_values=(
|
||||
# update.sh
|
||||
["PIP_PROXY"]=""
|
||||
["PACKAGE_CACHE_ROOT"]=""
|
||||
["GITHUB_PROXY"]=""
|
||||
["PROXY_HOST"]=""
|
||||
["GITHUB_TOKEN"]=""
|
||||
@@ -276,11 +294,10 @@ function ensure_backend_runtime_dependencies() {
|
||||
fi
|
||||
|
||||
WARN "→ 检测到后端核心依赖异常,开始尝试恢复主程序依赖..."
|
||||
apply_package_proxy_env
|
||||
local -a pip_cmd=("${VENV_PATH}/bin/pip" "install" "-r" "/app/requirements.txt")
|
||||
if [ -n "${PIP_PROXY}" ]; then
|
||||
pip_cmd+=("-i" "${PIP_PROXY}")
|
||||
elif [ -n "${PROXY_HOST}" ]; then
|
||||
pip_cmd+=("--proxy" "${PROXY_HOST}")
|
||||
fi
|
||||
|
||||
if ! "${pip_cmd[@]}" > /dev/stdout 2> /dev/stderr; then
|
||||
@@ -298,6 +315,7 @@ function ensure_backend_runtime_dependencies() {
|
||||
|
||||
# 使用env配置
|
||||
load_config_from_app_env
|
||||
apply_package_cache_env
|
||||
|
||||
# 一次性升级标记仅影响本次启动,避免把临时升级模式带入运行中的 Python 进程
|
||||
ONE_SHOT_UPDATE_FLAG="${CONFIG_DIR}/temp/moviepilot.pending_update"
|
||||
|
||||
@@ -24,6 +24,27 @@ function WARN() {
|
||||
VENV_PATH="${VENV_PATH:-/opt/venv}"
|
||||
export PATH="${VENV_PATH}/bin:$PATH"
|
||||
|
||||
CONFIG_DIR="${CONFIG_DIR:-/config}"
|
||||
|
||||
function apply_package_cache_env() {
|
||||
PACKAGE_CACHE_ROOT="${PACKAGE_CACHE_ROOT:-${CONFIG_DIR}/.cache}"
|
||||
export PACKAGE_CACHE_ROOT
|
||||
export PIP_CACHE_DIR="${PIP_CACHE_DIR:-${PACKAGE_CACHE_ROOT}/pip}"
|
||||
export UV_CACHE_DIR="${UV_CACHE_DIR:-${PACKAGE_CACHE_ROOT}/uv}"
|
||||
mkdir -p "${PIP_CACHE_DIR}" "${UV_CACHE_DIR}"
|
||||
}
|
||||
|
||||
apply_package_cache_env
|
||||
|
||||
function apply_package_proxy_env() {
|
||||
if [[ -n "${PROXY_HOST}" ]]; then
|
||||
export HTTP_PROXY="${PROXY_HOST}"
|
||||
export HTTPS_PROXY="${PROXY_HOST}"
|
||||
export http_proxy="${PROXY_HOST}"
|
||||
export https_proxy="${PROXY_HOST}"
|
||||
fi
|
||||
}
|
||||
|
||||
# 下载及解压
|
||||
function download_and_unzip() {
|
||||
local retries=0
|
||||
@@ -176,9 +197,16 @@ function test_connectivity_pip() {
|
||||
case "$1" in
|
||||
0)
|
||||
if [[ -n "${PIP_PROXY}" ]]; then
|
||||
if ${VENV_PATH}/bin/pip install -i ${PIP_PROXY} pip-hello-world > /dev/null 2>&1; then
|
||||
if [[ -n "${PROXY_HOST}" ]]; then
|
||||
HTTP_PROXY="${PROXY_HOST}" HTTPS_PROXY="${PROXY_HOST}" http_proxy="${PROXY_HOST}" https_proxy="${PROXY_HOST}" \
|
||||
${VENV_PATH}/bin/pip install -i ${PIP_PROXY} pip-hello-world > /dev/null 2>&1
|
||||
else
|
||||
${VENV_PATH}/bin/pip install -i ${PIP_PROXY} pip-hello-world > /dev/null 2>&1
|
||||
fi
|
||||
if [[ $? -eq 0 ]]; then
|
||||
PIP_OPTIONS="-i ${PIP_PROXY}"
|
||||
PIP_LOG="镜像代理模式"
|
||||
apply_package_proxy_env
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
@@ -186,9 +214,11 @@ function test_connectivity_pip() {
|
||||
;;
|
||||
1)
|
||||
if [[ -n "${PROXY_HOST}" ]]; then
|
||||
if ${VENV_PATH}/bin/pip install --proxy=${PROXY_HOST} pip-hello-world > /dev/null 2>&1; then
|
||||
PIP_OPTIONS="--proxy=${PROXY_HOST}"
|
||||
if HTTP_PROXY="${PROXY_HOST}" HTTPS_PROXY="${PROXY_HOST}" http_proxy="${PROXY_HOST}" https_proxy="${PROXY_HOST}" \
|
||||
${VENV_PATH}/bin/pip install pip-hello-world > /dev/null 2>&1; then
|
||||
PIP_OPTIONS=""
|
||||
PIP_LOG="全局代理模式"
|
||||
apply_package_proxy_env
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user