reduce dockerhub operations

This commit is contained in:
chrislu
2025-11-27 23:04:32 -08:00
parent 5734223b2b
commit 755b1b55ff

View File

@@ -91,7 +91,8 @@ jobs:
push: ${{ github.event_name != 'pull_request' }} push: ${{ github.event_name != 'pull_request' }}
file: ./docker/Dockerfile.go_build file: ./docker/Dockerfile.go_build
platforms: linux/${{ matrix.platform }} platforms: linux/${{ matrix.platform }}
tags: ${{ steps.docker_meta.outputs.tags }}-${{ matrix.platform }} # Push to GHCR only during build to avoid Docker Hub rate limits
tags: ghcr.io/chrislusf/seaweedfs:latest-${{ matrix.platform }}
labels: ${{ steps.docker_meta.outputs.labels }} labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
@@ -132,9 +133,28 @@ jobs:
registry: ghcr.io registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }} username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }} password: ${{ secrets.GHCR_TOKEN }}
- name: Install crane
run: |
# Install crane for efficient multi-arch image copying
cd $(mktemp -d)
curl -sL "https://github.com/google/go-containerregistry/releases/latest/download/go-containerregistry_Linux_x86_64.tar.gz" | tar xz
sudo mv crane /usr/local/bin/
crane version
- name: Create and push manifest - name: Create and push manifest
run: | run: |
# Function to retry command with exponential backoff # Create manifest on GHCR first (no rate limits)
echo "Creating GHCR manifest (no rate limits)..."
docker buildx imagetools create -t ghcr.io/chrislusf/seaweedfs:latest \
ghcr.io/chrislusf/seaweedfs:latest-amd64 \
ghcr.io/chrislusf/seaweedfs:latest-arm64 \
ghcr.io/chrislusf/seaweedfs:latest-arm \
ghcr.io/chrislusf/seaweedfs:latest-386
# Copy the complete multi-arch image from GHCR to Docker Hub
# This only requires one pull from GHCR (no rate limit) and one push to Docker Hub
echo "Copying manifest from GHCR to Docker Hub..."
# Function to retry with exponential backoff for Docker Hub operations
retry_with_backoff() { retry_with_backoff() {
local max_attempts=5 local max_attempts=5
local timeout=1 local timeout=1
@@ -161,16 +181,19 @@ jobs:
return $exit_code return $exit_code
} }
# Create manifest for Docker Hub with retry # Use crane or skopeo to copy, fallback to docker if not available
retry_with_backoff docker buildx imagetools create -t chrislusf/seaweedfs:latest \ if command -v crane &> /dev/null; then
chrislusf/seaweedfs:latest-amd64 \ echo "Using crane to copy..."
chrislusf/seaweedfs:latest-arm64 \ retry_with_backoff crane copy ghcr.io/chrislusf/seaweedfs:latest chrislusf/seaweedfs:latest
chrislusf/seaweedfs:latest-arm \ elif command -v skopeo &> /dev/null; then
chrislusf/seaweedfs:latest-386 echo "Using skopeo to copy..."
retry_with_backoff skopeo copy --all docker://ghcr.io/chrislusf/seaweedfs:latest docker://chrislusf/seaweedfs:latest
# Create manifest for GHCR with retry else
retry_with_backoff docker buildx imagetools create -t ghcr.io/chrislusf/seaweedfs:latest \ echo "Using docker buildx imagetools (pulling 4 images from Docker Hub)..."
ghcr.io/chrislusf/seaweedfs:latest-amd64 \ # Fallback: create manifest directly on Docker Hub (pulls from Docker Hub - rate limited)
ghcr.io/chrislusf/seaweedfs:latest-arm64 \ retry_with_backoff docker buildx imagetools create -t chrislusf/seaweedfs:latest \
ghcr.io/chrislusf/seaweedfs:latest-arm \ ghcr.io/chrislusf/seaweedfs:latest-amd64 \
ghcr.io/chrislusf/seaweedfs:latest-386 ghcr.io/chrislusf/seaweedfs:latest-arm64 \
ghcr.io/chrislusf/seaweedfs:latest-arm \
ghcr.io/chrislusf/seaweedfs:latest-386
fi