diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 000000000..b957ee2e1 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,46 @@ +name: Docker Image CI + +on: + push: + tags: + - 'v*.*.*' # 只在以 v 开头的标签推送时触发,例如 v1.0.0 + +jobs: + release: + name: Release Docker image + runs-on: ubuntu-latest + permissions: + packages: write + contents: write + id-token: write + issues: write + + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.TOKEN }} + + - name: Extract version from tag + id: get_version + run: | + echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - name: Build and push Docker image + id: build_push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + ghcr.io/${{ github.repository }}:${{ env.VERSION }} + ghcr.io/${{ github.repository }}:latest + platforms: linux/amd64,linux/arm64 diff --git a/.gitignore b/.gitignore index f93674901..6ad8d3502 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Byte-compiled / optimized / DLL files __pycache__/ +.idea/ *.py[cod] *$py.class @@ -144,4 +145,5 @@ tmp .config.yaml .secrets.yaml .private_config.yaml +.env.development docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 1ffad2d81..9648b7b58 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,46 +1,45 @@ # 第一阶段:前端构建 -FROM node:18 AS frontend-builder + +FROM kalicyh/node:v18-alpine AS frontend-builder WORKDIR /app/ZhiKongTaiWeb -RUN corepack enable && yarn config set registry https://registry.npmmirror.com +# RUN corepack enable && yarn config set registry https://registry.npmmirror.com COPY ZhiKongTaiWeb/package.json ZhiKongTaiWeb/yarn.lock ./ -RUN mkdir node_modules && yarn install --frozen-lockfile +RUN yarn install --frozen-lockfile COPY ZhiKongTaiWeb . RUN yarn build # 第二阶段:构建 Python 依赖 -FROM ccr.ccs.tencentyun.com/kalicyh/poetry:v3.10_latest AS builder + +FROM kalicyh/poetry:v3.10_xiaozhi AS builder + WORKDIR /app -COPY pyproject.toml poetry.lock /app/ + +# 同时拷贝本地环境.venv +COPY . . +# 检查是否有缺失 RUN poetry install --no-root -# 第三阶段:生产镜像 -FROM python:3.10-slim - -WORKDIR /opt/xiaozhi-esp32-server - -# 使用清华源加速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 update && \ - apt-get install -y --no-install-recommends libopus0 ffmpeg && \ - apt-get clean +# 使用清华源加速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 update && \ +# apt-get install -y --no-install-recommends libopus0 ffmpeg && \ +# apt-get clean # 从构建阶段复制虚拟环境和前端构建产物 -COPY --from=builder /app/.venv /opt/venv -COPY --from=frontend-builder /app/ZhiKongTaiWeb/dist /opt/xiaozhi-esp32-server/manager/static/webui -# 设置虚拟环境路径 -ENV PATH="/opt/venv/bin:$PATH" +COPY --from=frontend-builder /app/ZhiKongTaiWeb/dist /app/manager/static/webui -# 复制应用代码 -COPY . . +# 设置虚拟环境路径 +ENV PATH="/app/.venv/bin:$PATH" # 启动应用 -CMD ["python", "app.py"] \ No newline at end of file +ENTRYPOINT ["poetry", "run", "python"] +CMD ["app.py"] \ No newline at end of file diff --git a/Dockerfile-pip b/Dockerfile-pip new file mode 100755 index 000000000..612866730 --- /dev/null +++ b/Dockerfile-pip @@ -0,0 +1,51 @@ +# 第一阶段:前端构建 +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 pip install --no-cache-dir -r requirements.txt \ + -i https://mirrors.aliyun.com/pypi/simple/ + +# 第三阶段:生产镜像 +FROM python:3.10-slim + +WORKDIR /opt/xiaozhi-esp32-server + +# 优化apt安装 +RUN echo "deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ + echo "deb https://mirrors.aliyun.com/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/README.md b/README.md index 8f7c8c57d..452f21817 100644 --- a/README.md +++ b/README.md @@ -4,29 +4,81 @@ (中文 | [English](README_en.md)) -本项目为开源智能硬件项目 [xiaozhi-esp32](https://github.com/78/xiaozhi-esp32) 提供后端服务。根据 [小智通信协议](https://ccnphfhqs21z.feishu.cn/wiki/M0XiwldO9iJwHikpXD5cEx71nKh) 使用 `Python` 实现。 +本项目为开源智能硬件项目 [xiaozhi-esp32](https://github.com/78/xiaozhi-esp32) +提供后端服务。根据 [小智通信协议](https://ccnphfhqs21z.feishu.cn/wiki/M0XiwldO9iJwHikpXD5cEx71nKh) 使用 `Python` 实现。 --- ## 适用人群 👥 -本项目需要配合 ESP32 硬件设备使用。如果您已经购买了 ESP32 相关硬件,且成功对接过虾哥部署的后端服务,并希望独立搭建自己的 `xiaozhi-esp32` 后端服务,那么本项目非常适合您。 +本项目需要配合 ESP32 硬件设备使用。如果您已经购买了 ESP32 相关硬件,且成功对接过虾哥部署的后端服务,并希望独立搭建自己的 +`xiaozhi-esp32` 后端服务,那么本项目非常适合您。 + +想看使用效果?请猛戳视频 🎥 + +
+
+
+ |
+
+
+
+ |
+
+
+
+ |
+
+
+
+ |
+
+
+
+ |
+ + | +
-