diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 60c40a0..d7ca411 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,11 +1,14 @@ steps: # Delete previous containers based on the image (if any running) - - name: 'gcr.io/cloud-builders/docker' + - name: 'gcr.io/cloud-builders/gcloud' entrypoint: 'bash' args: - '-c' - | - docker ps -a | grep 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend' | awk '{print $1}' | xargs -r docker rm -f + set -x + for tag in $(gcloud container images list-tags "gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend" --format='get(digest)' --limit=999999); do + gcloud container images delete -q --force-delete-tags "gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend@$tag" || true + done # Delete previous images - name: 'gcr.io/cloud-builders/docker' @@ -13,6 +16,7 @@ steps: args: - '-c' - | + set -x docker images -a | grep 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend' | awk '{print $3}' | xargs -r docker rmi -f # Build the new image with the latest commit SHA as a tag @@ -49,22 +53,6 @@ steps: --image=gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend:$COMMIT_SHA \ --region=asia-south1 \ --project=shivam-contacts-generator \ - && gcloud run services update-traffic contacts-generator-backend-continuous --to-latest - - # Get the latest revision name - - name: 'gcr.io/cloud-builders/gcloud' - entrypoint: 'bash' - args: - - '-c' - - | - LATEST_REVISION=$(gcloud run services describe contacts-generator-backend-continuous --platform=managed --region=asia-south1 --format='value(status.latestRevisionName)') - - # Delete older revisions - - name: 'gcr.io/cloud-builders/gcloud' - entrypoint: 'bash' - args: - - '-c' - - | - gcloud run revisions list --platform=managed --region=asia-south1 --format='value(REVISION)%0A' \ - | grep -v $LATEST_REVISION \ - | xargs -I{} gcloud run revisions delete {} --platform=managed --region=asia-south1 --quiet + && gcloud run services update-traffic contacts-generator-backend-continuous --to-latest --region=asia-south1 +options: + logging: CLOUD_LOGGING_ONLY