diff --git a/.gitignore b/.gitignore index 0a545fa8..8be615c0 100644 --- a/.gitignore +++ b/.gitignore @@ -143,4 +143,5 @@ tmp .config.yaml .secrets.yaml .private_config.yaml +.env.development docker-compose.yml diff --git a/Dockerfile-pip b/Dockerfile-pip new file mode 100755 index 00000000..4eabb69f --- /dev/null +++ b/Dockerfile-pip @@ -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"] \ No newline at end of file diff --git a/docker-compose-example.yml b/docker-compose-example.yml index 41a4ebf9..ab97b6eb 100755 --- a/docker-compose-example.yml +++ b/docker-compose-example.yml @@ -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 \ No newline at end of file + # 配置文件 记得创建文件夹 + - ./data:/opt/xiaozhi-esp32-server/data + # 模型文件 //可以挂载本地下载好的模型 + #- ./models:/opt/xiaozhi-esp32-server/models + # 临时文件 //可以看log和音频文件 记得创建文件夹 + #- ./tmp:/opt/xiaozhi-esp32-server/tmp