-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
100 lines (85 loc) · 3.11 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
#Requires -Version 7
using namespace System.Management.Automation
param (
[Parameter(Mandatory)]
[ValidateSet('windows-server', 'linux-server')]
[string]$OSFamily,
[Parameter(Mandatory)]
[ArgumentCompleter({
param ( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters )
$WindowsOptions = @('standard-core', 'standard-gui', 'datacenter-core', 'datacenter-gui')
$LinuxOptions = @('ubuntu')
switch ($fakeBoundParameters.Values) {
'windows-server' {
$WindowsOptions.Where({ $_ -like "$wordToComplete*" }) | ForEach-Object {
[CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
'linux-server' {
$LinuxOptions.Where({ $_ -like "$wordToComplete*" }) | ForEach-Object {
[CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
}
})]
[string]$Build,
[Parameter(Mandatory)]
[ArgumentCompleter({
param ( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters )
$WindowsOptions = @('2022')
$LinuxOptions = @('20.04')
switch ($fakeBoundParameters.Values) {
'windows-server' {
$WindowsOptions.Where({ $_ -like "$wordToComplete*" }) | ForEach-Object {
[CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
'linux-server' {
$LinuxOptions.Where({ $_ -like "$wordToComplete*" }) | ForEach-Object {
[CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
}
})]
[string]$OSVersion,
[Parameter()]
[string]$AdditionalArgs
)
function Build-Windows {
switch ($Build) {
'standard-core' { $ImageIndex = 1 }
'standard-gui' { $ImageIndex = 2 }
'datacenter-core' { $ImageIndex = 3 }
'datacenter-gui' { $ImageIndex = 4 }
}
$PackerRoot = "$PSScriptRoot/packer/windows/server/$OSVersion/"
packer init $PackerRoot
packer validate `
-only="vsphere-iso.$OSFamily-$OSVersion-$Build" `
-var "image_type=$Build" `
-var "os_version=$OSVersion" `
-var "image_index=$ImageIndex" `
$PackerRoot
if ($LASTEXITCODE -eq 0) {
packer build $AdditionalArgs -force `
-timestamp-ui `
-only="vsphere-iso.$OSFamily-$OSVersion-$Build" `
-var "image_type=$Build" `
-var "os_version=$OSVersion" `
-var "image_index=$ImageIndex" `
$PackerRoot
}
}
function Build-Linux {
$PackerRoot = "$PSScriptRoot/packer/linux/$Build/$OSVersion/"
packer init $PackerRoot
packer validate $PackerRoot
if ($LASTEXITCODE -eq 0) {
packer build $AdditionalArgs -force -timestamp-ui $PackerRoot
}
}
if ($PSBoundParameters.Values.Contains('windows-server')) {
Build-Windows
} else {
Build-Linux
}