Skip to content

Commit 6e81262

Browse files
refactor: Simplify webapp packaging scripts and update build process for Azure deployment
1 parent 6527e40 commit 6e81262

File tree

3 files changed

+131
-30
lines changed

3 files changed

+131
-30
lines changed

azure_custom.yaml

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,14 @@ services:
2626
prepackage:
2727
windows:
2828
shell: pwsh
29+
run: ../../infra/scripts/package_webapp.ps1
30+
interactive: true
2931
continueOnError: false
30-
run: |
31-
Write-Host "=== React Build Starting ===" -ForegroundColor Cyan
32-
Write-Host "Current directory: $(Get-Location)" -ForegroundColor Yellow
33-
$apiUrl = azd env get-value API_APP_URL
34-
if (-not $apiUrl) {
35-
Write-Error "API_APP_URL not found. Run 'azd provision' first."
36-
exit 1
37-
}
38-
Write-Host "Setting REACT_APP_API_BASE_URL=$apiUrl" -ForegroundColor Yellow
39-
$env:REACT_APP_API_BASE_URL = $apiUrl
40-
Write-Host "Installing dependencies..." -ForegroundColor Cyan
41-
npm install
42-
Write-Host "Building React app..." -ForegroundColor Cyan
43-
npm run build
44-
Write-Host "=== React Build Complete ===" -ForegroundColor Green
4532
posix:
4633
shell: sh
34+
run: bash ../../infra/scripts/package_webapp.sh
35+
interactive: true
4736
continueOnError: false
48-
run: |
49-
echo "=== React Build Starting ==="
50-
echo "Current directory: $(pwd)"
51-
apiUrl=$(azd env get-value API_APP_URL)
52-
if [ -z "$apiUrl" ]; then
53-
echo "ERROR: API_APP_URL not found. Run 'azd provision' first."
54-
exit 1
55-
fi
56-
echo "Setting REACT_APP_API_BASE_URL=$apiUrl"
57-
export REACT_APP_API_BASE_URL="$apiUrl"
58-
echo "Installing dependencies..."
59-
npm install
60-
echo "Building React app..."
61-
npm run build
62-
echo "=== React Build Complete ==="
6337

6438
hooks:
6539
postprovision:

infra/scripts/package_webapp.ps1

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env pwsh
2+
3+
# Package React webapp for Azure App Service deployment
4+
# This script builds the React frontend with dynamic API URL injection
5+
# Run from workspace root OR from src/App (auto-detects location)
6+
7+
Write-Host "=== React App Build Started ===" -ForegroundColor Cyan
8+
9+
$ErrorActionPreference = "Stop"
10+
11+
# Detect if we're in src/App or workspace root and navigate accordingly
12+
if (Test-Path "package.json") {
13+
# Already in src/App
14+
Write-Host "Running from src/App directory" -ForegroundColor Gray
15+
} elseif (Test-Path "src/App/package.json") {
16+
# In workspace root, navigate to src/App
17+
Write-Host "Navigating to src/App directory" -ForegroundColor Gray
18+
Set-Location -Path "src/App"
19+
} else {
20+
Write-Error "Cannot find React app. Run from workspace root or src/App directory."
21+
exit 1
22+
}
23+
24+
# Clean old build folder to ensure fresh build
25+
if (Test-Path "build") {
26+
Write-Host "Cleaning old build folder..." -ForegroundColor Yellow
27+
Remove-Item -Path "build" -Recurse -Force
28+
}
29+
30+
# Get the API URL from azd environment
31+
Write-Host "Fetching API URL from azd environment..." -ForegroundColor Yellow
32+
$apiUrl = azd env get-value API_APP_URL
33+
34+
if (-not $apiUrl) {
35+
Write-Error "API_APP_URL not found in azd environment. Run 'azd provision' first."
36+
exit 1
37+
}
38+
39+
Write-Host "API URL: $apiUrl" -ForegroundColor Green
40+
41+
# Set environment variable for React build
42+
$env:REACT_APP_API_BASE_URL = $apiUrl
43+
Write-Host "Set REACT_APP_API_BASE_URL=$apiUrl" -ForegroundColor Yellow
44+
45+
# Install dependencies
46+
Write-Host "`nInstalling npm dependencies..." -ForegroundColor Cyan
47+
npm install
48+
if ($LASTEXITCODE -ne 0) {
49+
Write-Error "npm install failed"
50+
exit 1
51+
}
52+
53+
# Build React app
54+
Write-Host "`nBuilding React application..." -ForegroundColor Cyan
55+
npm run build
56+
if ($LASTEXITCODE -ne 0) {
57+
Write-Error "npm run build failed"
58+
exit 1
59+
}
60+
61+
Write-Host "`n=== React App Build Complete ===" -ForegroundColor Green
62+
Write-Host "Built files are in ./build directory" -ForegroundColor Gray

infra/scripts/package_webapp.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
# Package React webapp for Azure App Service deployment
4+
# This script builds the React frontend with dynamic API URL injection
5+
# Run from workspace root OR from src/App (auto-detects location)
6+
7+
set -e
8+
9+
echo "=== React App Build Started ==="
10+
11+
# Detect if we're in src/App or workspace root and navigate accordingly
12+
if [ -f "package.json" ]; then
13+
# Already in src/App
14+
echo "Running from src/App directory"
15+
elif [ -f "src/App/package.json" ]; then
16+
# In workspace root, navigate to src/App
17+
echo "Navigating to src/App directory"
18+
cd src/App
19+
else
20+
echo "ERROR: Cannot find React app. Run from workspace root or src/App directory."
21+
exit 1
22+
fi
23+
24+
# Clean old build folder to ensure fresh build
25+
if [ -d "build" ]; then
26+
echo "Cleaning old build folder..."
27+
rm -rf build
28+
fi
29+
30+
# Get the API URL from azd environment
31+
echo "Fetching API URL from azd environment..."
32+
apiUrl=$(azd env get-value API_APP_URL)
33+
34+
if [ -z "$apiUrl" ]; then
35+
echo "ERROR: API_APP_URL not found in azd environment. Run 'azd provision' first."
36+
exit 1
37+
fi
38+
39+
echo "API URL: $apiUrl"
40+
41+
# Set environment variable for React build
42+
export REACT_APP_API_BASE_URL="$apiUrl"
43+
echo "Set REACT_APP_API_BASE_URL=$apiUrl"
44+
45+
# Install dependencies
46+
echo ""
47+
echo "Installing npm dependencies..."
48+
npm install
49+
if [ $? -ne 0 ]; then
50+
echo "ERROR: npm install failed"
51+
exit 1
52+
fi
53+
54+
# Build React app
55+
echo ""
56+
echo "Building React application..."
57+
npm run build
58+
if [ $? -ne 0 ]; then
59+
echo "ERROR: npm run build failed"
60+
exit 1
61+
fi
62+
63+
echo ""
64+
echo "=== React App Build Complete ==="
65+
echo "Built files are in ./build directory"

0 commit comments

Comments
 (0)