fix: 優化 Docker 磁碟清理邏輯,針對大型模型與多架構建置進行強化,減少空間使用
This commit is contained in:
parent
37b56aed56
commit
5ad22e44ec
2 changed files with 179 additions and 19 deletions
97
.github/workflows/docker-publish.yml
vendored
97
.github/workflows/docker-publish.yml
vendored
|
|
@ -59,29 +59,86 @@ jobs:
|
||||||
# ========================================
|
# ========================================
|
||||||
# 清理磁碟空間(解決 no space left on device)
|
# 清理磁碟空間(解決 no space left on device)
|
||||||
# ========================================
|
# ========================================
|
||||||
- name: Free disk space
|
# 🔥 GitHub Actions Runner 只有約 14GB 可用空間
|
||||||
|
# 大型模型 build 需要清理更多預裝軟體
|
||||||
|
# ========================================
|
||||||
|
- name: Free disk space (aggressive)
|
||||||
run: |
|
run: |
|
||||||
echo "🧹 Cleaning up disk space..."
|
echo "🧹 Aggressive disk cleanup for large model builds..."
|
||||||
df -h
|
echo "========================================"
|
||||||
|
echo "📊 初始磁碟空間:"
|
||||||
|
df -h /
|
||||||
|
echo "========================================"
|
||||||
|
|
||||||
# 移除不需要的預裝軟體
|
# ========================================
|
||||||
|
# 移除大型預裝軟體(約可釋放 30-40GB)
|
||||||
|
# ========================================
|
||||||
|
echo "🗑️ 移除預裝開發工具..."
|
||||||
|
|
||||||
|
# .NET SDK(約 2-3GB)
|
||||||
sudo rm -rf /usr/share/dotnet || true
|
sudo rm -rf /usr/share/dotnet || true
|
||||||
|
|
||||||
|
# Android SDK(約 10-15GB)- 最大宗!
|
||||||
sudo rm -rf /usr/local/lib/android || true
|
sudo rm -rf /usr/local/lib/android || true
|
||||||
|
|
||||||
|
# Haskell/GHC(約 1GB)
|
||||||
sudo rm -rf /opt/ghc || true
|
sudo rm -rf /opt/ghc || true
|
||||||
|
|
||||||
|
# CodeQL(約 1GB)
|
||||||
sudo rm -rf /opt/hostedtoolcache/CodeQL || true
|
sudo rm -rf /opt/hostedtoolcache/CodeQL || true
|
||||||
|
|
||||||
|
# Boost(約 500MB)
|
||||||
sudo rm -rf /usr/local/share/boost || true
|
sudo rm -rf /usr/local/share/boost || true
|
||||||
|
|
||||||
|
# Swift(約 1.5GB)
|
||||||
sudo rm -rf /usr/share/swift || true
|
sudo rm -rf /usr/share/swift || true
|
||||||
|
|
||||||
|
# Hosted Tool Cache(約 5-8GB)
|
||||||
sudo rm -rf /opt/hostedtoolcache || true
|
sudo rm -rf /opt/hostedtoolcache || true
|
||||||
|
|
||||||
# 清理 apt cache
|
# Azure CLI(約 500MB)
|
||||||
|
sudo rm -rf /usr/share/az_* || true
|
||||||
|
sudo rm -rf /opt/az || true
|
||||||
|
|
||||||
|
# Google Cloud SDK(約 500MB)
|
||||||
|
sudo rm -rf /usr/lib/google-cloud-sdk || true
|
||||||
|
|
||||||
|
# PowerShell(約 200MB)
|
||||||
|
sudo rm -rf /usr/local/share/powershell || true
|
||||||
|
|
||||||
|
# Miniconda(約 500MB)
|
||||||
|
sudo rm -rf /usr/share/miniconda || true
|
||||||
|
|
||||||
|
# ========================================
|
||||||
|
# 清理系統 cache
|
||||||
|
# ========================================
|
||||||
|
echo "🗑️ 清理系統 cache..."
|
||||||
|
|
||||||
|
# apt cache
|
||||||
sudo apt-get clean || true
|
sudo apt-get clean || true
|
||||||
sudo apt-get autoremove -y || true
|
sudo apt-get autoremove -y || true
|
||||||
|
sudo rm -rf /var/lib/apt/lists/* || true
|
||||||
|
|
||||||
|
# npm/yarn global cache
|
||||||
|
sudo rm -rf /usr/local/share/.cache || true
|
||||||
|
|
||||||
|
# ========================================
|
||||||
# 清理 Docker 舊資料
|
# 清理 Docker 舊資料
|
||||||
|
# ========================================
|
||||||
|
echo "🗑️ 清理 Docker cache..."
|
||||||
docker system prune -af --volumes || true
|
docker system prune -af --volumes || true
|
||||||
|
|
||||||
echo "After cleanup:"
|
# ========================================
|
||||||
df -h
|
# 清理 BuildKit cache(關鍵!解決 overlayfs 爆空間)
|
||||||
|
# ========================================
|
||||||
|
echo "🗑️ 清理 BuildKit cache..."
|
||||||
|
# BuildKit 的 blob 和 layer cache 可能佔用大量空間
|
||||||
|
sudo rm -rf /var/lib/docker/buildkit || true
|
||||||
|
|
||||||
|
echo "========================================"
|
||||||
|
echo "📊 清理後磁碟空間:"
|
||||||
|
df -h /
|
||||||
|
echo "========================================"
|
||||||
|
|
||||||
- name: downcase REPO
|
- name: downcase REPO
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -93,10 +150,17 @@ jobs:
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/${{ env.REPO }}
|
images: ghcr.io/${{ env.REPO }}
|
||||||
|
|
||||||
|
# ========================================
|
||||||
|
# 設定 Docker Buildx(針對大型模型優化)
|
||||||
|
# ========================================
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
with:
|
with:
|
||||||
platforms: ${{ matrix.platform }}
|
platforms: ${{ matrix.platform }}
|
||||||
|
# 🔥 使用 docker-container driver 以獲得更好的 cache 控制
|
||||||
|
driver-opts: |
|
||||||
|
image=moby/buildkit:latest
|
||||||
|
network=host
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
# here we only login to ghcr.io since the this only pushes internal images
|
# here we only login to ghcr.io since the this only pushes internal images
|
||||||
|
|
@ -106,6 +170,14 @@ jobs:
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
# ========================================
|
||||||
|
# Build and Push(針對大型模型優化)
|
||||||
|
# ========================================
|
||||||
|
# 🔥 注意事項:
|
||||||
|
# - 使用 registry cache 而非 GHA cache(避免 10GB 限制)
|
||||||
|
# - 啟用 compression 減少傳輸量
|
||||||
|
# - 使用 inline cache 確保 layer 可重用
|
||||||
|
# ========================================
|
||||||
- name: Build and push by digest
|
- name: Build and push by digest
|
||||||
id: build
|
id: build
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
|
|
@ -116,10 +188,15 @@ jobs:
|
||||||
platforms: ${{ matrix.platform }}
|
platforms: ${{ matrix.platform }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
annotations: ${{ steps.meta.outputs.annotations }}
|
annotations: ${{ steps.meta.outputs.annotations }}
|
||||||
outputs: type=image,name=ghcr.io/${{ env.REPO }},push-by-digest=true,name-canonical=true,oci-mediatypes=true
|
outputs: type=image,name=ghcr.io/${{ env.REPO }},push-by-digest=true,name-canonical=true,oci-mediatypes=true,compression=zstd,compression-level=3
|
||||||
push: ${{ github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && contains(fromJSON('["COLLABORATOR","MEMBER","OWNER"]'), github.event.pull_request.author_association)) }}
|
push: ${{ github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && contains(fromJSON('["COLLABORATOR","MEMBER","OWNER"]'), github.event.pull_request.author_association)) }}
|
||||||
cache-from: type=gha,scope=${{ matrix.platform }}
|
# 🔥 使用 registry cache 取代 GHA cache
|
||||||
cache-to: type=gha,mode=max,scope=${{ matrix.platform }}
|
# registry cache 沒有 10GB 限制,更適合大型模型
|
||||||
|
cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache-${{ env.PLATFORM_PAIR }}
|
||||||
|
cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache-${{ env.PLATFORM_PAIR }},mode=max,compression=zstd
|
||||||
|
# 設定 build 參數
|
||||||
|
build-args: |
|
||||||
|
BUILDKIT_INLINE_CACHE=1
|
||||||
|
|
||||||
- name: Export digest
|
- name: Export digest
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
101
.github/workflows/release.yml
vendored
101
.github/workflows/release.yml
vendored
|
|
@ -32,29 +32,82 @@ jobs:
|
||||||
# ========================================
|
# ========================================
|
||||||
# 清理磁碟空間(解決 no space left on device)
|
# 清理磁碟空間(解決 no space left on device)
|
||||||
# ========================================
|
# ========================================
|
||||||
- name: Free disk space
|
# 🔥 GitHub Actions Runner 只有約 14GB 可用空間
|
||||||
|
# 大型模型 + Multi-Arch build 需要清理更多預裝軟體
|
||||||
|
# ========================================
|
||||||
|
- name: Free disk space (aggressive)
|
||||||
run: |
|
run: |
|
||||||
echo "🧹 Cleaning up disk space..."
|
echo "🧹 Aggressive disk cleanup for large model builds..."
|
||||||
df -h
|
echo "========================================"
|
||||||
|
echo "📊 初始磁碟空間:"
|
||||||
|
df -h /
|
||||||
|
echo "========================================"
|
||||||
|
|
||||||
# 移除不需要的預裝軟體
|
# ========================================
|
||||||
|
# 移除大型預裝軟體(約可釋放 30-40GB)
|
||||||
|
# ========================================
|
||||||
|
echo "🗑️ 移除預裝開發工具..."
|
||||||
|
|
||||||
|
# .NET SDK(約 2-3GB)
|
||||||
sudo rm -rf /usr/share/dotnet || true
|
sudo rm -rf /usr/share/dotnet || true
|
||||||
|
|
||||||
|
# Android SDK(約 10-15GB)- 最大宗!
|
||||||
sudo rm -rf /usr/local/lib/android || true
|
sudo rm -rf /usr/local/lib/android || true
|
||||||
|
|
||||||
|
# Haskell/GHC(約 1GB)
|
||||||
sudo rm -rf /opt/ghc || true
|
sudo rm -rf /opt/ghc || true
|
||||||
|
|
||||||
|
# CodeQL(約 1GB)
|
||||||
sudo rm -rf /opt/hostedtoolcache/CodeQL || true
|
sudo rm -rf /opt/hostedtoolcache/CodeQL || true
|
||||||
|
|
||||||
|
# Boost(約 500MB)
|
||||||
sudo rm -rf /usr/local/share/boost || true
|
sudo rm -rf /usr/local/share/boost || true
|
||||||
|
|
||||||
|
# Swift(約 1.5GB)
|
||||||
sudo rm -rf /usr/share/swift || true
|
sudo rm -rf /usr/share/swift || true
|
||||||
|
|
||||||
|
# Hosted Tool Cache(約 5-8GB)
|
||||||
sudo rm -rf /opt/hostedtoolcache || true
|
sudo rm -rf /opt/hostedtoolcache || true
|
||||||
|
|
||||||
# 清理 apt cache
|
# Azure CLI(約 500MB)
|
||||||
|
sudo rm -rf /usr/share/az_* || true
|
||||||
|
sudo rm -rf /opt/az || true
|
||||||
|
|
||||||
|
# Google Cloud SDK(約 500MB)
|
||||||
|
sudo rm -rf /usr/lib/google-cloud-sdk || true
|
||||||
|
|
||||||
|
# PowerShell(約 200MB)
|
||||||
|
sudo rm -rf /usr/local/share/powershell || true
|
||||||
|
|
||||||
|
# Miniconda(約 500MB)
|
||||||
|
sudo rm -rf /usr/share/miniconda || true
|
||||||
|
|
||||||
|
# ========================================
|
||||||
|
# 清理系統 cache
|
||||||
|
# ========================================
|
||||||
|
echo "🗑️ 清理系統 cache..."
|
||||||
|
|
||||||
|
# apt cache
|
||||||
sudo apt-get clean || true
|
sudo apt-get clean || true
|
||||||
sudo apt-get autoremove -y || true
|
sudo apt-get autoremove -y || true
|
||||||
|
sudo rm -rf /var/lib/apt/lists/* || true
|
||||||
|
|
||||||
|
# npm/yarn global cache
|
||||||
|
sudo rm -rf /usr/local/share/.cache || true
|
||||||
|
|
||||||
|
# ========================================
|
||||||
# 清理 Docker 舊資料
|
# 清理 Docker 舊資料
|
||||||
|
# ========================================
|
||||||
|
echo "🗑️ 清理 Docker cache..."
|
||||||
docker system prune -af --volumes || true
|
docker system prune -af --volumes || true
|
||||||
|
|
||||||
echo "✅ After cleanup:"
|
# 清理 BuildKit cache
|
||||||
df -h
|
sudo rm -rf /var/lib/docker/buildkit || true
|
||||||
|
|
||||||
|
echo "========================================"
|
||||||
|
echo "📊 清理後磁碟空間:"
|
||||||
|
df -h /
|
||||||
|
echo "========================================"
|
||||||
|
|
||||||
- name: Get tag name
|
- name: Get tag name
|
||||||
id: tag
|
id: tag
|
||||||
|
|
@ -68,8 +121,16 @@ jobs:
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
# ========================================
|
||||||
|
# 設定 Docker Buildx(針對大型模型優化)
|
||||||
|
# ========================================
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
# 🔥 使用 docker-container driver 以獲得更好的 cache 控制
|
||||||
|
driver-opts: |
|
||||||
|
image=moby/buildkit:latest
|
||||||
|
network=host
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
|
|
@ -77,6 +138,21 @@ jobs:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
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 需要更多磁碟空間,已在上方清理
|
||||||
|
# ========================================
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
|
|
@ -86,8 +162,15 @@ jobs:
|
||||||
${{ env.DOCKER_IMAGE }}:${{ steps.tag.outputs.version }}
|
${{ env.DOCKER_IMAGE }}:${{ steps.tag.outputs.version }}
|
||||||
${{ env.DOCKER_IMAGE }}:latest
|
${{ env.DOCKER_IMAGE }}:latest
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
cache-from: type=gha
|
# 🔥 使用 registry cache 取代 GHA cache
|
||||||
cache-to: type=gha,mode=max
|
# registry cache 沒有 10GB 限制,更適合大型模型
|
||||||
|
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache
|
||||||
|
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max,compression=zstd
|
||||||
|
# 啟用壓縮減少 image 大小
|
||||||
|
outputs: type=image,compression=zstd,compression-level=3
|
||||||
|
# 設定 build 參數
|
||||||
|
build-args: |
|
||||||
|
BUILDKIT_INLINE_CACHE=1
|
||||||
|
|
||||||
- name: Docker Build Summary
|
- name: Docker Build Summary
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue