Skip to content

Commit

Permalink
Modified cloud build file
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamgutgutia committed Nov 21, 2023
1 parent 4f65bc4 commit 99e16bd
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
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'
entrypoint: 'bash'
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
Expand Down Expand Up @@ -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

0 comments on commit 99e16bd

Please sign in to comment.