mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-05-11 09:59:51 +08:00
test beta
This commit is contained in:
91
docker/Dockerfile
Normal file
91
docker/Dockerfile
Normal file
@@ -0,0 +1,91 @@
|
||||
FROM python:3.12.8-slim-bookworm
|
||||
ENV LANG="C.UTF-8" \
|
||||
TZ="Asia/Shanghai" \
|
||||
HOME="/moviepilot" \
|
||||
CONFIG_DIR="/config" \
|
||||
TERM="xterm" \
|
||||
DISPLAY=:987 \
|
||||
PUID=0 \
|
||||
PGID=0 \
|
||||
UMASK=000 \
|
||||
PORT=3001 \
|
||||
NGINX_PORT=3000 \
|
||||
MOVIEPILOT_AUTO_UPDATE=release
|
||||
WORKDIR "/app"
|
||||
RUN apt-get update -y \
|
||||
&& apt-get upgrade -y \
|
||||
&& apt-get -y install \
|
||||
musl-dev \
|
||||
nginx \
|
||||
gettext-base \
|
||||
locales \
|
||||
procps \
|
||||
gosu \
|
||||
bash \
|
||||
wget \
|
||||
curl \
|
||||
busybox \
|
||||
dumb-init \
|
||||
jq \
|
||||
fuse3 \
|
||||
rsync \
|
||||
ffmpeg \
|
||||
nano \
|
||||
&& \
|
||||
if [ "$(uname -m)" = "x86_64" ]; \
|
||||
then ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1; \
|
||||
elif [ "$(uname -m)" = "aarch64" ]; \
|
||||
then ln -s /usr/lib/aarch64-linux-musl/libc.so /lib/libc.musl-aarch64.so.1; \
|
||||
fi \
|
||||
&& curl https://rclone.org/install.sh | bash \
|
||||
&& apt-get autoremove -y \
|
||||
&& apt-get clean -y \
|
||||
&& rm -rf \
|
||||
/tmp/* \
|
||||
/moviepilot/.cache \
|
||||
/var/lib/apt/lists/* \
|
||||
/var/tmp/*
|
||||
COPY ../requirements.in requirements.in
|
||||
RUN apt-get update -y \
|
||||
&& apt-get install -y build-essential \
|
||||
&& pip install --upgrade pip \
|
||||
&& pip install Cython pip-tools \
|
||||
&& pip-compile requirements.in \
|
||||
&& pip install -r requirements.txt \
|
||||
&& playwright install-deps chromium \
|
||||
&& apt-get remove -y build-essential \
|
||||
&& apt-get autoremove -y \
|
||||
&& apt-get clean -y \
|
||||
&& rm -rf \
|
||||
/tmp/* \
|
||||
/moviepilot/.cache \
|
||||
/var/lib/apt/lists/* \
|
||||
/var/tmp/*
|
||||
COPY .. .
|
||||
RUN cp -f /app/docker/nginx.common.conf /etc/nginx/common.conf \
|
||||
&& cp -f /app/docker/nginx.template.conf /etc/nginx/nginx.template.conf \
|
||||
&& cp -f /app/docker/update.sh /usr/local/bin/mp_update.sh \
|
||||
&& cp -f /app/docker/entrypoint.sh /entrypoint.sh \
|
||||
&& cp -f /app/docker/docker_http_proxy.conf /etc/nginx/docker_http_proxy.conf \
|
||||
&& chmod +x /entrypoint.sh /usr/local/bin/mp_update.sh \
|
||||
&& mkdir -p ${HOME} \
|
||||
&& groupadd -r moviepilot -g 918 \
|
||||
&& useradd -r moviepilot -g moviepilot -d ${HOME} -s /bin/bash -u 918 \
|
||||
&& python_ver=$(python3 -V | awk '{print $2}') \
|
||||
&& echo "/app/" > /usr/local/lib/python${python_ver%.*}/site-packages/app.pth \
|
||||
&& echo 'fs.inotify.max_user_watches=5242880' >> /etc/sysctl.conf \
|
||||
&& echo 'fs.inotify.max_user_instances=5242880' >> /etc/sysctl.conf \
|
||||
&& locale-gen zh_CN.UTF-8 \
|
||||
&& FRONTEND_VERSION=$(sed -n "s/^FRONTEND_VERSION\s*=\s*'\([^']*\)'/\1/p" /app/version.py) \
|
||||
&& curl -sL "https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${FRONTEND_VERSION}/dist.zip" | busybox unzip -d / - \
|
||||
&& mv /dist /public \
|
||||
&& curl -sL "https://github.com/jxxghp/MoviePilot-Plugins/archive/refs/heads/main.zip" | busybox unzip -d /tmp - \
|
||||
&& mv -f /tmp/MoviePilot-Plugins-main/plugins.v2/* /app/app/plugins/ \
|
||||
&& cat /tmp/MoviePilot-Plugins-main/package.json | jq -r 'to_entries[] | select(.value.v2 == true) | .key' | awk '{print tolower($0)}' | \
|
||||
while read -r i; do if [ ! -d "/app/app/plugins/$i" ]; then mv "/tmp/MoviePilot-Plugins-main/plugins/$i" "/app/app/plugins/"; else echo "跳过 $i"; fi; done \
|
||||
&& curl -sL "https://github.com/jxxghp/MoviePilot-Resources/archive/refs/heads/main.zip" | busybox unzip -d /tmp - \
|
||||
&& mv -f /tmp/MoviePilot-Resources-main/resources/* /app/app/helper/ \
|
||||
&& rm -rf /tmp/*
|
||||
EXPOSE 3000
|
||||
VOLUME [ "/config" ]
|
||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
||||
77
docker/cert.sh
Normal file
77
docker/cert.sh
Normal file
@@ -0,0 +1,77 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
Green="\033[32m"
|
||||
Red="\033[31m"
|
||||
Yellow='\033[33m'
|
||||
Font="\033[0m"
|
||||
INFO="[${Green}INFO${Font}]"
|
||||
ERROR="[${Red}ERROR${Font}]"
|
||||
WARN="[${Yellow}WARN${Font}]"
|
||||
function INFO() {
|
||||
echo -e "${INFO} ${1}"
|
||||
}
|
||||
function ERROR() {
|
||||
echo -e "${ERROR} ${1}"
|
||||
}
|
||||
function WARN() {
|
||||
echo -e "${WARN} ${1}"
|
||||
}
|
||||
|
||||
# 仅当启用HTTPS且需要自动签发时执行
|
||||
if [ "$ENABLE_SSL" = "true" ] && [ "$AUTO_ISSUE_CERT" = "true" ]; then
|
||||
INFO "▄■▀▄■▀▄■▀▄■▀▄■▀ 证书管理开始 ▀■▄▀■▄▀■▄▀■▄▀■▄"
|
||||
|
||||
# 创建证书目录
|
||||
mkdir -p /config/certs/"${SSL_DOMAIN}"
|
||||
chown moviepilot:moviepilot /config/certs -R
|
||||
|
||||
# 安装acme.sh
|
||||
if [ ! -d "/config/acme.sh" ]; then
|
||||
INFO "→ 安装acme.sh..."
|
||||
git clone https://github.com/acmesh-official/acme.sh.git /config/acme.sh
|
||||
cd /config/acme.sh
|
||||
./acme.sh --install --home /config/acme.sh \
|
||||
--config-home /config/acme.sh/data \
|
||||
--cert-home /config/certs \
|
||||
--accountemail "${SSL_EMAIL}"
|
||||
fi
|
||||
|
||||
# 签发证书(仅当证书不存在时)
|
||||
if [ ! -f "/config/certs/${SSL_DOMAIN}/fullchain.pem" ]; then
|
||||
# 检查必要参数
|
||||
[ -z "${DNS_PROVIDER}" ] && { ERROR "必须指定DNS_PROVIDER环境变量"; exit 1; }
|
||||
[ -z "${SSL_DOMAIN}" ] && { ERROR "必须指定SSL_DOMAIN环境变量"; exit 1; }
|
||||
|
||||
INFO "→ 签发证书: ${SSL_DOMAIN} (DNS验证方式: ${DNS_PROVIDER})"
|
||||
|
||||
# 导出所有ACME_ENV_开头的环境变量(自动去除前缀)
|
||||
INFO "正在加载ACME环境变量..."
|
||||
for acme_var in $(env | grep '^ACME_ENV_'); do
|
||||
key="${acme_var#ACME_ENV_}"
|
||||
key="${key%%=*}"
|
||||
value="${acme_var#ACME_ENV_${key}=}"
|
||||
export "${key}=${value}"
|
||||
INFO "已加载环境变量: ${key}=******"
|
||||
done
|
||||
|
||||
# 签发证书
|
||||
/config/acme.sh/acme.sh --issue \
|
||||
--dns "${DNS_PROVIDER}" \
|
||||
--domain "${SSL_DOMAIN}" \
|
||||
--key-file /config/certs/"${SSL_DOMAIN}"/privkey.pem \
|
||||
--fullchain-file /config/certs/"${SSL_DOMAIN}"/fullchain.pem \
|
||||
--force
|
||||
|
||||
# 创建稳定符号链接
|
||||
ln -sf /config/certs/"${SSL_DOMAIN}" /config/certs/latest
|
||||
fi
|
||||
|
||||
# 配置自动更新任务
|
||||
INFO "→ 配置cron自动更新..."
|
||||
echo "0 3 * * * /config/acme.sh/acme.sh --cron --home /config/acme.sh && nginx -s reload" > /etc/cron.d/acme
|
||||
chmod 644 /etc/cron.d/acme
|
||||
service cron start
|
||||
|
||||
INFO "▄■▀▄■▀▄■▀▄■▀▄■▀ 证书管理完成 ▀■▄▀■▄▀■▄▀■▄▀■▄"
|
||||
fi
|
||||
43
docker/docker_http_proxy.conf
Normal file
43
docker/docker_http_proxy.conf
Normal file
@@ -0,0 +1,43 @@
|
||||
worker_processes 1;
|
||||
user root;
|
||||
daemon on;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
upstream docker {
|
||||
server unix:/var/run/docker.sock fail_timeout=0;
|
||||
}
|
||||
server {
|
||||
listen 38379;
|
||||
server_name localhost;
|
||||
|
||||
access_log /dev/stdout combined;
|
||||
error_log /dev/stdout;
|
||||
|
||||
location / {
|
||||
proxy_pass http://docker;
|
||||
proxy_redirect off;
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
client_max_body_size 10m;
|
||||
client_body_buffer_size 128k;
|
||||
|
||||
proxy_connect_timeout 90;
|
||||
proxy_send_timeout 120;
|
||||
proxy_read_timeout 120;
|
||||
|
||||
proxy_buffer_size 4k;
|
||||
proxy_buffers 4 32k;
|
||||
proxy_busy_buffers_size 64k;
|
||||
proxy_temp_file_write_size 64k;
|
||||
}
|
||||
}
|
||||
}
|
||||
97
docker/entrypoint.sh
Normal file
97
docker/entrypoint.sh
Normal file
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2155
|
||||
|
||||
Green="\033[32m"
|
||||
Red="\033[31m"
|
||||
Yellow='\033[33m'
|
||||
Font="\033[0m"
|
||||
INFO="[${Green}INFO${Font}]"
|
||||
ERROR="[${Red}ERROR${Font}]"
|
||||
WARN="[${Yellow}WARN${Font}]"
|
||||
function INFO() {
|
||||
echo -e "${INFO} ${1}"
|
||||
}
|
||||
function ERROR() {
|
||||
echo -e "${ERROR} ${1}"
|
||||
}
|
||||
function WARN() {
|
||||
echo -e "${WARN} ${1}"
|
||||
}
|
||||
|
||||
# 生成HTTPS配置块
|
||||
if [ "$ENABLE_SSL" = "true" ]; then
|
||||
export HTTPS_SERVER_CONF=$(cat <<EOF
|
||||
server {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
server_name ${SSL_DOMAIN:-moviepilot};
|
||||
|
||||
# SSL证书路径
|
||||
ssl_certificate /etc/ssl/certs/latest/fullchain.pem;
|
||||
ssl_certificate_key /etc/ssl/certs/latest/privkey.pem;
|
||||
|
||||
# SSL安全配置
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
# 公共配置
|
||||
include common.conf;
|
||||
}
|
||||
EOF
|
||||
)
|
||||
else
|
||||
export HTTPS_SERVER_CONF="# HTTPS未启用"
|
||||
fi
|
||||
|
||||
# 使用 `envsubst` 将模板文件中的 ${NGINX_PORT} 替换为实际的环境变量值
|
||||
export NGINX_CLIENT_MAX_BODY_SIZE=${NGINX_CLIENT_MAX_BODY_SIZE:-10m}
|
||||
envsubst '${NGINX_PORT}${PORT}${NGINX_CLIENT_MAX_BODY_SIZE}${HTTPS_SERVER_CONF}' < /etc/nginx/nginx.template.conf > /etc/nginx/nginx.conf
|
||||
# 自动更新
|
||||
cd /
|
||||
source /usr/local/bin/mp_update.sh
|
||||
cd /app || exit
|
||||
# 更改 moviepilot userid 和 groupid
|
||||
groupmod -o -g "${PGID}" moviepilot
|
||||
usermod -o -u "${PUID}" moviepilot
|
||||
# 更改文件权限
|
||||
chown -R moviepilot:moviepilot \
|
||||
"${HOME}" \
|
||||
/app \
|
||||
/public \
|
||||
/config \
|
||||
/var/lib/nginx \
|
||||
/var/log/nginx
|
||||
chown moviepilot:moviepilot /etc/hosts /tmp
|
||||
# 下载浏览器内核
|
||||
if [[ "$HTTPS_PROXY" =~ ^https?:// ]] || [[ "$HTTPS_PROXY" =~ ^https?:// ]] || [[ "$PROXY_HOST" =~ ^https?:// ]]; then
|
||||
HTTPS_PROXY="${HTTPS_PROXY:-${https_proxy:-$PROXY_HOST}}" gosu moviepilot:moviepilot playwright install chromium
|
||||
else
|
||||
gosu moviepilot:moviepilot playwright install chromium
|
||||
fi
|
||||
# 证书管理
|
||||
source /app/docker/cert.sh
|
||||
# 启动前端nginx服务
|
||||
INFO "→ 启动前端nginx服务..."
|
||||
nginx
|
||||
# 启动docker http proxy nginx
|
||||
if [ -S "/var/run/docker.sock" ]; then
|
||||
INFO "→ 启动 Docker Proxy..."
|
||||
nginx -c /etc/nginx/docker_http_proxy.conf
|
||||
# 上面nginx是通过root启动的,会将目录权限改成root,所以需要重新再设置一遍权限
|
||||
chown -R moviepilot:moviepilot \
|
||||
/var/lib/nginx \
|
||||
/var/log/nginx
|
||||
fi
|
||||
# 设置后端服务权限掩码
|
||||
umask "${UMASK}"
|
||||
# 启动后端服务
|
||||
INFO "→ 启动后端服务..."
|
||||
exec dumb-init gosu moviepilot:moviepilot python3 app/main.py
|
||||
100
docker/nginx.common.conf
Normal file
100
docker/nginx.common.conf
Normal file
@@ -0,0 +1,100 @@
|
||||
|
||||
# 公共根目录
|
||||
root /public;
|
||||
|
||||
# 主应用路由
|
||||
location / {
|
||||
expires off;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# 图片类静态资源
|
||||
location ~* \.(png|jpg|jpeg|gif|ico|svg)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# assets目录
|
||||
location /assets {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# 站点图标
|
||||
location /api/v1/site/icon/ {
|
||||
# 站点图标缓存
|
||||
proxy_cache my_cache;
|
||||
# 缓存响应码为200和302的请求1小时
|
||||
proxy_cache_valid 200 302 1h;
|
||||
# 缓存其他响应码的请求5分钟
|
||||
proxy_cache_valid any 5m;
|
||||
# 缓存键的生成规则
|
||||
proxy_cache_key "$scheme$request_method$host$request_uri";
|
||||
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
||||
|
||||
# 向后端API转发请求
|
||||
proxy_pass http://backend_api;
|
||||
}
|
||||
|
||||
|
||||
# 本地CookieCloud
|
||||
location /cookiecloud {
|
||||
proxy_pass http://backend_api;
|
||||
rewrite ^.+mock-server/?(.*)$ /$1 break;
|
||||
proxy_http_version 1.1;
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
proxy_redirect off;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Nginx-Proxy true;
|
||||
|
||||
# 超时设置
|
||||
proxy_read_timeout 600s;
|
||||
}
|
||||
|
||||
# SSE特殊配置
|
||||
location ~ ^/api/v1/system/(message|progress/) {
|
||||
# SSE MIME类型设置
|
||||
default_type text/event-stream;
|
||||
|
||||
# 禁用缓存
|
||||
add_header Cache-Control no-cache;
|
||||
add_header X-Accel-Buffering no;
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
|
||||
# 代理设置
|
||||
proxy_pass http://backend_api;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
# 超时设置
|
||||
proxy_read_timeout 3600s;
|
||||
}
|
||||
|
||||
# API代理配置
|
||||
location /api {
|
||||
proxy_pass http://backend_api;
|
||||
rewrite ^.+mock-server/?(.*)$ /$1 break;
|
||||
proxy_http_version 1.1;
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
proxy_redirect off;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Nginx-Proxy true;
|
||||
|
||||
# 超时设置
|
||||
proxy_read_timeout 600s;
|
||||
}
|
||||
50
docker/nginx.template.conf
Normal file
50
docker/nginx.template.conf
Normal file
@@ -0,0 +1,50 @@
|
||||
user moviepilot;
|
||||
worker_processes auto;
|
||||
worker_cpu_affinity auto;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
# 设置缓存路径和缓存区大小
|
||||
proxy_cache_path /tmp levels=1:2 keys_zone=my_cache:10m max_size=100m inactive=60m use_temp_path=off;
|
||||
|
||||
sendfile on;
|
||||
|
||||
keepalive_timeout 3600;
|
||||
|
||||
client_max_body_size ${NGINX_CLIENT_MAX_BODY_SIZE};
|
||||
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
gzip_proxied any;
|
||||
gzip_min_length 256;
|
||||
gzip_vary on;
|
||||
gzip_comp_level 6;
|
||||
|
||||
# HTTP
|
||||
server {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
listen ${NGINX_PORT};
|
||||
listen [::]:${NGINX_PORT};
|
||||
server_name moviepilot;
|
||||
|
||||
# 公共配置
|
||||
include common.conf;
|
||||
}
|
||||
|
||||
# HTTPS
|
||||
${HTTPS_SERVER_CONF}
|
||||
|
||||
upstream backend_api {
|
||||
# 后端API的地址和端口
|
||||
server 127.0.0.1:${PORT};
|
||||
# 可以添加更多后端服务器作为负载均衡
|
||||
}
|
||||
|
||||
}
|
||||
334
docker/update.sh
Normal file
334
docker/update.sh
Normal file
@@ -0,0 +1,334 @@
|
||||
#!/bin/bash
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2086
|
||||
# shellcheck disable=SC2144
|
||||
|
||||
Green="\033[32m"
|
||||
Red="\033[31m"
|
||||
Yellow='\033[33m'
|
||||
Font="\033[0m"
|
||||
INFO="[${Green}INFO${Font}]"
|
||||
ERROR="[${Red}ERROR${Font}]"
|
||||
WARN="[${Yellow}WARN${Font}]"
|
||||
function INFO() {
|
||||
echo -e "${INFO} ${1}"
|
||||
}
|
||||
function ERROR() {
|
||||
echo -e "${ERROR} ${1}"
|
||||
}
|
||||
function WARN() {
|
||||
echo -e "${WARN} ${1}"
|
||||
}
|
||||
|
||||
# 下载及解压
|
||||
function download_and_unzip() {
|
||||
local retries=0
|
||||
local max_retries=3
|
||||
local url="$1"
|
||||
local target_dir="$2"
|
||||
INFO "→ 正在下载 ${url}..."
|
||||
while [ $retries -lt $max_retries ]; do
|
||||
if curl ${CURL_OPTIONS} "${url}" ${CURL_HEADERS} | busybox unzip -d ${TMP_PATH} - > /dev/null; then
|
||||
if [ -e ${TMP_PATH}/MoviePilot-* ]; then
|
||||
mv ${TMP_PATH}/MoviePilot-* ${TMP_PATH}/"${target_dir}"
|
||||
fi
|
||||
break
|
||||
else
|
||||
WARN "下载 ${url} 失败,正在进行第 $((retries + 1)) 次重试..."
|
||||
retries=$((retries + 1))
|
||||
fi
|
||||
done
|
||||
if [ $retries -eq $max_retries ]; then
|
||||
ERROR "下载 ${url} 失败,已达到最大重试次数!"
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# 下载程序资源,$1: 后端版本路径
|
||||
function install_backend_and_download_resources() {
|
||||
# 更新后端程序
|
||||
if ! download_and_unzip "${GITHUB_PROXY}https://github.com/jxxghp/MoviePilot/archive/refs/${1}" "App"; then
|
||||
WARN "后端程序下载失败,继续使用旧的程序来启动..."
|
||||
return 1
|
||||
fi
|
||||
INFO "后端程序下载成功"
|
||||
INFO "→ 正在安装依赖..."
|
||||
if ! pip install ${PIP_OPTIONS} --upgrade --root-user-action=ignore pip > /dev/null; then
|
||||
ERROR "pip 更新失败,请重新拉取镜像"
|
||||
return 1
|
||||
fi
|
||||
if ! pip install ${PIP_OPTIONS} --root-user-action=ignore -r ${TMP_PATH}/App/requirements.txt > /dev/null; then
|
||||
ERROR "依赖安装失败,请重新拉取镜像"
|
||||
return 1
|
||||
fi
|
||||
INFO "依赖安装成功"
|
||||
# 如果是"heads/v2.zip",则查找v2开头的最新版本号
|
||||
if [[ "${1}" == "heads/v2.zip" ]]; then
|
||||
INFO "→ 正在获取前端最新版本号..."
|
||||
# 获取所有发布的版本列表,并筛选出以v2开头的版本号
|
||||
releases=$(curl ${CURL_OPTIONS} "https://api.github.com/repos/jxxghp/MoviePilot-Frontend/releases" ${CURL_HEADERS} | jq -r '.[].tag_name' | grep "^v2\.")
|
||||
if [ -z "$releases" ]; then
|
||||
WARN "未找到任何v2前端版本,继续启动..."
|
||||
return 1
|
||||
else
|
||||
# 找到最新的v2版本
|
||||
frontend_version=$(echo "$releases" | sort -V | tail -n 1)
|
||||
fi
|
||||
INFO "前端最新版本号:${frontend_version}"
|
||||
else
|
||||
INFO "→ 正在获取前端版本号..."
|
||||
# 从后端文件中读取前端版本号
|
||||
frontend_version=$(sed -n "s/^FRONTEND_VERSION\s*=\s*'\([^']*\)'/\1/p" ${TMP_PATH}/App/version.py)
|
||||
if [[ "${frontend_version}" != *v* ]]; then
|
||||
WARN "前端版本号获取失败,继续启动..."
|
||||
return 1
|
||||
fi
|
||||
INFO "前端版本号:${frontend_version}"
|
||||
fi
|
||||
# 更新前端程序
|
||||
if ! download_and_unzip "${GITHUB_PROXY}https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${frontend_version}/dist.zip" "dist"; then
|
||||
WARN "前端程序下载失败,继续使用旧的程序来启动..."
|
||||
return 1
|
||||
fi
|
||||
INFO "前端程序下载成功"
|
||||
# 备份插件目录
|
||||
INFO "→ 正在备份插件目录..."
|
||||
rm -rf /plugins
|
||||
mkdir -p /plugins
|
||||
cp -a /app/app/plugins/* /plugins/
|
||||
rm -f /plugins/__init__.py
|
||||
# 备份站点资源
|
||||
INFO "→ 正在备份站点资源目录..."
|
||||
rm -rf /resources_bakcup
|
||||
mkdir /resources_bakcup
|
||||
cp -a /app/app/helper/user.sites.bin /resources_bakcup
|
||||
cp -a /app/app/helper/sites.cp* /resources_bakcup
|
||||
# 清空程序目录
|
||||
rm -rf /app
|
||||
mkdir -p /app
|
||||
# 复制新后端程序
|
||||
cp -a ${TMP_PATH}/App/* /app/
|
||||
# 复制新前端程序
|
||||
rm -rf /public
|
||||
mkdir -p /public
|
||||
cp -a ${TMP_PATH}/dist/* /public/
|
||||
INFO "程序部分更新成功,前端版本:${frontend_version},后端版本:${1}"
|
||||
# 恢复插件目录
|
||||
cp -a /plugins/* /app/app/plugins/
|
||||
# 更新站点资源
|
||||
INFO "→ 开始更新站点资源..."
|
||||
if ! download_and_unzip "${GITHUB_PROXY}https://github.com/jxxghp/MoviePilot-Resources/archive/refs/heads/main.zip" "Resources"; then
|
||||
cp -a /resources_bakcup/* /app/app/helper/
|
||||
rm -rf /resources_bakcup
|
||||
WARN "站点资源下载失败,继续使用旧的资源来启动..."
|
||||
return 1
|
||||
fi
|
||||
# 复制新站点资源
|
||||
cp -a ${TMP_PATH}/Resources/resources/* /app/app/helper/
|
||||
INFO "站点资源更新成功"
|
||||
# 清理临时目录
|
||||
rm -rf "${TMP_PATH}"
|
||||
return 0
|
||||
}
|
||||
|
||||
function test_connectivity_pip() {
|
||||
pip uninstall -y pip-hello-world > /dev/null 2>&1
|
||||
case "$1" in
|
||||
0)
|
||||
if [[ -n "${PIP_PROXY}" ]]; then
|
||||
if pip install -i ${PIP_PROXY} pip-hello-world > /dev/null 2>&1; then
|
||||
PIP_OPTIONS="-i ${PIP_PROXY}"
|
||||
PIP_LOG="镜像代理模式"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
;;
|
||||
1)
|
||||
if [[ -n "${PROXY_HOST}" ]]; then
|
||||
if pip install --proxy=${PROXY_HOST} pip-hello-world > /dev/null 2>&1; then
|
||||
PIP_OPTIONS="--proxy=${PROXY_HOST}"
|
||||
PIP_LOG="全局代理模式"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
;;
|
||||
2)
|
||||
PIP_OPTIONS=""
|
||||
PIP_LOG="不使用代理"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# 测试Github连通性
|
||||
function test_connectivity_github() {
|
||||
case "$1" in
|
||||
0)
|
||||
if [[ -n "${GITHUB_PROXY}" ]]; then
|
||||
if curl -sL "${GITHUB_PROXY}https://raw.githubusercontent.com/jxxghp/MoviePilot/main/README.md" > /dev/null 2>&1; then
|
||||
GITHUB_LOG="镜像代理模式"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
;;
|
||||
1)
|
||||
if [[ -n "${PROXY_HOST}" ]]; then
|
||||
if curl -sL -x ${PROXY_HOST} https://raw.githubusercontent.com/jxxghp/MoviePilot/main/README.md > /dev/null 2>&1; then
|
||||
CURL_OPTIONS="-sL -x ${PROXY_HOST}"
|
||||
GITHUB_LOG="全局代理模式"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
;;
|
||||
2)
|
||||
CURL_OPTIONS="-sL"
|
||||
GITHUB_LOG="不使用代理"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# 版本号比较
|
||||
function compare_versions() {
|
||||
local v1="$1"
|
||||
local v2="$2"
|
||||
# 去掉开头的 v 或 V
|
||||
v1="${v1#[vV]}"
|
||||
v2="${v2#[vV]}"
|
||||
local current_ver_parts=()
|
||||
local release_ver_parts=()
|
||||
IFS='.-' read -ra current_ver_parts <<< "$v1"
|
||||
IFS='.-' read -ra release_ver_parts <<< "$v2"
|
||||
local i
|
||||
local current_ver
|
||||
local release_ver
|
||||
|
||||
for ((i = 0; i < ${#current_ver_parts[@]} || i < ${#release_ver_parts[@]}; i++)); do
|
||||
# 版本号不足位补 0
|
||||
local current_ver_part="${current_ver_parts[i]:-0}"
|
||||
local release_ver_part="${release_ver_parts[i]:-0}"
|
||||
current_ver=$(get_priority "$current_ver_part")
|
||||
release_ver=$(get_priority "$release_ver_part")
|
||||
|
||||
# 任意一个为-5,不在合法版本号内,无法比较
|
||||
if (( current_ver == -5 || release_ver == -5 )); then
|
||||
ERROR "存在不合法版本号,无法判断,跳过更新步骤..."
|
||||
return 1
|
||||
else
|
||||
if (( current_ver > release_ver )); then
|
||||
WARN "当前版本高于远程版本,跳过更新步骤..."
|
||||
return 1
|
||||
elif (( current_ver < release_ver )); then
|
||||
INFO "发现新版本,开始自动升级..."
|
||||
install_backend_and_download_resources "tags/$2.zip"
|
||||
return 0
|
||||
else
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
done
|
||||
WARN "当前版本已是最新版本,跳过更新步骤..."
|
||||
}
|
||||
|
||||
# 优先级转换
|
||||
function get_priority() {
|
||||
local version="$1"
|
||||
if [[ $version =~ ^[0-9]+$ ]]; then
|
||||
echo $version
|
||||
else
|
||||
case $version in
|
||||
"stable")
|
||||
echo -1
|
||||
;;
|
||||
"rc")
|
||||
echo -2
|
||||
;;
|
||||
"beta")
|
||||
echo -3
|
||||
;;
|
||||
"alpha")
|
||||
echo -4
|
||||
;;
|
||||
# 非数字的不合法版本号
|
||||
*)
|
||||
echo -5
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "${MOVIEPILOT_AUTO_UPDATE}" = "true" ]] || [[ "${MOVIEPILOT_AUTO_UPDATE}" = "release" ]] || [[ "${MOVIEPILOT_AUTO_UPDATE}" = "dev" ]]; then
|
||||
INFO "▄■▀▄■▀▄■▀▄■▀▄■▀ 自动更新开始 ▀■▄▀■▄▀■▄▀■▄▀■▄"
|
||||
TMP_PATH=$(mktemp -d)
|
||||
if [ ! -d "${TMP_PATH}" ]; then
|
||||
# 如果自动生成 tmp 文件夹失败则手动指定,避免出现数据丢失等情况
|
||||
TMP_PATH=/tmp/mp_update_path
|
||||
if [ -d /tmp/mp_update_path ]; then
|
||||
rm -rf /tmp/mp_update_path
|
||||
fi
|
||||
mkdir -p /tmp/mp_update_path
|
||||
fi
|
||||
# 优先级:镜像站 > 全局 > 不代理
|
||||
# pip
|
||||
retries=0
|
||||
while true; do
|
||||
if test_connectivity_pip ${retries}; then
|
||||
break
|
||||
else
|
||||
retries=$((retries + 1))
|
||||
fi
|
||||
done
|
||||
# Github
|
||||
retries=0
|
||||
while true; do
|
||||
if test_connectivity_github ${retries}; then
|
||||
break
|
||||
else
|
||||
retries=$((retries + 1))
|
||||
fi
|
||||
done
|
||||
INFO "PIP:${PIP_LOG},Github:${GITHUB_LOG}"
|
||||
if [ -n "${GITHUB_TOKEN}" ]; then
|
||||
CURL_HEADERS="--oauth2-bearer ${GITHUB_TOKEN}"
|
||||
else
|
||||
CURL_HEADERS=""
|
||||
fi
|
||||
if [ "${MOVIEPILOT_AUTO_UPDATE}" = "dev" ]; then
|
||||
INFO "Dev 更新模式"
|
||||
install_backend_and_download_resources "heads/v2.zip"
|
||||
else
|
||||
INFO "Release 更新模式"
|
||||
old_version=$(grep -m -1 "^\s*APP_VERSION\s*=\s*" /app/version.py | tr -d '\r\n' | awk -F'#' '{print $1}' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')
|
||||
if [[ "${old_version}" == *APP_VERSION* ]]; then
|
||||
current_version=$(echo "${old_version}" | sed -rn "s/APP_VERSION\s*=\s*['\"](.*)['\"]/\1/gp")
|
||||
INFO "当前版本号:${current_version}"
|
||||
# 获取所有发布的版本列表,并筛选出以v2开头的版本号
|
||||
releases=$(curl ${CURL_OPTIONS} "https://api.github.com/repos/jxxghp/MoviePilot/releases" ${CURL_HEADERS} | jq -r '.[].tag_name' | grep "^v2\.")
|
||||
if [ -z "$releases" ]; then
|
||||
WARN "未找到任何v2后端版本,继续启动..."
|
||||
else
|
||||
# 找到最新的v2版本
|
||||
latest_v2=$(echo "$releases" | sort -V | tail -n 1)
|
||||
INFO "最新的v2后端版本号:${latest_v2}"
|
||||
# 使用版本号比较函数进行比较,并下载最新版本
|
||||
compare_versions "${current_version}" "${latest_v2}"
|
||||
fi
|
||||
else
|
||||
WARN "当前版本号获取失败,继续启动..."
|
||||
fi
|
||||
fi
|
||||
if [ -d "${TMP_PATH}" ]; then
|
||||
rm -rf "${TMP_PATH}"
|
||||
fi
|
||||
INFO "▄■▀▄■▀▄■▀▄■▀▄■▀ 自动更新完成 ▀■▄▀■▄▀■▄▀■▄▀■▄"
|
||||
elif [[ "${MOVIEPILOT_AUTO_UPDATE}" = "false" ]]; then
|
||||
INFO "程序自动升级已关闭,如需自动升级请在创建容器时设置环境变量:MOVIEPILOT_AUTO_UPDATE=release"
|
||||
else
|
||||
INFO "MOVIEPILOT_AUTO_UPDATE 变量设置错误"
|
||||
fi
|
||||
Reference in New Issue
Block a user