Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
cmd/conf.yaml
cmd/conf.yaml
.idea
.vscode
6 changes: 3 additions & 3 deletions cmd/docker_pull
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand All @@ -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")
Expand Down
9 changes: 5 additions & 4 deletions sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ set -eux


# 检查参数数量是否正确
if [ "$#" -ne 3 ]; then
echo "错误:脚本需要3个参数 images_file、docker_registry和docker_namespace"
echo "用法: $0 <images_file> <docker_registry> <docker_namespace>"
if [ "$#" -ne 4 ]; then
echo "错误:脚本需要4个参数 images_file、docker_registry、docker_namespace、platform"
echo "用法: $0 <images_file> <docker_registry> <docker_namespace> <platform>"
exit 1
fi


IMAGES_FILE=$1
TARGET_REGISTRY=$2
TARGET_NAMESPACE=$3
TARGET_PLATFORM=$4

# 检查文件是否存在
if [ ! -f "$IMAGES_FILE" ]; then
Expand All @@ -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..."
Expand Down