Shell - harbor

2022-06-16
#!/bin/bash
url="https://harbor.sa.iyunquna.com"
user="admin"
password="xxxxx"
pull_sh="/tmp/pull.sh"
cat /dev/null > ${pull_sh}

project="yqn-library"
repos=$(curl -s  -u "${user}:${password}" -X GET -H "Content-Type: application/json" "${url}/api/v2.0/search?q=library" | jq .repository  |jq '.[]' | jq -r ".repository_name" )
for repo in ${repos}
do
    echo $repo
    image=$(echo ${repo} | awk -F '/' '{print $2}')
    curl -s -u "${user}:${password}" -X GET -H "Content-Type: application/json" "${url}/api/v2.0/projects/${project}/repositories/${image}/artifacts"  | jq ".[].tags"|jq -r ".[]|.name" | awk '{print "docker pull harbor.sa.iyunquna.com/""'"${repo}"'"":"$1}' | grep ${project} | grep ":"  >> ${pull_sh}
done