You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Continuous Integration and Continuous Delivery (CI/CD) is the practice of automatically building, testing, and deploying software whenever changes are made. Google Cloud provides a comprehensive set of services for building CI/CD pipelines — Cloud Build for execution, Artifact Registry for artefact storage, Cloud Deploy for managed delivery, and various deployment targets including Cloud Run, GKE, and App Engine.
CI is the practice of frequently merging code changes into a shared repository and automatically building and testing each change:
| Step | Purpose | Tool |
|---|---|---|
| Code commit | Developer pushes code | Git (CSR, GitHub, GitLab) |
| Build trigger | Detect the change | Cloud Build triggers |
| Compile/Build | Compile code, build artefacts | Cloud Build |
| Unit tests | Run automated tests | Cloud Build |
| Lint/Static analysis | Check code quality | Cloud Build |
| Container build | Build Docker images | Cloud Build |
| Push artefact | Store built artefacts | Artifact Registry |
| Scan | Vulnerability scanning | Container Analysis |
CD extends CI by automatically deploying verified artefacts to target environments:
| Step | Purpose | Tool |
|---|---|---|
| Deploy to staging | Automated deployment after CI | Cloud Build / Cloud Deploy |
| Integration tests | Test in staging environment | Cloud Build |
| Approval gate | Manual approval for production | Cloud Deploy |
| Deploy to production | Controlled production release | Cloud Deploy |
| Canary/Blue-green | Gradual rollout strategy | Cloud Deploy |
| Monitor | Post-deployment verification | Cloud Monitoring |
A typical GCP CI/CD pipeline looks like this:
Push to GitHub
|
v
Cloud Build Trigger
|
v
Cloud Build (CI)
- Install dependencies
- Run lint
- Run tests
- Build Docker image
- Push to Artifact Registry
- Scan for vulnerabilities
|
v
Cloud Deploy (CD)
- Deploy to dev
- Deploy to staging (auto)
- Deploy to production (manual approval)
|
v
Cloud Run / GKE / App Engine
# cloudbuild.yaml
steps:
# Install dependencies
- name: 'node:18'
id: 'install'
entrypoint: 'npm'
args: ['ci']
# Run linter
- name: 'node:18'
id: 'lint'
entrypoint: 'npm'
args: ['run', 'lint']
waitFor: ['install']
# Run unit tests
- name: 'node:18'
id: 'test'
entrypoint: 'npm'
args: ['test']
waitFor: ['install']
env:
- 'CI=true'
# Build Docker image
- name: 'gcr.io/cloud-builders/docker'
id: 'build-image'
args:
- 'build'
- '-t'
- 'europe-west1-docker.pkg.dev/$PROJECT_ID/my-repo/my-app:$SHORT_SHA'
- '-t'
- 'europe-west1-docker.pkg.dev/$PROJECT_ID/my-repo/my-app:latest'
- '.'
waitFor: ['lint', 'test']
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.