fix: 多种docker build 编译方式

This commit is contained in:
TOM88812
2025-02-18 14:56:53 +08:00
parent 5fb89ee83c
commit 899b5b682b
2 changed files with 65 additions and 3 deletions
Executable
+57
View File
@@ -0,0 +1,57 @@
# 第一阶段:前端构建
FROM node:18 AS frontend-builder
WORKDIR /app/ZhiKongTaiWeb
# 配置npm使用淘宝源
RUN npm config set registry https://registry.npmmirror.com
COPY ZhiKongTaiWeb/package*.json ./
# 安装axios依赖
RUN npm install axios
RUN npm install
COPY ZhiKongTaiWeb .
RUN npm run build
# 第二阶段:构建Python依赖
FROM python:3.10-slim AS builder
WORKDIR /app
COPY requirements.txt .
# 优化apt安装
RUN 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 && \
apt-get update && \
apt-get install -y --no-install-recommends gcc libopus-dev ffmpeg && \
rm -rf /var/lib/apt/lists/* && \
# 直接使用系统Python
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
# 优化apt安装
RUN 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 && \
apt-get update && \
apt-get install -y --no-install-recommends libopus0 ffmpeg && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 从构建阶段复制Python包和前端构建产物
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=frontend-builder /app/ZhiKongTaiWeb/dist /opt/xiaozhi-esp32-server/manager/static/webui
# 复制应用代码
COPY . .
# 启动应用
CMD ["python", "app.py"]
+8 -3
View File
@@ -6,7 +6,12 @@ services:
#security_opt:
# - seccomp:unconfined
ports:
- "8000:8000"
- "8002:8002"
- "8000:8000" # ws服务端
- "8002:8002" # 管理后台
volumes:
- ./.config.yaml:/opt/xiaozhi-esp32-server/config.yaml
# 配置文件 记得创建文件夹
- ./data:/opt/xiaozhi-esp32-server/data
# 模型文件 //可以挂载本地下载好的模型
#- ./models:/opt/xiaozhi-esp32-server/models
# 临时文件 //可以看log和音频文件 记得创建文件夹
#- ./tmp:/opt/xiaozhi-esp32-server/tmp