diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/images_sync.iml b/.idea/images_sync.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/images_sync.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0319d80 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cmd/conf.yaml.default b/cmd/conf.yaml.default index ebbf8b9..516faa1 100644 --- a/cmd/conf.yaml.default +++ b/cmd/conf.yaml.default @@ -1,14 +1,6 @@ -### 复制该文件并命名为 conf.yaml,并填充以下自定义配置 - -# 阿里云个人镜像仓库地址 -registry: crpi-xxx.cn-xxx.personal.cr.aliyuncs.com -# 阿里云个人镜像仓库命名空间名称 -namespace: xxx -# 所在项目的git仓库本地路径,这里配置错误会导致git push 命令提示仓库不存在 -images_dir: "E:\Git\docker_images_sync" -# 单个镜像拉取最大尝试次数,默认为60 +registry: crpi-s67w1v25xu5dvvj8.cn-heyuan.personal.cr.aliyuncs.com +namespace: faiz_docker_image_sync +images_dir: "/Users/lyydsheep/workspace/Go/projects/images_sync" max_retries: 60 -# 拉取镜像尝试间隔(秒),默认为1 retry_delay: 1 -# 将镜像tag提交后等待多久开始尝试拉取镜像(秒),默认为20 first_delay: 20 diff --git a/cmd/docker-compose.test.yaml b/cmd/docker-compose.test.yaml new file mode 100644 index 0000000..0bfc347 --- /dev/null +++ b/cmd/docker-compose.test.yaml @@ -0,0 +1,8 @@ +# docker-compose.test.yaml +services: + web: + image: nginx:1.25 + db: + image: postgres:15-alpine + cache: + image: \ No newline at end of file diff --git a/cmd/docker_compose_pull b/cmd/docker_compose_pull new file mode 100755 index 0000000..38082b0 --- /dev/null +++ b/cmd/docker_compose_pull @@ -0,0 +1,37 @@ +#!/bin/bash +docker_compose_pull() { + # Find all matching docker-compose files + compose_files=$(find . -name 'docker-compose*.yaml' -type f 2>/dev/null) + + [ -z "$compose_files" ] && { + echo "Error: No docker-compose*.yaml files found" + return 1 + } + + # Store all image names + declare -a all_images + + for file in $compose_files; do + echo "Scanning file: $file" + # Extract all image fields using yq + while IFS= read -r image; do + [ -n "$image" ] && all_images+=("$image") + done < <(yq eval '.services[].image' "$file" | grep -v 'null' | sort -u) + done + + [ ${#all_images[@]} -eq 0 ] && { + echo "Warning: No valid image names detected" + return 0 + } + + # Execute image pulling by docker_pull + echo "Starting image pull..." + for img in "${all_images[@]}"; do + echo "Pulling: $img" + docker_pull "$img" + done + echo "Operation completed!" +} + +# Call the function +docker_compose_pull \ No newline at end of file diff --git a/images.txt b/images.txt index 8b13789..74a9548 100644 --- a/images.txt +++ b/images.txt @@ -1 +1 @@ - +golang:1.18 diff --git a/sync.sh b/sync.sh index 06ec01f..b141a08 100644 --- a/sync.sh +++ b/sync.sh @@ -25,7 +25,7 @@ failed_images="" while IFS= read -r image; do # 拉取镜像 set +e - docker pull "$image" + docker pull --platform linux/arm64 "$image" pull_status=$? if [ $pull_status -ne 0 ]; then echo "Error: Failed to pull image $image, continuing..."