From 5b6899052a6e5a3d3cca33b8f94d9884e60f483d Mon Sep 17 00:00:00 2001 From: TOM88812 Date: Sat, 15 Feb 2025 22:36:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DWebUI=20api=20=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=9C=B0=E5=9D=80=EF=BC=8C=E6=9B=B4=E6=96=B0docker=20?= =?UTF-8?q?=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 46 +++++++++++++++---- ZhiKongTaiWeb/.env.development | 2 +- ZhiKongTaiWeb/.env.production | 2 +- ZhiKongTaiWeb/src/App.vue | 2 +- ZhiKongTaiWeb/src/components/Login.vue | 4 +- ZhiKongTaiWeb/src/components/Registration.vue | 4 +- ZhiKongTaiWeb/src/components/RoleSetting.vue | 5 +- ZhiKongTaiWeb/src/components/panel.vue | 3 +- ZhiKongTaiWeb/src/config/api.js | 16 +++++++ app.py | 20 ++++++++ core/webui.py | 4 ++ manager/static/webui/assets/index-xClKUcGO.js | 6 +-- run_webui.py | 12 ----- 13 files changed, 93 insertions(+), 33 deletions(-) create mode 100644 ZhiKongTaiWeb/src/config/api.js delete mode 100644 run_webui.py diff --git a/Dockerfile b/Dockerfile index cf709a71..f19d7a22 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,31 @@ -# 第一阶段:构建依赖 +# 第一阶段:前端构建 +FROM node:18 as frontend-builder + +WORKDIR /app/ZhiKongTaiWeb + +COPY ZhiKongTaiWeb/package*.json ./ + +RUN npm install + +COPY ZhiKongTaiWeb . + +RUN npm run build + +# 第二阶段:构建Python依赖 FROM python:3.10-slim as builder WORKDIR /app COPY requirements.txt . -# 安装构建依赖 -RUN apt-get update && \ +# 使用清华源加速apt安装 +RUN rm -rf /etc/apt/sources.list.d/* && \ + echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ + echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + apt-get clean && \ + apt-get update && \ apt-get install -y --no-install-recommends \ gcc \ libopus-dev \ @@ -16,24 +35,31 @@ RUN apt-get update && \ # 安装Python依赖到虚拟环境 RUN python -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" -RUN pip install --no-cache-dir -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ +RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple -# 第二阶段:生产镜像 +# 第三阶段:生产镜像 FROM python:3.10-slim WORKDIR /opt/xiaozhi-esp32-server -# 从构建阶段复制虚拟环境 -COPY --from=builder /opt/venv /opt/venv - -# 安装运行时依赖 -RUN apt-get update && \ +# 使用清华源加速apt安装 +RUN rm -rf /etc/apt/sources.list.d/* && \ + echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ + echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + apt-get clean && \ + apt-get update && \ apt-get install -y --no-install-recommends \ libopus0 \ ffmpeg && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* +# 从构建阶段复制虚拟环境和前端构建产物 +COPY --from=builder /opt/venv /opt/venv +COPY --from=frontend-builder /app/ZhiKongTaiWeb/dist /opt/xiaozhi-esp32-server/manager/static + # 设置虚拟环境路径 ENV PATH="/opt/venv/bin:$PATH" diff --git a/ZhiKongTaiWeb/.env.development b/ZhiKongTaiWeb/.env.development index d3109bfe..296f5314 100644 --- a/ZhiKongTaiWeb/.env.development +++ b/ZhiKongTaiWeb/.env.development @@ -1 +1 @@ -VITE_API_BASE_URL=http://localhost:8002 +VITE_API_BASE_URL='' diff --git a/ZhiKongTaiWeb/.env.production b/ZhiKongTaiWeb/.env.production index d3109bfe..adc0b5df 100644 --- a/ZhiKongTaiWeb/.env.production +++ b/ZhiKongTaiWeb/.env.production @@ -1 +1 @@ -VITE_API_BASE_URL=http://localhost:8002 +VITE_API_BASE_URL='' # 空字符串表示使用当前域名和端口 diff --git a/ZhiKongTaiWeb/src/App.vue b/ZhiKongTaiWeb/src/App.vue index eb393f54..de9472b9 100644 --- a/ZhiKongTaiWeb/src/App.vue +++ b/ZhiKongTaiWeb/src/App.vue @@ -24,7 +24,7 @@ import Login from './components/Login.vue'; import Registration from './components/Registration.vue'; import panel from './components/panel.vue'; -import MainPage from './components/main.vue'; +import MainPage from './components/Main.vue'; import RoleSetting from './components/RoleSetting.vue'; import Footer from './components/Footer.vue'; diff --git a/ZhiKongTaiWeb/src/components/Login.vue b/ZhiKongTaiWeb/src/components/Login.vue index 6593f892..575d2539 100644 --- a/ZhiKongTaiWeb/src/components/Login.vue +++ b/ZhiKongTaiWeb/src/components/Login.vue @@ -17,6 +17,8 @@