内容目录
如何利用api清理harbor镜像
获取项目名
page_size限制最大100
curl -u admin:Harbor12345 -H "Content-Type: application/json" -X GET https://harbor.chenjie.info/api/v2.0/projects?page=1&page_size=100 -k
请求返回形如:
[{"chart_count":0,"creation_time":"2023-03-21T06:30:01.319Z","current_user_role_id":1,"current_user_role_ids":[1],"cve_allowlist":{"creation_time":"0001-01-01T00:00:00.000Z","id":181,"items":[],"project_id":181,"update_time":"0001-01-01T00:00:00.000Z"},"metadata":{"public":"true"},"name":"alpine","owner_id":1,"owner_name":"admin","project_id":181,"repo_count":1,"update_time":"2023-03-21T06:30:01.319Z"},{"chart_count":0,"creation_time":"2023-03-21T06:30:00.721Z","current_user_role_id":1,"current_user_role_ids":[1],"cve_allowlist":{"creation_time":"0001-01-01T00:00:00.000Z","id":110,"items":[],"project_id":110,"update_time":"0001-01-01T00:00:00.000Z"},"metadata":{"public":"true"},"name":"alpine2","owner_id":1,"owner_name":"admin","project_id":110,"repo_count":1,"update_time":"2023-03-21T06:30:00.721Z"}]
项目名是key为name的值:”name”:”alpine”
获取镜像
page_size 限制最大100
例如把上面项目alpine代入
curl -u admin:Harbor12345 -H "Content-Type: application/json" -X GET https://harbor.chenjie.info/api/v2.0/projects/alpine/repositories?page=1&page_size=100 -k
请求返回形如:
[{"artifact_count":1,"creation_time":"2023-03-21T06:35:17.983Z","id":52,"name":"alpine/alpine","project_id":181,"pull_count":1,"update_time":"2023-03-21T07:45:57.490Z"}]
获取到镜像名(此处镜像名含项目名)
镜像名是key为name的值:alpine/alpine
获取所有镜像tag
代入项目alpine 镜像alpine
curl -u admin:Harbor12345 -H "Content-Type: application/json" -X GET https://harbor.chenjie.info/v2/alpine/alpine/tags/list -k
请求返回形如:
{"name":"alpine/alpine","tags":["3.16","test"]}
获取tag列表在tags的数组中[“3.16,”test””]
获取指定tag推送时间
curl -u admin:Harbor12345 -H "Content-Type: application/json" -X GET https://harbor.chenjie.info/api/v2.0/projects/alpine/repositories/alpine/artifacts/3.16/tags -k
请求返回形如:
[{"artifact_id":6539,"id":6656,"immutable":false,"name":"3.16","pull_time":"0001-01-01T00:00:00.000Z","push_time":"2023-03-23T08:45:51.093Z","repository_id":52,"signed":false}]
push_time 是utc时间 实际需要+8小时
删除指定tag
代入项目名alpine,镜像名alpine,tag名test
curl -u admin:Harbor12345 -H "Content-Type: application/json" -X DELETE https://harbor.chenjie.info/api/v2.0/projects/alpine/repositories/alpine/artifacts/test/tags/test -k
删除后需要在harbor平台手动进行垃圾清理