🐈

Remove old Google App Engine instances regularly

2023/06/29に公開
  • cloudbuild-remove-outdated-instances.yaml
steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    entrypoint: 'bash'
    args: [ 'remove-outdated-instances.sh' ]
  • remove-outdated-instances.sh
#!/usr/bin/env bash

services=("target_service_name_A" "target_service_name_B" ...)

for src in "${services[@]}"; do
  versions=$(gcloud app versions list \
    --service "$src" \
    --sort-by '~VERSION.ID' \
    --format 'value(VERSION.ID)' | sed 1,3d) # latest three versions

#  echo "$versions"

  for version in $versions; do
    gcloud app versions delete "$version" \
      --service "$src" \
      --quiet
  done
done

# echo "remove done"
  • You can set the yaml file in Cloud Build and execute it regularly, or execute on demand by hand.

appendix

Discussion