One-click deployment solution for Google Cloud Run with automatic infrastructure provisioning.
- Google Cloud Platform account with billing enabled
gcloudCLI installed and configured- Required API keys (see Configuration section)
config.env before deployment.
# Navigate to cloudrun directory
cd cloudrun
# Copy the template
cp config.env.template config.env
# Edit the configuration file with your API keys
nano config.envOpen config.env and configure the following required fields:
# ✅ REQUIRED - GMI API Key for LLM services
GMI_API_KEY=your-actual-gmi-api-key-here
# ✅ REQUIRED - Your Google Cloud Project ID
GOOGLE_CLOUD_PROJECT=your-gcp-project-id
# ✅ REQUIRED - Tavily API Key for web search functionality
# Free tier available at https://tavily.com/ (1,000 searches/month)
TAVILY_API_KEY=your-tavily-api-key-here
# ✅ REQUIRED - Langtrace API Key for monitoring
# Sign up at https://langtrace.com/
LANGTRACE_API_KEY=your-langtrace-api-key-here📝 Note: config.env.template is provided as an example. Do NOT edit the template directly - always copy it to config.env and edit that file.
# Execute deployment script
./deploy-cloudrun.shThe deployment script will automatically:
- ✅ Enable required GCP APIs
- ✅ Create Cloud Memorystore Redis instance
- ✅ Create GCS storage bucket
- ✅ Configure VPC connector
- ✅ Create service accounts with minimal permissions
- ✅ Deploy backend and frontend services
- ✅ Configure CORS and networking
After successful deployment, you'll see:
🎉 Deployment Complete!
==========================
🤖 Chatbot Frontend: https://chatbot-frontend-xxx.a.run.app
📚 API Documentation: https://chatbot-backend-xxx.a.run.app/docs
🔍 Health Check: https://chatbot-backend-xxx.a.run.app/
All API keys and URLs must be configured in config.env:
| Configuration | Description | How to Obtain |
|---|---|---|
GMI_API_KEY |
GMI LLM service API key | GMI Console |
GOOGLE_CLOUD_PROJECT |
Your GCP project ID | GCP Console |
TAVILY_API_KEY |
Web search API key | Tavily - Free tier: 1K searches/month |
LANGTRACE_API_KEY |
Conversation tracing & monitoring | Langtrace |
| Configuration | Description | Default Value |
|---|---|---|
GCS_BUCKET |
Storage bucket name | chatbot-vectordb-{project-id} |
REGION |
Deployment region | us-central1 |
GMI_BASE_URL |
GMI service base URL | https://api.gmi-serving.com |
OPENAI_BASE_URL |
OpenAI-compatible API URL | https://api.gmi-serving.com/v1 |
cloudrun/
├── config.env.template ← Example template (DO NOT EDIT)
└── config.env ← Your actual configuration (EDIT THIS)
config.envcontains sensitive API keys - NEVER commit this file to Git- It's already in
.gitignorefor your protection - Only
config.env.templateshould be committed as documentation
For testing without affecting production, use the test deployment script:
# Deploy test environment (separate services)
./deploy-test-cloudrun.sh --region us-central1
# This creates:
# - chatbot-backend-test (test backend)
# - chatbot-frontend-test (test frontend)
# (Production services remain untouched)
# Clean up test resources when done
./deploy-test-cloudrun.sh --cleanup# List all Cloud Run services
gcloud run services list --region=us-central1
# Describe specific service
gcloud run services describe chatbot-backend --region=us-central1# Real-time logs (backend)
gcloud run services logs read chatbot-backend --region=us-central1 --limit=100
# Real-time logs (frontend)
gcloud run services logs read chatbot-frontend --region=us-central1 --limit=100
# Filter for errors only
gcloud run services logs read chatbot-backend --region=us-central1 --log-filter='severity>=ERROR'# Redeploy with latest code changes
./deploy-cloudrun.sh
# Update environment variables only (no rebuild)
gcloud run services update chatbot-backend \
--region=us-central1 \
--set-env-vars="NEW_VAR=value"# Remove all deployed resources
./cleanup.sh
# This will delete:
# - Cloud Run services (frontend & backend)
# - Redis instance
# - VPC connector
# - Service accounts
# (GCS bucket is preserved by default)┌─────────────────┐ ┌─────────────────┐
│ Frontend │ ──────► │ Backend │
│ (Cloud Run) │ HTTPS │ (Cloud Run) │
│ Next.js │ │ FastAPI │
└─────────────────┘ └─────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────┐ ┌──────────┐
│ Redis │ │ GCS │ │ GMI API │
│ Memorystore │ │ Storage │ │ (External)│
│ (Sessions) │ │ (Vectors)│ │ │
└──────────────┘ └──────────┘ └──────────┘
- Frontend: Next.js application providing chat interface
- Backend: FastAPI application handling AI requests
- Redis: Cloud Memorystore for session storage and caching
- GCS: Google Cloud Storage for vector databases and uploaded files
- VPC Connector: Enables secure communication between Cloud Run and Redis
- ✅ Multi-modal RAG: Upload and query PDF, audio (WAV/MP3), images (PNG/JPG)
- ✅ Web Search: Real-time information retrieval via Tavily API
- ✅ Multiple Output Formats: Text, Audio (TTS), PDF, Image (Stable Diffusion), Video
- ✅ Voice-to-Voice: Real-time voice conversation via WebSocket
- ✅ Streaming: Server-sent events for real-time text streaming
- ✅ Session Management: Redis-backed persistent sessions with rate limiting
- ✅ Tool Router: Intelligent ReAct agent for web search integration
- LLM Models: Meta-Llama, DeepSeek, and other GMI-supported models
- Embedding: SentenceTransformer (all-MiniLM-L6-v2)
- TTS: Kokoro (multi-language support)
- Image Generation: Stable Diffusion 2.1
- Video Generation: Veo3, and other T2V models via GMI IE API
| Service | Configuration | Est. Cost |
|---|---|---|
| Cloud Run (Backend) | 16GB RAM, 4 CPU, min=0 | $20-40 |
| Cloud Run (Frontend) | 1GB RAM, 1 CPU, min=0 | $5-10 |
| Cloud Memorystore Redis | Basic tier, 1GB | $45 |
| Cloud Storage | Vector databases | $1-5 |
| VPC Connector | Standard | $9 |
Total: ~$80-110/month (varies with usage)
- Set
min-instances=0for auto-scaling to zero during idle periods - Use Basic tier Redis (not High Availability)
- Set up lifecycle policies to delete old GCS objects
- Monitor usage with Cloud Billing reports
- ✅ API keys stored in Secret Manager (never in environment variables)
- ✅ Service accounts with least-privilege IAM roles
- ✅ VPC-based private network communication
- ✅ HTTPS-only with automatic SSL certificates
- ✅ Session cookies with
secureandhttponlyflags
- Configure Custom Domain: Use your own domain with Cloud Run
- Enable Cloud Armor: DDoS protection and WAF
- Set Up Monitoring: Cloud Monitoring alerts for errors and latency
- Implement Backups: Regular Redis snapshots and GCS versioning
- Audit Logs: Enable Cloud Audit Logs for compliance
# Manually enable required APIs
gcloud services enable run.googleapis.com \
redis.googleapis.com \
vpcaccess.googleapis.com \
secretmanager.googleapis.com \
storage.googleapis.com# Check VPC connector status
gcloud compute networks vpc-access connectors describe chatbot-connector \
--region=us-central1
# Verify Redis instance
gcloud redis instances describe chatbot-redis --region=us-central1- Verify
NEXT_PUBLIC_API_URLis correctly set during build - Check backend CORS middleware includes frontend origin
- Test backend directly:
curl https://your-backend.run.app/
This usually happens when models are being downloaded on first startup:
- Solution: Use lazy loading (models download on first use)
- Wait 2-3 minutes for models to download
- Increase startup timeout if needed:
--timeout=1800
- Verify API keys in
config.envhave no trailing spaces/newlines - Test API key validity:
curlthe GMI API directly - Check Secret Manager contains correct values
# View revision status
gcloud run revisions list --service=chatbot-backend --region=us-central1
# Check environment variables
gcloud run services describe chatbot-backend --region=us-central1 \
--format="value(spec.template.spec.containers[0].env)"
# View recent build logs
gcloud builds list --limit=5
# Test backend health
curl https://chatbot-backend-xxx.a.run.app/-
chatbot-backend
- Image: Built from
chatbot_project/ - Memory: 16GB
- CPU: 4
- Port: 8000
- Timeout: 30 minutes
- Image: Built from
-
chatbot-frontend
- Image: Built from
chatbot_project/chatbot-nextjs/ - Memory: 1GB
- CPU: 1
- Port: 3000
- Image: Built from
- VPC Connector:
chatbot-connector(for Cloud Run → Redis communication) - Redis Instance:
chatbot-redis(1GB Basic tier) - GCS Bucket:
chatbot-vectordb-{project-id} - Service Accounts:
chatbot-backend-sa: Backend service identitychatbot-frontend-sa: Frontend service identity (if needed)
gmi-api-key: GMI API keytavily-api-key: Tavily search API key (if configured)langtrace-api-key: Langtrace monitoring key (if configured)hf-token: Hugging Face token (for model downloads)
# 1. Make changes to code in chatbot_project/
# 2. Test locally (optional)
# 3. Deploy to test environment first
./deploy-test-cloudrun.sh
# 4. Verify test deployment works
# 5. Deploy to production
./deploy-cloudrun.sh# 1. Edit config.env with new values
nano config.env
# 2. Update secrets in Secret Manager
source config.env
printf '%s' "$GMI_API_KEY" | gcloud secrets versions add gmi-api-key --data-file=-
# 3. Redeploy to pick up new configuration
./deploy-cloudrun.sh- Main Project README:
../chatbot_project/README.md - API Documentation: Available at
https://your-backend.run.app/docsafter deployment - Google Cloud Run Docs: https://cloud.google.com/run/docs
If you encounter issues:
- ✅ Verify all required fields in
config.envare filled - ✅ Check GCP permissions and billing status
- ✅ Review deployment logs for specific errors
- ✅ Consult the Troubleshooting section above
- ✅ Test individual components (Redis, GCS) separately
config.env.template: Example configuration file - DO NOT edit directlyconfig.env: Your actual configuration - MUST be created and filled before deployment- All API keys and sensitive values MUST be specified in
config.env - The
config.envfile is.gitignoredfor security
- Initial deployment takes 15-20 minutes (infrastructure provisioning)
- Subsequent deployments take 5-10 minutes (code updates only)
- Models are lazy-loaded on first use (expect slower first request)
Before going to production:
- All API keys configured in
config.env - Custom domain configured (optional)
- Monitoring and alerts set up
- Backup strategy defined
- Budget alerts configured
- CORS origins reviewed and restricted
Happy Deploying! 🎉
For questions or issues, please refer to the troubleshooting section or consult the main project documentation.