refactor: 重構釋放工作流程,分開構建 AMD64 和 ARM64 映像以優化磁碟空間使用
This commit is contained in:
parent
7f74d18089
commit
1eaf5e4c2c
1 changed files with 131 additions and 110 deletions
241
.github/workflows/release.yml
vendored
241
.github/workflows/release.yml
vendored
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue