Skip to content

Commit

Permalink
Modified cloudbuild file
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamgutgutia committed Nov 19, 2023
1 parent fed36b9 commit b17cbde
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
steps:
# Set the project ID as a variable
- name: 'gcr.io/cloud-builders/gcloud'
# Delete previous containers based on the image (if any running)
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
PROJECT_ID=$(gcloud config get-value project -q)
echo "export PROJECT_ID=${PROJECT_ID}" >> '$HOME/.bashrc'
docker ps -a | grep 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend' | awk '{print $1}' | xargs -r docker rm -f
# Enable Cloud Logging for the build
- name: 'gcr.io/cloud-builders/gcloud'
# Delete previous images
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
gcloud config set builds/use_kaniko True
docker images -a | grep 'gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend' | awk '{print $3}' | xargs -r docker rmi -f
# Delete previous containers based on the image (if any running)
# 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'
- '.'

# Push the new image to Google Container Registry
- 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'
- |
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)
COMMIT_SHA=$(echo $COMMIT_SHA)
# Deploy the new revision to Cloud Run using the updated image with the latest commit SHA
- name: 'gcr.io/cloud-builders/gcloud'
Expand All @@ -36,12 +49,26 @@ steps:
--image=gcr.io/shivam-contacts-generator/github.com/shivamgutgutia/contactsgeneratorbackend:$COMMIT_SHA \
--region=asia-south1 \
--project=shivam-contacts-generator \
--platform=managed \
--use-http2 \
--quiet \
--log-http
&& 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
# ... (remaining steps)
options:
logging: CLOUD_LOGGING_ONLY

0 comments on commit b17cbde

Please sign in to comment.