From 1eaf5e4c2c161084acf4804b2f3b9e578c221d48 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 25 Jan 2026 16:22:03 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=A7=8B=E9=87=8B?= =?UTF-8?q?=E6=94=BE=E5=B7=A5=E4=BD=9C=E6=B5=81=E7=A8=8B=EF=BC=8C=E5=88=86?= =?UTF-8?q?=E9=96=8B=E6=A7=8B=E5=BB=BA=20AMD64=20=E5=92=8C=20ARM64=20?= =?UTF-8?q?=E6=98=A0=E5=83=8F=E4=BB=A5=E5=84=AA=E5=8C=96=E7=A3=81=E7=A2=9F?= =?UTF-8?q?=E7=A9=BA=E9=96=93=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 241 ++++++++++++++++++---------------- 1 file changed, 131 insertions(+), 110 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1cd0388..0a6722d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,9 +19,9 @@ env: jobs: # ============================================================================== - # 🐳 Build and Push Docker Image(關鍵流程) + # 🐳 Build AMD64 Image(分開構建解決空間不足問題) # ============================================================================== - build-and-push: + build-amd64: runs-on: ubuntu-latest permissions: contents: read @@ -31,12 +31,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # ======================================== - # 清理磁碟空間(解決 no space left on device) - # ======================================== - # 🔥 GitHub Actions Runner 只有約 14GB 可用空間 - # 大型模型 + Multi-Arch build 需要清理更多預裝軟體 - # ======================================== # ======================================== # 🔥 極限磁碟清理(釋放 50-60GB 空間) # ======================================== @@ -54,72 +48,81 @@ jobs: - name: Additional disk cleanup run: | echo "🧹 額外磁碟清理..." - echo "========================================" - echo "📊 初始磁碟空間:" df -h / - echo "========================================" - - # ======================================== - # 移除額外大型軟體 - # ======================================== - echo "🗑️ 移除額外預裝軟體..." - - # Swift(約 1.5GB) - sudo rm -rf /usr/share/swift || true - - # 移除預裝資料庫 - sudo rm -rf /var/lib/mysql || true - sudo rm -rf /var/lib/postgresql || true - - # 移除預裝瀏覽器 - sudo rm -rf /usr/local/share/chromium || true - sudo rm -rf /usr/local/share/chrome || true - - # 移除文件和 man pages - sudo rm -rf /usr/share/doc || true - sudo rm -rf /usr/share/man || true - sudo rm -rf /usr/share/locale || true - - # 移除 Rust 工具鏈 - sudo rm -rf /usr/share/rust || true - sudo rm -rf ~/.rustup || true - sudo rm -rf ~/.cargo || true - - # 移除 Go - sudo rm -rf /usr/local/go || true - sudo rm -rf ~/go || true - - # 移除 Julia - sudo rm -rf /usr/local/julia* || true - - # 移除 R - sudo rm -rf /usr/share/R || true - sudo rm -rf /usr/lib/R || true - - # 清理 apt - sudo apt-get clean || true - sudo apt-get autoremove -y || true - sudo rm -rf /var/lib/apt/lists/* || true - sudo rm -rf /var/cache/apt/archives || true - - # 清理 npm/yarn - sudo rm -rf /usr/local/share/.cache || true - sudo rm -rf ~/.npm || true - - # 清理 pip cache - sudo rm -rf ~/.cache/pip || true - - # 清理 Docker(確保乾淨) + sudo rm -rf /usr/share/swift /var/lib/mysql /var/lib/postgresql || true + sudo rm -rf /usr/share/doc /usr/share/man /usr/share/locale || true + sudo rm -rf /usr/local/go ~/go /usr/local/julia* || true + sudo apt-get clean && sudo rm -rf /var/lib/apt/lists/* || true + docker system prune -af --volumes || true + df -h / + + - name: Get tag name + id: tag + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + echo "version=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT + else + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + fi + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push AMD64 image + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile + push: true + tags: ${{ env.DOCKER_IMAGE }}:${{ steps.tag.outputs.version }}-amd64 + platforms: linux/amd64 + cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache-amd64 + cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache-amd64,mode=max,compression=zstd + provenance: false + sbom: false + build-args: | + BUILDKIT_INLINE_CACHE=1 + + # ============================================================================== + # 🐳 Build ARM64 Image(分開構建解決空間不足問題) + # ============================================================================== + build-arm64: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Free disk space (maximum) + uses: jlumbroso/free-disk-space@main + with: + tool-cache: true + android: true + dotnet: true + haskell: true + large-packages: true + docker-images: true + swap-storage: true + + - name: Additional disk cleanup + run: | + echo "🧹 額外磁碟清理..." + df -h / + sudo rm -rf /usr/share/swift /var/lib/mysql /var/lib/postgresql || true + sudo rm -rf /usr/share/doc /usr/share/man /usr/share/locale || true + sudo rm -rf /usr/local/go ~/go /usr/local/julia* || true + sudo apt-get clean && sudo rm -rf /var/lib/apt/lists/* || true docker system prune -af --volumes || true - sudo rm -rf /var/lib/docker/buildkit || true - - # 清理 tmp - sudo rm -rf /tmp/* || true - - echo "========================================" - echo "📊 清理後磁碟空間:" df -h / - echo "========================================" - name: Get tag name id: tag @@ -133,16 +136,8 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v3 - # ======================================== - # 設定 Docker Buildx(針對大型模型優化) - # ======================================== - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - with: - # 🔥 使用 docker-container driver 以獲得更好的 cache 控制 - driver-opts: | - image=moby/buildkit:latest - network=host - name: Login to Docker Hub uses: docker/login-action@v3 @@ -150,44 +145,70 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # ======================================== - # Build and Push(針對大型模型優化) - # ======================================== - # 🔥 注意事項: - # - 使用 registry cache 而非 GHA cache(避免 10GB 限制) - # - 啟用 zstd compression 減少傳輸量和儲存空間 - # - Multi-arch build 需要更多磁碟空間,已在上方清理 - # - 明確指定 file: Dockerfile 避免與 Lite 版混淆 - # - 使用 CACHE_BUST 強制重新下載模型 - # - 🔥 禁用 provenance 減少磁碟使用 - # ======================================== - - name: Build and push Docker image + - name: Build and push ARM64 image uses: docker/build-push-action@v6 with: context: . file: Dockerfile push: true - tags: | - ${{ env.DOCKER_IMAGE }}:${{ steps.tag.outputs.version }} - ${{ env.DOCKER_IMAGE }}:latest - platforms: linux/amd64,linux/arm64 - # 使用 registry cache(已手動刪除 Docker Hub 上的 buildcache tag) - cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache-full - cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache-full,mode=max,compression=zstd - # 🔥 禁用 provenance 和 sbom 減少磁碟和記憶體使用 + tags: ${{ env.DOCKER_IMAGE }}:${{ steps.tag.outputs.version }}-arm64 + platforms: linux/arm64 + cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache-arm64 + cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache-arm64,mode=max,compression=zstd provenance: false sbom: false - # 設定 build 參數(使用時間戳強制重新下載模型層) build-args: | BUILDKIT_INLINE_CACHE=1 - CACHE_BUST=${{ github.run_id }} + + # ============================================================================== + # 🐳 Create Multi-Arch Manifest(合併兩個架構) + # ============================================================================== + create-manifest: + runs-on: ubuntu-latest + needs: [build-amd64, build-arm64] + permissions: + contents: read + packages: write + + steps: + - name: Get tag name + id: tag + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + echo "version=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT + else + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + fi + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Create and push multi-arch manifest + run: | + VERSION="${{ steps.tag.outputs.version }}" + IMAGE="${{ env.DOCKER_IMAGE }}" + + echo "🔄 創建 multi-arch manifest..." + + # 創建版本 tag 的 manifest + docker buildx imagetools create -t ${IMAGE}:${VERSION} \ + ${IMAGE}:${VERSION}-amd64 \ + ${IMAGE}:${VERSION}-arm64 + + # 創建 latest tag 的 manifest + docker buildx imagetools create -t ${IMAGE}:latest \ + ${IMAGE}:${VERSION}-amd64 \ + ${IMAGE}:${VERSION}-arm64 + + echo "✅ Multi-arch manifest 創建完成" + + # 驗證 manifest + echo "🔍 驗證 manifest..." + docker buildx imagetools inspect ${IMAGE}:${VERSION} + docker buildx imagetools inspect ${IMAGE}:latest - name: Docker Build Summary run: | @@ -207,7 +228,7 @@ jobs: verify-image: name: Verify Docker Image runs-on: ubuntu-latest - needs: build-and-push + needs: create-manifest timeout-minutes: 45 steps: @@ -534,7 +555,7 @@ jobs: # ============================================================================== create-release: runs-on: ubuntu-latest - needs: [build-and-push, verify-image] + needs: [create-manifest, verify-image] permissions: contents: write