This commit is contained in:
anjia0532 2018-06-21 09:48:15 +08:00
parent 58d9695425
commit 216e6d978e
1 changed files with 18 additions and 22 deletions

View File

@ -34,7 +34,7 @@ function init_namespace()
for img in ${imgs[@]} ; do for img in ${imgs[@]} ; do
process_run "init_imgs $img" process_run "init_imgs $img"
done done
wait ${!} wait
} }
function init_imgs() function init_imgs()
@ -56,7 +56,6 @@ function init_imgs()
function compare() function compare()
{ {
echo -e "${yellow}compare image diff ...${plain}" echo -e "${yellow}compare image diff ...${plain}"
find ./gcr.io_mirror/ -name "*.tmp" | while read t find ./gcr.io_mirror/ -name "*.tmp" | while read t
do do
@ -74,8 +73,8 @@ function pull_push_diff()
{ {
n=$1 n=$1
img=$2 img=$2
all_of_imgs=$(find ./gcr.io_mirror -type f \( ! -iname "*.md" \) |wc -l) all_of_imgs=$(find ./gcr.io_mirror -type f -name "*.t*" |wc -l)
current_ns_imgs=$(find ./gcr.io_mirror/${n}/ -type f \( ! -iname "*.md" \) |wc -l) current_ns_imgs=$(find ./gcr.io_mirror/${n}/ -type f -name "*.t*" |wc -l)
tmps=($(find ./gcr.io_mirror/${n}/${img}/ -type f \( -iname "*.tmp" \) -exec basename {} .tmp \; | uniq)) tmps=($(find ./gcr.io_mirror/${n}/${img}/ -type f \( -iname "*.tmp" \) -exec basename {} .tmp \; | uniq))
echo -e "${red}wait for mirror${plain}/${yellow}gcr.io/${n}/* images${plain}/${green}all of images${plain}:${red}${#tmps[@]}${plain}/${yellow}${current_ns_imgs}${plain}/${green}${all_of_imgs}${plain}" echo -e "${red}wait for mirror${plain}/${yellow}gcr.io/${n}/* images${plain}/${green}all of images${plain}:${red}${#tmps[@]}${plain}/${yellow}${current_ns_imgs}${plain}/${green}${all_of_imgs}${plain}"
@ -90,13 +89,14 @@ function pull_push_diff()
docker tag gcr.io/${n}/${img}:${tag} ${user_name}/${n}.${img}:${tag} docker tag gcr.io/${n}/${img}:${tag} ${user_name}/${n}.${img}:${tag}
docker push ${user_name}/${n}.${img}:${tag} docker push ${user_name}/${n}.${img}:${tag}
[[ -e ./commit.lck ]] && break [[ -e ./commit.lck ]] && echo -e "${red} commit.lck exist "&& break
mv ./gcr.io_mirror/${n}/${img}/${tag}.tmp ./gcr.io_mirror/${n}/${img}/${tag}.tag mv ./gcr.io_mirror/${n}/${img}/${tag}.tmp ./gcr.io_mirror/${n}/${img}/${tag}.tag
echo -e "[gcr.io/${n}/${image}:${tag}](https://hub.docker.com/r/${user_name}/${n}.${image}/tags/)\n\n" >> CHANGES.md echo -e "[gcr.io/${n}/${image}:${tag}](https://hub.docker.com/r/${user_name}/${n}.${image}/tags/)\n\n" >> CHANGES.md
rm -rf $lock rm -rf $lock
done done
echo -e "${red} push ${n}/${img} done"
} }
function mirror() function mirror()
@ -107,7 +107,7 @@ function mirror()
for n in ${ns[@]} ; do for n in ${ns[@]} ; do
process_run "init_namespace $n" process_run "init_namespace $n"
done done
wait ${!} wait
fi fi
sleep 30 sleep 30
@ -115,22 +115,18 @@ function mirror()
sleep 30 sleep 30
compare compare
while true tmp_imgs=$(find ./gcr.io_mirror/ -type f \( -iname "*.tmp" \) -exec dirname {} \; | uniq | cut -d'/' -f3-4)
do
tmps=$(find ./gcr.io_mirror/ -type f \( -iname "*.tmp" \) -exec dirname {} \; | uniq | cut -d'/' -f3-4) if [ -n "$tmp_imgs[@]" ]; then
if [ -n "$tmps[@]" ]; then echo -e "${red} wait for push ${tmp_imgs[@]}"
echo -e "${red} wait for push ${tmps[@]}" for img in ${tmp_imgs[@]} ; do
for img in ${tmps[@]} ; do echo -e "${red} wait for push ${img}"
n=$(echo ${img}|cut -d'/' -f1) n=$(echo ${img}|cut -d'/' -f1)
image=$(echo ${img}|cut -d'/' -f2) image=$(echo ${img}|cut -d'/' -f2)
process_run "pull_push_diff $n $image" process_run "pull_push_diff $n $image"
done done
wait wait
else fi
break
fi
sleep 30
done
images=($(find ./gcr.io_mirror/ -type f -name "*.tag" |uniq|sort)) images=($(find ./gcr.io_mirror/ -type f -name "*.tag" |uniq|sort))