zoukankan      html  css  js  c++  java
  • harbor清理存储

    harbor仓库中镜像按tag清理,删除tag后需要清理gc才能释放空间

    #!/bin/bash
    set -e
    HARBOR_URL=127.0.0.1
    HARBOR_PASSWD=harbor123
    OLD_VERSION_NUM=50
    
    function get_repos_list(){
      repos_list=$(curl -s -k -u admin:${HARBOR_PASSWD} http://${HARBOR_URL}/api/projects?page=1&page_size=50)
      mkdir -p $PWD/reposList
      echo "${repos_list}" | jq '.[]' | jq -r '.project_id' > $PWD/reposList/reposList.txt
    }
    function get_images_list(){
      mkdir -p $PWD/imagesList
      for repo in $(cat $PWD/reposList/reposList.txt);do
        images_list=$(curl -s -k -u admin:${HARBOR_PASSWD} http://${HARBOR_URL}/api/repositories?project_id=${repo})
        echo "${images_list}" | jq '.[]' | jq -r '.name' > $PWD/imagesList/${repo}.txt
      done
    }
    function delete_images(){
      #### get html
      htmlinfo=$(curl -s -k -u admin:${HARBOR_PASSWD} http://${HARBOR_URL}/api/repositories/$1/tags)
      #### images num
      num=$(echo "${htmlinfo}" | jq "length - ${OLD_VERSION_NUM}")
      if [[ "${num}" -le "0" ]]; then
        echo "$1 has no need of cleanup!!!"
        return
      fi
      #### get images_tag
      for index in $(seq 0 ${num}); do
        tag=$(echo "${htmlinfo}" | jq ".[${index}]" | jq -r '.name')
        echo "images=$1 ************************** tag= ${tag}"
        curl -s -k -u admin:${HARBOR_PASSWD} -X DELETE http://${HARBOR_URL}/api/repositories/$1/tags/${tag}
      done
    }
    function clean_registry(){
      image_name=$(docker ps | grep registry | grep photon | awk -F " " '{print $2}')
      docker run -it --name gc --rm --volumes-from registry ${image_name} garbage-collect  /etc/registry/config.yml
    }
    function entrance(){
      get_repos_list
      get_images_list
      for repo in $(cat $PWD/reposList/reposList.txt);do
        for images in $(cat $PWD/imagesList/${repo}.txt); do
          delete_images ${images}
        done
      done
      clean_registry
    }
    entrance

    - 参考: https://blog.csdn.net/u014305062/article/details/92770753

  • 相关阅读:
    预备作业02 : 体会做中学(Learning By Doing)
    7-1 货币转换
    秋季学校总结
    人生路上对我影响最大的三个老师
    自我介绍
    2019寒假作业3(抓老鼠啊~亏了还是赚了?)编程总结
    人生路上对我影响最大的三位老师
    自我介绍
    秋季学期学习总结
    7-1 抓老鼠啊~亏了还是赚了?
  • 原文地址:https://www.cnblogs.com/dolphintwo/p/11302212.html
Copyright © 2011-2022 走看看