Fixed Agent Packaging Script

This commit is contained in:
2025-04-24 01:02:22 -06:00
parent 9c68cdea84
commit f1203c4451
5 changed files with 63 additions and 36 deletions

View File

@ -1,50 +1,68 @@
#////////// PROJECT FILE SEPARATION LINE ////////// CODE AFTER THIS LINE ARE FROM: <ProjectRoot>/Agent/Package_Borealis-Agent.ps1
#////////// PROJECT FILE SEPARATION LINE ////////// CODE AFTER THIS LINE ARE FROM: <ProjectRoot>/Data/Agent/Package_Borealis-Agent.ps1
# Configuration
$packagingDir = "Packaging_Data"
$venvDir = "$packagingDir\Pyinstaller_Virtual_Environment"
$distDir = "$packagingDir\dist"
$buildDir = "$packagingDir\build"
$specPath = "$packagingDir"
$agentScript = "borealis-agent.py"
$outputName = "Borealis-Agent"
$finalExeName = "$outputName.exe"
$packagingDir = "Packaging_Data"
$venvDir = "$packagingDir\Pyinstaller_Virtual_Environment"
$distDir = "$packagingDir\dist"
$buildDir = "$packagingDir\build"
$specPath = "$packagingDir"
$agentScript = "borealis-agent.py"
$outputName = "Borealis-Agent"
$finalExeName = "$outputName.exe"
$requirementsPath = "requirements.txt"
$iconPath = "..\Borealis.ico"
$iconPath = "..\Borealis.ico"
# figure out where everything lives
$scriptDir = Split-Path $MyInvocation.MyCommand.Definition -Parent
$projectRoot = Resolve-Path (Join-Path $scriptDir "..\..")
$embeddedPython = Join-Path $projectRoot 'Dependencies\Python\python.exe'
# Ensure Packaging_Data directory exists
if (-Not (Test-Path $packagingDir)) {
New-Item -ItemType Directory -Path $packagingDir | Out-Null
}
# Set up virtual environment
if (-Not (Test-Path "$venvDir\Scripts\Activate.ps1")) {
Write-Host "[SETUP] Creating virtual environment at $venvDir"
python -m venv $venvDir
# 1) Create or recreate virtual environment using the embedded Python
if (-Not (Test-Path "$venvDir\Scripts\python.exe")) {
Write-Host "[SETUP] Creating virtual environment at $venvDir using embedded Python"
& $embeddedPython -m venv --upgrade-deps $venvDir
}
# Activate virtual environment
Write-Host "[INFO] Activating virtual environment"
. "$venvDir\Scripts\Activate.ps1"
# helper for calling into that venv
$venvPy = Join-Path $venvDir 'Scripts\python.exe'
# Install agent dependencies from requirements file
# 2) Bootstrap pip (in case ensurepip wasnt automatic) and upgrade
Write-Host "[INFO] Ensuring pip is available in the venv"
& $venvPy -m ensurepip --upgrade
Write-Host "[INFO] Upgrading pip"
& $venvPy -m pip install --upgrade pip
# 3) Install your agents dependencies
Write-Host "[INFO] Installing agent dependencies from $requirementsPath"
pip install --upgrade pip > $null
pip install -r $requirementsPath > $null
& $venvPy -m pip install -r $requirementsPath
# Install PyInstaller
# 4) Install PyInstaller into that same venv
Write-Host "[INFO] Installing PyInstaller"
pip install pyinstaller > $null
& $venvPy -m pip install pyinstaller
# Clean previous build artifacts
# 5) Clean previous build artifacts
Write-Host "[INFO] Cleaning previous build artifacts"
Remove-Item -Recurse -Force $distDir, $buildDir, "$specPath\$outputName.spec" -ErrorAction SilentlyContinue
# Run PyInstaller to create single-file executable with custom icon
# 6) Run PyInstaller
Write-Host "[INFO] Running PyInstaller with icon $iconPath"
pyinstaller --onefile --icon "$iconPath" --noconfirm --name $outputName --distpath $distDir --workpath $buildDir --specpath $specPath $agentScript
& $venvPy -m PyInstaller `
--onefile `
--icon "$iconPath" `
--noconfirm `
--name $outputName `
--distpath $distDir `
--workpath $buildDir `
--specpath $specPath `
$agentScript
# Copy resulting executable to Agent folder
# 7) Copy the final exe back into your Agent folder
if (Test-Path "$distDir\$finalExeName") {
Copy-Item "$distDir\$finalExeName" ".\$finalExeName" -Force
Write-Host "[SUCCESS] Agent packaged at .\$finalExeName"