Deploy agentic-flow to Google Cloud Platform with Docker containers, Cloud Run, and Secret Manager integration.
# Install gcloud CLI
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
# Authenticate
gcloud auth login
gcloud auth application-default login
# Set project
export GCP_PROJECT_ID="your-project-id"
gcloud config set project $GCP_PROJECT_IDcd docker/cloud-run
# Option A: From .env file
GCP_PROJECT_ID=$GCP_PROJECT_ID ./setup-secrets.sh setup
# Option B: Interactive
GCP_PROJECT_ID=$GCP_PROJECT_ID ./setup-secrets.sh interactive
# Verify secrets
GCP_PROJECT_ID=$GCP_PROJECT_ID ./setup-secrets.sh list# Deploy with Claude (default)
GCP_PROJECT_ID=$GCP_PROJECT_ID \
MODEL_PROVIDER=anthropic \
./deploy.sh
# Deploy with OpenRouter (99% cost savings!)
GCP_PROJECT_ID=$GCP_PROJECT_ID \
MODEL_PROVIDER=openrouter \
MODEL_NAME=meta-llama/llama-3.1-8b-instruct \
./deploy.sh
# Deploy with custom configuration
GCP_PROJECT_ID=$GCP_PROJECT_ID \
MODEL_PROVIDER=openrouter \
MODEL_NAME=deepseek/deepseek-chat-v3.1 \
REGION=us-west1 \
MEMORY=4Gi \
CPU=4 \
MAX_INSTANCES=20 \
./deploy.sh# Get service URL
SERVICE_URL=$(gcloud run services describe agentic-flow \
--region=us-central1 \
--format='value(status.url)')
# Health check
curl $SERVICE_URL/health
# List agents
curl $SERVICE_URL/agents
# Run an agent
curl -X POST $SERVICE_URL/agent \
-H "Content-Type: application/json" \
-d '{
"agent": "coder",
"task": "Create a Python hello world script"
}'┌─────────────────────────────────────┐
│ Stage 1: Builder │
│ - Node 20 Alpine │
│ - Install dependencies │
│ - Build TypeScript → JavaScript │
│ - Copy .claude agents │
└─────────────────────────────────────┘
↓
┌─────────────────────────────────────┐
│ Stage 2: Production │
│ - Node 20 Alpine (minimal) │
│ - Copy built artifacts │
│ - Non-root user (nodejs:1001) │
│ - Health checks enabled │
│ - Tini for signal handling │
└─────────────────────────────────────┘
- Cloud Run: Serverless container hosting
- Secret Manager: API key and credentials storage
- Container Registry: Docker image storage
- Cloud Build: Automated Docker builds
- Cloud Logging: Centralized logging
- Cloud Monitoring: Performance metrics
Pros:
- Serverless, auto-scaling
- Pay only for requests
- HTTPS out of the box
- No infrastructure management
Use Cases:
- Production deployments
- API endpoints
- Variable load patterns
cd docker/cloud-run
GCP_PROJECT_ID=my-project ./deploy.shPros:
- Full control
- Local development
- Multiple configurations
Use Cases:
- Development
- Testing
- On-premise deployments
cd docker
docker-compose up -d
# View logs
docker-compose logs -f
# Scale services
docker-compose up -d --scale agentic-flow-openrouter=3Pros:
- Full Kubernetes features
- Advanced orchestration
- Multi-region deployments
Use Cases:
- Enterprise deployments
- Complex workflows
- High availability
# Coming soon - kubernetes/ directory
cd docker/kubernetes
kubectl apply -f deployment.yamlBest for: Complex reasoning, code reviews, architecture
# Configuration
MODEL_PROVIDER=anthropic
MODEL_NAME=claude-3-5-sonnet-20241022
ANTHROPIC_API_KEY=sk-ant-...
# Cost: ~$0.080 per taskBest for: Cost savings, variety of models
# Llama 3.1 8B - Fastest, cheapest
MODEL_PROVIDER=openrouter
MODEL_NAME=meta-llama/llama-3.1-8b-instruct
OPENROUTER_API_KEY=sk-or-...
# Cost: ~$0.0003 per task (99% savings!)
# Other options:
# DeepSeek - Excellent for code
MODEL_NAME=deepseek/deepseek-chat-v3.1
# Gemini 2.5 Flash - Very fast
MODEL_NAME=google/gemini-2.5-flash-preview
# Claude via OpenRouter - Same quality
MODEL_NAME=anthropic/claude-3-5-sonnetBest for: Offline, air-gapped environments
MODEL_PROVIDER=onnx
MODEL_PATH=/app/models/phi-4.onnx
# Cost: $0 (runs locally, one-time model download)Use pre-configured templates from docker/configs/:
claude.env.template- Premium Claude configurationopenrouter.env.template- Cost-optimized OpenRoutermulti-model.env.template- Multiple providers simultaneously
# Copy and customize
cp docker/configs/openrouter.env.template .env
# Edit .env with your API keys
nano .env# Small deployment (development)
MEMORY=1Gi
CPU=1
MAX_INSTANCES=3
CONCURRENCY=40
# Medium deployment (production)
MEMORY=2Gi
CPU=2
MAX_INSTANCES=10
CONCURRENCY=80
# Large deployment (enterprise)
MEMORY=4Gi
CPU=4
MAX_INSTANCES=50
CONCURRENCY=160Never commit secrets to Git!
Use GCP Secret Manager for all sensitive data:
# Create secrets
./setup-secrets.sh setup
# Grant access to service account
./setup-secrets.sh grant-all
# List secrets
./setup-secrets.sh list
# Rotate secret
gcloud secrets versions add ANTHROPIC_API_KEY --data-file=new-key.txt
# Disable old version
gcloud secrets versions disable 1 --secret=ANTHROPIC_API_KEYRequired roles for deployment:
# Grant roles to service account
gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
--member="serviceAccount:SERVICE_ACCOUNT@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/run.admin"
gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
--member="serviceAccount:SERVICE_ACCOUNT@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/secretmanager.secretAccessor"# Restrict to VPC (optional)
gcloud run services update agentic-flow \
--vpc-connector=my-connector \
--vpc-egress=all-traffic
# Require authentication
gcloud run services update agentic-flow \
--no-allow-unauthenticated
# Add custom domain with SSL
gcloud run domain-mappings create \
--service=agentic-flow \
--domain=agents.example.com# View logs
gcloud logging read "resource.type=cloud_run_revision AND resource.labels.service_name=agentic-flow" \
--limit=50 \
--format=json
# Filter by severity
gcloud logging read "severity>=ERROR" --limit=20
# Stream logs
gcloud logging tail "resource.type=cloud_run_revision"# Create alerting policy for errors
gcloud alpha monitoring policies create \
--notification-channels=CHANNEL_ID \
--display-name="High Error Rate" \
--condition-display-name="Error rate > 5%" \
--condition-threshold-value=0.05 \
--condition-threshold-duration=300sBuilt-in health endpoint:
# Manual health check
curl https://your-service-url/health
# Expected response:
{
"status": "healthy",
"timestamp": "2025-10-04T20:30:00Z",
"uptime": 3600,
"memory": {"used": "150MB", "free": "1.85GB"},
"agents": {"loaded": 66, "status": "ready"}
}Cost Comparison (per 1000 tasks):
# Scale to zero when idle
MIN_INSTANCES=0 # Saves money during low traffic
# Optimize for cost
MEMORY=1Gi # Minimum viable memory
CPU=1 # Single CPU core
CONCURRENCY=100 # Max requests per container
# Set request timeout
TIMEOUT=60 # Faster timeout = lower costsRoute expensive Claude requests only for complex tasks:
// Use Claude for complex tasks
if (taskComplexity === 'high') {
provider = 'anthropic';
model = 'claude-3-5-sonnet';
}
// Use OpenRouter for simple tasks
else {
provider = 'openrouter';
model = 'meta-llama/llama-3.1-8b-instruct';
}# View Cloud Run costs
gcloud billing accounts get-iam-policy BILLING_ACCOUNT_ID
# Set budget alerts
gcloud billing budgets create \
--billing-account=BILLING_ACCOUNT_ID \
--display-name="Agentic Flow Budget" \
--budget-amount=100USD \
--threshold-rule=percent=801. Deployment fails with "permission denied"
# Grant Cloud Build permissions
gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
--member=serviceAccount:$PROJECT_NUMBER@cloudbuild.gserviceaccount.com \
--role=roles/run.admin2. Container fails to start
# Check logs
gcloud logging read "resource.type=cloud_run_revision" --limit=50
# Check build logs
gcloud builds list --limit=5
gcloud builds log BUILD_ID3. Out of memory errors
# Increase memory
gcloud run services update agentic-flow --memory=4Gi
# Or reduce concurrency
gcloud run services update agentic-flow --concurrency=404. Secrets not accessible
# Grant secret access
./setup-secrets.sh grant-all
# Verify service account
gcloud run services describe agentic-flow --format="value(spec.template.spec.serviceAccountName)"# Deploy to multiple regions
for region in us-central1 europe-west1 asia-east1; do
gcloud run deploy agentic-flow-$region \
--image=gcr.io/$PROJECT_ID/agentic-flow \
--region=$region \
--platform=managed
done
# Setup global load balancer
gcloud compute backend-services create agentic-flow-backend \
--global# .github/workflows/deploy.yml
name: Deploy to Cloud Run
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: google-github-actions/setup-gcloud@v0
- run: |
cd docker/cloud-run
./deploy.sh# Map custom domain
gcloud run domain-mappings create \
--service=agentic-flow \
--domain=api.yourdomain.com \
--region=us-central1
# Get DNS records to configure
gcloud run domain-mappings describe \
--domain=api.yourdomain.com \
--region=us-central1- Documentation:
/docs - Issues: https://github.com/ruvnet/agentic-flow/issues
- NPM: https://www.npmjs.com/package/agentic-flow
See LICENSE file in the repository root.
