Skip to content

Commit 18abb9b

Browse files
authored
Merge pull request #727 from frlda/main
Docker构建支持更新
2 parents 86ae3cf + 10446ba commit 18abb9b

File tree

2 files changed

+59
-32
lines changed

2 files changed

+59
-32
lines changed

Dockerfile

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,57 @@
11
FROM ubuntu:22.04 AS ubuntu-base
2-
2+
# 部署教程参考https://www.cnblogs.com/frinda/p/18702822
33
# 设置环境变量以避免tzdata的交互式提示
4-
ENV DEBIAN_FRONTEND noninteractive
4+
ENV DEBIAN_FRONTEND=noninteractive
55

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 && \
810
apt-get install -y software-properties-common && \
911
add-apt-repository ppa:deadsnakes/ppa && \
1012
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 镜像作为基础镜像构建前端
2126
FROM node:18 AS node-base
2227
WORKDIR /app/ui
2328

2429
# 安装前端依赖并构建
25-
COPY ui/package*.json ./
30+
COPY ui/package*.json ./
2631
COPY ui/. .
27-
RUN npm ci
28-
RUN npm run build --no-update-notifier
2932

33+
RUN npm config set registry https://registry.npmmirror.com && \
34+
npm ci --verbose && \
35+
npm run build --no-update-notifier
3036

31-
32-
# 合并阶段,使用Python环境为基础,将构建好的前端加入
37+
# 将 Ubuntu 基础镜像作为最终运行镜像
3338
FROM ubuntu-base AS final
3439
WORKDIR /app
40+
41+
# 复制前端构建产出
3542
COPY --from=node-base /app/ui/dist ./ui/dist
3643
COPY . .
3744

45+
# 设置 pip 国内镜像源
46+
RUN python3.12 -m ensurepip --upgrade && \
47+
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
3848

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
4555

4656
# 运行应用
47-
ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"]
57+
ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"]

entrypoint.sh

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
#!/bin/bash
22

3-
ln -s ui/dist .
3+
# 清理 Xvfb 锁文件,防止容器因为异常关闭而重启失败
4+
if [ -f /tmp/.X99-lock ]; then
5+
echo "Cleaning up Xvfb lock file"
6+
rm -f /tmp/.X99-lock
7+
fi
48

5-
# 启动Xvfb
9+
# 启动 Xvfb
10+
echo "Starting Xvfb on DISPLAY=:99"
611
Xvfb :99 -screen 0 1280x1024x24 &
12+
sleep 2
713

8-
export DISPLAY=":99"
14+
# 检查 Xvfb 是否正常运行
15+
if ! xdpyinfo -display :99 >/dev/null 2>&1; then
16+
echo "Xvfb failed to start"
17+
exit 1
18+
fi
919

10-
# 等待Xvfb启动完成
11-
sleep 5
20+
# 设置 DISPLAY 环境变量
21+
export DISPLAY=:99
22+
echo "DISPLAY is set to $DISPLAY"
1223

13-
# 启动应用
24+
# 创建符号链接
25+
if [ ! -L "./dist" ]; then
26+
ln -s ui/dist ./dist
27+
fi
28+
29+
# 启动mower应用
30+
echo "Starting application..."
1431
dbus-run-session -- ./venv/bin/python /app/webview_ui.py

0 commit comments

Comments
 (0)