-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.sh
More file actions
76 lines (64 loc) · 2.9 KB
/
deploy.sh
File metadata and controls
76 lines (64 loc) · 2.9 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
#!/bin/bash
# PDF2CSV GCP Deployment Script
set -e
# Configuration
PROJECT_ID="pdf2csv-475708"
REGION="us-central1"
SERVICE_ACCOUNT="805037964827-compute@developer.gserviceaccount.com"
echo "🚀 Starting PDF2CSV deployment to GCP..."
# 1. Enable required APIs
echo "📋 Enabling required APIs..."
gcloud services enable cloudbuild.googleapis.com
gcloud services enable run.googleapis.com
gcloud services enable sqladmin.googleapis.com
gcloud services enable storage.googleapis.com
gcloud services enable documentai.googleapis.com
# 2. Set project
gcloud config set project $PROJECT_ID
# 3. Build and push backend Docker image
echo "🐳 Building backend Docker image..."
cd server
gcloud builds submit --tag gcr.io/$PROJECT_ID/pdf2csv-backend:latest .
# 4. Build and push frontend Docker image
echo "🐳 Building frontend Docker image..."
cd ../client
gcloud builds submit --tag gcr.io/$PROJECT_ID/pdf2csv-frontend:latest .
# 5. Deploy backend to Cloud Run
echo "🚀 Deploying backend to Cloud Run..."
cd ../server
gcloud run deploy pdf2csv-backend \
--image gcr.io/$PROJECT_ID/pdf2csv-backend:latest \
--platform managed \
--region $REGION \
--allow-unauthenticated \
--service-account $SERVICE_ACCOUNT \
--set-env-vars="NODE_ENV=production,PROJECT_ID=$PROJECT_ID,LOCATION=us,PROCESSOR_ID=ac7cd16151a4efbe,OUTPUT_BUCKET=pdf-data-extraction-output-bucket,STORAGE_LOCATION=us,DELETE_RAW_AFTER_PROCESS=false,DB_HOST=/cloudsql/pdf2csv-475708:us-central1:pdf2csv-new,DB_PORT=5432,DB_NAME=pdf2csv_new_db,DB_USER=pdf2csv_app_user,DB_PASSWORD=AppUser2024!,DB_SSL=false,MAX_CONCURRENT_BATCHES=5,BATCH_QUEUE_TIMEOUT=1800000,MAX_QUEUE_LENGTH=500,DB_POOL_MAX=50,DB_POOL_MIN=2,WORKER_THREAD_POOL_SIZE=4,DB_INSERT_CHUNK_SIZE=5000,ENABLE_DUPLICATE_DETECTION=true,MAX_CONCURRENT_DOCAI_REQUESTS=80" \
--set-cloudsql-instances="pdf2csv-475708:us-central1:pdf2csv-new" \
--memory=4Gi \
--cpu=4 \
--concurrency=80 \
--min-instances=1 \
--max-instances=10 \
--timeout=1800
# 6. Get backend URL and derive WS_URL
BACKEND_URL=$(gcloud run services describe pdf2csv-backend --platform managed --region $REGION --format 'value(status.url)')
WS_URL=$(echo $BACKEND_URL | sed 's|https://|wss://|g')
echo "✅ Backend deployed at: $BACKEND_URL"
echo "✅ WebSocket URL configured at: $WS_URL"
# 7. Deploy frontend to Cloud Run
echo "🚀 Deploying frontend to Cloud Run..."
cd ../client
gcloud run deploy pdf2csv-frontend \
--image gcr.io/$PROJECT_ID/pdf2csv-frontend:latest \
--platform managed \
--region $REGION \
--allow-unauthenticated \
--set-env-vars="VITE_API_URL=$BACKEND_URL,VITE_WS_URL=$WS_URL" \
--memory=1Gi \
--cpu=1
# 8. Get frontend URL
FRONTEND_URL=$(gcloud run services describe pdf2csv-frontend --platform managed --region $REGION --format 'value(status.url)')
echo "✅ Frontend deployed at: $FRONTEND_URL"
echo "🎉 Deployment completed successfully!"
echo "Frontend URL: $FRONTEND_URL"
echo "Backend URL: $BACKEND_URL"