274 lines
10 KiB
PowerShell
274 lines
10 KiB
PowerShell
# Script to populate .env file with Azure configuration
|
|
# This script gathers Azure information and creates/updates the .env file
|
|
|
|
param(
|
|
[Parameter(Mandatory=$false)]
|
|
[string]$ResourceGroupName = "rg-miraclesinmotion-prod",
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[string]$Location = "eastus2",
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[string]$Domain = "mim4u.org",
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[switch]$CreateResourceGroup = $false
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
Write-Host "🔧 Populating .env file with Azure configuration" -ForegroundColor Green
|
|
Write-Host "=============================================" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Check if logged in to Azure
|
|
$account = az account show --output json 2>$null | ConvertFrom-Json
|
|
if (-not $account) {
|
|
Write-Host "❌ Not logged in to Azure. Please run: az login" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "✅ Logged in to Azure" -ForegroundColor Green
|
|
Write-Host " Subscription: $($account.name)" -ForegroundColor Gray
|
|
Write-Host " Tenant ID: $($account.tenantId)" -ForegroundColor Gray
|
|
Write-Host ""
|
|
|
|
# Get subscription ID
|
|
$subscriptionId = $account.id
|
|
$tenantId = $account.tenantId
|
|
|
|
# Check if resource group exists
|
|
$rgExists = az group exists --name $ResourceGroupName --output tsv
|
|
if ($rgExists -eq "false") {
|
|
if ($CreateResourceGroup) {
|
|
Write-Host "📁 Creating resource group: $ResourceGroupName" -ForegroundColor Cyan
|
|
az group create --name $ResourceGroupName --location $Location | Out-Null
|
|
Write-Host "✅ Resource group created" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "⚠️ Resource group '$ResourceGroupName' does not exist." -ForegroundColor Yellow
|
|
Write-Host " Run with -CreateResourceGroup to create it, or deploy infrastructure first." -ForegroundColor Yellow
|
|
}
|
|
} else {
|
|
Write-Host "✅ Resource group exists: $ResourceGroupName" -ForegroundColor Green
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# Check for existing resources
|
|
Write-Host "🔍 Checking for existing resources..." -ForegroundColor Cyan
|
|
|
|
# Check for Static Web App
|
|
$staticWebApp = az staticwebapp list --resource-group $ResourceGroupName --output json 2>$null | ConvertFrom-Json | Select-Object -First 1
|
|
$staticWebAppName = ""
|
|
$staticWebAppUrl = ""
|
|
|
|
if ($staticWebApp) {
|
|
$staticWebAppName = $staticWebApp.name
|
|
$staticWebAppUrl = "https://$($staticWebApp.defaultHostname)"
|
|
Write-Host "✅ Found Static Web App: $staticWebAppName" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "⚠️ Static Web App not found (will use placeholder)" -ForegroundColor Yellow
|
|
$staticWebAppUrl = "https://mim4u.org"
|
|
}
|
|
|
|
# Check for Function App
|
|
$functionApp = az functionapp list --resource-group $ResourceGroupName --output json 2>$null | ConvertFrom-Json | Select-Object -First 1
|
|
$functionAppName = ""
|
|
$functionAppUrl = ""
|
|
|
|
if ($functionApp) {
|
|
$functionAppName = $functionApp.name
|
|
$functionAppUrl = "https://$($functionApp.defaultHostName)"
|
|
Write-Host "✅ Found Function App: $functionAppName" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "⚠️ Function App not found (will use placeholder)" -ForegroundColor Yellow
|
|
$functionAppUrl = "https://YOUR_FUNCTION_APP.azurewebsites.net"
|
|
}
|
|
|
|
# Check for Key Vault
|
|
$keyVault = az keyvault list --resource-group $ResourceGroupName --output json 2>$null | ConvertFrom-Json | Select-Object -First 1
|
|
$keyVaultName = ""
|
|
$keyVaultUrl = ""
|
|
|
|
if ($keyVault) {
|
|
$keyVaultName = $keyVault.name
|
|
$keyVaultUrl = "https://$keyVaultName.vault.azure.net/"
|
|
Write-Host "✅ Found Key Vault: $keyVaultName" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "⚠️ Key Vault not found (will use placeholder)" -ForegroundColor Yellow
|
|
$keyVaultUrl = "https://YOUR_KEY_VAULT_NAME.vault.azure.net/"
|
|
}
|
|
|
|
# Check for Cosmos DB
|
|
$cosmosAccount = az cosmosdb list --resource-group $ResourceGroupName --output json 2>$null | ConvertFrom-Json | Select-Object -First 1
|
|
$cosmosEndpoint = ""
|
|
|
|
if ($cosmosAccount) {
|
|
$cosmosEndpoint = "https://$($cosmosAccount.name).documents.azure.com:443/"
|
|
Write-Host "✅ Found Cosmos DB: $($cosmosAccount.name)" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "⚠️ Cosmos DB not found (will use placeholder)" -ForegroundColor Yellow
|
|
$cosmosEndpoint = "https://YOUR_COSMOS_ACCOUNT.documents.azure.com:443/"
|
|
}
|
|
|
|
# Check for Application Insights
|
|
$appInsights = az monitor app-insights component show --app $ResourceGroupName --output json 2>$null | ConvertFrom-Json
|
|
if (-not $appInsights) {
|
|
$appInsights = az resource list --resource-group $ResourceGroupName --resource-type "Microsoft.Insights/components" --output json 2>$null | ConvertFrom-Json | Select-Object -First 1
|
|
}
|
|
$appInsightsConnectionString = ""
|
|
|
|
if ($appInsights) {
|
|
$appInsightsConnectionString = $appInsights.connectionString
|
|
Write-Host "✅ Found Application Insights: $($appInsights.name)" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "⚠️ Application Insights not found (will use placeholder)" -ForegroundColor Yellow
|
|
$appInsightsConnectionString = "InstrumentationKey=YOUR_KEY;IngestionEndpoint=https://YOUR_REGION.in.applicationinsights.azure.com/"
|
|
}
|
|
|
|
# Check for SignalR
|
|
$signalR = az signalr list --resource-group $ResourceGroupName --output json 2>$null | ConvertFrom-Json | Select-Object -First 1
|
|
$signalRConnectionString = ""
|
|
|
|
if ($signalR) {
|
|
$signalRKeys = az signalr key list --name $signalR.name --resource-group $ResourceGroupName --output json 2>$null | ConvertFrom-Json
|
|
if ($signalRKeys) {
|
|
$signalREndpoint = $signalR.hostName
|
|
$signalRKey = $signalRKeys.primaryKey
|
|
$signalRConnectionString = "Endpoint=https://$signalREndpoint;AccessKey=$signalRKey;Version=1.0;"
|
|
Write-Host "✅ Found SignalR: $($signalR.name)" -ForegroundColor Green
|
|
}
|
|
} else {
|
|
Write-Host "⚠️ SignalR not found (will use placeholder)" -ForegroundColor Yellow
|
|
$signalRConnectionString = "Endpoint=https://YOUR_SIGNALR.service.signalr.net;AccessKey=YOUR_KEY;Version=1.0;"
|
|
}
|
|
|
|
# Check for Azure AD App Registration
|
|
$appReg = az ad app list --display-name "Miracles In Motion Web App" --output json 2>$null | ConvertFrom-Json | Select-Object -First 1
|
|
$azureClientId = ""
|
|
|
|
if ($appReg) {
|
|
$azureClientId = $appReg.appId
|
|
Write-Host "✅ Found Azure AD App Registration: $azureClientId" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "⚠️ Azure AD App Registration not found (will use placeholder)" -ForegroundColor Yellow
|
|
Write-Host " Run: .\scripts\setup-azure-entra.ps1 to create it" -ForegroundColor Yellow
|
|
$azureClientId = "your-azure-client-id"
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# Prompt for Stripe keys
|
|
Write-Host "💳 Stripe Configuration" -ForegroundColor Cyan
|
|
$stripePublishableKey = Read-Host "Enter Stripe Publishable Key (pk_live_...) [or press Enter to skip]"
|
|
if ([string]::IsNullOrWhiteSpace($stripePublishableKey)) {
|
|
$stripePublishableKey = "pk_live_YOUR_KEY"
|
|
}
|
|
|
|
$stripeSecretKey = Read-Host "Enter Stripe Secret Key (sk_live_...) [or press Enter to skip]"
|
|
if ([string]::IsNullOrWhiteSpace($stripeSecretKey)) {
|
|
$stripeSecretKey = "sk_live_YOUR_KEY"
|
|
}
|
|
|
|
$stripeWebhookSecret = Read-Host "Enter Stripe Webhook Secret (whsec_...) [or press Enter to skip]"
|
|
if ([string]::IsNullOrWhiteSpace($stripeWebhookSecret)) {
|
|
$stripeWebhookSecret = "whsec_YOUR_SECRET"
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# Create .env file content
|
|
$envContent = @"
|
|
# Azure Configuration
|
|
AZURE_SUBSCRIPTION_ID=$subscriptionId
|
|
AZURE_TENANT_ID=$tenantId
|
|
AZURE_RESOURCE_GROUP=$ResourceGroupName
|
|
AZURE_LOCATION=$Location
|
|
AZURE_STATIC_WEB_APP_URL=$staticWebAppUrl
|
|
AZURE_STATIC_WEB_APP_NAME=$staticWebAppName
|
|
AZURE_FUNCTION_APP_URL=$functionAppUrl
|
|
AZURE_FUNCTION_APP_NAME=$functionAppName
|
|
AZURE_CLIENT_ID=$azureClientId
|
|
AZURE_TENANT_ID=$tenantId
|
|
AZURE_CLIENT_SECRET=your-azure-client-secret
|
|
|
|
# Stripe Configuration
|
|
VITE_STRIPE_PUBLISHABLE_KEY=$stripePublishableKey
|
|
STRIPE_SECRET_KEY=$stripeSecretKey
|
|
STRIPE_WEBHOOK_SECRET=$stripeWebhookSecret
|
|
|
|
# Cosmos DB Configuration
|
|
COSMOS_DATABASE_NAME=MiraclesInMotion
|
|
COSMOS_ENDPOINT=$cosmosEndpoint
|
|
COSMOS_KEY=your-cosmos-key
|
|
|
|
# Application Insights
|
|
APPLICATIONINSIGHTS_CONNECTION_STRING=$appInsightsConnectionString
|
|
|
|
# Key Vault
|
|
KEY_VAULT_URL=$keyVaultUrl
|
|
KEY_VAULT_NAME=$keyVaultName
|
|
|
|
# SignalR
|
|
SIGNALR_CONNECTION_STRING=$signalRConnectionString
|
|
|
|
# Custom Domain
|
|
CUSTOM_DOMAIN=$Domain
|
|
|
|
# Environment
|
|
NODE_ENV=production
|
|
VITE_API_BASE_URL=$staticWebAppUrl/api
|
|
|
|
# Feature Flags
|
|
VITE_ENABLE_ANALYTICS=true
|
|
VITE_ENABLE_PWA=true
|
|
VITE_ENABLE_AI=true
|
|
|
|
# Cloudflare (Optional)
|
|
CLOUDFLARE_ZONE_ID=your-cloudflare-zone-id
|
|
CLOUDFLARE_API_TOKEN=your-cloudflare-api-token
|
|
|
|
# Salesforce (Optional)
|
|
SALESFORCE_CLIENT_ID=your-salesforce-client-id
|
|
SALESFORCE_CLIENT_SECRET=your-salesforce-client-secret
|
|
SALESFORCE_USERNAME=your-salesforce-username
|
|
SALESFORCE_PASSWORD=your-salesforce-password
|
|
SALESFORCE_SECURITY_TOKEN=your-salesforce-security-token
|
|
|
|
# Email Configuration (Optional)
|
|
SMTP_HOST=smtp.office365.com
|
|
SMTP_PORT=587
|
|
SMTP_USER=your-email@domain.com
|
|
SMTP_PASSWORD=your-email-password
|
|
SMTP_FROM=noreply@mim4u.org
|
|
|
|
# Monitoring (Optional)
|
|
SENTRY_DSN=your-sentry-dsn
|
|
LOG_LEVEL=info
|
|
|
|
# Security
|
|
SESSION_SECRET=your-session-secret
|
|
JWT_SECRET=your-jwt-secret
|
|
ENCRYPTION_KEY=your-encryption-key
|
|
"@
|
|
|
|
# Write .env file
|
|
$envFile = ".env.production"
|
|
$envContent | Out-File -FilePath $envFile -Encoding UTF8 -NoNewline
|
|
|
|
Write-Host "✅ Created .env file: $envFile" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "📋 Summary:" -ForegroundColor Cyan
|
|
Write-Host " Subscription: $($account.name)" -ForegroundColor Gray
|
|
Write-Host " Tenant ID: $tenantId" -ForegroundColor Gray
|
|
Write-Host " Resource Group: $ResourceGroupName" -ForegroundColor Gray
|
|
Write-Host " Domain: $Domain" -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host "⚠️ Next Steps:" -ForegroundColor Yellow
|
|
Write-Host "1. Review and update placeholder values in $envFile" -ForegroundColor White
|
|
Write-Host "2. Run: .\scripts\setup-azure-entra.ps1 to create Azure AD app registration" -ForegroundColor White
|
|
Write-Host "3. Deploy infrastructure: az deployment group create ..." -ForegroundColor White
|
|
Write-Host "4. Store secrets in Key Vault using: .\scripts\store-secrets-in-keyvault.ps1" -ForegroundColor White
|
|
Write-Host ""
|
|
|