#!/bin/bash

harbor2="harbor.sddts.cn"
harbor1List=("docker.io" "dockerproxy.com" "docker.nju.edu.cn")

docker login -u zzlyzq -p "111" docker.io
docker login -u admin -p "123" 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
  tagList=$(docker-ls tags -r https://docker.io -u zzlyzq -p "123" $project 2>/dev/null | grep '\- ' | tr -d '"' | awk '{print $2}')
  tagList2=$(docker-ls tags -r https://$harbor2 -u admin -p 123 $project 2>/dev/null | grep '\- ' | tr -d '"' | awk '{print $2}')
  for tag in $tagList; do
    if [ "$tag" = "latest" ]; then
      continue
    else
      #ifExistsIn=`echo $tagList2 | grep $tag | wc -l`
      if [ $(echo $tagList2 | grep $tag | wc -l) -eq 1 ]; then
        echo "tag $tag 已存在目标harbor中,本次跳过"
        continue
      else
        echo "tag $tag 不存在目标harbor中,本次继续"
      fi
    fi

    for harbor1 in "${harbor1List[@]}"; do
      imageName="$project:$tag"
      imageName1="$harbor1/$imageName"
      echo "开始下载$imageName1"
      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 日
如果觉得我的文章对你有用,请随意赞赏