diff --git a/.github/workflows/sync.yaml b/.github/workflows/sync.yaml index 730c0cb..f2b5348 100644 --- a/.github/workflows/sync.yaml +++ b/.github/workflows/sync.yaml @@ -3,6 +3,11 @@ run-name: ${{ github.actor }} is running GitHub Actions on: [push] jobs: Sync-Docker-Image-Actions: + strategy: + matrix: + platform: +# - linux/amd64 + - linux/arm64 runs-on: ubuntu-latest steps: - name: Check out repository code @@ -12,5 +17,5 @@ jobs: docker login -u "${{ secrets.DOCKER_USER }}" -p "${{ secrets.DOCKER_PWD }}" "${{ secrets.DOCKER_REGISTRY }}" - name: execute sync.sh run: | - bash "${{ github.workspace }}/sync.sh" "${{ github.workspace }}/images.txt" "${{ secrets.DOCKER_REGISTRY }}" "${{ secrets.DOCKER_NS }}" + bash "${{ github.workspace }}/sync.sh" "${{ github.workspace }}/images.txt" "${{ secrets.DOCKER_REGISTRY }}" "${{ secrets.DOCKER_NS }}" "${{ matrix.platform }}" - run: echo "This job's status is ${{ job.status }}" diff --git a/.gitignore b/.gitignore index 0156556..756d778 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -cmd/conf.yaml \ No newline at end of file +cmd/conf.yaml +.idea +.vscode \ No newline at end of file diff --git a/cmd/docker_pull b/cmd/docker_pull old mode 100644 new mode 100755 index c096336..5d1a985 --- a/cmd/docker_pull +++ b/cmd/docker_pull @@ -104,12 +104,12 @@ for tag in "$@"; do last_part=$(basename "$tag") full_tag="$REGISTRY_URL/$REGISTRY_NS/$last_part" success=0 - + for ((attempt=1; attempt<=MAX_RETRIES; attempt++)); do if [ $success -eq 0 ]; then echo "[Attempt $attempt/$MAX_RETRIES] Pulling $full_tag" docker pull "$full_tag" - + if [ $? -eq 0 ]; then success=1 echo "[pull images] Successfully pulled $full_tag, now delete origin image $full_tag:" @@ -122,7 +122,7 @@ for tag in "$@"; do fi fi done - + if [ $success -eq 0 ]; then echo "[pull images] Failed to pull $full_tag after $MAX_RETRIES attempts" FAILED_TAGS+=("$tag") diff --git a/sync.sh b/sync.sh index 06ec01f..3ac9780 100644 --- a/sync.sh +++ b/sync.sh @@ -3,9 +3,9 @@ set -eux # 检查参数数量是否正确 -if [ "$#" -ne 3 ]; then - echo "错误:脚本需要3个参数 images_file、docker_registry和docker_namespace" - echo "用法: $0 " +if [ "$#" -ne 4 ]; then + echo "错误:脚本需要4个参数 images_file、docker_registry、docker_namespace、platform" + echo "用法: $0 " exit 1 fi @@ -13,6 +13,7 @@ fi IMAGES_FILE=$1 TARGET_REGISTRY=$2 TARGET_NAMESPACE=$3 +TARGET_PLATFORM=$4 # 检查文件是否存在 if [ ! -f "$IMAGES_FILE" ]; then @@ -25,7 +26,7 @@ failed_images="" while IFS= read -r image; do # 拉取镜像 set +e - docker pull "$image" + docker pull --platform="$TARGET_PLATFORM" "$image" pull_status=$? if [ $pull_status -ne 0 ]; then echo "Error: Failed to pull image $image, continuing..."