auto_agent/edge-agent/scripts/package-windows.ps1
2521690 591df2d18e feat: 增强 edge-agent 服务控制与便携打包能力
- 将 Windows/Linux service control 执行器从占位实现推进到可用
- 新增 service control 测试,覆盖 status/start/stop/restart 主路径
- 增强 edge-agent 启动脚本,优先使用包内私有 Python 运行时
- 增强 Windows/Linux 打包脚本,支持携带私有 Python 运行时
- 更新 edge-agent README 与当前进度总结
- 新增 dist 忽略规则,避免打包产物污染仓库
2026-04-09 11:26:42 +08:00

54 lines
1.9 KiB
PowerShell

param(
[string]$PythonHome = $env:EDGE_PYTHON_HOME
)
$ErrorActionPreference = "Stop"
function Resolve-PythonHome {
param([string]$InputPythonHome)
if ($InputPythonHome) {
return (Resolve-Path -LiteralPath $InputPythonHome).Path
}
$candidates = @(
"C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python311",
"C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python312",
"C:\Python311",
"C:\Python312"
)
foreach ($candidate in $candidates) {
if (Test-Path (Join-Path $candidate "python.exe")) {
return (Resolve-Path -LiteralPath $candidate).Path
}
}
throw "PythonHome not provided and no local Python runtime directory was found."
}
$root = Split-Path -Parent $PSScriptRoot
$dist = Join-Path $root "dist"
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$packageRoot = Join-Path $dist "edge-agent-windows-$timestamp"
$runtimeRoot = Join-Path $packageRoot "runtime\python"
$zipPath = Join-Path $dist "edge-agent-windows-$timestamp.zip"
$resolvedPythonHome = Resolve-PythonHome -InputPythonHome $PythonHome
if (Test-Path $zipPath) {
Remove-Item -LiteralPath $zipPath -Force
}
New-Item -ItemType Directory -Path $packageRoot -Force | Out-Null
New-Item -ItemType Directory -Path $runtimeRoot -Force | Out-Null
New-Item -ItemType Directory -Path $dist -Force | Out-Null
Copy-Item -LiteralPath (Join-Path $root "app") -Destination $packageRoot -Recurse
Copy-Item -LiteralPath (Join-Path $root "README.md") -Destination $packageRoot
Copy-Item -LiteralPath (Join-Path $root "pyproject.toml") -Destination $packageRoot
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "start-windows.ps1") -Destination (Join-Path $packageRoot "start.ps1")
Get-ChildItem -LiteralPath $resolvedPythonHome -Force | Copy-Item -Destination $runtimeRoot -Recurse
Compress-Archive -Path (Join-Path $packageRoot "*") -DestinationPath $zipPath -Force
Write-Output $zipPath