1
0
mirror of https://github.com/hanxi/xiaomusic.git synced 2026-03-15 08:13:16 +08:00

docker: 优化构建速度

This commit is contained in:
涵曦
2026-01-14 07:38:22 +08:00
parent 5ebb9f9e92
commit 6c11ba011b

View File

@@ -18,7 +18,7 @@ permissions:
id-token: write
jobs:
# Job 并行构建不同架构的镜像
# Job 并行构建不同架构的镜像(按架构独立缓存)
build:
runs-on: ubuntu-latest
strategy:
@@ -54,9 +54,9 @@ jobs:
push: false
load: true
tags: ${{ env.VERSION_TAG }}-${{ matrix.arch.suffix }}
# 只有amd64架构写入缓存其他架构只读缓存避免缓存冲突
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache
${{ matrix.arch.suffix == 'amd64' && 'cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache,mode=max' || '' }}
# 核心修改:每个架构使用专属的缓存标签
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
- name: Save ${{ matrix.arch.suffix }} image to tar
run: |
@@ -88,10 +88,10 @@ jobs:
path: xiaomusic-*.tar
retention-days: 1
# Job 推送 Docker 镜像
# Job 推送 Docker 镜像(推送时也使用按架构缓存)
push-docker:
runs-on: ubuntu-latest
needs: collect-artifacts # 依赖汇总任务完成
needs: collect-artifacts
if: github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
@@ -116,7 +116,11 @@ jobs:
context: .
push: true
tags: ${{ env.VERSION_TAG }}
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache
# 推送时也复用各架构的缓存
cache-from: |
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache-amd64
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache-arm64
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache-armv7
- name: Publish to Docker Hub latest and stable
if: startsWith(github.ref, 'refs/tags/v')
@@ -126,12 +130,16 @@ jobs:
context: .
push: true
tags: ${{ env.VERSION_TAG }}, ${{ env.LATEST_TAG }}, ${{ env.STABLE_TAG }}
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache
# 推送时也复用各架构的缓存
cache-from: |
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache-amd64
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache-arm64
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache-armv7
# Job 发布 Release
# 以下 publish-release、publish-pypi 任务保持不变,省略(和之前的配置一致)
publish-release:
runs-on: ubuntu-latest
needs: collect-artifacts # 依赖汇总任务完成
needs: collect-artifacts
if: github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
@@ -176,10 +184,9 @@ jobs:
gh release upload "${RELEASE_NAME}" "${FILE}" --clobber
done
# Job 发布 PyPI 版本
publish-pypi:
runs-on: ubuntu-latest
needs: build # 只需要build完成即可不需要等汇总
needs: build
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4