#!/bin/bash
harbor2="harbor.sddts.cn"
dockerhubTokens=("zzlyzq:111" "zzlyzq1:111")
docker login -u zzlyzq -p "111" docker.io
docker login -u admin -p "111" harbor.sddts.cn
#projects=("library/mysql" "library/alpine")
projects=("library/mysql" "library/alpine" "library/centos" "library/debian" "library/ubuntu" "library/python" "library/redis" "library/nginx" "library/busybox" "library/postgres" "library/node" "library/memcached" "library/httpd" "library/mongo" "library/rabbitmq" "library/mariadb" "library/docker" "library/hello-world" "library/openjdk" "library/golang" "library/registry" "library/wordpress" "library/php" "library/consul" "library/influxdb" "library/haproxy" "library/tomcat" "library/maven" "library/bash" "library/ghost" "library/kong" "library/zookeeper" "jenkins/jenkins" "library/mediawiki" "library/django" "library/gcc" "chaitin/safeline-tengine" "chaitin/safeline-mgt-api" "chaitin/safeline-detector" "chaitin/safeline-mario" "jumpserver/lion" "jumpserver/koko" "jumpserver/guacamole" "jumpserver/core" "jumpserver/jms_all" "jumpserver/web" "jumpserver/redis" "jumpserver/nginx" "jumpserver/core" "jumpserver/mysql" "jumpserver/magnus" "jumpserver/mariadb" "jumpserver/luna" "jumpserver/guacamole" "jumpserver/lina" "jumpserver/chen" "jumpserver/kael" "jumpserver/guacd" "jumpserver/python" "jumpserver/jms_web")
if [ ! -e /bin/docker-ls ]; then
wget https://vip.123pan.cn/1815238395/download/docker-ls/docker-ls-linux-amd64.zip -O /tmp/docker-ls-linux-amd64.zip
unzip -d /bin/ /tmp/docker-ls-linux-amd64.zip
fi
for project in "${projects[@]}"; do
echo "开始新的project"
echo $project
tagList=$(docker-ls tags $project 2>/dev/null | grep '\- ' | tr -d '"' | awk '{print $2}')
echo "tagList is $tagList"
tagList2=$(docker-ls tags -r https://$harbor2 -u admin -p 111 $project 2>/dev/null | grep '\- ' | tr -d '"' | awk '{print $2}')
echo "tagList2 is $tagList2"
for tag in $tagList; do
if [ "$tag" == "latest" ]; then
echo "发现latest TAG标签"
else
if [ $(echo $tagList2 | grep $tag | wc -l) -eq 1 ]; then
echo "tag $tag 已存在目标harbor中,本次跳过"
continue
else
echo "tag $tag 不存在目标harbor中,本次继续"
fi
fi
imageName="$project:$tag"
imageName1="docker.io/$imageName"
for token in "${dockerhubTokens[@]}"; do
IFS=":" read -ra values <<<"$token"
token_id="${values[0]}"
echo $token_id
echo $token_key
token_key="${values[1]}"
docker login -u $token_id -p $token_key https://docker.io
docker pull "$imageName1"
if [ $? -eq 0 ]; then
echo "下载$imageName1正常。"
break
else
echo "下载$imageName1异常。"
fi
done
imageName2="$harbor2/$imageName"
docker tag $imageName1 $imageName2
docker push $imageName2
docker rmi $imageName1 $imageName2
done
done
最后修改:2024 年 05 月 11 日
© 允许规范转载