简体   繁体   English

命令删除工件注册表的所有图像版本,除了最新的?

[英]Command To Delete All Image Versions of Artifact Registry Except Latest?

I have a GitHub Action that pushes my image to Artifact Registry.我有一个 GitHub Action 将我的图像推送到 Artifact Registry。 This is the steps that authenticates and then pushes it to my Google Cloud Artifact Registry这是验证然后将其推送到我的 Google Cloud Artifact Registry 的步骤

      - name: Configure Docker Client
        run: |-
          gcloud auth configure-docker --quiet
          gcloud auth configure-docker $GOOGLE_ARTIFACT_HOST_URL --quiet
      - name: Push Docker Image to Artifact Registry
        run: |-
          docker tag $IMAGE_NAME:latest $GOOGLE_ARTIFACT_HOST_URL/$PROJECT_ID/images/$IMAGE_NAME:$GIT_TAG
          docker push $GOOGLE_ARTIFACT_HOST_URL/$PROJECT_ID/images/$IMAGE_NAME:$GIT_TAG


Where $GIT_TAG is always 'latest' $GIT_TAG 始终是“最新的”

I want to add one more command that then purges all except the latest version.我想再添加一个命令,然后清除除最新版本之外的所有命令。 In this screenshot below, you see theres 2 images在下面的屏幕截图中,您可以看到 2 张图片在此处输入图像描述

I would like to remove the one that was 3 days ago as its not the one with the tag 'latest'.我想删除 3 天前的那个,因为它不是带有“最新”标签的那个。

Is there a terminal command to do this?是否有终端命令来执行此操作?

You may initially check through the filtered list of container images for your specific criteria.您最初可能会根据您的特定条件检查过滤后的容器图像列表

gcloud artifacts docker images list --include-tags

Once you have the view of the images to be deleted, move to the following.看到要删除的图像后,请转到以下内容。
You may use the following command to delete an Artifact Registry container image.您可以使用以下命令删除 Artifact Registry 容器映像。

gcloud artifacts docker images delete IMAGE [--async] [--delete-tags] [GCLOUD_WIDE_FLAG …]

A valid container image that can be referenced by tag or digest, has the format of一个可以被标签或摘要引用的有效容器镜像,格式为

LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY-ID/IMAGE:tag

This command can fail for the following reasons:由于以下原因,此命令可能会失败:

  • Trying to delete an image by digest when the image is still tagged.当图像仍被标记时,尝试通过摘要删除图像。 Add --delete-tags to delete the digest and the tags.添加 --delete-tags 以删除摘要和标签。
  • Trying to delete an image by tag when the image has other tags.当图像有其他标签时,尝试按标签删除图像。 Add --delete-tags to delete all tags.添加 --delete-tags 删除所有标签。
  • A valid repository format was not provided.未提供有效的存储库格式。
  • The specified image does not exist.指定的图像不存在。
  • The active account does not have permission to delete images.活动帐户无权删除图像。

It is always recommended to check and reconfirm any deletion operations so you don't lose any useful artifacts and data items.始终建议检查并重新确认任何删除操作,以免丢失任何有用的工件和数据项。 Also check this helpful document here for Artifacts docker Image Deletion guidelines and some useful information on Managing Images .还可以在此处查看此有用文档,了解Artifacts docker 图像删除指南和有关管理图像的一些有用信息。

As guillaume blaquiere mentioned you may have a look at this link which may help you.正如 guillaume blaquiere 提到的,您可以查看此链接,这可能会对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从工件注册表中获取最新版本的图像 - How to get latest version of an image from artifact registry 如何自动从 Artifact Registry 中删除图像 - How to remove an image from Artifact Registry automatically 服务帐户无法将 Docker 图像推送到 Google Artifact Registry - Service Account Unable to Push Docker Image to Google Artifact Registry 将 Packer VM 映像保存到 GCP Artifact Registry 的路径和选项 - Path and options for saving a Packer VM image to GCP Artifact Registry 谷歌云:Artifact Registry 与 Container Registry - Google Cloud: Artifact Registry vs Container Registry 过渡到 Artifact Registry 的简单示例 - simple example for Transition to Artifact Registry Google Cloud Container Registry/Artifact Registry 权限 - Google Cloud Container Registry/Artifact Registry Permissions 从工件注册表中删除图像时如何忽略 cloudbuild.yaml 中的“找不到图像”错误? - How to ignore "image not found" error in cloudbuild.yaml when deleting images from the artifact registry? 如何使用 Terraform 使用来自 Artifact Registry 的 Docker 映像部署 GKE 工作负载? - How do I deploy a GKE Workload with my Docker image from the Artifact Registry using Terraform? Cloud Build 不会将我的 Docker 图像推送到带有 cloudbuild.yaml 图像字段的 Artifact Registry - Cloud Build does not push my Docker image to Artifact Registry with images field in cloudbuild.yaml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM