-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack-agent-release.ps1
More file actions
165 lines (133 loc) · 5.52 KB
/
Copy pathpack-agent-release.ps1
File metadata and controls
165 lines (133 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<#
.SYNOPSIS
Builds a deployable LabSync Agent folder (no repo needed on target machines).
.DESCRIPTION
On dev machine / CI:
1. dotnet publish agent
2. dotnet build all LabSync.Modules.* projects
3. copy *.dll from each module bin/Release/net9.0 into <output>/Modules
4. copy install-agent.ps1 and install-linux.sh
Output: folder (optional .zip) you copy to the target and run:
install-agent.ps1 -SourcePath <folder> -ServerUrl ...
.PARAMETER RuntimeIdentifier
e.g. win-x64 (default), linux-x64, linux-arm64
.PARAMETER SelfContained
If true, bundles .NET runtime (larger output; no dotnet install on host).
#>
param(
[Parameter(Mandatory = $false)]
[string]$RepoRoot = "",
[Parameter(Mandatory = $false)]
[string]$OutputDir = "",
[Parameter(Mandatory = $false)]
[string]$RuntimeIdentifier = "win-x64",
[Parameter(Mandatory = $false)]
[switch]$SelfContained = $false,
[Parameter(Mandatory = $false)]
[switch]$Zip = $false
)
$ErrorActionPreference = "Stop"
function Write-Info([string]$Message) {
Write-Host "[pack-agent] $Message" -ForegroundColor Cyan
}
if ([string]::IsNullOrWhiteSpace($RepoRoot)) {
$RepoRoot = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Path }
}
$RepoRoot = [System.IO.Path]::GetFullPath($RepoRoot)
$agentProject = Join-Path $RepoRoot "src\LabSync.Agent\LabSync.Agent.csproj"
if (-not (Test-Path -LiteralPath $agentProject)) {
throw "Agent project not found: $agentProject"
}
if ([string]::IsNullOrWhiteSpace($OutputDir)) {
$suffix = if ($SelfContained) { "self-contained" } else { "fx-dep" }
$OutputDir = Join-Path $RepoRoot "dist\LabSync.Agent-release-$RuntimeIdentifier-$suffix"
}
$OutputDir = [System.IO.Path]::GetFullPath($OutputDir)
if (Test-Path -LiteralPath $OutputDir) {
Remove-Item -LiteralPath $OutputDir -Recurse -Force
}
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
$publishArgs = @(
"publish", $agentProject,
"-c", "Release",
"-o", $OutputDir,
"-r", $RuntimeIdentifier
)
if ($SelfContained) {
$publishArgs += "--self-contained", "true"
} else {
$publishArgs += "--self-contained", "false"
}
Write-Info "Publishing agent: dotnet $($publishArgs -join ' ')"
& dotnet @publishArgs
if ($LASTEXITCODE -ne 0) {
throw "dotnet publish agent failed."
}
$modulesRoot = Join-Path $RepoRoot "src\Modules"
if (-not (Test-Path -LiteralPath $modulesRoot)) {
Write-Warning "Modules folder missing: $modulesRoot"
} else {
$modulesOut = Join-Path $OutputDir "Modules"
New-Item -ItemType Directory -Path $modulesOut -Force | Out-Null
$moduleDirs = Get-ChildItem -LiteralPath $modulesRoot -Directory -Filter "LabSync.Modules.*"
foreach ($moduleDir in $moduleDirs) {
$proj = Join-Path $moduleDir.FullName "$($moduleDir.Name).csproj"
if (-not (Test-Path -LiteralPath $proj)) {
continue
}
Write-Info "Building module: $($moduleDir.Name)"
dotnet build $proj -c Release
if ($LASTEXITCODE -ne 0) {
throw "dotnet build failed for module $($moduleDir.Name)."
}
$releaseDir = Join-Path $moduleDir.FullName "bin\Release\net9.0"
if (-not (Test-Path -LiteralPath $releaseDir)) {
Write-Warning "Build output not found: $releaseDir"
continue
}
Get-ChildItem -LiteralPath $releaseDir -File -Filter "*.dll" | ForEach-Object {
Copy-Item -LiteralPath $_.FullName -Destination (Join-Path $modulesOut $_.Name) -Force
}
}
$dllCount = (Get-ChildItem -LiteralPath $modulesOut -File -Filter "*.dll" -ErrorAction SilentlyContinue).Count
Write-Info "Modules: copied $dllCount DLL file(s) to $modulesOut"
}
$installer = Join-Path $RepoRoot "install-agent.ps1"
if (Test-Path -LiteralPath $installer) {
Copy-Item -LiteralPath $installer -Destination (Join-Path $OutputDir "install-agent.ps1") -Force
Write-Info "Included install-agent.ps1"
}
$linuxInstall = Join-Path $RepoRoot "src\LabSync.Agent\scripts\install-linux.sh"
if (Test-Path -LiteralPath $linuxInstall) {
Copy-Item -LiteralPath $linuxInstall -Destination (Join-Path $OutputDir "install-linux.sh") -Force
Write-Info "Included install-linux.sh"
}
$reqLine = if (-not $SelfContained) {
'- Host needs .NET 9 runtime (Windows: Hosting Bundle / desktop runtime; Linux: dotnet-runtime). Framework-dependent package.'
} else {
'- No separate dotnet install (self-contained package; larger size).'
}
$readme = @"
LabSync Agent - deployment bundle (no git repo on target)
Target machine requirements:
$reqLine
Windows (PowerShell as Administrator):
cd <extracted_folder>
.\install-agent.ps1 -ServerUrl "http://your-server:5000" -SourcePath "."
If scripts are blocked (Execution Policy), use:
powershell -ExecutionPolicy Bypass -File ".\install-agent.ps1" -ServerUrl "http://your-server:5000" -SourcePath "."
Linux (build with -RuntimeIdentifier linux-x64):
sudo chmod +x install-linux.sh
sudo ./install-linux.sh --server-url "http://your-server:5000" --source-path "/full/path/to/extracted/folder"
Installer sets AGENT_SERVER_URL.
"@
Set-Content -LiteralPath (Join-Path $OutputDir "README-DEPLOY.txt") -Value $readme -Encoding UTF8
if ($Zip) {
$zipPath = "$OutputDir.zip"
if (Test-Path -LiteralPath $zipPath) {
Remove-Item -LiteralPath $zipPath -Force
}
Compress-Archive -Path (Join-Path $OutputDir "*") -DestinationPath $zipPath -Force
Write-Info "Created archive: $zipPath"
}
Write-Host "[pack-agent] Done: $OutputDir" -ForegroundColor Green