tback
tback

Reputation: 11561

gcloud docker registry filter by timestamp

I'm trying to find images older than some date using the gcloud sdk. I tried

gcloud container images list-tags gcr.io/my-project/my-image --filter='timestamp < 2017-07-01'

but this gives me all images, so the filter doesn't work.

Upvotes: 2

Views: 1645

Answers (2)

crazy-matt
crazy-matt

Reputation: 33

Another way of doing and letting you select which field values you want to obtain:

gcloud container images list-tags \
  --quiet --project "${PROJECT}" "gcr.io/${PROJECT}/${IMAGE_NAME}" \
  --sort-by="~timestamp" --format='get(digest)' \
  --filter="timestamp.datetime < 2021-10-29"

And to avoid the confusing gcloud warning WARNING: The following filter keys were not present in any resource : timestamp.datetime, you can use this condition:

if [[ $(gcloud container images list-tags --project "${PROJECT}" "gcr.io/${PROJECT}/${IMAGE_NAME}" --format='get(digest)' | wc -l) -gt 0 ]]; then
    gcloud container images list-tags \
      --quiet --project "${PROJECT}" "gcr.io/${PROJECT}/${IMAGE_NAME}" \
      --sort-by="~timestamp" --format='get(digest)' \
      --filter="timestamp.datetime < 2021-10-29"
fi

Upvotes: 0

tback
tback

Reputation: 11561

Well, that one was easier than I initially thought. This is the solution:

gcloud container images list-tags gcr.io/my-project/my-image --filter='timestamp.datetime < 2017-07-01'

--format=json showed me the right fieldname.

Upvotes: 2

Related Questions