1

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"
Bengt
  • 131
  • 5

1 Answers1

2

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:

Bengt
  • 131
  • 5
  • 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` – tm_lv Apr 22 '23 at 09:43
  • Thanks for the hint. I updated the command and added the man pages to both `xargs` and `glcoud run` as sources. – Bengt Apr 22 '23 at 14:22