diff --git a/.github/workflows/sync.yaml b/.github/workflows/sync.yaml index 730c0cb..173ecf1 100644 --- a/.github/workflows/sync.yaml +++ b/.github/workflows/sync.yaml @@ -9,7 +9,7 @@ jobs: uses: actions/checkout@v4 - name: login to docker registry run: | - docker login -u "${{ secrets.DOCKER_USER }}" -p "${{ secrets.DOCKER_PWD }}" "${{ secrets.DOCKER_REGISTRY }}" + 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 }}" diff --git a/cmd/docker_pull b/cmd/docker_pull old mode 100644 new mode 100755 index c096336..771fb92 --- a/cmd/docker_pull +++ b/cmd/docker_pull @@ -8,6 +8,36 @@ if [ ! -f "$CONFIG_FILE" ]; then exit 1 fi +# Get operating system type +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +if [[ "$OS" == "darwin" ]]; then + OS="linux" # Docker Desktop on macOS runs Linux containers +fi + +# Get architecture +ARCH=$(uname -m) +case "$ARCH" in + x86_64) + ARCH="amd64" + ;; + aarch64|arm64) + ARCH="arm64" + ;; + armv7*) + ARCH="arm/v7" + ;; + armv6*) + ARCH="arm/v6" + ;; + i386|i686) + ARCH="386" + ;; + *) + # 保持原样 + ;; +esac +DOCKER_PLATFORM="$OS/$ARCH" + # Initialize variables REGISTRY_URL="" REGISTRY_NS="" @@ -83,7 +113,7 @@ popd > /dev/null # Write images.txt file echo "[record images] Writing tags to $IMAGES_DIR/images.txt" -printf "%s\n" "$@" > "$IMAGES_DIR/images.txt" +printf "%s --platform=$DOCKER_PLATFORM \n" "$@" > "$IMAGES_DIR/images.txt" # Execute git commit echo "[commit images] Start git commit:" diff --git a/images.txt b/images.txt index 8b13789..ed31784 100644 --- a/images.txt +++ b/images.txt @@ -1 +1 @@ - +node:lts --platform=linux/arm64 diff --git a/sync.sh b/sync.sh index 06ec01f..6decf96 100644 --- a/sync.sh +++ b/sync.sh @@ -22,10 +22,20 @@ fi failed_count=0 failed_images="" -while IFS= read -r image; do +while IFS= read -r image_and_platform; do + # Check if platform information is present + if [[ "$image_and_platform" == *"--platform="* ]]; then + # Extract platform information and image name + image=$(echo "$image_and_platform" | sed -e "s/--platform=[^ ]*//g" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + platform_arg=$(echo "$image_and_platform" | grep -o -- "--platform=[^ ]*") + else + # No platform information + image="$image_and_platform" + platform_arg="" + fi # 拉取镜像 set +e - docker pull "$image" + docker pull "$image" $platform_arg pull_status=$? if [ $pull_status -ne 0 ]; then echo "Error: Failed to pull image $image, continuing..."