#!/bin/bash # GCP Deployment Script for Phishing Detection API # This script helps deploy the application to Google Cloud Run set -e PROJECT_ID=${1:-"your-project-id"} REGION=${2:-"us-central1"} SERVICE_NAME="phishing-detection-api" echo "==========================================" echo "Phishing Detection API - GCP Deployment" echo "==========================================" echo "Project ID: $PROJECT_ID" echo "Region: $REGION" echo "Service Name: $SERVICE_NAME" echo "==========================================" # Check if gcloud is installed if ! command -v gcloud &> /dev/null; then echo "Error: gcloud CLI is not installed. Please install it first." exit 1 fi # Check if docker is installed if ! command -v docker &> /dev/null; then echo "Error: Docker is not installed. Please install it first." exit 1 fi # Set the project echo "Setting GCP project..." gcloud config set project $PROJECT_ID # Enable required APIs echo "Enabling required APIs..." 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 echo "Checking for GROQ_API_KEY secret..." if ! gcloud secrets describe GROQ_API_KEY --project=$PROJECT_ID &> /dev/null; then echo "GROQ_API_KEY secret not found. Creating it..." read -sp "Enter your GROQ_API_KEY: " GROQ_KEY echo echo -n "$GROQ_KEY" | gcloud secrets create GROQ_API_KEY \ --data-file=- \ --replication-policy="automatic" \ --project=$PROJECT_ID # Grant Cloud Run service account access to the secret PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)") gcloud secrets add-iam-policy-binding GROQ_API_KEY \ --member="serviceAccount:$PROJECT_NUMBER-compute@developer.gserviceaccount.com" \ --role="roles/secretmanager.secretAccessor" \ --project=$PROJECT_ID else echo "GROQ_API_KEY secret already exists." fi # Build and deploy using Cloud Build echo "Building and deploying using Cloud Build..." gcloud builds submit --config=cloudbuild.yaml --project=$PROJECT_ID # Get the service URL echo "Deployment complete!" echo "Getting service URL..." SERVICE_URL=$(gcloud run services describe $SERVICE_NAME \ --region=$REGION \ --format="value(status.url)" \ --project=$PROJECT_ID) echo "==========================================" echo "Deployment Successful!" echo "Service URL: $SERVICE_URL" echo "Health Check: $SERVICE_URL/health" echo "API Docs: $SERVICE_URL/docs" echo "=========================================="