forked from mcpmessenger/langchain-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-cloud-run.sh
More file actions
104 lines (88 loc) · 3.08 KB
/
deploy-cloud-run.sh
File metadata and controls
104 lines (88 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# Deployment script for Google Cloud Run
# Usage: ./deploy-cloud-run.sh [project-id] [region]
set -e
# Configuration
PROJECT_ID=${1:-${GOOGLE_CLOUD_PROJECT}}
REGION=${2:-us-central1}
SERVICE_NAME="langchain-agent-mcp-server"
IMAGE_NAME="gcr.io/${PROJECT_ID}/${SERVICE_NAME}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}🚀 Deploying LangChain Agent MCP Server to Google Cloud Run${NC}"
echo ""
# Check if PROJECT_ID is set
if [ -z "$PROJECT_ID" ]; then
echo -e "${RED}❌ Error: PROJECT_ID not set${NC}"
echo "Usage: ./deploy-cloud-run.sh [project-id] [region]"
echo "Or set GOOGLE_CLOUD_PROJECT environment variable"
exit 1
fi
echo -e "${YELLOW}Configuration:${NC}"
echo " Project ID: $PROJECT_ID"
echo " Region: $REGION"
echo " Service Name: $SERVICE_NAME"
echo ""
# Check if gcloud is installed
if ! command -v gcloud &> /dev/null; then
echo -e "${RED}❌ Error: gcloud CLI not found${NC}"
echo "Please install Google Cloud SDK: https://cloud.google.com/sdk/docs/install"
exit 1
fi
# Check if docker is installed
if ! command -v docker &> /dev/null; then
echo -e "${RED}❌ Error: Docker not found${NC}"
echo "Please install Docker: https://docs.docker.com/get-docker/"
exit 1
fi
# Set the project
echo -e "${YELLOW}📋 Setting GCP project...${NC}"
gcloud config set project $PROJECT_ID
# Enable required APIs
echo -e "${YELLOW}🔧 Enabling required APIs...${NC}"
gcloud services enable cloudbuild.googleapis.com
gcloud services enable run.googleapis.com
gcloud services enable containerregistry.googleapis.com
# Build the Docker image
echo -e "${YELLOW}🏗️ Building Docker image...${NC}"
docker build -t $IMAGE_NAME .
# Push the image to Container Registry
echo -e "${YELLOW}📤 Pushing image to Container Registry...${NC}"
docker push $IMAGE_NAME
# Deploy to Cloud Run
echo -e "${YELLOW}🚀 Deploying to Cloud Run...${NC}"
gcloud run deploy $SERVICE_NAME \
--image $IMAGE_NAME \
--platform managed \
--region $REGION \
--allow-unauthenticated \
--memory 2Gi \
--cpu 2 \
--timeout 300 \
--max-instances 10 \
--min-instances 0 \
--set-env-vars "OPENAI_MODEL=gpt-4o-mini,MAX_ITERATIONS=10,VERBOSE=false" \
--port 8000
# Get the service URL
SERVICE_URL=$(gcloud run services describe $SERVICE_NAME --platform managed --region $REGION --format 'value(status.url)')
echo ""
echo -e "${GREEN}✅ Deployment complete!${NC}"
echo ""
echo -e "${GREEN}Service URL:${NC} $SERVICE_URL"
echo ""
echo -e "${YELLOW}⚠️ Important: Set your OPENAI_API_KEY as a secret:${NC}"
echo " gcloud run services update $SERVICE_NAME \\"
echo " --update-secrets=OPENAI_API_KEY=openai-api-key:latest \\"
echo " --region $REGION"
echo ""
echo -e "${YELLOW}Or set it as an environment variable:${NC}"
echo " gcloud run services update $SERVICE_NAME \\"
echo " --set-env-vars OPENAI_API_KEY=your-key-here \\"
echo " --region $REGION"
echo ""
echo -e "${GREEN}Test your deployment:${NC}"
echo " curl $SERVICE_URL/health"
echo " curl $SERVICE_URL/mcp/manifest"