From e4bf5d2d21601320cea978d39a311196b8d4f2e0 Mon Sep 17 00:00:00 2001 From: Chingfeng Li Date: Mon, 20 Oct 2025 15:07:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BAbase=E9=95=9C=E5=83=8F?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E6=9C=89=E5=BD=93=E4=BE=9D=E8=B5=96=E5=8F=91?= =?UTF-8?q?=E7=94=9F=E5=8F=98=E5=8C=96=E6=97=B6=E5=86=8D=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=9E=84=E5=BB=BA=EF=BC=8C=E5=90=A6=E5=88=99?= =?UTF-8?q?=E5=8F=AA=E4=BD=BF=E7=94=A8=E4=B9=8B=E5=89=8D=E7=9A=84base?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E8=BF=9B=E8=A1=8C=E6=9E=84=E5=BB=BA=EF=BC=8C?= =?UTF-8?q?=E8=83=BD=E5=A4=9F=E4=BD=BF=E6=9C=AC=E5=9C=B0=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=9A=84=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-base-image.yml | 50 ++++++++++++++++++++++++++ Dockerfile-server | 34 ++---------------- Dockerfile-server-base | 24 +++++++++++++ 3 files changed, 76 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/build-base-image.yml create mode 100644 Dockerfile-server-base diff --git a/.github/workflows/build-base-image.yml b/.github/workflows/build-base-image.yml new file mode 100644 index 00000000..148bf975 --- /dev/null +++ b/.github/workflows/build-base-image.yml @@ -0,0 +1,50 @@ +name: Build Base Image + +on: + push: + branches: + - main + - master + paths: + - 'main/xiaozhi-server/requirements.txt' + - 'Dockerfile-server-base' + - '.github/workflows/build-base-image.yml' + +jobs: + build-base: + name: Build and push server base image + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.TOKEN }} + + - name: Build and push server-base + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile-server-base + push: true + tags: ghcr.io/${{ github.repository }}:server-base + platforms: linux/amd64 + cache-from: type=gha,scope=server-base + cache-to: type=gha,mode=max,scope=server-base + build-args: | + BUILDKIT_PROGRESS=plain + + - name: Output image info + run: | + echo "✅ Base image built and pushed successfully!" + echo "📦 Tag: ghcr.io/${{ github.repository }}:server-base" diff --git a/Dockerfile-server b/Dockerfile-server index a12fbb11..9df93c9e 100644 --- a/Dockerfile-server +++ b/Dockerfile-server @@ -1,36 +1,6 @@ -# 第一阶段:构建Python依赖 -FROM python:3.10-slim AS builder +# 生产镜像,仅包含应用代码 +FROM ghcr.io/xinnan-tech/xiaozhi-esp32-server:server-base -WORKDIR /app - -# 配置pip使用国内镜像源(阿里云)并设置超时和重试 -RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \ - pip config set global.trusted-host mirrors.aliyun.com && \ - pip config set global.timeout 120 && \ - pip config set install.retries 5 - -COPY main/xiaozhi-server/requirements.txt . - -# 安装Python依赖,使用并行下载 -RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \ - pip install --no-cache-dir -r requirements.txt --default-timeout=120 --retries 5 - -# 第二阶段:生产镜像 -FROM python:3.10-slim - -WORKDIR /opt/xiaozhi-esp32-server - -# 安装系统依赖 -RUN 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=builder /usr/local/bin/mcp-proxy /usr/local/bin/mcp-proxy - -# 复制应用代码 COPY main/xiaozhi-server . # 启动应用 diff --git a/Dockerfile-server-base b/Dockerfile-server-base new file mode 100644 index 00000000..ab232a17 --- /dev/null +++ b/Dockerfile-server-base @@ -0,0 +1,24 @@ +# Dockerfile-server-base +# 基础镜像,包含系统依赖和Python包 +FROM python:3.10-slim + +# 安装系统依赖 +RUN apt-get update && \ + apt-get install -y --no-install-recommends libopus0 ffmpeg && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# 配置pip使用国内镜像源(阿里云)并设置超时和重试 +RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \ + pip config set global.trusted-host mirrors.aliyun.com && \ + pip config set global.timeout 120 && \ + pip config set install.retries 5 + +WORKDIR /opt/xiaozhi-esp32-server + +# 复制requirements.txt +COPY main/xiaozhi-server/requirements.txt . + +# 安装Python依赖 +RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \ + pip install --no-cache-dir -r requirements.txt --default-timeout=120 --retries 5 \ No newline at end of file