From b7487c70ba423c706502f876366e5104a276726f Mon Sep 17 00:00:00 2001 From: TL <43626236+OnlyTL@users.noreply.github.com> Date: Thu, 1 Aug 2024 13:49:56 +0800 Subject: [PATCH] Create docker-image-sync.yml --- .github/workflows/docker-image-sync.yml | 51 +++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/docker-image-sync.yml diff --git a/.github/workflows/docker-image-sync.yml b/.github/workflows/docker-image-sync.yml new file mode 100644 index 0000000..8c0c6f8 --- /dev/null +++ b/.github/workflows/docker-image-sync.yml @@ -0,0 +1,51 @@ +name: Docker Image Sync to Tencent Coding + +on: + push: + paths: + - 'images.txt' + +env: + CODING_REGISTRY: ${{ secrets.CODING_REGISTRY }} # 腾讯云 Coding 镜像仓库地址 + CODING_NAMESPACE: ${{ secrets.CODING_NAMESPACE }} # 腾讯云 Coding 命名空间 + +jobs: + sync-images: + runs-on: ubuntu-latest + steps: + - name: 检出代码 + uses: actions/checkout@v2 + + - name: 设置 Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: 登录到腾讯云 Coding 镜像仓库 + uses: docker/login-action@v1 + with: + registry: ${{ secrets.CODING_REGISTRY }} + username: ${{ secrets.CODING_USERNAME }} + password: ${{ secrets.CODING_PASSWORD }} + + - name: 读取镜像列表并同步 + run: | + # 读取 images.txt 文件中的镜像列表 + while IFS= read -r image || [[ -n "$image" ]]; do + # 跳过空行和注释行 + [[ -z "$image" || "$image" =~ ^#.*$ ]] && continue + + # 解析镜像名称和标签 + IFS=':' read -r name tag <<< "$image" + + echo "处理镜像: $image" + + # 拉取镜像 + docker pull $image + + # 标记镜像 + docker tag $image ${{ secrets.CODING_REGISTRY }}/${{ secrets.CODING_NAMESPACE }}/$name:$tag + + # 推送镜像到腾讯云 Coding + docker push ${{ secrets.CODING_REGISTRY }}/${{ secrets.CODING_NAMESPACE }}/$name:$tag + + echo "镜像 $image 同步完成" + done < images.txt