在我们搭建完 Harbor 后: https://www.cnblogs.com/klvchen/p/9482153.html
如果想要通过 API 获取 Harbor 上面的镜像及 tag 可以使用下面整理的脚本:

cat get_images.sh 
#!/bin/bash

USER="admin"
PASS="Harbor12345"
HURL="http://192.168.0.241"

rtoken=$(curl -k -s  -u ${USER}:${PASS} ${HURL}/service/token?account=${USER}\&service=harbor-registry\&scope=registry:catalog:*|grep "token" |awk -F '"' '{print $4}')

#echo $rtoken

rlist=$(curl -k -s -H "authorization: bearer $rtoken " ${HURL}/v2/_catalog|awk -F '[' '{print $2}'|awk -F ']' '{print $1}'|sed 's/"//g')

echo $rlist|sed 's/,/\n/g'

# 解析一下变量:
USER="admin"                 Harbor 的用户名
PASS="Harbor12345"           Harbor 的密码
HURL="http://192.168.0.241"  Harbor 的地址

运行结果:
1334255-20180822173720216-1532409807.png

获取到 images 后,可以进一步查看镜像的 tag:

cat get_tag.sh 
#!/bin/bash

USER="admin"
PASS="Harbor12345"
HURL="http://192.168.0.241"
MTAG=$1

ttoken=$(curl -iksL -X GET -u $USER:$PASS $HURL/service/token?account=${USER}\&service=harbor-registry\&scope=repository:${MTAG}:pull|grep "token" |awk -F '"' '{print $4}')

#echo $ttoken

tlist=$(curl -ksL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $ttoken" ${HURL}/v2/${MTAG}/tags/list|awk -F '[' '{print $2}'|awk -F ']' '{print $1}'|sed 's/"//g')


echo $tlist|sed 's/,/\n/g'

# 解析一下变量:
USER="admin"                 Harbor 的用户名
PASS="Harbor12345"           Harbor 的密码
HURL="http://192.168.0.241"  Harbor 的地址
MTAG=$1                      需传入一个镜像名字,上一脚本输出的结果

运行结果:
1334255-20180822174126313-1863746252.png
脚本还有很多可以完善的地方,这里就不做讨论了~ 该脚本也适用于部署了 https 证书的 Harbor 需要把 HURL 中的变量改成 https 即可。

转载于:https://www.cnblogs.com/klvchen/p/9519169.html

GitHub 加速计划 / ha / harbor
23.24 K
4.67 K
下载
Harbor 是一个开源的容器镜像仓库,用于存储和管理 Docker 镜像和其他容器镜像。 * 容器镜像仓库、存储和管理 Docker 镜像和其他容器镜像 * 有什么特点:支持多种镜像格式、易于使用、安全性和访问控制
最近提交(Master分支:1 个月前 )
c5d26723 chore(deps): bump github.com/go-openapi/runtime in /src Bumps [github.com/go-openapi/runtime](https://github.com/go-openapi/runtime) from 0.26.2 to 0.28.0. - [Release notes](https://github.com/go-openapi/runtime/releases) - [Commits](https://github.com/go-openapi/runtime/compare/v0.26.2...v0.28.0) --- updated-dependencies: - dependency-name: github.com/go-openapi/runtime dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: miner <yminer@vmware.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Shengwen YU <yshengwen@vmware.com> Co-authored-by: miner <yminer@vmware.com> 11 天前
76624373 chore(deps): bump github.com/coreos/go-oidc/v3 in /src Bumps [github.com/coreos/go-oidc/v3](https://github.com/coreos/go-oidc) from 3.10.0 to 3.11.0. - [Release notes](https://github.com/coreos/go-oidc/releases) - [Commits](https://github.com/coreos/go-oidc/compare/v3.10.0...v3.11.0) --- updated-dependencies: - dependency-name: github.com/coreos/go-oidc/v3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Shengwen YU <yshengwen@vmware.com> Co-authored-by: miner <yminer@vmware.com> 11 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐