Overview
This document describes the Continuous Integration and Continuous Deployment (CI/CD) pipeline for the HandaUncle Backend application. The pipeline automates building, testing, security scanning, and deploying the application across multiple environments.Architecture
Environments
Development
Staging
developProject: Staging GCP ProjectPurpose: Pre-production testing and QAProduction
mainProject: Production GCP ProjectPurpose: Live production environmentBranch Strategy
Git Flow
Branch Rules
feature/* - Development branches
feature/* - Development branches
- Created from
develop - Manual deployment to Dev environment (Claim β Deploy β Release)
- Must pass CI checks before merging
- Used for individual feature development
develop - Integration branch
develop - Integration branch
- Receives merges from feature branches via PR
- Auto-deploys to Staging environment on push
- Protected: Requires PR with passing checks
- Used for integration testing
main - Production branch
main - Production branch
- Only accepts PRs from
develop - Auto-deploys to Production on push
- Protected: Requires PR from develop only
- Never push directly to main
Dev Environment Lock System
How It Works
Workflow Steps
Claim the Environment
- Blocks other developers from deploying
- Shows who has the environment claimed
Deploy Your Branch
- Enter your branch name (e.g.,
feature/my-feature) - Only works if you own the claim
Test Your Changes
- Environment stays locked to you
- Other developers see βclaimed by @youβ
Release When Done
- Frees the environment for others
- Donβt forget this step!
Emergency Release
If a developer forgets to release and is unavailable:- Run π Release Dev Environment
- Check the Force release checkbox
- This will release even if claimed by someone else
Workflow Files
CI Pipeline (ci.yml)
- Overview
- Jobs
- Push to:
main,develop,feature/** - Pull requests to:
main,develop
- Vulnerability report (JSON) - 30-day retention
Dev Environment Workflows
Deploy to Staging (deploy-staging.yml)
Authenticate to GCP
Build Docker Image
Push to Artifact Registry
Deploy to Cloud Run
Output URL
PR Checks (pr-checks.yml)
GCP Infrastructure
Projects
Enabled APIs
Cloud Run Admin API
Artifact Registry API
Secret Manager API
IAM API
Workload Identity Federation
- GitHub Actions generates an OIDC token
- GCP exchanges it for a short-lived access token
- No long-lived credentials stored anywhere
Service Accounts
- Cloud Run Admin
- Artifact Registry Writer
- Service Account User
- Secret Manager Accessor
Secrets Management
GitHub Repository Secrets
GitHub Repository Variables
GCP Secret Manager
Core Configuration
Core Configuration
Database
Database
Authentication
Authentication
AI Services
AI Services
Vector DB & Memory
Vector DB & Memory
Observability
Observability
File Processing
File Processing
Web Search
Web Search
Payments
Payments
Feature Flags
Feature Flags
Development Workflow
Creating a New Feature
Start from develop
Create feature branch
Make changes and commit
Push your branch
Deploying to Dev
Claim the environment
Deploy your branch
- Enter your branch name (e.g.,
feature/my-new-feature)Your code is deploying to Dev!
Test your changes
Release when done
Promoting to Staging
Create Pull Request
feature/my-new-feature β developWait for CI checks
Get code review
Merge PR
Promoting to Production
Create PR from develop to main
develop β mainWait for CI checks
Get approval
Merge PR
Monitoring & Debugging
Viewing Workflow Runs
- Go to: GitHub Actions
- Select the workflow (CI Pipeline, Deploy Dev, etc.)
- Click on a specific run to see logs
Viewing Deployment Logs
Getting Deployment URLs
Downloading Security Reports
- Go to the CI Pipeline workflow run
- Scroll to βArtifactsβ section
- Download the vulnerability report
Troubleshooting
Dev Environment Claimed by Someone Else
Dev Environment Claimed by Someone Else
Dev environment is claimed by @usernameSolution:- Contact the developer and ask them to release
- If unavailable, use Force release option in the Release workflow
Deploy Blocked - Not Claimed
Deploy Blocked - Not Claimed
Dev environment is not claimedSolution:
Run π Claim Dev Environment workflow first, then deployWorkload Identity Authentication Failed
Workload Identity Authentication Failed
Unable to get federated tokenSolution:
Verify the Workload Identity pool and provider exist in GCPSecret Access Denied
Secret Access Denied
Permission denied on secretSolution:
Ensure the service account has Secret Manager Accessor roleCloud Run Deployment Failed
Cloud Run Deployment Failed
Could not find service accountSolution:
Verify the Cloud Run service account exists in the projectDocker Build Cache Miss
Docker Build Cache Miss
Security Considerations
Secrets Protection
- All secrets stored in GCP Secret Manager (encrypted at rest)
- Workload Identity Federation (no long-lived keys)
- Minimal IAM permissions (principle of least privilege)
- Security scanning on every build
Branch Protection
mainonly accepts PRs fromdevelop- CI checks must pass before merge
- Code review recommended
Container Security
- Multi-stage Docker builds (minimal attack surface)
- Non-root user in container
- Vulnerability scanning
- Secret scanning to prevent credential leaks
Network Security
- HTTPS only endpoints
- Cloud Run automatic TLS
- No exposed ports except 443
Maintenance
Updating Secrets
Adding New Secrets
Create the secret in GCP
Update the deployment workflow