forked from dcflachs/compose_plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.ps1
More file actions
203 lines (174 loc) · 7.08 KB
/
build.ps1
File metadata and controls
203 lines (174 loc) · 7.08 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#Requires -Version 7.0
<#
.SYNOPSIS
Builds the compose.manager plugin package using Docker.
.DESCRIPTION
This script runs a Slackware Docker container to build the .txz package.
It downloads Docker Compose and Compose Switch, then packages
everything together.
.PARAMETER Version
The version string for the package (e.g., "0.1.0"). Defaults to version in .plg file.
.PARAMETER Dev
Generate a development build with timestamp: YYYY.MM.DD.HHmm
.PARAMETER SkipTests
Skip running tests before building. Not recommended.
.PARAMETER ComposeVersion
Docker Compose version to include. Default: 5.0.2
.EXAMPLE
./build.ps1
./build.ps1 -Version "0.2.0"
./build.ps1 -Dev
./build.ps1 -ComposeVersion "2.41.0"
#>
param(
[string]$Version,
[switch]$Dev,
[switch]$SkipTests,
[string]$ComposeVersion
)
$ErrorActionPreference = "Stop"
$ScriptDir = $PSScriptRoot
# Run tests before building
$testScript = Join-Path $ScriptDir "test.ps1"
if (Test-Path $testScript) {
if (-not $SkipTests) {
Write-Host "Running tests..." -ForegroundColor Yellow
& $testScript
if ($LASTEXITCODE -ne 0) {
throw "Tests failed. Build aborted."
}
}
} else {
throw "test.ps1 not found. Cannot run tests."
}
# Read component versions from versions.env if not supplied as parameters
$versionsFile = Join-Path $ScriptDir "versions.env"
if (Test-Path $versionsFile) {
Get-Content $versionsFile | ForEach-Object {
if ($_ -match '^COMPOSE_VERSION=(.+)$' -and -not $ComposeVersion) { $ComposeVersion = $Matches[1].Trim() }
}
}
if (-not $ComposeVersion) { $ComposeVersion = "5.0.2" }
# Generate dev version with timestamp if -Dev flag is used
if ($Dev) {
$now = Get-Date
$Version = $now.ToString("yyyy.MM.dd.HHmm")
Write-Host "Generated dev version: $Version" -ForegroundColor Cyan
}
# If no version specified, read from .plg file
if (-not $Version) {
$plgContent = Get-Content "$ScriptDir\compose.manager.plg" -Raw
if ($plgContent -match 'ENTITY version\s+"([^"]+)"') {
$Version = $Matches[1]
Write-Host "Using version from .plg file: $Version" -ForegroundColor Cyan
} else {
throw "Could not determine version. Please specify -Version parameter."
}
}
# Extract HHmm from version for dev builds (YYYY.MM.DD.HHmm), otherwise generate fresh
if ($Version -match '\d{4}\.\d{2}\.\d{2}\.(\d{4})$') {
$BuildNum = $Matches[1]
} else {
$BuildNum = (Get-Date).ToString("HHmm")
}
$PackageName = "compose.manager-$Version-noarch-$BuildNum.txz"
$OutputPath = "$ScriptDir\archive"
# Ensure output directory exists
if (-not (Test-Path $OutputPath)) {
New-Item -ItemType Directory -Path $OutputPath -Force | Out-Null
}
# Generate a temporary plugin manifest for this specific build so install on remote will use local package path
$plgSourcePath = Join-Path $ScriptDir "compose.manager.plg"
if (-not (Test-Path $plgSourcePath -PathType Leaf)) {
throw "Plugin manifest not found: $plgSourcePath"
}
$PackageBaseName = "compose.manager-$Version-noarch-$BuildNum"
$PackageFileName = "$PackageBaseName.txz"
$PackageURL = 'file:///tmp/' + $PackageFileName
$TempPluginPath = Join-Path $OutputPath "compose.manager.plg"
$plgLines = Get-Content $plgSourcePath
$plgLines = $plgLines | ForEach-Object {
if ($_ -match '^\s*<!ENTITY version "') { "<!ENTITY version `"$Version`">" }
elseif ($_ -match '^\s*<!ENTITY packageVER "') { "<!ENTITY packageVER `"$Version`">" }
elseif ($_ -match '^\s*<!ENTITY pkgBUILD "') { "<!ENTITY pkgBUILD `"$BuildNum`">" }
elseif ($_ -match '^\s*<!ENTITY packageName "') { "<!ENTITY packageName `"$PackageBaseName`">" }
elseif ($_ -match '^\s*<!ENTITY packagefile "') { "<!ENTITY packagefile `"$PackageFileName`">" }
elseif ($_ -match '^\s*<!ENTITY packageURL "') { "<!ENTITY packageURL `"$PackageURL`">" }
elseif ($_ -match '^\s*<FILE Name="&pluginLOC;/&packagefile;"') { "<FILE Name='/tmp/$PackageFileName' Run='upgradepkg --install-new'>" }
elseif ($_ -match '^\s*<URL>') { "<URL>$PackageURL</URL>" }
else { $_ }
}
Set-Content -Path $TempPluginPath -Value $plgLines -Encoding UTF8
Write-Host "Generated temporary plugin manifest for build: $TempPluginPath" -ForegroundColor Cyan
Write-Host "Building compose.manager package v$Version (build $BuildNum)" -ForegroundColor Green
Write-Host " Docker Compose: v$ComposeVersion" -ForegroundColor Gray
Write-Host ""
# Convert Windows paths to Docker-compatible paths
$ArchivePath = $OutputPath -replace '\\', '/' -replace '^([A-Za-z]):', '/$1'
$SourcePath = "$ScriptDir/source" -replace '\\', '/' -replace '^([A-Za-z]):', '/$1'
# CA bundle setup (host side) for Docker HTTPS validation
$HostCACert = $env:CA_CERT_PATH
if (-not $HostCACert) {
$HostCACert = Join-Path $env:TEMP 'cacert.pem'
}
if (-not (Test-Path $HostCACert)) {
Write-Host "CA bundle not found at $HostCACert. Downloading fresh bundle..." -ForegroundColor Yellow
try {
Invoke-WebRequest -Uri 'https://curl.se/ca/cacert.pem' -OutFile $HostCACert -UseBasicParsing -ErrorAction Stop
}
catch {
Write-Host "Failed to download CA bundle for Docker build: $_" -ForegroundColor Red
throw "CA bundle not available. Set CA_CERT_PATH to a valid file and rerun."
}
}
# In-container path for CA bundle
$ContainerCACert = '/etc/ssl/certs/ca-certificates.crt'
# Build in Docker
$dockerArgs = @(
"run", "--rm", "--tmpfs", "/tmp"
"-v", "${ArchivePath}:/mnt/output:rw"
"-v", "${SourcePath}:/mnt/source:ro"
"-v", "${HostCACert}:${ContainerCACert}:ro"
"-e", "TZ=America/New_York"
"-e", "COMPOSE_VERSION=$ComposeVersion"
"-e", "OUTPUT_FOLDER=/mnt/output"
"-e", "PKG_VERSION=$Version"
"-e", "PKG_BUILD=$BuildNum"
"-e", "CA_CERT=${ContainerCACert}"
"vbatts/slackware:latest"
"/mnt/source/pkg_build.sh"
)
Write-Host "Running Docker build..." -ForegroundColor Yellow
docker @dockerArgs
if ($LASTEXITCODE -ne 0) {
throw "Docker build failed with exit code $LASTEXITCODE"
}
$PackagePath = Join-Path $OutputPath $PackageName
if (Test-Path $PackagePath) {
# Calculate MD5
$md5 = (Get-FileHash -Path $PackagePath -Algorithm MD5).Hash.ToLower()
Write-Host ""
Write-Host "Build successful!" -ForegroundColor Green
Write-Host " Package: $PackagePath" -ForegroundColor Cyan
Write-Host " MD5: $md5" -ForegroundColor Cyan
# Update packageMD5 in the temporary plugin manifest so plugin installer can validate local package
$tempPlgLines = Get-Content $TempPluginPath
$tempPlgLines = $tempPlgLines | ForEach-Object {
if ($_ -match '^\s*<!ENTITY packageMD5 "') { "<!ENTITY packageMD5 `"$md5`">" }
elseif ($_ -match '^\s*<MD5>') { "<MD5>$md5</MD5>" }
else { $_ }
}
Set-Content -Path $TempPluginPath -Value $tempPlgLines -Encoding UTF8
# Return build info for use by release script
return @{
Version = $Version
PackagePath = $PackagePath
PackageName = $PackageName
MD5 = $md5
ComposeVersion = $ComposeVersion
AceVersion = $AceVersion
PluginPath = $TempPluginPath
}
} else {
throw "Package was not created: $PackagePath"
}