Skip to content

Commit 5022c24

Browse files
committed
feat: Add frontend deployment script and fix Vertex AI authentication scope error
1 parent d80ba60 commit 5022c24

4 files changed

Lines changed: 226 additions & 1 deletion

File tree

.claude/settings.local.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(git add backend/main.py backend/config/settings.py backend/api/endpoints_new.py frontend/components/site-header.tsx frontend/public/assets/)",
5+
"Bash(git commit -m \"$\\(cat <<''EOF''\nfix: Fix backend routing and improve API robustness\n\n- Switch backend to use app_new with correct endpoints_new module\n- Update endpoints_new to handle empty sessions gracefully\n- Update settings.py to use pydantic model_config pattern\n- Update site-header to use emoji logo \\(removes image dependency\\)\n- Copy image asset to frontend public directory for availability\n\nThis fixes:\n- 500 errors on /chat/sessions endpoint \\(now handles gracefully\\)\n- 500 errors on /chat endpoint \\(uses correct chatbot manager\\)\n- Missing logo issue \\(now renders emoji + image available\\)\n\nCo-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>\nEOF\n\\)\")",
6+
"Bash(git push:*)",
7+
"Bash(gcloud builds submit:*)",
8+
"Bash(gcloud builds log:*)",
9+
"Bash(gcloud builds list:*)",
10+
"Bash(gcloud run deploy:*)",
11+
"Bash(gcloud run logs read:*)",
12+
"Bash(gcloud logging read:*)",
13+
"Bash(git add:*)",
14+
"Bash(git commit:*)"
15+
]
16+
}
17+
}

scripts/cloudbuild-backend.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ steps:
4343
- 'us-central1'
4444
- '--allow-unauthenticated'
4545
- '--set-env-vars'
46-
- 'GOOGLE_CLOUD_PROJECT=$PROJECT_ID,DEBUG=false'
46+
- 'GOOGLE_CLOUD_PROJECT=$PROJECT_ID,DEBUG=false,USE_VERTEX_AI=true'
4747

4848
images:
4949
- 'gcr.io/$PROJECT_ID/legalmind-backend:latest'

scripts/deploy-frontend.ps1

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env pwsh
2+
3+
# LegalMind Frontend Deployment Script
4+
# Deploys updated frontend to Cloud Run
5+
6+
$projectId = "legalmind-486106"
7+
$region = "us-central1"
8+
$serviceName = "legalmind-frontend"
9+
$image = "gcr.io/$projectId/$serviceName"
10+
11+
Write-Host "╔════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
12+
Write-Host "║ LegalMind Frontend Deployment - Cloud Run ║" -ForegroundColor Cyan
13+
Write-Host "╚════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan
14+
Write-Host ""
15+
16+
Write-Host "ℹ️ Configuration:" -ForegroundColor White
17+
Write-Host " Project: $projectId"
18+
Write-Host " Region: $region"
19+
Write-Host " Service: $serviceName"
20+
Write-Host " Image: $image"
21+
Write-Host ""
22+
23+
# Check prerequisites
24+
Write-Host "✓ Checking prerequisites..." -ForegroundColor Green
25+
$checks = @(
26+
@{ cmd = "gcloud"; name = "Google Cloud CLI" },
27+
@{ cmd = "docker"; name = "Docker" }
28+
)
29+
30+
foreach ($check in $checks) {
31+
if (Get-Command $check.cmd -ErrorAction SilentlyContinue) {
32+
Write-Host "$($check.name) found" -ForegroundColor Green
33+
} else {
34+
Write-Host "$($check.name) not found" -ForegroundColor Red
35+
exit 1
36+
}
37+
}
38+
Write-Host ""
39+
40+
# Set Google Cloud project
41+
Write-Host "✓ Setting Google Cloud project..." -ForegroundColor Green
42+
gcloud config set project $projectId --quiet
43+
Write-Host ""
44+
45+
# Build Docker image using Cloud Build
46+
Write-Host "✓ Building Docker image with Cloud Build..." -ForegroundColor Green
47+
Write-Host ""
48+
49+
$buildCmd = @(
50+
"builds",
51+
"submit",
52+
"--tag=$image`:latest",
53+
"--timeout=30m",
54+
"--verbosity=info",
55+
"."
56+
)
57+
58+
gcloud @buildCmd
59+
if ($LASTEXITCODE -ne 0) {
60+
Write-Host "❌ Build failed" -ForegroundColor Red
61+
exit 1
62+
}
63+
64+
Write-Host ""
65+
Write-Host "✓ Build completed successfully" -ForegroundColor Green
66+
Write-Host ""
67+
68+
# Deploy to Cloud Run
69+
Write-Host "✓ Deploying to Cloud Run..." -ForegroundColor Green
70+
Write-Host ""
71+
72+
$deployCmd = @(
73+
"run",
74+
"deploy",
75+
$serviceName,
76+
"--image=$image`:latest",
77+
"--platform=managed",
78+
"--region=$region",
79+
"--allow-unauthenticated",
80+
"--port=3000",
81+
"--cpu=2",
82+
"--memory=2Gi",
83+
"--max-instances=10",
84+
"--min-instances=1",
85+
"--set-env-vars=NEXT_PUBLIC_API_URL=https://legalmind-backend-677928716377.us-central1.run.app",
86+
"--quiet"
87+
)
88+
89+
gcloud @deployCmd
90+
if ($LASTEXITCODE -ne 0) {
91+
Write-Host "❌ Deployment failed" -ForegroundColor Red
92+
exit 1
93+
}
94+
95+
Write-Host ""
96+
Write-Host "✅ Deployment completed successfully!" -ForegroundColor Green
97+
Write-Host ""
98+
99+
# Get service URL
100+
Write-Host "✓ Retrieving service URL..." -ForegroundColor Green
101+
$serviceUrl = gcloud run services describe $serviceName --region=$region --format='value(status.url)'
102+
103+
Write-Host ""
104+
Write-Host "╔════════════════════════════════════════════════════════════╗" -ForegroundColor Green
105+
Write-Host "║ Deployment Complete ✅ ║" -ForegroundColor Green
106+
Write-Host "╚════════════════════════════════════════════════════════════╝" -ForegroundColor Green
107+
Write-Host ""
108+
Write-Host "Frontend URL: $serviceUrl"
109+
Write-Host "Backend URL: https://legalmind-backend-677928716377.us-central1.run.app"
110+
Write-Host ""
111+
Write-Host "📊 Next Steps:"
112+
Write-Host " 1. Visit the frontend URL above"
113+
Write-Host " 2. Test the chat interface"
114+
Write-Host " 3. Upload a contract for analysis"
115+
Write-Host " 4. Monitor logs: gcloud run logs read $serviceName --region=$region"
116+
Write-Host ""

scripts/fix-vertex-ai-403.ps1

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env pwsh
2+
3+
# Fix Vertex AI 403 Authentication Scope Error
4+
# Grants proper IAM permissions to Cloud Run service account
5+
6+
$projectId = "legalmind-486106"
7+
$region = "us-central1"
8+
$backendService = "legalmind-backend"
9+
$projectNumber = "677928716377"
10+
11+
Write-Host "╔════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
12+
Write-Host "║ Fixing Vertex AI Authentication Scope Error ║" -ForegroundColor Cyan
13+
Write-Host "╚════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan
14+
Write-Host ""
15+
16+
# Set project
17+
Write-Host "✓ Setting project..." -ForegroundColor Green
18+
gcloud config set project $projectId --quiet
19+
20+
# Get the Cloud Run service account
21+
Write-Host "✓ Getting Cloud Run service account..." -ForegroundColor Green
22+
$serviceAccount = "$projectNumber-compute@developer.gserviceaccount.com"
23+
Write-Host " Service Account: $serviceAccount" -ForegroundColor White
24+
25+
# Grant required IAM roles
26+
Write-Host ""
27+
Write-Host "✓ Granting IAM permissions..." -ForegroundColor Green
28+
29+
$roles = @(
30+
"roles/aiplatform.user",
31+
"roles/ml.developer",
32+
"roles/datastore.user",
33+
"roles/storage.objectAdmin"
34+
)
35+
36+
foreach ($role in $roles) {
37+
Write-Host " Adding $role..." -ForegroundColor White
38+
gcloud projects add-iam-policy-binding $projectId `
39+
--member="serviceAccount:$serviceAccount" `
40+
--role="$role" `
41+
--condition=None `
42+
--quiet 2>$null
43+
}
44+
45+
Write-Host ""
46+
Write-Host "✓ Enabling required APIs..." -ForegroundColor Green
47+
48+
$apis = @(
49+
"aiplatform.googleapis.com",
50+
"generativelanguage.googleapis.com"
51+
)
52+
53+
foreach ($api in $apis) {
54+
Write-Host " Enabling $api..." -ForegroundColor White
55+
gcloud services enable $api --quiet 2>$null
56+
}
57+
58+
Write-Host ""
59+
Write-Host "✓ Redeploying backend with updated configuration..." -ForegroundColor Green
60+
Write-Host ""
61+
62+
# Redeploy backend
63+
gcloud run deploy $backendService `
64+
--image="gcr.io/$projectId/${backendService}:latest" `
65+
--platform=managed `
66+
--region=$region `
67+
--allow-unauthenticated `
68+
--port=8000 `
69+
--cpu=2 `
70+
--memory=4Gi `
71+
--max-instances=10 `
72+
--min-instances=1 `
73+
--service-account="$serviceAccount" `
74+
--set-env-vars="GOOGLE_CLOUD_PROJECT=$projectId,DEBUG=false,USE_VERTEX_AI=true" `
75+
--quiet
76+
77+
if ($LASTEXITCODE -eq 0) {
78+
Write-Host ""
79+
Write-Host "╔════════════════════════════════════════════════════════════╗" -ForegroundColor Green
80+
Write-Host "║ ✅ Fix Applied Successfully! ║" -ForegroundColor Green
81+
Write-Host "╚════════════════════════════════════════════════════════════╝" -ForegroundColor Green
82+
Write-Host ""
83+
Write-Host "Backend URL: https://$backendService-$projectNumber.$region.run.app"
84+
Write-Host "API Docs: https://$backendService-$projectNumber.$region.run.app/docs"
85+
Write-Host ""
86+
Write-Host "✓ The 403 authentication scope error should now be resolved."
87+
Write-Host ""
88+
} else {
89+
Write-Host ""
90+
Write-Host "❌ Deployment failed. Check the logs above." -ForegroundColor Red
91+
exit 1
92+
}

0 commit comments

Comments
 (0)