Fix Windows deployment scripts for missing Python dependencies
Issues fixed: 1. Build-Frontend.ps1: Add verification that requirements.txt is included in deployment package - Prevents incomplete packages that cause ModuleNotFoundError on server - Throws error if critical files are missing before package is transferred 2. Deploy-ROA2WEB.ps1: Auto-detect first deployment and force install dependencies - Automatically sets ForceInstallDependencies=true on first deployment - Add -ForceInstallDependencies parameter for manual override - Better error handling and validation for pip install - Shows clear error messages with manual recovery instructions This fixes the "ModuleNotFoundError: No module named 'httpx'" error that occurred when deploying to Windows Server without explicitly forcing dependency installation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -281,6 +281,15 @@ function Copy-BackendFiles {
|
|||||||
|
|
||||||
$backendFiles = Get-ChildItem -Path $DestPath -Recurse -File
|
$backendFiles = Get-ChildItem -Path $DestPath -Recurse -File
|
||||||
Write-Success "Copied $(($backendFiles).Count) backend files"
|
Write-Success "Copied $(($backendFiles).Count) backend files"
|
||||||
|
|
||||||
|
# Verify critical files are present
|
||||||
|
$requirementsTxt = Join-Path $DestPath "requirements.txt"
|
||||||
|
if (-not (Test-Path $requirementsTxt)) {
|
||||||
|
Write-Error "CRITICAL: requirements.txt not found in backend package!"
|
||||||
|
Write-Host " Expected: $requirementsTxt" -ForegroundColor Red
|
||||||
|
throw "Backend package incomplete - missing requirements.txt"
|
||||||
|
}
|
||||||
|
Write-Success "Verified: requirements.txt present"
|
||||||
}
|
}
|
||||||
|
|
||||||
function New-DeploymentPackage {
|
function New-DeploymentPackage {
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
.PARAMETER UpdateFrontend
|
.PARAMETER UpdateFrontend
|
||||||
Update frontend files (default: true)
|
Update frontend files (default: true)
|
||||||
|
|
||||||
|
.PARAMETER ForceInstallDependencies
|
||||||
|
Force reinstall all Python dependencies even if requirements.txt hasn't changed (default: false)
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
cd C:\Deploy\ROA2WEB\scripts
|
cd C:\Deploy\ROA2WEB\scripts
|
||||||
.\Deploy-ROA2WEB.ps1
|
.\Deploy-ROA2WEB.ps1
|
||||||
@@ -36,6 +39,10 @@
|
|||||||
.\Deploy-ROA2WEB.ps1 -UpdateBackend -UpdateFrontend:$false
|
.\Deploy-ROA2WEB.ps1 -UpdateBackend -UpdateFrontend:$false
|
||||||
Update only backend files
|
Update only backend files
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
.\Deploy-ROA2WEB.ps1 -ForceInstallDependencies $true
|
||||||
|
Update files and force reinstall all Python dependencies
|
||||||
|
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: ROA2WEB Team
|
Author: ROA2WEB Team
|
||||||
Requires: PowerShell 5.1+, Administrator privileges
|
Requires: PowerShell 5.1+, Administrator privileges
|
||||||
@@ -48,7 +55,8 @@ param(
|
|||||||
[bool]$BackupEnabled = $true,
|
[bool]$BackupEnabled = $true,
|
||||||
[bool]$RestartService = $true,
|
[bool]$RestartService = $true,
|
||||||
[bool]$UpdateBackend = $true,
|
[bool]$UpdateBackend = $true,
|
||||||
[bool]$UpdateFrontend = $true
|
[bool]$UpdateFrontend = $true,
|
||||||
|
[bool]$ForceInstallDependencies = $false
|
||||||
)
|
)
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
@@ -242,27 +250,51 @@ function Update-BackendFiles {
|
|||||||
|
|
||||||
Write-Success "Backend files updated"
|
Write-Success "Backend files updated"
|
||||||
|
|
||||||
# Check if requirements.txt changed
|
# Check if requirements.txt changed or if force install is requested
|
||||||
$sourceReq = Join-Path $sourceBackend "requirements.txt"
|
$sourceReq = Join-Path $sourceBackend "requirements.txt"
|
||||||
$destReq = Join-Path $Config.BackendPath "requirements.txt"
|
$destReq = Join-Path $Config.BackendPath "requirements.txt"
|
||||||
|
|
||||||
if (Test-Path $sourceReq) {
|
if (Test-Path $sourceReq) {
|
||||||
$sourceHash = (Get-FileHash $sourceReq).Hash
|
$sourceHash = (Get-FileHash $sourceReq).Hash
|
||||||
$destHash = if (Test-Path $destReq) { (Get-FileHash $destReq).Hash } else { "" }
|
$destHash = if (Test-Path $destReq) { (Get-FileHash $destReq).Hash } else { "" }
|
||||||
|
$requirementsChanged = $sourceHash -ne $destHash
|
||||||
|
|
||||||
if ($sourceHash -ne $destHash) {
|
if ($requirementsChanged -or $ForceInstallDependencies) {
|
||||||
|
if ($ForceInstallDependencies) {
|
||||||
|
Write-Step "Force installing Python dependencies..."
|
||||||
|
} else {
|
||||||
Write-Step "Requirements changed, updating Python dependencies..."
|
Write-Step "Requirements changed, updating Python dependencies..."
|
||||||
|
}
|
||||||
|
|
||||||
Copy-Item -Path $sourceReq -Destination $destReq -Force
|
Copy-Item -Path $sourceReq -Destination $destReq -Force
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
# Verify Python is available
|
||||||
|
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
||||||
|
if (-not $pythonCmd) {
|
||||||
|
Write-Error "Python not found in PATH. Please ensure Python 3.11+ is installed."
|
||||||
|
throw "Python not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host " Installing/upgrading dependencies from: $destReq" -ForegroundColor Gray
|
||||||
& python -m pip install -r $destReq --upgrade
|
& python -m pip install -r $destReq --upgrade
|
||||||
Write-Success "Python dependencies updated"
|
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Success "Python dependencies installed successfully"
|
||||||
|
} else {
|
||||||
|
Write-Error "pip install failed with exit code: $LASTEXITCODE"
|
||||||
|
throw "Dependency installation failed"
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error "Failed to update Python dependencies: $_"
|
Write-Error "Failed to update Python dependencies: $_"
|
||||||
|
Write-Warning "Try running manually: python -m pip install -r $destReq"
|
||||||
|
throw
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Write-Success "Python dependencies unchanged"
|
Write-Success "Python dependencies unchanged"
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Write-Warning "requirements.txt not found in source package"
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error "Failed to update backend files: $_"
|
Write-Error "Failed to update backend files: $_"
|
||||||
@@ -466,6 +498,13 @@ function Main {
|
|||||||
}
|
}
|
||||||
Write-Success "Installation path exists"
|
Write-Success "Installation path exists"
|
||||||
|
|
||||||
|
# Check if this is first deployment (no backend files yet)
|
||||||
|
$isFirstDeployment = -not (Test-Path (Join-Path $Config.BackendPath "app"))
|
||||||
|
if ($isFirstDeployment) {
|
||||||
|
Write-Warning "First deployment detected - will install all dependencies"
|
||||||
|
$script:ForceInstallDependencies = $true
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
# Deployment steps
|
# Deployment steps
|
||||||
$backupPath = Backup-CurrentDeployment
|
$backupPath = Backup-CurrentDeployment
|
||||||
|
|||||||
Reference in New Issue
Block a user