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 750e2ef commit fed36b9
Showing 1 changed file with 18 additions and 43 deletions.
61 changes: 18 additions & 43 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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

0 comments on commit fed36b9

Please sign in to comment.