CI/CD on Google Cloud: Cloud Build, Artifact Registry, Cloud Deploy and Safe Release Strategies
CI and CD
| Term | Meaning |
|---|---|
| Continuous Integration | Merge code often. Each change is built and tested automatically |
| Continuous Delivery | Every good build can be released, usually with approval |
| Continuous Deployment | Every good build is released automatically |
text
Git push ─► Cloud Build (test, build image, scan) ─► Artifact Registry ─► Cloud Deploy
dev → staging → (approval) → production (GKE / Cloud Run), with canary and rollback
Artifact Registry
- Private storage for container images and language packages (npm, Maven, Python, apt, yum) and Helm charts
- Regional or multi-regional repositories with IAM, vulnerability scanning and cleanup policies
- Replaces the older Container Registry
bash
gcloud artifacts repositories create apps --repository-format=docker --location=asia-south1 --description="App images"
gcloud auth configure-docker asia-south1-docker.pkg.dev
docker tag shop:1.0 asia-south1-docker.pkg.dev/my-proj/apps/shop:1.0
docker push asia-south1-docker.pkg.dev/my-proj/apps/shop:1.0
Cloud Build
- Serverless build service. Each step runs in a container. Triggers: push to GitHub, GitLab or Cloud Source style repos, pull request, tag, manual, Pub/Sub
- Use a dedicated service account with minimum permissions
- Private pools for builds inside your VPC
- Store results (images, test reports) in Artifact Registry and Cloud Storage
yaml
steps:
- name: python:3.12
entrypoint: bash
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/shop:$SHORT_SHA', '.']
- name: gcr.io/cloud-builders/docker
args: ['push', 'asia-south1-docker.pkg.dev/$PROJECT_ID/apps/shop:$SHORT_SHA']
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
entrypoint: gcloud
args: ['run', 'deploy', 'shop', '--image', 'asia-south1-docker.pkg.dev/$PROJECT_ID/apps/shop:$SHORT_SHA', '--region', 'asia-south1']
options: {logging: CLOUD_LOGGING_ONLY}
bash
gcloud builds submit --config=cloudbuild.yaml .
gcloud builds triggers create github --name=shop-main --repo-name=shop --repo-owner=acme --branch-pattern='^main$' --build-config=cloudbuild.yaml
Cloud Deploy
- Managed continuous delivery to GKE, Cloud Run and Anthos clusters
- A delivery pipeline has ordered targets (dev, staging, prod) with approvals, verification, automatic rollback and canary strategies
- Gives an audit trail of what ran where
| Strategy | How it works | Risk |
|---|---|---|
| Rolling | Replace instances gradually | Mixed versions during rollout |
| Blue/green | Run new version beside old, switch traffic, keep old for rollback | Double capacity during switch |
| Canary | Send a small percent (5, 25, 50, 100) to the new version and watch metrics | Needs good monitoring |
| Recreate | Stop old, start new | Downtime |
| Feature flags | Ship code turned off, enable for some users | Flag management |
Supply Chain Security
- Use trusted base images and pin versions
- Scan images in Artifact Registry (Artifact Analysis) and fail the build on critical issues
- Sign images and use Binary Authorization to allow only signed images into GKE or Cloud Run
- Use SLSA provenance from Cloud Build
- Never put secrets in images or repos: use Secret Manager
- Use Workload Identity Federation for GitHub Actions instead of key files
Testing in the Pipeline
- Unit tests, integration tests (emulators for Firestore, Pub/Sub, Spanner), security scans, load tests before production, smoke tests after deploy
- Fail fast: run quick tests first
Practice
- Create an Artifact Registry repo and push an image
- Write a cloudbuild.yaml that tests, builds and deploys to Cloud Run
- Create a trigger on your main branch
- Explain when you would choose canary vs blue/green
Conclusion
Cloud Build tests and builds, Artifact Registry stores artifacts, and Cloud Deploy promotes releases with approvals and canary or blue/green strategies. Secure the supply chain with scanning, signing and Binary Authorization.
Quick Summary: CI CD; Artifact Registry; Cloud Build; Cloud Deploy; supply chain; testing.

