Score:1

How to delete all but the latest revision of Google cloud run container images?

ua flag

I am hosting my containerized application using Google cloud run. To save cost, I want to delete all but the active revisions of my application's Docker image.

I use a job of my GitLab pipeline to handle the credentials and settings using environment variables.

I can list my revisions like so:

gcloud run revisions list --region="$GCP_REGION"
Score:2
ua flag

The latest revision of your application is the only one active. Exploiting that fact, we can delete all other revisions:

gcloud run revisions list --filter="status.conditions.type:Active AND status.conditions.status:'False'" --format='value(metadata.name)' | xargs -r -L1 gcloud run revisions delete --quiet

Sources:

tm_lv avatar
es flag
the xargs command needs `-L1` flag so that it also works when you have several obsolete versions. Here's the complete line: `gcloud run revisions list --filter="status.conditions.type:Active AND status.conditions.status:'False'" --format='value(metadata.name)' | xargs -r -L1 gcloud run revisions delete --quiet`
Bengt avatar
ua flag
Thanks for the hint. I updated the command and added the man pages to both `xargs` and `glcoud run` as sources.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.