@@ -18,6 +18,20 @@ function usage() {
18
18
exit 1
19
19
}
20
20
21
+ function skopeo_retry() {
22
+ for attempt in $( seq 3) ; do
23
+ if ! skopeo " $@ " ; then
24
+ echo " WARNING: Failed to run skopeo, retry #${attempt} "
25
+ else
26
+ return 0
27
+ fi
28
+ sleep $(( "${attempt} " * 10 ))
29
+ done
30
+
31
+ echo " ERROR: Failed to run skopeo, quitting after 3 tries"
32
+ return 1
33
+ }
34
+
21
35
function mirror_registry() {
22
36
local -r img_pull_file=$1
23
37
local -r img_file_list=$2
@@ -39,15 +53,13 @@ function mirror_registry() {
39
53
40
54
# Run the image mirror and tag command
41
55
echo " Mirroring '${src_img} ' to '${dst_img} '"
42
- skopeo copy --all --quiet \
43
- --retry-times 3 \
56
+ skopeo_retry copy --all --quiet \
44
57
--preserve-digests \
45
58
--authfile " ${img_pull_file} " \
46
59
docker://" ${src_img} " docker://" ${dst_img} "
47
60
48
61
echo " Tagging '${dst_img_no_tag} ' as 'latest'"
49
- skopeo copy --all --quiet \
50
- --retry-times 3 \
62
+ skopeo_retry copy --all --quiet \
51
63
--preserve-digests \
52
64
--authfile " ${img_pull_file} " \
53
65
docker://" ${dst_img} " docker://" ${dst_img_no_tag} :latest"
@@ -56,6 +68,7 @@ function mirror_registry() {
56
68
57
69
# Export functions for xargs to use
58
70
export -f process_image_copy
71
+ export -f skopeo_retry
59
72
# Note that images are passed as one argument by replacing "{}" in xarg input.
60
73
xargs -P 8 -I {} -a " ${img_file_list} " \
61
74
bash -c ' process_image_copy "$@"' _ " ${img_pull_file} " " ${dest_registry} " " {}"
@@ -78,15 +91,15 @@ function registry_to_dir() {
78
91
# Run the image download command
79
92
echo " Downloading '${src_img} ' to '${local_dir} '"
80
93
mkdir -p " ${local_dir} /${dst_img} "
81
- skopeo copy --all --quiet \
82
- --retry-times 3 \
94
+ skopeo_retry copy --all --quiet \
83
95
--preserve-digests \
84
96
--authfile " ${img_pull_file} " \
85
97
docker://" ${src_img} " dir://" ${local_dir} /${dst_img} "
86
98
}
87
99
88
100
# Export functions for xargs to use
89
101
export -f process_image_copy
102
+ export -f skopeo_retry
90
103
# Generate a list for each image and run copy in parallel.
91
104
# Note that the image is passed by replacing "{}" in xarg input.
92
105
xargs -P 8 -I {} -a " ${img_file_list} " \
@@ -113,22 +126,21 @@ function dir_to_registry() {
113
126
114
127
# Run the image upload and tag commands
115
128
echo " Uploading '${src_img} ' to '${dst_img} '"
116
- skopeo copy --all --quiet \
117
- --retry-times 3 \
129
+ skopeo_retry copy --all --quiet \
118
130
--preserve-digests \
119
131
--authfile " ${img_pull_file} " \
120
132
dir://" ${local_dir} /${src_img} " docker://" ${dst_img} "
121
133
122
134
echo " Tagging '${dst_img} ' as '${dst_img_no_tag} :latest'"
123
135
skopeo copy --all --quiet \
124
- --retry-times 3 \
125
136
--preserve-digests \
126
137
--authfile " ${img_pull_file} " \
127
138
docker://" ${dst_img} " docker://" ${dst_img_no_tag} :latest"
128
139
}
129
140
130
141
# Export functions for xargs to use
131
142
export -f process_image_copy
143
+ export -f skopeo_retry
132
144
133
145
# Generate a list with an incremental counter for each image and run copy in parallel.
134
146
# Note that the counter and image pairs are passed as one argument by replacing "{}" in xarg input.
0 commit comments