两个Harbor镜像库之间备份拉取镜像的shell脚本

#当前日期
now=`date +%Y%m%d`

#镜像名
ImageName=web

#项目版本
itemVersion=v2.1

#测试环境镜像
test_images=测试环境IP地址:端口号/pbplatform/$ImageName

#产品环境镜像
project_images=正式环境IP地址:端口号/pbplatform/$ImageName

#产品备份镜像仓库
bk_project_images=测试环境IP地址:端口号/pbplatform/$ImageName:$itemVersion-$now.$BUILD_NUMBER

#清理环境
echo y | docker system prune -a

#拉取产品仓库的镜像
check_imges_project=`docker pull $project_images:$itemVersion | grep $test_images | wc -l`
if test $check_imges_project -gt 1;then
docker pull $project_images:$itemVersion
else
echo "产品仓库中没有该镜像"
fi

#备份该镜像
check_images=`docker images | grep $project_images | wc -l`
if ! test $check_images -lt 1;then
docker tag $project_images:$itemVersion $bk_project_images
#上传备份镜像
docker push $bk_project_images
else
echo "本地环境没有源自产品仓库镜像,无需删除"
fi

#清理环境
echo y | docker system prune -a

#拉取测试环境镜像
check_imges_tet=`docker pull $test_images:$TestVersion | grep $test_images | wc -l`
if test $check_imges_test -gt 1;then
docker pull $test_images:$TestVersion
else
echo "测试仓库中没有该镜像"
fi
 
**#Tag镜像**
check_images1=`docker images | grep $test_images | wc -l`
if ! test $check_images1 -lt 1;then
docker tag $test_images:$TestVersion $project_images:$itemVersion
#上传镜像到产品镜像仓库
docker push $project_images:$itemVersion
else
echo "不存在该镜像,无需删除"
fi

#清理环境
echo y | docker system prune -a

你可能感兴趣的:(两个Harbor镜像库之间备份拉取镜像的shell脚本)