Skip to content

Commit 0e8f833

Browse files
copilot review fixes and readme updates
1 parent 1f4e632 commit 0e8f833

4 files changed

Lines changed: 124 additions & 40 deletions

File tree

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ AZURE_OPENAI_MAX_TOKENS=2000
5353
# =============================================================================
5454
# Azure Cosmos DB
5555
# =============================================================================
56+
COSMOSDB_ACCOUNT_NAME=your-cosmos-account
5657
AZURE_COSMOS_ENDPOINT=https://your-cosmos.documents.azure.com:443/
5758
AZURE_COSMOS_DATABASE_NAME=content-generation
5859
AZURE_COSMOS_PRODUCTS_CONTAINER=products
@@ -106,6 +107,7 @@ BRAND_REQUIRED_DISCLOSURES=
106107
# =============================================================================
107108
# Application Settings
108109
# =============================================================================
110+
RESOURCE_GROUP_NAME=your-resource-group
109111
# Server configuration
110112
PORT=5000
111113
WORKERS=4

docs/LocalDevelopmentSetup.md

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,68 @@ content-generation-solution-accelerator/ ← Repository root (start here)
3636

3737
## Step 1: Prerequisites - Install Required Tools
3838

39-
### Windows (PowerShell)
39+
### Windows Development
40+
41+
#### Option 1: Native Windows (PowerShell)
4042

4143
```powershell
42-
# Install Python 3.11+, Node.js 18+, Git, and Azure CLI
43-
winget install Python.Python.3.12
44-
winget install OpenJS.NodeJS.LTS
44+
# Install Git
4545
winget install Git.Git
46+
47+
# Install Node.js for frontend
48+
winget install OpenJS.NodeJS.LTS
49+
50+
# Install Python 3.11+
51+
winget install Python.Python.3.12
52+
53+
# Install Azure CLI and Azure Developer CLI
4654
winget install Microsoft.AzureCLI
4755
winget install Microsoft.Azd
56+
```
4857

49-
# Verify installations
50-
python --version
51-
node --version
52-
git --version
53-
az --version
54-
azd version
58+
#### Option 2: Windows with WSL2 (Recommended)
59+
60+
```bash
61+
# Install WSL2 first (run in PowerShell as Administrator):
62+
# wsl --install -d Ubuntu
63+
64+
# Then in WSL2 Ubuntu terminal:
65+
sudo apt update && sudo apt install git curl python3.11 python3.11-venv -y
66+
67+
# Install Node.js 20+ from NodeSource
68+
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
69+
sudo apt install -y nodejs
70+
71+
# Install Azure CLI
72+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
73+
74+
# Install Azure Developer CLI
75+
curl -fsSL https://aka.ms/install-azd.sh | bash
5576
```
5677

57-
### Linux (Ubuntu/Debian)
78+
### Linux Development
79+
80+
#### Ubuntu/Debian
5881

5982
```bash
6083
# Install prerequisites
61-
sudo apt update && sudo apt install python3.11 python3.11-venv git curl nodejs npm -y
84+
sudo apt update && sudo apt install git curl python3.11 python3.11-venv -y
85+
86+
# Install Node.js 20+ from NodeSource
87+
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
88+
sudo apt install -y nodejs
6289

6390
# Install Azure CLI
6491
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
6592

6693
# Install Azure Developer CLI
6794
curl -fsSL https://aka.ms/install-azd.sh | bash
95+
```
96+
97+
### Verify Installations
6898

69-
# Verify installations
70-
python3 --version
99+
```bash
100+
python3 --version # or python --version on Windows
71101
node --version
72102
git --version
73103
az --version

scripts/local_dev.ps1

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ function Invoke-Setup {
293293
# Check for .env file
294294
if (-not (Test-Path ".env")) {
295295
Write-Warning ".env file not found"
296-
if (Test-Path ".env.template") {
297-
Write-Info "Copying .env.template to .env..."
298-
Copy-Item ".env.template" ".env"
296+
if (Test-Path ".env.sample") {
297+
Write-Info "Copying .env.sample to .env..."
298+
Copy-Item ".env.sample" ".env"
299299
Write-Warning "Please update .env with your Azure resource values"
300300
}
301301
} else {
@@ -357,9 +357,9 @@ function Invoke-EnvGeneration {
357357
Write-Warning "Azure Developer CLI not found or no azure.yaml"
358358
Write-Info "Please manually update .env with your Azure resource values"
359359

360-
if (-not (Test-Path ".env") -and (Test-Path ".env.template")) {
361-
Copy-Item ".env.template" ".env"
362-
Write-Info "Created .env from template"
360+
if (-not (Test-Path ".env") -and (Test-Path ".env.sample")) {
361+
Copy-Item ".env.sample" ".env"
362+
Write-Info "Created .env from .env.sample"
363363
}
364364
}
365365

@@ -423,6 +423,8 @@ function Start-Backend {
423423
Push-Location $BackendDir
424424
try {
425425
# Use hypercorn for async support
426+
# Output filter suppresses benign Ctrl+C shutdown noise from Python (InterruptedError tracebacks,
427+
# sys.exit, frozen importlib). Real startup/runtime errors appear before these patterns.
426428
if (Test-Command "hypercorn") {
427429
hypercorn app:app --bind "0.0.0.0:$BackendPort" --reload 2>&1 | ForEach-Object {
428430
if ($_ -notmatch "Traceback|File.*frozen|InterruptedError|sys\.exit") {
@@ -437,7 +439,7 @@ function Start-Backend {
437439
}
438440
}
439441
} catch {
440-
# Suppress Ctrl+C exceptions
442+
# Suppress Ctrl+C PipelineStoppedException — not a real error
441443
} finally {
442444
Pop-Location
443445
}
@@ -481,6 +483,33 @@ function Start-All {
481483

482484
Set-Location $ProjectRoot
483485

486+
# Handle .env: generate if missing, or prompt to refresh if exists
487+
if (-not (Test-Path ".env")) {
488+
Write-Warning ".env file not found. Generating from Azure resources..."
489+
Invoke-EnvGeneration
490+
# Fallback to .env.sample if generation didn't produce .env
491+
if (-not (Test-Path ".env") -and (Test-Path ".env.sample")) {
492+
Write-Warning "Env generation did not create .env. Copying .env.sample as fallback..."
493+
Copy-Item ".env.sample" ".env"
494+
Write-Info "Created .env from .env.sample. Update the file with your Azure resource values."
495+
}
496+
if (-not (Test-Path ".env")) {
497+
Write-Error "Failed to create .env. Run '.\scripts\local_dev.ps1 -Command env' or create .env manually from .env.sample."
498+
exit 1
499+
}
500+
} else {
501+
Write-Success "Found existing .env file"
502+
$overwrite = Read-Host "Do you want to overwrite it with fresh values from Azure deployment? (y/N)"
503+
if ($overwrite -eq 'y' -or $overwrite -eq 'Y') {
504+
Write-Info "Regenerating .env from Azure resources..."
505+
Remove-Item ".env" -Force
506+
Invoke-EnvGeneration
507+
Write-Success "Environment variables refreshed."
508+
} else {
509+
Write-Info "Preserving existing .env. Using local configuration."
510+
}
511+
}
512+
484513
# Auto-run setup if prerequisites are missing
485514
$needsSetup = $false
486515
if (-not (Test-Path ".venv")) {
@@ -495,12 +524,6 @@ function Start-All {
495524
Invoke-Setup
496525
}
497526

498-
# Auto-run env generation if .env is missing
499-
if (-not (Test-Path ".env")) {
500-
Write-Warning ".env file not found. Generating from Azure resources..."
501-
Invoke-EnvGeneration
502-
}
503-
504527
# Ensure Azure roles
505528
Ensure-AzureLogin
506529
Ensure-AzureAIUserRole
@@ -572,8 +595,15 @@ function Start-All {
572595
}
573596
}
574597

575-
if ($backendJob.State -eq 'Failed' -or $frontendJob.State -eq 'Failed') {
576-
Write-Error "One of the services failed"
598+
# Break if either job is no longer running
599+
$backendState = $backendJob.State
600+
$frontendState = $frontendJob.State
601+
if ($backendState -ne 'Running' -or $frontendState -ne 'Running') {
602+
if ($backendState -eq 'Failed' -or $frontendState -eq 'Failed') {
603+
Write-Error "One of the services failed (backend: $backendState, frontend: $frontendState)"
604+
} else {
605+
Write-Warning "A service has stopped (backend: $backendState, frontend: $frontendState)"
606+
}
577607
break
578608
}
579609

scripts/local_dev.sh

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ setup() {
283283
# Check for .env file
284284
if [ ! -f ".env" ]; then
285285
print_warning ".env file not found"
286-
if [ -f ".env.template" ]; then
287-
print_info "Copying .env.template to .env..."
288-
cp .env.template .env
286+
if [ -f ".env.sample" ]; then
287+
print_info "Copying .env.sample to .env..."
288+
cp .env.sample .env
289289
print_warning "Please update .env with your Azure resource values"
290290
fi
291291
else
@@ -340,8 +340,9 @@ generate_env() {
340340
print_warning "Azure Developer CLI not found or no azure.yaml"
341341
print_info "Please manually update .env with your Azure resource values"
342342

343-
if [ ! -f ".env" ] && [ -f ".env.template" ]; then
344-
cp .env.template .env
343+
if [ ! -f ".env" ] && [ -f ".env.sample" ]; then
344+
cp .env.sample .env
345+
print_info "Created .env from .env.sample"
345346
print_info "Created .env from template"
346347
fi
347348
fi
@@ -437,6 +438,33 @@ start_all() {
437438

438439
cd "$PROJECT_ROOT"
439440

441+
# Handle .env: generate if missing, or prompt to refresh if exists
442+
if [ ! -f ".env" ]; then
443+
print_warning ".env file not found. Generating from Azure resources..."
444+
generate_env
445+
# Fallback to .env.sample if generation didn't produce .env
446+
if [ ! -f ".env" ] && [ -f ".env.sample" ]; then
447+
print_warning "Env generation did not create .env. Copying .env.sample as fallback..."
448+
cp .env.sample .env
449+
print_info "Created .env from .env.sample. Update the file with your Azure resource values."
450+
fi
451+
if [ ! -f ".env" ]; then
452+
print_error "Failed to create .env. Run './scripts/local_dev.sh env' or create .env manually from .env.sample."
453+
exit 1
454+
fi
455+
else
456+
print_success "Found existing .env file"
457+
read -p "Do you want to overwrite it with fresh values from Azure deployment? (y/N): " overwrite
458+
if [ "$overwrite" = "y" ] || [ "$overwrite" = "Y" ]; then
459+
print_info "Regenerating .env from Azure resources..."
460+
rm -f .env
461+
generate_env
462+
print_success "Environment variables refreshed."
463+
else
464+
print_info "Preserving existing .env. Using local configuration."
465+
fi
466+
fi
467+
440468
# Auto-run setup if prerequisites are missing
441469
local needs_setup=false
442470
if [ ! -d ".venv" ]; then
@@ -451,12 +479,6 @@ start_all() {
451479
setup
452480
fi
453481

454-
# Auto-run env generation if .env is missing
455-
if [ ! -f ".env" ]; then
456-
print_warning ".env file not found. Generating from Azure resources..."
457-
generate_env
458-
fi
459-
460482
# Ensure Azure authentication and role assignments
461483
ensure_azure_login
462484
ensure_azure_ai_user_role

0 commit comments

Comments
 (0)