forked from aopkcn/docker-pull
-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (77 loc) · 2.54 KB
/
docker-pull.yml
File metadata and controls
91 lines (77 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: 批量镜像同步
on:
workflow_dispatch:
inputs:
TARGET_REGISTRY:
description: '仓库地址'
required: true
default: 'swr.cn-south-1.myhuaweicloud.com'
TARGET_REPOSITORY:
description: '空间名称'
required: true
default: 'kehang'
ARCH:
description: '系统架构'
required: true
default: 'amd64'
type: choice
options:
- amd64
- arm64
- arm/v7
- arm/v6
- 386
- s390x
- ppc64le
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v2
- name: 登录到华为云ACR
id: login
env:
ACR_USERNAME: cn-south-1@YNRH4VJ88CVFYLAADKLQ
ACR_PASSWORD: 66ea1b435399a90247838f0d3cd049b9ff1300b91a4c8dd0102cc58c91a3a965
run: |
docker login -u $ACR_USERNAME -p $ACR_PASSWORD ${{ inputs.TARGET_REGISTRY }}
- name: 读取镜像列表文件
id: read_images
run: |
# 验证文件存在
if [ ! -f images.txt ]; then
echo "❌ 镜像列表文件 images.txt 未找到"
exit 1
fi
# 输出文件内容供调试
echo "📋 镜像列表内容:"
cat images.txt
echo "------------------------------------"
- name: 批量同步镜像
id: sync_images
run: |
while IFS=',' read -r src_image dst_image; do
# 去除首尾空格
src_image=$(echo $src_image | xargs)
dst_image=$(echo $dst_image | xargs)
echo "🔄 正在处理镜像对: $src_image → $dst_image"
# 完整目标镜像地址
target_image="${{ inputs.TARGET_REGISTRY }}/${{ inputs.TARGET_REPOSITORY }}/$dst_image"
# 拉取镜像
echo "⬇️ 拉取镜像: $src_image"
docker pull --platform ${{ inputs.ARCH }} $src_image
# 重新打标签
echo "🏷️ 标记镜像: $target_image"
docker tag $src_image $target_image
# 推送镜像
echo "⬆️ 推送镜像: $target_image"
docker push $target_image
echo "✅ 完成: $src_image → $target_image"
echo "------------------------------------"
done < images.txt
- name: 清理工作环境
if: always()
run: |
echo "🧹 清理临时镜像..."
docker image prune -a -f