From c48f8720c908bd4184219fd232fc02c94b14e666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Wed, 14 Jan 2026 16:51:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=95=9C=E5=83=8F=E6=9E=84?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-base-image.yml | 48 ----------------------- .github/workflows/ci.yml | 54 ++++++++++---------------- Dockerfile | 53 ++++++++++++++++++++----- Dockerfile.builder | 28 ------------- Dockerfile.runtime | 13 ------- supervisord.conf | 28 ------------- 6 files changed, 65 insertions(+), 159 deletions(-) delete mode 100644 .github/workflows/build-base-image.yml delete mode 100644 Dockerfile.builder delete mode 100644 Dockerfile.runtime delete mode 100644 supervisord.conf diff --git a/.github/workflows/build-base-image.yml b/.github/workflows/build-base-image.yml deleted file mode 100644 index 977110c..0000000 --- a/.github/workflows/build-base-image.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Build Docker Base Image - -on: - push: - branches: ["main"] - paths: - - 'Dockerfile.builder' - - 'Dockerfile.runtime' - - 'install_dependencies.sh' - - '.github/workflows/build-base-image.yml' - workflow_dispatch: - -permissions: - contents: read - -jobs: - build-image: - runs-on: ubuntu-latest - if: github.event_name != 'pull_request' - strategy: - fail-fast: false - matrix: - image-type: [runtime, builder] - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - submodules: true - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push ${{ matrix.image-type }} - uses: docker/build-push-action@v4 - with: - context: . - file: ./Dockerfile.${{ matrix.image-type }} - platforms: linux/amd64, linux/arm64, linux/arm/v7 - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ matrix.image-type }} - # 核心缓存配置:每个镜像类型使用独立缓存标签 - cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache-${{ matrix.image-type }} - cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache-${{ matrix.image-type }},mode=max diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0a8cba..50efb53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,12 +22,15 @@ jobs: build: runs-on: ubuntu-latest strategy: - fail-fast: false # 一个架构构建失败不影响其他架构 matrix: - arch: - - { platform: linux/amd64, suffix: amd64 } - - { platform: linux/arm64, suffix: arm64 } - - { platform: linux/arm/v7, suffix: armv7 } + platform: [amd64, arm64, armv7] + include: + - platform: amd64 + arch: amd64 + - platform: arm64 + arch: arm64 + - platform: armv7 + arch: arm/v7 steps: - uses: actions/checkout@v4 with: @@ -46,42 +49,27 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and save Docker image for ${{ matrix.arch.suffix }} + - name: Build Docker image for ${{ matrix.platform }} uses: docker/build-push-action@v6 with: - platforms: ${{ matrix.arch.platform }} + platforms: linux/${{ matrix.arch }} context: . push: false load: true - tags: ${{ env.VERSION_TAG }}-${{ matrix.arch.suffix }} - # 核心修改:每个架构使用专属的缓存标签 - cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache-${{ matrix.arch.suffix }} - cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache-${{ matrix.arch.suffix }},mode=max + tags: ${{ env.VERSION_TAG }}-${{ matrix.platform }} + cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache + cache-to: ${{ matrix.platform == 'amd64' && 'type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache,mode=max' || '' }} - - name: Save ${{ matrix.arch.suffix }} image to tar + - name: Test Docker image for ${{ matrix.platform }} run: | - docker save ${{ env.VERSION_TAG }}-${{ matrix.arch.suffix }} -o xiaomusic-${{ github.ref_name }}-${{ matrix.arch.suffix }}.tar + docker run --rm ${{ env.VERSION_TAG }}-${{ matrix.platform }} /app/.venv/bin/python3 /app/xiaomusic.py -h - - name: Upload ${{ matrix.arch.suffix }} image as artifact - uses: actions/upload-artifact@v4 - with: - name: docker-image-${{ matrix.arch.suffix }} - path: xiaomusic-${{ github.ref_name }}-${{ matrix.arch.suffix }}.tar - retention-days: 1 + - name: Save ${{ matrix.platform }} image to tar + run: | + docker save ${{ env.VERSION_TAG }}-${{ matrix.platform }} -o xiaomusic-${{ github.ref_name }}-${{ matrix.platform }}.tar - # 汇总所有架构的镜像包 - collect-artifacts: - runs-on: ubuntu-latest - needs: build - steps: - - name: Download all architecture artifacts - uses: actions/download-artifact@v4 - with: - pattern: docker-image-* - merge-multiple: true - path: ./ - - - name: Upload combined Docker images as artifacts + - name: Upload Docker images as artifacts + if: matrix.platform == 'amd64' uses: actions/upload-artifact@v4 with: name: docker-images @@ -209,4 +197,4 @@ jobs: - name: Publish package distributions to PyPI run: pdm publish - continue-on-error: true + continue-on-error: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ae3bd87..2bc6dc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,49 @@ -FROM hanxi/xiaomusic:builder AS builder +# 第一阶段:构建阶段 +FROM python:3.14-alpine AS builder + +# 安装构建依赖 +RUN apk add --no-cache \ + build-base \ + nodejs \ + npm \ + zlib-dev \ + jpeg-dev \ + freetype-dev \ + lcms2-dev \ + openjpeg-dev \ + tiff-dev \ + libwebp-dev + +# 安装PDM +RUN pip install -U pdm +ENV PDM_CHECK_UPDATE=false WORKDIR /app COPY pyproject.toml README.md package.json ./ -RUN pip install -U pdm && \ - pdm install --prod --no-editable -v && \ - npm install --loglevel=verbose +# 安装Python和Node.js依赖 +RUN pdm install --prod --no-editable -v +RUN npm install --loglevel=verbose +# 复制应用代码 COPY xiaomusic/ ./xiaomusic/ COPY plugins/ ./plugins/ COPY holiday/ ./holiday/ COPY xiaomusic.py . -FROM hanxi/xiaomusic:runtime +# 第二阶段:运行阶段 +FROM python:3.14-alpine +# 安装运行时依赖 +RUN apk add --no-cache \ + ffmpeg \ + nodejs \ + npm + +# 设置工作目录 WORKDIR /app +# 从构建阶段复制产物 COPY --from=builder /app/.venv ./.venv COPY --from=builder /app/node_modules ./node_modules/ COPY --from=builder /app/xiaomusic/ ./xiaomusic/ @@ -24,15 +52,22 @@ COPY --from=builder /app/holiday/ ./holiday/ COPY --from=builder /app/xiaomusic.py . COPY --from=builder /app/xiaomusic/__init__.py /base_version.py COPY --from=builder /app/package.json . + +# 创建FFmpeg软链接目录 +RUN mkdir -p /app/ffmpeg/bin \ + && ln -s /usr/bin/ffmpeg /app/ffmpeg/bin/ffmpeg \ + && ln -s /usr/bin/ffprobe /app/ffmpeg/bin/ffprobe + RUN touch /app/.dockerenv -COPY supervisord.conf /etc/supervisor/supervisord.conf -RUN rm -f /var/run/supervisor.sock - +# 设置卷和暴露端口 VOLUME /app/conf VOLUME /app/music EXPOSE 8090 + +# 设置环境变量 ENV TZ=Asia/Shanghai ENV PATH=/app/.venv/bin:/usr/local/bin:$PATH -ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"] +# 直接启动xiaomusic应用 +CMD ["/app/.venv/bin/python3", "/app/xiaomusic.py"] \ No newline at end of file diff --git a/Dockerfile.builder b/Dockerfile.builder deleted file mode 100644 index a3d2326..0000000 --- a/Dockerfile.builder +++ /dev/null @@ -1,28 +0,0 @@ -FROM python:3.12-slim-bookworm - -RUN apt-get update && apt-get install -y --no-install-recommends \ - build-essential \ - nodejs \ - npm \ - zlib1g-dev \ - libjpeg-dev \ - libfreetype6-dev \ - liblcms2-dev \ - libopenjp2-7-dev \ - libtiff-dev \ - libwebp-dev \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -RUN pip install -U pdm -ENV PDM_CHECK_UPDATE=false -WORKDIR /app -COPY pyproject.toml README.md package.json ./ - -RUN pdm install --prod --no-editable -v -RUN npm install --loglevel=verbose - -COPY xiaomusic/ ./xiaomusic/ -COPY plugins/ ./plugins/ -COPY holiday/ ./holiday/ -COPY xiaomusic.py . diff --git a/Dockerfile.runtime b/Dockerfile.runtime deleted file mode 100644 index 6d66d6f..0000000 --- a/Dockerfile.runtime +++ /dev/null @@ -1,13 +0,0 @@ -FROM python:3.12-slim-bookworm - -RUN apt-get update && apt-get install -y --no-install-recommends \ - supervisor \ - ffmpeg \ - nodejs \ - npm \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* -WORKDIR /app -RUN mkdir -p /app/ffmpeg/bin \ - && ln -s /usr/bin/ffmpeg /app/ffmpeg/bin/ffmpeg \ - && ln -s /usr/bin/ffprobe /app/ffmpeg/bin/ffprobe diff --git a/supervisord.conf b/supervisord.conf deleted file mode 100644 index 8a82c9e..0000000 --- a/supervisord.conf +++ /dev/null @@ -1,28 +0,0 @@ -[unix_http_server] -file=/var/run/supervisor.sock ; Unix套接字文件路径 -chmod=0777 ; 套接字权限 - -[supervisord] -nodaemon=true ; 前台运行 -pidfile=/tmp/supervisord.pid ; PID文件路径 -logfile=/dev/stdout ; 日志输出到标准输出 -logfile_maxbytes=0 ; 禁用日志文件大小限制 -loglevel=info ; 日志级别 - - -[rpcinterface:supervisor] -supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface - -[supervisorctl] -serverurl=unix:///var/run/supervisor.sock ; 使用Unix套接字与服务通信 - -[program:xiaomusic] -command=/app/.venv/bin/python3 /app/xiaomusic.py -directory=/app -autostart=true -autorestart=true -startretries=99999 -startsecs=60 -redirect_stderr=true -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0