
GCP Serverless Deployment
Published on Sat May 31 2025
🚀 Deployment Overview: GitHub → GCP Cloud Build → Cloud Run
Scenario Flow
- Code is pushed to GitHub repository
- GCP Cloud Build is triggered and builds the image as per Dockerfile
- The image is pushed to GCP Artifact Registry
- Cloud Run automatically pulls the latest image and deploys it in a serverless environment
- Custom domain is configured via Load Balancer with SSL certificate provisioning
✅ Prerequisites
- Google Cloud Platform (GCP) account
- Source code hosted on GitHub
- Appropriate server or project permissions
🔧 Services Used
- `Artifact Registry` = Store built Docker images
- `Cloud Build` = Build Docker images from GitHub source code
- `Cloud Run` = Deploy container images in a serverless environment
- `Load Balancer` = Attach custom domains and manage HTTPS/SSL
📦 Artifact Registry Configuration
Navigate to Artifact Registry in GCP Console
Click Create Repository
Settings:
- Repository Name: your-app-name
- Format: Docker
- Mode: Standard
- Region: Choose as per your app's needs
- Labels: Optional
- Encryption: Default
- Immutable Image Tags: Default (Disabled)
✅ Optional: Set a cleanup policy to auto-remove old images
☁️ Cloud Run Setup
Go to Cloud Run in GCP Console and click Create Service
Select image from Artifact Registry
Fill in service settings:
- Service Name: e.g., your-app-service
- Region: same as registry
- Authentication:
- Public API/Website: Allow unauthenticated invocations
- Private: Require IAM authentication
- CPU Allocation:
- "Only during request processing" (lower cost)
- "Always allocated" (higher cost)
- Autoscaling: Set min/max instances
- Ingress Settings: Choose based on access needs
- Configure volumes, networking, and environment variables per your Docker setup
🔁 Continuous Deployment (CI/CD)
In the Cloud Run service dashboard, click Set up Continuous Deployment
Select your GitHub repository
Set configurations:
- Branch: e.g., main
- Dockerfile path: e.g., ./Dockerfile
Click Save
🔄 This auto-generates a cloudbuild.yaml file and configures Cloud Build triggers.
🔨 Cloud Build Notes
The CI/CD setup above will automatically configure Cloud Build with default behavior. You can customize further:
- Triggers:
- Push to branch
- New tag creation
- Pull request
- Manual
- Pub/Sub message
- Webhook
🛠 Customize cloudbuild.yaml for advanced use-cases like multi-step builds, test pipelines, or Slack notifications.