-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-api.sh
More file actions
executable file
·102 lines (88 loc) · 3.08 KB
/
deploy-api.sh
File metadata and controls
executable file
·102 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
#!/bin/bash
# Deploy API-only Service to Cloud Run
# For api.stratint.com subdomain
# Lightweight - no frontend, no Playwright
set -e
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Configuration - set these environment variables before running
export PROJECT_ID="${GCP_PROJECT_ID:?Error: Set GCP_PROJECT_ID environment variable}"
export REGION="${GCP_REGION:-us-central1}"
export INSTANCE_NAME="${CLOUD_SQL_INSTANCE:-osint-db}"
export INSTANCE_CONNECTION_NAME="${PROJECT_ID}:${REGION}:${INSTANCE_NAME}"
export DB_NAME="${DB_NAME:-stratint}"
export DB_USER="${DB_USER:-postgres}"
export SERVICE_NAME="${SERVICE_NAME:-stratint-api}"
echo -e "${GREEN}OSINTMCP API Service Deployment${NC}"
echo "Project: $PROJECT_ID"
echo "Region: $REGION"
echo "Service: $SERVICE_NAME (API-only, lightweight)"
echo "Cloud SQL: $INSTANCE_CONNECTION_NAME"
echo ""
# Check if secrets exist
echo -e "${YELLOW}Checking secrets...${NC}"
SECRETS_EXIST=true
for SECRET in db-password admin-jwt-secret admin-password; do
if ! gcloud secrets describe $SECRET --project=$PROJECT_ID &>/dev/null; then
echo -e "${YELLOW}Warning: Secret '$SECRET' not found${NC}"
SECRETS_EXIST=false
else
echo "✓ Secret '$SECRET' exists"
fi
done
if [ "$SECRETS_EXIST" = false ]; then
echo ""
echo -e "${YELLOW}Run ./setup-secrets.sh to create missing secrets${NC}"
read -p "Press Enter to continue anyway, or Ctrl+C to exit..."
fi
# Build and push image
TIMESTAMP=$(date +%Y%m%d%H%M%S)
IMAGE_TAG="gcr.io/$PROJECT_ID/$SERVICE_NAME:$TIMESTAMP"
IMAGE_LATEST="gcr.io/$PROJECT_ID/$SERVICE_NAME:latest"
echo ""
echo -e "${GREEN}Building API-only Docker image...${NC}"
docker build -f Dockerfile.api -t "$IMAGE_TAG" -t "$IMAGE_LATEST" .
echo ""
echo -e "${GREEN}Pushing to Container Registry...${NC}"
gcloud auth configure-docker --quiet
docker push "$IMAGE_TAG"
docker push "$IMAGE_LATEST"
echo ""
echo -e "${GREEN}Deploying API service to Cloud Run...${NC}"
gcloud run deploy $SERVICE_NAME \
--image="$IMAGE_TAG" \
--region=$REGION \
--platform=managed \
--allow-unauthenticated \
--memory=2Gi \
--cpu=2 \
--timeout=300 \
--max-instances=10 \
--min-instances=0 \
--concurrency=80 \
--project=$PROJECT_ID \
--add-cloudsql-instances=$INSTANCE_CONNECTION_NAME \
--set-env-vars=ENVIRONMENT=production,LOG_LEVEL=info,LOG_FORMAT=json,INSTANCE_CONNECTION_NAME=$INSTANCE_CONNECTION_NAME,DB_NAME=$DB_NAME,DB_USER=$DB_USER,ADMIN_ENABLED=true \
--set-secrets=DB_PASSWORD=db-password:latest,ADMIN_JWT_SECRET=admin-jwt-secret:latest,ADMIN_PASSWORD=admin-password:latest \
--no-cpu-throttling \
--cpu-boost
echo ""
echo -e "${GREEN}Getting service URL...${NC}"
SERVICE_URL=$(gcloud run services describe $SERVICE_NAME \
--region=$REGION \
--project=$PROJECT_ID \
--format='value(status.url)')
echo ""
echo -e "${GREEN}✓ API Service deployment complete!${NC}"
echo ""
echo "API Service URL: $SERVICE_URL"
echo "Health Check: $SERVICE_URL/healthz"
echo "Events API: $SERVICE_URL/api/events"
echo ""
echo "Test it with: curl $SERVICE_URL/api/events"
echo ""
echo "Map subdomain:"
echo " api.stratint.com → $SERVICE_URL"
echo ""