Skip to content

Update images.txt

Update images.txt #6

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
echo "处理镜像: $image"
# 拉取镜像
docker pull $image
# 解析镜像名称和标签
IFS=':' read -r name tag <<< "$image"
# 处理可能包含额外层级的镜像名称
IFS='/' read -r org repo <<< "$name"
if [ -z "$repo" ]; then
repo=$org
org=""
fi
# 构建目标镜像名称(确保使用三级目录结构)
if [ -z "$org" ]; then
target_image="${CODING_REGISTRY}/${CODING_NAMESPACE}/${repo}:${tag}"
else
target_image="${CODING_REGISTRY}/${CODING_NAMESPACE}/${org}-${repo}:${tag}"
fi
# 标记镜像
docker tag $image $target_image
# 推送镜像到腾讯云 Coding
docker push $target_image
echo "镜像 $image 同步完成,已推送到 $target_image"
done < images.txt