@@ -21,17 +21,30 @@ function usage() {
21
21
function skopeo_retry() {
22
22
for attempt in $( seq 3) ; do
23
23
if ! skopeo " $@ " ; then
24
- echo " WARNING: Failed to run skopeo, retry #${attempt} "
24
+ echo " WARNING: Failed to run skopeo, retry #${attempt} " >&2
25
25
else
26
26
return 0
27
27
fi
28
28
sleep $(( "${attempt} " * 10 ))
29
29
done
30
30
31
- echo " ERROR: Failed to run skopeo, quitting after 3 tries"
31
+ echo " ERROR: Failed to run skopeo, quitting after 3 tries" >&2
32
32
return 1
33
33
}
34
34
35
+ function skopeo_opts_for_image() {
36
+ local -r img_pull_file=" $1 "
37
+ local -r img_src_ref=" $2 "
38
+
39
+ # Cannot copy a single platform for manifest image references
40
+ local media_type
41
+ media_type=$( skopeo_retry inspect --raw --authfile " ${img_pull_file} " " ${img_src_ref} " | jq -r .mediaType)
42
+ if [ " ${media_type} " == " application/vnd.docker.distribution.manifest.list.v2+json" ] ; then
43
+ echo -n " --all"
44
+ fi
45
+ echo -n " "
46
+ }
47
+
35
48
function mirror_registry() {
36
49
local -r img_pull_file=$1
37
50
local -r img_file_list=$2
@@ -50,25 +63,29 @@ function mirror_registry() {
50
63
# Add the target registry prefix
51
64
dst_img=" ${dest_registry} /${dst_img} "
52
65
dst_img_no_tag=" ${dest_registry} /${dst_img_no_tag} "
66
+ # Determine skopeo options
67
+ local -r skopeo_opts=$( skopeo_opts_for_image " ${img_pull_file} " docker://" ${src_img} " )
53
68
54
69
# Run the image mirror and tag command
55
70
echo " Mirroring '${src_img} ' to '${dst_img} '"
56
- skopeo_retry copy --all --quiet \
71
+ # shellcheck disable=SC2086
72
+ skopeo_retry copy ${skopeo_opts} --quiet \
57
73
--preserve-digests \
58
74
--authfile " ${img_pull_file} " \
59
75
docker://" ${src_img} " docker://" ${dst_img} "
60
76
61
77
echo " Tagging '${dst_img_no_tag} ' as 'latest'"
62
- skopeo_retry copy --all --quiet \
78
+ # shellcheck disable=SC2086
79
+ skopeo_retry copy ${skopeo_opts} --quiet \
63
80
--preserve-digests \
64
81
--authfile " ${img_pull_file} " \
65
82
docker://" ${dst_img} " docker://" ${dst_img_no_tag} :latest"
66
-
67
83
}
68
84
69
85
# Export functions for xargs to use
70
86
export -f process_image_copy
71
87
export -f skopeo_retry
88
+ export -f skopeo_opts_for_image
72
89
# Note that images are passed as one argument by replacing "{}" in xarg input.
73
90
xargs -P 8 -I {} -a " ${img_file_list} " \
74
91
bash -c ' process_image_copy "$@"' _ " ${img_pull_file} " " ${dest_registry} " " {}"
@@ -87,11 +104,14 @@ function registry_to_dir() {
87
104
# Remove the source registry prefix
88
105
local dst_img
89
106
dst_img=$( echo " ${src_img} " | cut -d ' /' -f 2-)
107
+ # Determine skopeo options
108
+ local -r skopeo_opts=$( skopeo_opts_for_image " ${img_pull_file} " docker://" ${src_img} " )
90
109
91
110
# Run the image download command
92
111
echo " Downloading '${src_img} ' to '${local_dir} '"
93
112
mkdir -p " ${local_dir} /${dst_img} "
94
- skopeo_retry copy --all --quiet \
113
+ # shellcheck disable=SC2086
114
+ skopeo_retry copy ${skopeo_opts} --quiet \
95
115
--preserve-digests \
96
116
--authfile " ${img_pull_file} " \
97
117
docker://" ${src_img} " dir://" ${local_dir} /${dst_img} "
@@ -100,6 +120,7 @@ function registry_to_dir() {
100
120
# Export functions for xargs to use
101
121
export -f process_image_copy
102
122
export -f skopeo_retry
123
+ export -f skopeo_opts_for_image
103
124
# Generate a list for each image and run copy in parallel.
104
125
# Note that the image is passed by replacing "{}" in xarg input.
105
126
xargs -P 8 -I {} -a " ${img_file_list} " \
@@ -123,16 +144,20 @@ function dir_to_registry() {
123
144
# Add the target registry prefix and remove SHA
124
145
local -r dst_img=" ${dest_registry} /${src_img} "
125
146
local -r dst_img_no_tag=" ${dest_registry} /${src_img%% [@:]* } "
147
+ # Determine skopeo options
148
+ local -r skopeo_opts=$( skopeo_opts_for_image " ${img_pull_file} " dir://" ${src_img} " )
126
149
127
150
# Run the image upload and tag commands
128
151
echo " Uploading '${src_img} ' to '${dst_img} '"
129
- skopeo_retry copy --all --quiet \
152
+ # shellcheck disable=SC2086
153
+ skopeo_retry copy ${skopeo_opts} --quiet \
130
154
--preserve-digests \
131
155
--authfile " ${img_pull_file} " \
132
156
dir://" ${local_dir} /${src_img} " docker://" ${dst_img} "
133
157
134
158
echo " Tagging '${dst_img} ' as '${dst_img_no_tag} :latest'"
135
- skopeo_retry copy --all --quiet \
159
+ # shellcheck disable=SC2086
160
+ skopeo_retry copy ${skopeo_opts} --quiet \
136
161
--preserve-digests \
137
162
--authfile " ${img_pull_file} " \
138
163
docker://" ${dst_img} " docker://" ${dst_img_no_tag} :latest"
@@ -141,6 +166,7 @@ function dir_to_registry() {
141
166
# Export functions for xargs to use
142
167
export -f process_image_copy
143
168
export -f skopeo_retry
169
+ export -f skopeo_opts_for_image
144
170
145
171
# Generate a list with an incremental counter for each image and run copy in parallel.
146
172
# Note that the counter and image pairs are passed as one argument by replacing "{}" in xarg input.
0 commit comments