From da3bbd6acb92c6be2e85de390d206c6a9da0ab7b Mon Sep 17 00:00:00 2001 From: frlda <97551927+frlda@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:49:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=8C=E5=96=84dockerfile=EF=BC=8Cpython?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E8=AE=BE=E7=BD=AE=E4=B8=BA3.12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3761c0882..77519d3d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,24 @@ FROM ubuntu:22.04 AS ubuntu-base # 设置环境变量以避免tzdata的交互式提示 -ENV DEBIAN_FRONTEND noninteractive +ENV DEBIAN_FRONTEND=noninteractive -# 安装必要的系统库 +# 安装系统依赖和 Python 3.12 RUN apt-get update && \ apt-get install -y software-properties-common && \ add-apt-repository ppa:deadsnakes/ppa && \ apt-get update && \ - apt-get install -y python3.8 python3.8-venv python3.8-tk python3.8-dev python3-pip \ + apt-get install -y python3.12 python3.12-venv python3.12-tk python3.12-dev python3-pip \ build-essential libgirepository1.0-dev gcc libcairo2-dev pkg-config libzbar0 adb git \ libgtk-3-dev gir1.2-webkit2-4.1 gir1.2-appindicator3-0.1 gobject-introspection tk8.6 \ - xvfb \ - dbus \ - && rm -rf /var/lib/apt/lists/* + xvfb dbus && \ + rm -rf /var/lib/apt/lists/* +# 设置 Python 3.12 为默认 Python 版本 +RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \ + update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \ + update-alternatives --set python3 /usr/bin/python3.12 && \ + update-alternatives --set python /usr/bin/python3.12 # 使用官方Node.js 18镜像作为基础镜像构建前端 @@ -24,24 +28,26 @@ WORKDIR /app/ui # 安装前端依赖并构建 COPY ui/package*.json ./ COPY ui/. . -RUN npm ci -RUN npm run build --no-update-notifier - +RUN npm config set registry https://registry.npmmirror.com +RUN npm ci --verbose +RUN npm run build --no-update-notifier -# 合并阶段,使用Python环境为基础,将构建好的前端加入 FROM ubuntu-base AS final WORKDIR /app COPY --from=node-base /app/ui/dist ./ui/dist COPY . . -# 设置Python虚拟环境并安装依赖 -RUN python3.8 -m venv venv - +# 设置pip国内镜像源 +RUN python3.12 -m ensurepip --upgrade RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ - -RUN . venv/bin/activate && pip install --upgrade pip && pip install -r requirements.txt && pip install pycairo PyGObject - +# 设置 Python 虚拟环境并安装依赖 +RUN python3.12 -m venv venv && \ + . venv/bin/activate && \ + pip install --upgrade pip && \ + pip install -r requirements.txt && \ + pip install pycairo PyGObject + # 运行应用 -ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"] From e95cb3a0d4a505cc8d98470fc4d1c518bbd9fa34 Mon Sep 17 00:00:00 2001 From: frlda <97551927+frlda@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:52:05 +0800 Subject: [PATCH 2/3] Update entrypoint.sh --- entrypoint.sh | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 9a04e1c01..f9f95780e 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,14 +1,31 @@ #!/bin/bash -ln -s ui/dist . +# 清理 Xvfb 锁文件 +if [ -f /tmp/.X99-lock ]; then + echo "Cleaning up Xvfb lock file" + rm -f /tmp/.X99-lock +fi -# 启动Xvfb +# 启动 Xvfb +echo "Starting Xvfb on DISPLAY=:99" Xvfb :99 -screen 0 1280x1024x24 & +sleep 2 -export DISPLAY=":99" +# 检查 Xvfb 是否正常运行 +if ! xdpyinfo -display :99 >/dev/null 2>&1; then + echo "Xvfb failed to start" + exit 1 +fi -# 等待Xvfb启动完成 -sleep 5 +# 设置 DISPLAY 环境变量 +export DISPLAY=:99 +echo "DISPLAY is set to $DISPLAY" + +# 创建符号链接 +if [ ! -L "./dist" ]; then + ln -s ui/dist ./dist +fi # 启动应用 -dbus-run-session -- ./venv/bin/python /app/webview_ui.py \ No newline at end of file +echo "Starting application..." +dbus-run-session -- ./venv/bin/python /app/webview_ui.py From 10446ba8a40d3bed0e28aa1467419569d9a9736e Mon Sep 17 00:00:00 2001 From: frlda Date: Fri, 7 Feb 2025 18:59:13 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Docker=E6=9E=84=E5=BB=BA=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 36 ++++++++++++++++++++---------------- entrypoint.sh | 6 +++--- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 77519d3d3..beee65795 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,19 @@ FROM ubuntu:22.04 AS ubuntu-base - +# 部署教程参考https://www.cnblogs.com/frinda/p/18702822 # 设置环境变量以避免tzdata的交互式提示 ENV DEBIAN_FRONTEND=noninteractive -# 安装系统依赖和 Python 3.12 -RUN apt-get update && \ +# 替换APT源为阿里云镜像源,提高下载速度,安装系统依赖和 Python 3.12 +RUN sed -i 's|http://archive.ubuntu.com/ubuntu/|https://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list && \ + sed -i 's|http://security.ubuntu.com/ubuntu|https://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list && \ + apt-get update && \ apt-get install -y software-properties-common && \ add-apt-repository ppa:deadsnakes/ppa && \ apt-get update && \ apt-get install -y python3.12 python3.12-venv python3.12-tk python3.12-dev python3-pip \ - build-essential libgirepository1.0-dev gcc libcairo2-dev pkg-config libzbar0 adb git \ - libgtk-3-dev gir1.2-webkit2-4.1 gir1.2-appindicator3-0.1 gobject-introspection tk8.6 \ - xvfb dbus && \ + build-essential libgirepository1.0-dev gcc libcairo2-dev fish nano wget pkg-config libzbar0 adb git \ + libgtk-3-dev gir1.2-webkit2-4.1 gir1.2-appindicator3-0.1 gobject-introspection tk8.6 \ + xvfb dbus && \ rm -rf /var/lib/apt/lists/* # 设置 Python 3.12 为默认 Python 版本 @@ -20,34 +22,36 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 & update-alternatives --set python3 /usr/bin/python3.12 && \ update-alternatives --set python /usr/bin/python3.12 - -# 使用官方Node.js 18镜像作为基础镜像构建前端 +# 使用官方 Node.js 18 镜像作为基础镜像构建前端 FROM node:18 AS node-base WORKDIR /app/ui # 安装前端依赖并构建 -COPY ui/package*.json ./ +COPY ui/package*.json ./ COPY ui/. . -RUN npm config set registry https://registry.npmmirror.com -RUN npm ci --verbose -RUN npm run build --no-update-notifier +RUN npm config set registry https://registry.npmmirror.com && \ + npm ci --verbose && \ + npm run build --no-update-notifier +# 将 Ubuntu 基础镜像作为最终运行镜像 FROM ubuntu-base AS final WORKDIR /app + +# 复制前端构建产出 COPY --from=node-base /app/ui/dist ./ui/dist COPY . . +# 设置 pip 国内镜像源 +RUN python3.12 -m ensurepip --upgrade && \ + pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ -# 设置pip国内镜像源 -RUN python3.12 -m ensurepip --upgrade -RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ # 设置 Python 虚拟环境并安装依赖 RUN python3.12 -m venv venv && \ . venv/bin/activate && \ pip install --upgrade pip && \ pip install -r requirements.txt && \ pip install pycairo PyGObject - + # 运行应用 ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index f9f95780e..84b7b65a2 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/bash -# 清理 Xvfb 锁文件 +# 清理 Xvfb 锁文件,防止容器因为异常关闭而重启失败 if [ -f /tmp/.X99-lock ]; then echo "Cleaning up Xvfb lock file" rm -f /tmp/.X99-lock @@ -26,6 +26,6 @@ if [ ! -L "./dist" ]; then ln -s ui/dist ./dist fi -# 启动应用 +# 启动mower应用 echo "Starting application..." -dbus-run-session -- ./venv/bin/python /app/webview_ui.py +dbus-run-session -- ./venv/bin/python /app/webview_ui.py \ No newline at end of file