拉取镜像代码

# 检测是否含有 yq 命令
echo -e "正在将内容输出至 $Images_File 文件中,请稍等..."

# 获取Harbor中所有的项目(Projects)
Project_List=$(curl -u ${Harbor_User}:${Harbor_Passwd} -H "Content-Type: application/json" -X GET "${Harbor_Schema}://${Harbor_Address}/api/v2.0/projects?page_size=100" -k -s | yq '.[].name' -)

for Project in $Project_List;do
# 循环获取项目下所有的镜像
Image_Names=$(curl -u ${Harbor_User}:${Harbor_Passwd} -H "Content-Type: application/json" -X GET "${Harbor_Schema}://${Harbor_Address}/api/v2.0/projects/$Project/repositories?page_size=100" -k -s | yq '.[].name' -)
for Image in $Image_Names;do
# 循环获取镜像的版本(tag)
Image_Tags=$(curl -u ${Harbor_User}:${Harbor_Passwd} -H "Content-Type: application/json" -X GET ${Harbor_Schema}://${Harbor_Address}/v2/$Image/tags/list -k -s | yq '.tags' | awk -F "[" '{print $2}' | awk -F "]" '{print $1}' | sed 's/\,//g')
for Tag in $Image_Tags;do
# 格式化输出镜像信息
echo "$Harbor_Address/$Image:$Tag" >> harbor-images-$DATE.txt
done
done
done
sed -i 's/"//g' harbor-images-$DATE.txt
echo -e "输出完成,请查看 $Images_File 文件"
for i in $(cat harbor-images-$DATE.txt)
do
docker pull $i
done

posted @ 2023-12-07 17:58  繁星下的晴空  阅读(19)  评论(0编辑  收藏  举报