# GCP Deployment Script for Phishing Detection API (PowerShell) # This script helps deploy the application to Google Cloud Run param( [Parameter(Mandatory=$true)] [string]$ProjectId, [Parameter(Mandatory=$false)] [string]$Region = "us-central1" ) $ServiceName = "phishing-detection-api" Write-Host "==========================================" -ForegroundColor Cyan Write-Host "Phishing Detection API - GCP Deployment" -ForegroundColor Cyan Write-Host "==========================================" -ForegroundColor Cyan Write-Host "Project ID: $ProjectId" Write-Host "Region: $Region" Write-Host "Service Name: $ServiceName" Write-Host "==========================================" -ForegroundColor Cyan # Check if gcloud is installed try { $null = Get-Command gcloud -ErrorAction Stop } catch { Write-Host "Error: gcloud CLI is not installed. Please install it first." -ForegroundColor Red exit 1 } # Check if docker is installed try { $null = Get-Command docker -ErrorAction Stop } catch { Write-Host "Error: Docker is not installed. Please install it first." -ForegroundColor Red exit 1 } # Set the project Write-Host "Setting GCP project..." -ForegroundColor Yellow gcloud config set project $ProjectId # Enable required APIs Write-Host "Enabling required APIs..." -ForegroundColor Yellow gcloud services enable cloudbuild.googleapis.com gcloud services enable run.googleapis.com gcloud services enable containerregistry.googleapis.com # Check if GROQ_API_KEY secret exists, if not create it Write-Host "Checking for GROQ_API_KEY secret..." -ForegroundColor Yellow $secretExists = gcloud secrets describe GROQ_API_KEY --project=$ProjectId 2>&1 if ($LASTEXITCODE -ne 0) { Write-Host "GROQ_API_KEY secret not found. Creating it..." -ForegroundColor Yellow $GroqKey = Read-Host "Enter your GROQ_API_KEY" -AsSecureString $GroqKeyPlain = [Runtime.InteropServices.Marshal]::PtrToStringAuto( [Runtime.InteropServices.Marshal]::SecureStringToBSTR($GroqKey) ) echo $GroqKeyPlain | gcloud secrets create GROQ_API_KEY ` --data-file=- ` --replication-policy="automatic" ` --project=$ProjectId # Grant Cloud Run service account access to the secret $ProjectNumber = (gcloud projects describe $ProjectId --format="value(projectNumber)") gcloud secrets add-iam-policy-binding GROQ_API_KEY ` --member="serviceAccount:$ProjectNumber-compute@developer.gserviceaccount.com" ` --role="roles/secretmanager.secretAccessor" ` --project=$ProjectId } else { Write-Host "GROQ_API_KEY secret already exists." -ForegroundColor Green } # Build and deploy using Cloud Build Write-Host "Building and deploying using Cloud Build..." -ForegroundColor Yellow gcloud builds submit --config=cloudbuild.yaml --project=$ProjectId # Get the service URL Write-Host "Deployment complete!" -ForegroundColor Green Write-Host "Getting service URL..." -ForegroundColor Yellow $ServiceUrl = (gcloud run services describe $ServiceName ` --region=$Region ` --format="value(status.url)" ` --project=$ProjectId) Write-Host "==========================================" -ForegroundColor Green Write-Host "Deployment Successful!" -ForegroundColor Green Write-Host "Service URL: $ServiceUrl" Write-Host "Health Check: $ServiceUrl/health" Write-Host "API Docs: $ServiceUrl/docs" Write-Host "==========================================" -ForegroundColor Green