forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
winmake.ps1
288 lines (250 loc) · 9.73 KB
/
winmake.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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env powershell
. ./contrib/cirrus/win-lib.ps1
# Targets
function Podman-Remote{
New-Item -ItemType Directory -Force -Path "./bin/windows"
$buildInfo = Get-Date -UFormat %s -Millisecond 0
$buildInfo = "-X github.com/containers/podman/v5/libpod/define.buildInfo=$buildInfo "
$commit = Git-Commit
$commit = "-X github.com/containers/podman/v5/libpod/define.gitCommit=$commit "
Run-Command "go build --ldflags `"$commit $buildInfo `" --tags `"$remotetags`" --o ./bin/windows/podman.exe ./cmd/podman/."
}
function Make-Clean{
Remove-Item ./bin -Recurse -Force -Confirm:$false
}
function Local-Machine {
param (
[string]$files
);
Build-Ginkgo
if ($files) {
$files = " --focus-file $files "
}
Run-Command "./test/tools/build/ginkgo.exe -vv --tags `"$remotetags`" -timeout=90m --trace --no-color $files pkg/machine/e2e/."
}
# Expect starting directory to be /podman
function Win-SSHProxy {
param (
[string]$Version
);
New-Item -ItemType Directory -Force -Path "./bin/windows"
if (-Not $Version) {
$Version = "v0.7.2"
}
curl.exe -sSL -o "./bin/windows/gvproxy.exe" --retry 5 "https://github.com/containers/gvisor-tap-vsock/releases/download/$Version/gvproxy-windowsgui.exe"
curl.exe -sSL -o "./bin/windows/win-sshproxy.exe" --retry 5 "https://github.com/containers/gvisor-tap-vsock/releases/download/$Version/win-sshproxy.exe"
}
function Installer{
param (
[string]$version,
[string]$suffix = "dev"
);
Write-Host "Building the windows installer"
# Check for the files to include in the installer
$requiredArtifacts = @(
"$PSScriptRoot\bin\windows\podman.exe"
"$PSScriptRoot\bin\windows\gvproxy.exe"
"$PSScriptRoot\bin\windows\win-sshproxy.exe"
"$PSScriptRoot\docs\build\remote\podman-for-windows.html"
)
$requiredArtifacts | ForEach-Object {
if (!(Test-Path -Path $PSItem -PathType Leaf)) {
Write-Host "$PSItem not found."
Write-Host "Make 'podman', 'win-gvproxy' and 'docs' before making the installer:"
Write-Host " .\winmake.ps1 podman-remote"
Write-Host " .\winmake.ps1 win-gvproxy"
Write-Host " .\winmake.ps1 docs"
Exit 1
}
}
# Create the ZIP file with the full client distribution
$zipFileDest = "$PSScriptRoot\contrib\win-installer\current"
Build-Distribution-Zip-File -destinationPath $zipFileDest
if (-Not $version) {
# Get Podman version from local source code
$version = Get-Podman-Version
}
# Run \contrib\win-installer\build.ps1
Push-Location $PSScriptRoot\contrib\win-installer
Run-Command ".\build.ps1 $version $suffix `"$zipFileDest`""
Pop-Location
}
function Documentation{
Write-Host "Generating the documentation artifacts"
# Check that pandoc is installed
if (!(Get-Command -Name "pandoc" -ErrorAction SilentlyContinue)) {
Write-Host "Pandoc not found. Pandoc is required to convert the documentation Markdown files into HTML files."
Exit 1
}
# Check that the podman client is built
$podmanClient = "$PSScriptRoot\bin\windows\podman.exe"
if (!(Test-Path -Path $podmanClient -PathType Leaf)) {
Write-Host "$podmanClient not found. Make 'podman-remote' before 'documentation'."
Exit 1
}
Run-Command "$PSScriptRoot\docs\make.ps1 $podmanClient"
}
function Validate{
$podmanExecutable = "podman"
$podmanSrcVolumeMount = "${PSScriptRoot}:/go/src/github.com/containers/podman"
# All files bind mounted from a Windows host are marked as executable.
# That makes the pre-commit hook "check-executables-have-shebangs" fail.
# Setting the environment variable "SKIP=check-executables-have-shebangs"
# allow to skip that pre-commit hook.
$podmanEnvVariable = "-e SKIP=check-executables-have-shebangs"
$podmanRunArgs = "--rm -v $podmanSrcVolumeMount --security-opt label=disable -t -w /go/src/github.com/containers/podman $podmanEnvVariable"
$validateImage = "quay.io/libpod/validatepr:latest"
$validateCommand = "make .validatepr"
# Check that podman is installed
if (!(Get-Command -Name $podmanExecutable -ErrorAction SilentlyContinue)) {
Write-Host "$podmanExecutable not found. $podmanExecutable is required to run the validate script."
Exit 1
}
# Check that a podman machine exist
$currentMachine = (podman machine info -f json | ConvertFrom-Json).Host.CurrentMachine
if (!$currentMachine) {
Write-Host "Podman machine doesn't exist. Initialize and start one before running the validate script."
Exit 1
}
# Check that the podman machine is running
$state = (podman machine info -f json | ConvertFrom-Json).Host.MachineState
if ($state -ne "Running") {
Write-Host "Podman machine is not running. Start the machine before running the validate script."
Exit 1
}
Run-Command "$podmanExecutable run $podmanRunArgs $validateImage $validateCommand"
}
function Lint{
# Check that golangci-lint is installed
if (!(Get-Command -Name "golangci-lint" -ErrorAction SilentlyContinue)) {
Write-Host "The tool ""golangci-lint"" not found. Install https://golangci-lint.run/ before running the lint script."
Exit 1
}
# Check that pre-commit is installed
if (!(Get-Command -Name "pre-commit" -ErrorAction SilentlyContinue)) {
Write-Host "The tool ""pre-commit"" not found. Install https://pre-commit.com/ before running the lint script."
Exit 1
}
Run-Command "golangci-lint run --timeout=10m --build-tags=`"$remotetags`" $PSScriptRoot\cmd\podman"
Run-Command "pre-commit run --all-files"
}
# Helpers
function Build-Ginkgo{
if (Test-Path -Path ./test/tools/build/ginkgo.exe -PathType Leaf) {
return
}
Write-Host "Building Ginkgo"
Push-Location ./test/tools
Run-Command "go build -o build/ginkgo.exe ./vendor/github.com/onsi/ginkgo/v2/ginkgo"
Pop-Location
}
function Git-Commit{
# git is not installed by default on windows,
# so if we can't get the commit, we don't include this info
Get-Command git -ErrorAction SilentlyContinue | out-null
if(!$?){
return
}
$commit = git rev-parse HEAD
$dirty = git status --porcelain --untracked-files=no
if ($dirty){
$commit = "$commit-dirty"
}
return $commit
}
function Build-Distribution-Zip-File{
param (
[string]$destinationPath
);
$binariesFolder = "$PSScriptRoot\bin\windows"
$documentationFolder = "$PSScriptRoot\docs\build\remote\"
$zipFile = "$destinationPath\podman-remote-release-windows_amd64.zip"
# Create a temporary folder to store the distribution files
$tempFolder = New-Item -ItemType Directory -Force -Path "$env:TEMP\podman-windows"
# Copy bin\windows\ content to the temporary folder
Copy-Item -Recurse -Force -Path "$binariesFolder\*" -Destination "$tempFolder\"
# Copy docs\build\remote to the temporary folder
Copy-Item -Recurse -Force -Path "$documentationFolder" -Destination "$tempFolder\docs\"
# If $destination path doesn't exist, create it
if (-Not (Test-Path -Path $destinationPath -PathType Container)) {
New-Item -ItemType Directory -Force -Path $destinationPath
}
# Create the ZIP file with the full client distribution
Compress-Archive -Path "$tempFolder\*" -DestinationPath $zipFile -Force
# Delete the temporary folder
Remove-Item -Recurse -Force -Path "$tempFolder"
}
function Get-Podman-Version{
$versionSrc = "$PSScriptRoot\test\version\"
$versionBin = "$PSScriptRoot\test\version\version.exe"
# If version.exe doesn't exist, build it
if (-Not (Test-Path -Path "$versionBin" -PathType Leaf)) {
Run-Command "go build --o `"$versionBin`" `"$versionSrc`""
}
$version = Invoke-Expression "$versionBin"
# Remove the '-dev' suffix from the version
$version = $version -replace "-.*", ""
return $version
}
# Init script
$target = $args[0]
$remotetags = "remote exclude_graphdriver_btrfs btrfs_noversion exclude_graphdriver_devicemapper containers_image_openpgp"
switch ($target) {
{$_ -in '', 'podman-remote', 'podman'} {
Podman-Remote
}
'localmachine' {
if ($args.Count -gt 1) {
$files = $args[1]
}
Local-Machine -files $files
}
'clean' {
Make-Clean
}
{$_ -in 'win-sshproxy', 'win-gvproxy'} {
if ($args.Count -gt 1) {
$ref = $args[1]
}
Win-SSHProxy -Ref $ref
}
'installer' {
Installer
}
'docs' {
Documentation
}
'validatepr' {
Validate
}
'lint' {
Lint
}
default {
Write-Host "Usage: " $MyInvocation.MyCommand.Name "<target> [options]"
Write-Host
Write-Host "Example: Build podman-remote "
Write-Host " .\winmake podman-remote"
Write-Host
Write-Host "Example: Run all machine tests "
Write-Host " .\winmake localmachine"
Write-Host
Write-Host "Example: Run specfic machine tests "
Write-Host " .\winmake localmachine "basic_test.go""
Write-Host
Write-Host "Example: Download win-gvproxy and win-sshproxy helpers"
Write-Host " .\winmake win-gvproxy"
Write-Host
Write-Host "Example: Build the windows installer"
Write-Host " .\winmake installer"
Write-Host
Write-Host "Example: Generate the documetation artifacts"
Write-Host " .\winmake docs"
Write-Host
Write-Host "Example: Validate code changes before submitting a PR"
Write-Host " .\winmake validatepr"
Write-Host
Write-Host "Example: Run linters"
Write-Host " .\winmake lint"
}
}