Cloud Build CI/CD

cloudbuild.yaml

Example

On every push to main: run tests, build, push and deploy to Cloud Run:

cloudbuild.yaml

steps:
  - name: python:3.12-slim
    entrypoint: sh
    args: ["-c", "pip install -r requirements.txt && pytest -q"]

  - name: gcr.io/cloud-builders/docker
    args: ["build", "-t", "asia-south1-docker.pkg.dev/$PROJECT_ID/apps/course-api:$SHORT_SHA", "."]

  - name: gcr.io/cloud-builders/docker
    args: ["push", "asia-south1-docker.pkg.dev/$PROJECT_ID/apps/course-api:$SHORT_SHA"]

  - name: gcr.io/google.com/cloudsdktool/cloud-sdk
    entrypoint: gcloud
    args: ["run", "deploy", "course-api",
           "--image", "asia-south1-docker.pkg.dev/$PROJECT_ID/apps/course-api:$SHORT_SHA",
           "--region", "asia-south1"]

images:
  - asia-south1-docker.pkg.dev/$PROJECT_ID/apps/course-api:$SHORT_SHA

Connect the GitHub repository and create a trigger on the main branch in Cloud Build. For progressive delivery across environments, Cloud Deploy adds promotion and approvals.