File size: 1,189 Bytes
5fd7795
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Deploy CropAI Backend to Google Cloud Run
set -e

PROJECT_ID=${1:-"$(gcloud config get-value project)"}
REGION=${2:-"us-central1"}
SERVICE_NAME="cropai-backend"
IMAGE_NAME="gcr.io/${PROJECT_ID}/${SERVICE_NAME}:latest"

echo "=================================================="
echo "Deploying CropAI Backend to Google Cloud Run"
echo "Project: $PROJECT_ID | Region: $REGION"
echo "=================================================="

# 1. Build container image using Google Cloud Build
echo "[1/3] Building container image on Cloud Build..."
gcloud builds submit --tag ${IMAGE_NAME} .

# 2. Deploy to Cloud Run
echo "[2/3] Deploying to Cloud Run..."
gcloud run deploy ${SERVICE_NAME} \
    --image ${IMAGE_NAME} \
    --platform managed \
    --region ${REGION} \
    --allow-unauthenticated \
    --memory 2Gi \
    --cpu 2 \
    --min-instances 0 \
    --max-instances 10 \
    --port 8080

# 3. Retrieve service URL
SERVICE_URL=$(gcloud run services describe ${SERVICE_NAME} --platform managed --region ${REGION} --format 'value(status.url)')
echo "[3/3] Deployment complete!"
echo "CropAI API Endpoint: ${SERVICE_URL}"
echo "Test endpoint: ${SERVICE_URL}/health"