Cleaning Up AppEngine Versions
If you deploy services on Google’s App Engine. You might use Google’s Cloud Build trigger for your CI/CD pipeline. And at some point you will max out the number of versions allowed by App Engine.
So you can go in and delete many previous versions of your service(s). BUT you also could add a final step to your cloudbuild.yaml
to clean them up for you !
This example will clean up for a service named “nicks-app-engine-service” and remove any versions besides the 10 most recent, but for yours your App Engine service might be named “default” or a specific name you use. Check in your App Engine dashboard for your service’s name.
// the rest of your cloudbuild.yaml
//
// and then as your final step a clean up step for older versions, this keeps the 10 most recent
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk”
entrypoint: bash
args:
- "-c"
- |
versions=$(gcloud app versions list --service nicks-app-engine-service --sort-by '~version' --format 'value(VERSION.ID)' | sed 1,10d)
for version in $versions; do
gcloud app versions delete $version --service nicks-app-engine-service --quiet || echo "Error deleting version: $version"
done
Hopefully it helps someone with their pipeline. Going to do a video here in the future about deploying on google cloud run / app engine and setting up custom domains, variables and more. Can be found in the google docs of course, but distilling down to a few real world examples hopefully saves some peeps some time.