deploy-staging.sh•8.2 kB
#!/bin/bash
# ================================================================
# LEGACY SCRIPT - Replaced by GitHub Actions
# ================================================================
# This script is kept for emergency manual deployments only.
# Normal deployments should use the GitHub Actions workflow:
# - Push to 'staging' branch for automatic deployment
# - See GITHUB_CICD_PLAN.md for details
# ================================================================
# ============================================
# Tableau MCP Server - STAGING Deployment
# ============================================
# This script automates the deployment of the
# Tableau MCP Server to Google Cloud Run (Staging)
# ============================================
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# ============================================
# Configuration
# ============================================
ENVIRONMENT="staging"
SERVICE_NAME="tableau-mcp-staging"
REGION="australia-southeast1"
IMAGE_TAG="staging-latest"
echo -e "${BLUE}============================================${NC}"
echo -e "${BLUE}Tableau MCP Server - STAGING Deployment${NC}"
echo -e "${BLUE}============================================${NC}"
echo ""
# ============================================
# Deployment Warning
# ============================================
echo -e "${YELLOW}⚠️ WARNING: This is a legacy manual deployment script.${NC}"
echo -e "${YELLOW} GitHub Actions is now the primary deployment method.${NC}"
echo ""
read -p "Continue with manual deployment? (yes/no): " CONFIRM
if [ "$CONFIRM" != "yes" ]; then
echo -e "${RED}Deployment cancelled.${NC}"
exit 0
fi
echo ""
# ============================================
# Step 1: Verify Prerequisites
# ============================================
echo -e "${YELLOW}[Step 1/8] Verifying prerequisites...${NC}"
# Check if gcloud is installed
if ! command -v gcloud &> /dev/null; then
echo -e "${RED}ERROR: gcloud CLI is not installed${NC}"
echo "Install from: 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 is not installed${NC}"
echo "Install from: https://docs.docker.com/get-docker/"
exit 1
fi
# Get current project
PROJECT_ID=$(gcloud config get-value project 2>/dev/null)
if [ -z "$PROJECT_ID" ]; then
echo -e "${RED}ERROR: No Google Cloud project set${NC}"
echo "Run: gcloud config set project YOUR_PROJECT_ID"
exit 1
fi
echo -e "${GREEN}✓ Prerequisites verified${NC}"
echo " - Project: $PROJECT_ID"
echo " - Region: $REGION"
echo " - Service: $SERVICE_NAME"
echo ""
# ============================================
# Step 2: Confirm Deployment
# ============================================
echo -e "${YELLOW}[Step 2/8] Deployment confirmation${NC}"
read -p "Deploy to STAGING environment in project '$PROJECT_ID'? (y/N) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Deployment cancelled${NC}"
exit 0
fi
echo ""
# ============================================
# Step 3: Enable Required APIs
# ============================================
echo -e "${YELLOW}[Step 3/8] Enabling required Google Cloud APIs...${NC}"
gcloud services enable \
run.googleapis.com \
containerregistry.googleapis.com \
cloudbuild.googleapis.com \
secretmanager.googleapis.com \
--project=$PROJECT_ID
echo -e "${GREEN}✓ APIs enabled${NC}"
echo ""
# ============================================
# Step 4: Build Docker Image
# ============================================
echo -e "${YELLOW}[Step 4/8] Building Docker image...${NC}"
IMAGE_NAME="gcr.io/$PROJECT_ID/tableau-mcp:$IMAGE_TAG"
docker build -t $IMAGE_NAME . --platform linux/amd64
echo -e "${GREEN}✓ Docker image built: $IMAGE_NAME${NC}"
echo ""
# ============================================
# Step 5: Push to Google Container Registry
# ============================================
echo -e "${YELLOW}[Step 5/8] Pushing image to Google Container Registry...${NC}"
# Configure Docker authentication
gcloud auth configure-docker --quiet
# Push image
docker push $IMAGE_NAME
echo -e "${GREEN}✓ Image pushed to GCR${NC}"
echo ""
# ============================================
# Step 6: Verify Secrets Exist
# ============================================
echo -e "${YELLOW}[Step 6/8] Verifying secrets...${NC}"
SECRETS=("tableau-token-staging" "mcp-api-key-staging")
MISSING_SECRETS=()
for SECRET in "${SECRETS[@]}"; do
if ! gcloud secrets describe $SECRET --project=$PROJECT_ID &>/dev/null; then
MISSING_SECRETS+=($SECRET)
fi
done
if [ ${#MISSING_SECRETS[@]} -ne 0 ]; then
echo -e "${RED}ERROR: Missing required secrets:${NC}"
for SECRET in "${MISSING_SECRETS[@]}"; do
echo " - $SECRET"
done
echo ""
echo "Create secrets using: ./create-secrets.sh staging"
echo "Or see: SECRETS_SETUP.md"
exit 1
fi
echo -e "${GREEN}✓ All required secrets exist${NC}"
echo ""
# ============================================
# Step 7: Deploy to Cloud Run
# ============================================
echo -e "${YELLOW}[Step 7/8] Deploying to Cloud Run...${NC}"
# Get environment configuration
echo "Please provide the following configuration:"
read -p "Tableau Server URL (e.g., https://your-server.tableau.com): " TABLEAU_SERVER_URL
read -p "Tableau Site ID (leave empty for default site): " TABLEAU_SITE_ID
read -p "Tableau Token Name: " TABLEAU_TOKEN_NAME
# Deploy service
gcloud run deploy $SERVICE_NAME \
--image=$IMAGE_NAME \
--platform=managed \
--region=$REGION \
--allow-unauthenticated \
--min-instances=0 \
--max-instances=5 \
--cpu=1 \
--memory=512Mi \
--timeout=300 \
--concurrency=80 \
--set-env-vars="NODE_ENV=staging,PORT=8080,TABLEAU_SERVER_URL=$TABLEAU_SERVER_URL,TABLEAU_SITE_ID=$TABLEAU_SITE_ID,TABLEAU_TOKEN_NAME=$TABLEAU_TOKEN_NAME,TABLEAU_API_VERSION=3.23" \
--set-secrets="TABLEAU_TOKEN_VALUE=tableau-token-staging:latest,MCP_API_KEY=mcp-api-key-staging:latest" \
--project=$PROJECT_ID
echo -e "${GREEN}✓ Deployed to Cloud Run${NC}"
echo ""
# ============================================
# Step 8: Get Service URL and Test
# ============================================
echo -e "${YELLOW}[Step 8/8] Verifying deployment...${NC}"
# Get service URL
SERVICE_URL=$(gcloud run services describe $SERVICE_NAME \
--region=$REGION \
--project=$PROJECT_ID \
--format='value(status.url)')
echo ""
echo -e "${GREEN}============================================${NC}"
echo -e "${GREEN}✓ STAGING DEPLOYMENT SUCCESSFUL!${NC}"
echo -e "${GREEN}============================================${NC}"
echo ""
echo "Service URL: $SERVICE_URL"
echo ""
echo "Endpoints:"
echo " - Health: $SERVICE_URL/health"
echo " - Readiness: $SERVICE_URL/ready"
echo " - Liveness: $SERVICE_URL/alive"
echo " - MCP SSE: $SERVICE_URL/sse"
echo ""
# Test health endpoint
echo "Testing health endpoint..."
HEALTH_STATUS=$(curl -s -o /dev/null -w "%{http_code}" $SERVICE_URL/health)
if [ "$HEALTH_STATUS" == "200" ]; then
echo -e "${GREEN}✓ Health check passed${NC}"
else
echo -e "${RED}✗ Health check failed (HTTP $HEALTH_STATUS)${NC}"
fi
echo ""
# Get MCP API Key for Cursor configuration
MCP_API_KEY=$(gcloud secrets versions access latest --secret=mcp-api-key-staging --project=$PROJECT_ID)
echo "Next steps:"
echo "1. Test MCP endpoints with your API key"
echo "2. Create Cursor MCP configuration (Phase 7)"
echo "3. Test all 9 MCP tools"
echo ""
echo "MCP Configuration for Cursor:"
echo "---"
echo "URL: $SERVICE_URL/sse"
echo "API Key: $MCP_API_KEY"
echo "---"
echo ""
echo "View logs:"
echo " gcloud run logs read $SERVICE_NAME --region=$REGION --project=$PROJECT_ID"
echo ""
echo "Update service:"
echo " ./deploy-staging.sh"
echo ""
echo "Rollback:"
echo " gcloud run revisions list --service=$SERVICE_NAME --region=$REGION"
echo " gcloud run services update-traffic $SERVICE_NAME --region=$REGION --to-revisions=REVISION_NAME=100"
echo ""
echo -e "${BLUE}Deployment complete!${NC}"