From fed36b98f74555a03861b8d319f226474831b764 Mon Sep 17 00:00:00 2001 From: Shivam Gutgutia Date: Sun, 19 Nov 2023 22:07:29 +0530 Subject: [PATCH] Modified cloudbuild file --- cloudbuild.yaml | 61 +++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 7d0f41e..0c13324 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,45 +1,30 @@ steps: - # Delete previous containers based on the image (if any running) - - name: 'gcr.io/cloud-builders/docker' + # Set the project ID as a variable + - 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 + PROJECT_ID=$(gcloud config get-value project -q) + echo "export PROJECT_ID=${PROJECT_ID}" >> '$HOME/.bashrc' - # Delete previous images - - name: 'gcr.io/cloud-builders/docker' + # Enable Cloud Logging for the build + - name: 'gcr.io/cloud-builders/gcloud' entrypoint: 'bash' args: - '-c' - | - docker images -a | grep 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend' | awk '{print $3}' | xargs -r docker rmi -f + gcloud config set builds/use_kaniko True - # Build the new image with the latest commit SHA as a tag - - name: 'gcr.io/cloud-builders/docker' - args: - - 'build' - - '-t' - - 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend:$COMMIT_SHA' - - '-f' - - 'Dockerfile' - - '.' - options: - logging: CLOUD_LOGGING_ONLY - - # Push the new image to Google Container Registry + # Delete previous containers based on the image (if any running) - name: 'gcr.io/cloud-builders/docker' - args: - - 'push' - - 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend:$COMMIT_SHA' - - # Fetch the latest commit SHA from environment variables - - name: 'gcr.io/cloud-builders/gcloud' entrypoint: 'bash' args: - '-c' - | - COMMIT_SHA=$(echo $COMMIT_SHA) + docker ps -a | grep 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend' | awk '{print $1}' | xargs -r docker rm -f + + # ... (rest of your build steps) # Deploy the new revision to Cloud Run using the updated image with the latest commit SHA - name: 'gcr.io/cloud-builders/gcloud' @@ -51,22 +36,12 @@ 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 + --platform=managed \ + --use-http2 \ + --quiet \ + --log-http - # 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)') + # ... (remaining steps) - # 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 +options: + logging: CLOUD_LOGGING_ONLY