mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 09:33:55 +08:00
🐳 chore(docker): 优化打包速度
使用poetry代替pip,重写dockerfile,修改部署文档
This commit is contained in:
+5
-13
@@ -13,16 +13,10 @@ COPY ZhiKongTaiWeb .
|
|||||||
RUN yarn build
|
RUN yarn build
|
||||||
|
|
||||||
# 第二阶段:构建 Python 依赖
|
# 第二阶段:构建 Python 依赖
|
||||||
FROM python:3.10-slim AS builder
|
FROM ccr.ccs.tencentyun.com/kalicyh/poetry:v3.10_latest AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
COPY pyproject.toml poetry.lock /app/
|
||||||
COPY requirements.txt .
|
RUN poetry install --no-root
|
||||||
|
|
||||||
# 安装Python依赖到虚拟环境
|
|
||||||
RUN python -m venv /opt/venv
|
|
||||||
ENV PATH="/opt/venv/bin:$PATH"
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
||||||
|
|
||||||
# 第三阶段:生产镜像
|
# 第三阶段:生产镜像
|
||||||
FROM python:3.10-slim
|
FROM python:3.10-slim
|
||||||
@@ -35,14 +29,12 @@ RUN rm -rf /etc/apt/sources.list.d/* && \
|
|||||||
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-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/ 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 && \
|
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 update && \
|
||||||
apt-get install -y --no-install-recommends libopus0 ffmpeg && \
|
apt-get install -y --no-install-recommends libopus0 ffmpeg && \
|
||||||
apt-get clean && \
|
apt-get clean
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# 从构建阶段复制虚拟环境和前端构建产物
|
# 从构建阶段复制虚拟环境和前端构建产物
|
||||||
COPY --from=builder /opt/venv /opt/venv
|
COPY --from=builder /app/.venv /opt/venv
|
||||||
COPY --from=frontend-builder /app/ZhiKongTaiWeb/dist /opt/xiaozhi-esp32-server/manager/static/webui
|
COPY --from=frontend-builder /app/ZhiKongTaiWeb/dist /opt/xiaozhi-esp32-server/manager/static/webui
|
||||||
# 设置虚拟环境路径
|
# 设置虚拟环境路径
|
||||||
ENV PATH="/opt/venv/bin:$PATH"
|
ENV PATH="/opt/venv/bin:$PATH"
|
||||||
|
|||||||
+35
-6
@@ -96,19 +96,48 @@ cd xiaozhi-esp32-server
|
|||||||
|
|
||||||
或手动下载 [ZIP 包](https://github.com/xinnan-tech/xiaozhi-esp32-server/archive/refs/heads/main.zip),解压后重命名为 `xiaozhi-esp32-server`。
|
或手动下载 [ZIP 包](https://github.com/xinnan-tech/xiaozhi-esp32-server/archive/refs/heads/main.zip),解压后重命名为 `xiaozhi-esp32-server`。
|
||||||
|
|
||||||
### 2. 运行 Docker
|
## 2.运行docker
|
||||||
|
|
||||||
|
修改完配置后,打开命令行工具,`cd`进入到你的项目目录下,执行以下命令
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker run -d --name xiaozhi-esp32-server --restart always --security-opt seccomp:unconfined \
|
docker run -it --name xiaozhi-env --restart always --security-opt seccomp:unconfined \
|
||||||
-p 8000:8000 \
|
-p 8000:8000 \
|
||||||
-v ./:/opt/xiaozhi-esp32-server \
|
-p 8002:8002 \
|
||||||
ccr.ccs.tencentyun.com/xinnan/xiaozhi-esp32-server:latest
|
-v ./:/app \
|
||||||
|
ccr.ccs.tencentyun.com/kalicyh/poetry:v3.10_latest
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. 修改代码 & 重启 Docker
|
然后就和正常开发一样了
|
||||||
|
|
||||||
|
## 3.安装依赖
|
||||||
|
|
||||||
|
在刚刚的打开的终端运行
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker restart xiaozhi-esp32-server
|
poetry install --no-root
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y --no-install-recommends libopus0 ffmpeg
|
||||||
|
```
|
||||||
|
|
||||||
|
速度慢可以尝试使用清华镜像
|
||||||
|
|
||||||
|
```sh
|
||||||
|
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 update
|
||||||
|
apt-get install -y --no-install-recommends libopus0 ffmpeg
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4.运行项目
|
||||||
|
|
||||||
|
```sh
|
||||||
|
poetry run python app.py
|
||||||
```
|
```
|
||||||
|
|
||||||
## 方式三:本地运行(适用于开发)
|
## 方式三:本地运行(适用于开发)
|
||||||
|
|||||||
+33
-25
@@ -42,25 +42,10 @@ docker run -d --name xiaozhi-esp32-server --restart always --security-opt seccom
|
|||||||
|
|
||||||
3.按本教程重新来一遍
|
3.按本教程重新来一遍
|
||||||
|
|
||||||
# 方式二:借助docker环境运行部署
|
# 方式二:借助docker环境运行部署(仅限开发人员/小白勿用)
|
||||||
|
|
||||||
## 1.克隆项目
|
## 1.克隆项目
|
||||||
|
|
||||||
这个方法的原理,其实是和第一种方式类似。区别在于,第一种方式只要下载一个配置文件,而本方式要下载项目源码。
|
|
||||||
|
|
||||||
优点就是源码在你主机躺着,你可以使用本机的代码编辑器加载项目和修改源码。每次修改完项目,想要看效果,那就要重启docker。
|
|
||||||
|
|
||||||
缺点就要下载本项目的代码,还要下载模型文件,如果这个项目不常用,确实会占用您电脑的空间。
|
|
||||||
|
|
||||||
你先要下载本项目源码,源码可以通过`git clone`命令下载,如果你不熟悉`git clone`命令。
|
|
||||||
|
|
||||||
你可以用浏览器打开这个地址`https://github.com/xinnan-tech/xiaozhi-esp32-server.git`
|
|
||||||
|
|
||||||
打开完,找到页面中一个绿色的按钮,写着`Code`的按钮,点开它,然后你就看到`Download ZIP`的按钮。
|
|
||||||
|
|
||||||
点击它,下载本项目源码压缩包。下载到你电脑后,解压它,此时它的名字可能叫`xiaozhi-esp32-server-main`
|
|
||||||
你需要把它重命名成`xiaozhi-esp32-server`,好了请记住这个目录,我们暂且称它为`项目目录`。
|
|
||||||
|
|
||||||
## 2.[跳转到下载语音识别模型文件](#模型文件)
|
## 2.[跳转到下载语音识别模型文件](#模型文件)
|
||||||
|
|
||||||
## 3.[跳转到配置项目文件](#配置项目)
|
## 3.[跳转到配置项目文件](#配置项目)
|
||||||
@@ -69,21 +54,44 @@ docker run -d --name xiaozhi-esp32-server --restart always --security-opt seccom
|
|||||||
|
|
||||||
修改完配置后,打开命令行工具,`cd`进入到你的项目目录下,执行以下命令
|
修改完配置后,打开命令行工具,`cd`进入到你的项目目录下,执行以下命令
|
||||||
|
|
||||||
```
|
```sh
|
||||||
docker run -d --name xiaozhi-esp32-server --restart always --security-opt seccomp:unconfined \
|
docker run -it --name xiaozhi-env --restart always --security-opt seccomp:unconfined \
|
||||||
-p 8000:8000 \
|
-p 8000:8000 \
|
||||||
-v ./:/opt/xiaozhi-esp32-server \
|
-p 8002:8002 \
|
||||||
ccr.ccs.tencentyun.com/xinnan/xiaozhi-esp32-server:latest
|
-v ./:/app \
|
||||||
|
ccr.ccs.tencentyun.com/kalicyh/poetry:v3.10_latest
|
||||||
```
|
```
|
||||||
|
|
||||||
## 5.[跳转到运行状态确认](#运行状态确认)
|
然后就和正常开发一样了
|
||||||
|
|
||||||
后期,如果你修改了代码,想让新代码跑起来,可以用以下命令让docker容器重启:
|
## 5.安装依赖
|
||||||
|
|
||||||
|
在刚刚的打开的终端运行
|
||||||
|
|
||||||
|
```sh
|
||||||
|
poetry install --no-root
|
||||||
```
|
```
|
||||||
docker restart xiaozhi-esp32-server
|
|
||||||
# 查看日志输出
|
```sh
|
||||||
docker logs -f xiaozhi-esp32-server
|
apt-get update
|
||||||
|
apt-get install -y --no-install-recommends libopus0 ffmpeg
|
||||||
|
```
|
||||||
|
|
||||||
|
速度慢可以尝试使用清华镜像
|
||||||
|
|
||||||
|
```sh
|
||||||
|
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 update
|
||||||
|
apt-get install -y --no-install-recommends libopus0 ffmpeg
|
||||||
|
```
|
||||||
|
|
||||||
|
## 6.运行项目
|
||||||
|
|
||||||
|
```sh
|
||||||
|
poetry run python app.py
|
||||||
```
|
```
|
||||||
|
|
||||||
# 方式三:本地源码运行
|
# 方式三:本地源码运行
|
||||||
|
|||||||
Generated
+4349
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
|||||||
|
[tool.poetry]
|
||||||
|
name = "xiaozhi-esp32-server"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = ""
|
||||||
|
authors = ["kalicyh <34980061+kaliCYH@users.noreply.github.com>"]
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
python = "^3.10.16"
|
||||||
|
pyyml = "0.0.2"
|
||||||
|
torch = "2.2.2"
|
||||||
|
silero-vad = "5.1.2"
|
||||||
|
websockets = "14.2"
|
||||||
|
opuslib = "3.0.1"
|
||||||
|
numpy = "1.26.4"
|
||||||
|
pydub = "0.25.1"
|
||||||
|
funasr = "1.2.3"
|
||||||
|
torchaudio = "2.2.2"
|
||||||
|
openai = "1.61.0"
|
||||||
|
google-generativeai = "0.8.4"
|
||||||
|
edge-tts = "7.0.0"
|
||||||
|
httpx = "0.27.2"
|
||||||
|
aiohttp = "3.9.3"
|
||||||
|
aiohttp-cors = "0.7.0"
|
||||||
|
ormsgpack = "1.7.0"
|
||||||
|
ruamel-yaml = "0.18.10"
|
||||||
|
setuptools = "^75.8.0"
|
||||||
|
|
||||||
|
|
||||||
|
[[tool.poetry.source]]
|
||||||
|
name = "mirrors"
|
||||||
|
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
|
||||||
|
priority = "primary"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
||||||
Reference in New Issue
Block a user