This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
103 lines (88 loc) · 3.51 KB
/
build.ps1
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
param (
[string]$BuildTarget
)
if(-not($BuildTarget)) { Throw "You must supply a value for -BuildTarget"}
function BundleIntoSingleExe {
param(
[string] $ExeName,
[string] $ScriptPath,
[string] $AdditionalPaths,
[string] $ExeOutputDirectory
)
$LogLevel = "ERROR"
$PyInstallerPath = "$TempDirectory\pyinstaller"
& pyinstaller.exe --noconfirm --clean --log-level=$LogLevel `
--workpath=$PyInstallerPath `
--distpath=$ExeOutputDirectory `
--specpath=$PyInstallerPath `
--name=$ExeName `
--paths=$AdditionalPaths `
--onefile $ScriptPath
if ($LASTEXITCODE -ne 0) {
throw "Error creating single executable from $ScriptPath using PyInstaller."
}
}
function CreateChocolateyPackage {
param(
[string] $PackageId,
[string] $Version
)
$OutputDirectory = "$TempDirectory\output"
$DataDirectory = "$OutputDirectory\data"
Write-Host "Setting up $OutputDirectory for package staging..."
New-Item $OutputDirectory -type directory
Write-Host "Copying content of $RootDirectory\windows\chocolatey to temporary directory..."
Copy-Item $RootDirectory\windows\chocolatey\* $OutputDirectory -Recurse
Write-Host "Updating version in $OutputDirectory\package.nuspec to $Version..."
$NuspecFile = @(Get-Item $OutputDirectory\package.nuspec)
$Nuspec = [xml] (Get-Content $NuspecFile)
$Nuspec.package.metadata.version = $Version
$Nuspec.package.metadata.id = $PackageId
$Nuspec.package.metadata.title = $PackageId
$Nuspec.package.metadata.summary = $PackageId
$Nuspec.package.metadata.tags = $PackageId
$Nuspec.Save($NuspecFile)
Write-Host "Packaging deployment agent code into a single executable..."
BundleIntoSingleExe "consul-deployment-agent" "$RootDirectory\agent\core.py" "$RootDirectory\agent" $DataDirectory
# Write-Host "Copying configuration file..."
# Copy-Item $RootDirectory\config\config-logging-windows.yml $DataDirectory\config-logging.yml -Recurse
Write-Host "Adding ignore files to all .exe files in $DataDirectory to avoid Chocolatey shimming..."
$Files = get-childitem $DataDirectory -include *.exe -recurse
foreach ($File in $Files) {
New-Item "$File.ignore" -type file -force | Out-Null
}
Write-Host "Making sure Chocolatey is installed..."
if ((Test-Path env:\CHOCOLATEYINSTALL) -and (Test-Path $env:CHOCOLATEYINSTALL)) {
$ChocolateyPath = $env:CHOCOLATEYINSTALL
}
else {
throw "Chocolatey is not installed."
}
Write-Host "Creating Chocolatey package with choco.exe..."
Set-Location $OutputDirectory
& choco pack package.nuspec
if ($LASTEXITCODE -ne 0) {
throw "Error creating Chocolatey package."
}
Set-Location $RootDirectory
}
try {
Write-Host "Cleaning up temporary directory..."
$RootDirectory = (Get-Item -Path ".\" -Verbose).FullName
$TempDirectory = "$RootDirectory\temp"
if (Test-Path $TempDirectory) {
Remove-Item $TempDirectory -Recurse -Force
}
$PackageId = "ttl-consul-deployment-agent-" + $BuildTarget
$Version = $env:BUILD_NUMBER
if ($Version -eq $null) {
Throw "Could not determine build version"
}
Write-Host "Creating Chocolatey package..."
CreateChocolateyPackage $PackageId $Version
Write-Host "Publishing disabled..."
}
catch {
Write-Host "FATAL EXCEPTION: $_"
exit 1
}