forked from biliup/biliup
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfileLocal
More file actions
148 lines (130 loc) · 5.62 KB
/
Copy pathDockerfileLocal
File metadata and controls
148 lines (130 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# 使用ARG定义可配置的构建参数,增加灵活性
ARG NODE_VERSION=lts
ARG PYTHON_VERSION=3.12
# =================================================================
# Stage 1: Build Web UI (前端构建阶段)
# =================================================================
FROM node:${NODE_VERSION}-slim AS webui
WORKDIR /biliuplocal
ENV LANG=C.UTF-8 \
LANGUAGE=C.UTF-8 \
LC_ALL=C.UTF-8 \
TZ=Asia/Shanghai \
DEBIAN_FRONTEND=noninteractive
# --- APT 源配置 ---
# 对于中国大陆用户,使用华为云镜像可以显著加速。
# 对于非中国大陆用户,请注释掉下面的 【华为云镜像】 代码块,并取消注释 【Debian 官方源】 代码块。
#
# [华为云镜像] - 适用于中国大陆用户
RUN \
echo "deb http://repo.huaweicloud.com/debian bookworm main" > /etc/apt/sources.list && \
apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
sed -i 's#http://deb.debian.org#https://repo.huaweicloud.com#g' /etc/apt/sources.list.d/debian.sources && \
rm /etc/apt/sources.list && \
apt-get update && \
apt-get install -y --no-install-recommends git && \
rm -rf /var/lib/apt/lists/*
#
# [Debian 官方源] - 适用于非中国大陆用户
# RUN apt-get update && \
# apt-get install -y --no-install-recommends git ca-certificates && \
# rm -rf /var/lib/apt/lists/*
# --- Git 和 NPM 加速配置 ---
# 对于中国大陆用户,此配置可以加速依赖下载。
# 对于非中国大陆用户,可以注释掉整个 RUN 代码块。
RUN \
git config --global url."https://github.geekery.cn/https://github.com/".insteadOf "https://github.com/" && \
npm config set registry https://registry.npmmirror.com/
# 优化文件复制顺序,最大化利用Docker缓存
COPY package*.json ./
COPY scripts/ ./scripts/
# 同时复制CHANGELOG.md,因为前端构建执行的脚本依赖它
COPY CHANGELOG.md ./
RUN npm install
COPY app ./app
COPY public ./public
COPY next.config.js ./
COPY tsconfig.json ./
# 创建构建脚本所需的目标目录并执行构建
RUN \
mkdir -p ./biliup/web/public && \
npm run build && \
npm cache clean --force
# =================================================================
# Stage 2: Final Application (最终应用阶段)
# =================================================================
FROM python:${PYTHON_VERSION}-slim AS biliup
WORKDIR /biliuplocal
ENV LANG=C.UTF-8 \
LANGUAGE=C.UTF-8 \
LC_ALL=C.UTF-8 \
TZ=Asia/Shanghai \
DEBIAN_FRONTEND=noninteractive
EXPOSE 19159/tcp
VOLUME /opt
COPY pyproject.toml setup.py README.md ./
COPY biliup ./biliup/
# 优化APT、FFmpeg和Python依赖的安装过程
RUN \
# --- APT 源配置 ---
# 对于中国大陆用户,使用华为云镜像可以显著加速。
# 对于非中国大陆用户,请注释掉 【华为云镜像】 部分,并取消注释 【Debian 官方源】 部分。
#
# [华为云镜像] - 适用于中国大陆用户
echo "deb http://repo.huaweicloud.com/debian bookworm main" > /etc/apt/sources.list && \
apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
sed -i 's#http://deb.debian.org#https://repo.huaweicloud.com#g' /etc/apt/sources.list.d/debian.sources && \
rm /etc/apt/sources.list && \
apt-get update && \
apt-get install -y --no-install-recommends wget xz-utils g++ ; \
#
# [Debian 官方源] - 适用于非中国大陆用户
# apt-get update && \
# apt-get install -y --no-install-recommends ca-certificates wget xz-utils g++ ; \
\
# --- FFmpeg 安装 ---
arch="$(dpkg --print-architecture)"; \
USE_APT_FFMPEG=false; \
case "$arch" in \
'amd64') file_name="ffmpeg-master-latest-linux64-gpl.tar.xz"; ;; \
'arm64') file_name="ffmpeg-master-latest-linuxarm64-gpl.tar.xz"; ;; \
*) \
echo "Unsupported architecture: $arch. Installing FFmpeg from APT." >&2; \
apt-get install -y --no-install-recommends ffmpeg; \
USE_APT_FFMPEG=true; \
;; \
esac; \
if [ "$USE_APT_FFMPEG" = false ]; then \
# --- FFmpeg 下载加速 ---
# 对于中国大陆用户,使用 Github 代理可以加速下载。
# 对于非中国大陆用户,请注释掉 【代理下载】 行,并取消注释 【官方直接下载】 行。
#
# [代理下载] - 适用于中国大陆用户
FFMPEG_URL="https://github.geekery.cn/https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/${file_name}"; \
#
# [官方直接下载] - 适用于非中国大陆用户
# FFMPEG_URL="https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/${file_name}"; \
#
wget -t 2 -T 30 -O ffmpeg.tar.xz "$FFMPEG_URL" || (echo "FFmpeg download failed." >&2 && exit 1); \
tar -xJf ffmpeg.tar.xz -C /usr/local --strip-components=1 && \
rm -rf /usr/local/doc /usr/local/man /usr/local/bin/ffplay && \
rm -f ffmpeg.tar.xz && \
chmod a+x /usr/local/bin/*; \
fi; \
\
# --- Python 依赖安装 ---
# 对于中国大陆用户,使用 PyPI 镜像可以加速。
# 对于非中国大陆用户,可以注释掉下面这行 `pip config`。
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple; \
pip install --no-cache-dir -e . && \
\
# --- 清理所有构建时依赖和缓存 ---
apt-get purge -y --auto-remove g++ wget xz-utils && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 从前端构建阶段复制静态文件
COPY --from=webui /biliuplocal/biliup/web/public/ ./biliup/web/public/
WORKDIR /opt
ENTRYPOINT ["biliup"]