6

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
  • 231
  • 2
  • 7

3 Answers3

7

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
  • 231
  • 2
  • 7
3

Previous response by Bengt is perfect, but as I can't comment just want to add that you need to add --region in my case this is the command:

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

As of Apr 2024, according to Google docs https://cloud.google.com/run/docs/managing/revisions

Non-serving revisions do not consume any resources and are not billed.

So there is really no need to delete old versions as they do not incur any cost

Ryan
  • 111