1
1
FROM ubuntu:22.04 AS ubuntu-base
2
-
2
+ # 部署教程参考https://www.cnblogs.com/frinda/p/18702822
3
3
# 设置环境变量以避免tzdata的交互式提示
4
- ENV DEBIAN_FRONTEND noninteractive
4
+ ENV DEBIAN_FRONTEND= noninteractive
5
5
6
- # 安装必要的系统库
7
- RUN apt-get update && \
6
+ # 替换APT源为阿里云镜像源,提高下载速度,安装系统依赖和 Python 3.12
7
+ RUN sed -i 's|http://archive.ubuntu.com/ubuntu/|https://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list && \
8
+ sed -i 's|http://security.ubuntu.com/ubuntu|https://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list && \
9
+ apt-get update && \
8
10
apt-get install -y software-properties-common && \
9
11
add-apt-repository ppa:deadsnakes/ppa && \
10
12
apt-get update && \
11
- apt-get install -y python3.8 python3.8-venv python3.8-tk python3.8-dev python3-pip \
12
- build-essential libgirepository1.0-dev gcc libcairo2-dev pkg-config libzbar0 adb git \
13
- libgtk-3-dev gir1.2-webkit2-4.1 gir1.2-appindicator3-0.1 gobject-introspection tk8.6 \
14
- xvfb \
15
- dbus \
16
- && rm -rf /var/lib/apt/lists/*
17
-
18
-
19
-
20
- # 使用官方Node.js 18镜像作为基础镜像构建前端
13
+ apt-get install -y python3.12 python3.12-venv python3.12-tk python3.12-dev python3-pip \
14
+ build-essential libgirepository1.0-dev gcc libcairo2-dev fish nano wget pkg-config libzbar0 adb git \
15
+ libgtk-3-dev gir1.2-webkit2-4.1 gir1.2-appindicator3-0.1 gobject-introspection tk8.6 \
16
+ xvfb dbus && \
17
+ rm -rf /var/lib/apt/lists/*
18
+
19
+ # 设置 Python 3.12 为默认 Python 版本
20
+ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \
21
+ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \
22
+ update-alternatives --set python3 /usr/bin/python3.12 && \
23
+ update-alternatives --set python /usr/bin/python3.12
24
+
25
+ # 使用官方 Node.js 18 镜像作为基础镜像构建前端
21
26
FROM node:18 AS node-base
22
27
WORKDIR /app/ui
23
28
24
29
# 安装前端依赖并构建
25
- COPY ui/package*.json ./
30
+ COPY ui/package*.json ./
26
31
COPY ui/. .
27
- RUN npm ci
28
- RUN npm run build --no-update-notifier
29
32
33
+ RUN npm config set registry https://registry.npmmirror.com && \
34
+ npm ci --verbose && \
35
+ npm run build --no-update-notifier
30
36
31
-
32
- # 合并阶段,使用Python环境为基础,将构建好的前端加入
37
+ # 将 Ubuntu 基础镜像作为最终运行镜像
33
38
FROM ubuntu-base AS final
34
39
WORKDIR /app
40
+
41
+ # 复制前端构建产出
35
42
COPY --from=node-base /app/ui/dist ./ui/dist
36
43
COPY . .
37
44
45
+ # 设置 pip 国内镜像源
46
+ RUN python3.12 -m ensurepip --upgrade && \
47
+ pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
38
48
39
- # 设置Python虚拟环境并安装依赖
40
- RUN python3.8 -m venv venv
41
-
42
- RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
43
-
44
- RUN . venv/bin/activate && pip install --upgrade pip && pip install -r requirements.txt && pip install pycairo PyGObject
49
+ # 设置 Python 虚拟环境并安装依赖
50
+ RUN python3.12 -m venv venv && \
51
+ . venv/bin/activate && \
52
+ pip install --upgrade pip && \
53
+ pip install -r requirements.txt && \
54
+ pip install pycairo PyGObject
45
55
46
56
# 运行应用
47
- ENTRYPOINT ["/bin/bash" , "/app/entrypoint.sh" ]
57
+ ENTRYPOINT ["/bin/bash" , "/app/entrypoint.sh" ]
0 commit comments