diff --git a/.github/workflows/sync.yaml b/.github/workflows/sync.yaml index 730c0cb..39c40ad 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,10 @@ 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 }}" + if [[ "${{ matrix.platform }}" == "linux/arm64" ]]; then + NS="${{ secrets.DOCKER_NS_ARM }}" + else + NS="${{ secrets.DOCKER_NS }}" + fi + bash "${{ github.workspace }}/sync.sh" "${{ github.workspace }}/images.txt" "${{ secrets.DOCKER_REGISTRY }}" "$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/README.md b/README.md index 5b903a5..3500dc0 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ ![image](images/077GE2yiN_IRLeapyG-PvWwf2xKNMgeiVPtFWVIW-GA.png) +这里创建两个命名空间,一个用于x86架构,一个用于arm架构,方便后续脚本配置 + 记住该命名空间名称,后续配置会用到。 4. **记录登录凭证** @@ -98,7 +100,8 @@ fork开源仓库[https://github.com/you8023/docker\_images\_sync](https://github * `DOCKER_USER`:阿里云账户 * `DOCKER_PWD`:2.1中第2步设置的阿里云镜像仓库密码 * `DOCKER_REGISTRY`:2.1中第4步中记住的登录凭证页面中的仓库地址 -* `DOCKER_NS`:2.1中第3步创建的命名空间名称 +* `DOCKER_NS`:2.1中第3步创建的x86架构的命名空间名称 +* `DOCKER_NS_ARM`:2.1中第3步创建的arm64架构的命名空间名称 添加后应能看到: @@ -112,9 +115,9 @@ fork开源仓库[https://github.com/you8023/docker\_images\_sync](https://github 1. 复制本地仓库中的`cmd/conf.yaml.default`文件并命名为`cmd/conf.yaml` 2. 编辑`cmd/conf.yaml` ,配置说明如下: -```bash +```yaml registry: 阿里云个人镜像仓库地址,形如:crpi-xxx.cn-xxx.personal.cr.aliyuncs.com -namespace: 阿里云个人镜像仓库命名空间名称 +namespace: 阿里云个人镜像仓库命名空间名称(根据自己的cpu架构选择对应的命名空间) images_dir: git仓库路径,例如:"E:\Git\docker_images_sync" max_retries: 拉取镜像重试次数,默认为60 retry_delay: 拉取镜像尝试间隔(秒),默认为1 diff --git a/cmd/docker_pull b/cmd/docker_pull old mode 100644 new mode 100755 index c096336..0abaeb6 --- a/cmd/docker_pull +++ b/cmd/docker_pull @@ -49,8 +49,8 @@ while IFS= read -r line || [ -n "$line" ]; do done < "$CONFIG_FILE" # Set defaults -MAX_RETRIES=${MAX_RETRIES:-60} -RETRY_DELAY=${RETRY_DELAY:-1} +MAX_RETRIES=${MAX_RETRIES:-120} +RETRY_DELAY=${RETRY_DELAY:-5} FIRST_DELAY=${FIRST_DELAY:-20} # Check required configurations diff --git a/cmd/images.txt b/cmd/images.txt new file mode 100644 index 0000000..93e1a34 --- /dev/null +++ b/cmd/images.txt @@ -0,0 +1 @@ +mysql:8.4.5 diff --git a/images.txt b/images.txt index 8b13789..871b2dd 100644 --- a/images.txt +++ b/images.txt @@ -1 +1 @@ - +justlikemaki/openclaw-docker-cn-im:latest 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..."