要获取推送到Google容器注册表的最新20个左右的镜像版本(标签),可以使用Google Cloud Platform(GCP)提供的Container Registry API来实现。以下是一种可能的解决方案:
list
方法来列出所有的镜像版本(标签)。你可以指定pageSize
参数来限制返回结果的数量。orderBy
参数并指定creationTimestamp desc
来实现。以下是一个示例使用Python和Google Cloud SDK的代码片段:
from google.cloud import containerregistry_v1
def get_latest_image_tags(project_id, registry_name):
client = containerregistry_v1.RegistryClient()
parent = f"projects/{project_id}/locations/global/registries/{registry_name}"
response = client.list_tags(parent, page_size=20, order_by="~creation_time")
image_tags = []
for tag in response:
image_tags.append(tag.name)
return image_tags
# 调用函数并打印结果
project_id = "your-project-id"
registry_name = "your-registry-name"
latest_tags = get_latest_image_tags(project_id, registry_name)
print(latest_tags)
请注意,上述代码仅为示例,你需要将your-project-id
和your-registry-name
替换为你自己的项目ID和注册表名称。
推荐的腾讯云相关产品:腾讯云容器镜像服务(Tencent Container Registry,TCR)。TCR是腾讯云提供的容器镜像托管服务,支持私有镜像仓库和镜像版本管理。你可以通过访问腾讯云容器镜像服务官方文档了解更多信息。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云