Created
November 9, 2018 03:26
-
-
Save yiichou/233f5adf9c24b36f71fc00ee2645abe4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
registry=registry.cn-hangzhou.aliyuncs.com | |
inner_registry=registry-internal.cn-hangzhou.aliyuncs.com | |
vpc_registry=registry-vpc.cn-hangzhou.aliyuncs.com | |
if [ $(uname -a | awk '{print $1}') != "Darwin" ]; then | |
ping -c 1 -W 1 $vpc_registry > /dev/null | |
if [ "$?" == "0" ]; then | |
registry=$vpc_registry | |
else | |
ping -c 1 -W 1 $inner_registry > /dev/null | |
if [ "$?" == "0" ]; then | |
registry=$inner_registry | |
fi | |
fi | |
fi | |
rm_dangling_images () { | |
image_ids=$(docker images -q -f dangling=true) | |
[ -z "$image_ids" ] || docker rmi $image_ids | |
} | |
echo_r () { | |
[ $# -ne 1 ] && return 0 | |
echo -e "\033[31m$1\033[0m" | |
} | |
echo_g () { | |
[ $# -ne 1 ] && return 0 | |
echo -e "\033[32m$1\033[0m" | |
} | |
echo_y () { | |
[ $# -ne 1 ] && return 0 | |
echo -e "\033[33m$1\033[0m" | |
} | |
echo_b () { | |
[ $# -ne 1 ] && return 0 | |
echo -e "\033[34m$1\033[0m" | |
} | |
usage() { | |
docker images | |
echo "" | |
echo "Usage:" | |
echo " 1. push" | |
echo_g " $0 push REPOSITORY:TAG" | |
echo " 2. pull" | |
echo_g " $0 pull REPOSITORY:TAG" | |
} | |
[ $# -lt 1 ] && usage && exit 0 | |
echo_b "The registry server is $registry" | |
case "$1" in | |
push) | |
echo_b "Uploading $2..." | |
docker tag $2 $registry/$2 | |
docker push $registry/$2 | |
docker rmi $registry/$2 | |
echo_g "Done" | |
exit 0 | |
;; | |
pull) | |
echo_b "Pulling $2..." | |
docker pull $registry/$2 | |
docker tag $registry/$2 $2 | |
docker rmi $registry/$2 | |
echo_g "Done" | |
rm_dangling_images | |
exit 0 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment