forked from jenkinsci/docker-ssh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.ps1
150 lines (136 loc) · 5.63 KB
/
make.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
[CmdletBinding()]
Param(
[Parameter(Position=1)]
[String] $Target = "build",
[String] $AdditionalArgs = '',
[String] $Build = '',
[String] $VersionTag = '1.0-1',
[switch] $PushVersions = $false
)
$Repository = 'ssh-agent'
$Organization = 'jenkins'
if(![String]::IsNullOrWhiteSpace($env:DOCKERHUB_REPO)) {
$Repository = $env:DOCKERHUB_REPO
}
if(![String]::IsNullOrWhiteSpace($env:DOCKERHUB_ORGANISATION)) {
$Organization = $env:DOCKERHUB_ORGANISATION
}
$builds = @{
'jdk11' = @{
'Folder' = '11\windows\windowsservercore-ltsc2019';
'Tags' = @( "windowsservercore-1809", "windowsservercore-1809-jdk11", "windowsservercore-ltsc2019", "windowsservercore-ltsc2019-jdk11" );
};
'nanoserver-jdk11' = @{
'Folder' = '11\windows\nanoserver-ltsc2019';
'Tags' = @( "nanoserver-1809", "nanoserver-ltsc2019", "nanoserver-1809-jdk11", "nanoserver-ltsc2019", "nanoserver-ltsc2019-jdk11" );
};
}
if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) {
foreach($tag in $builds[$Build]['Tags']) {
Copy-Item -Path 'setup-sshd.ps1' -Destination (Join-Path $builds[$Build]['Folder'] 'setup-sshd.ps1') -Force
Copy-Item -Path 'CreateProfile.psm1' -Destination (Join-Path $builds[$Build]['Folder'] 'CreateProfile.psm1') -Force
Write-Host "Building $Build => tag=$tag"
$cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$Build]['Folder']
Invoke-Expression $cmd
if($PushVersions) {
$buildTag = "$VersionTag-$tag"
if($tag -eq 'latest') {
$buildTag = "$VersionTag"
}
Write-Host "Building $Build => tag=$buildTag"
$cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$Build]['Folder']
Invoke-Expression $cmd
}
}
} else {
foreach($b in $builds.Keys) {
Copy-Item -Path 'setup-sshd.ps1' -Destination (Join-Path $builds[$b]['Folder'] 'setup-sshd.ps1') -Force
Copy-Item -Path 'CreateProfile.psm1' -Destination (Join-Path $builds[$b]['Folder'] 'CreateProfile.psm1') -Force
foreach($tag in $builds[$b]['Tags']) {
Write-Host "Building $b => tag=$tag"
$cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$b]['Folder']
Invoke-Expression $cmd
if($PushVersions) {
$buildTag = "$VersionTag-$tag"
if($tag -eq 'latest') {
$buildTag = "$VersionTag"
}
Write-Host "Building $Build => tag=$buildTag"
$cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$b]['Folder']
Invoke-Expression $cmd
}
}
}
}
if($lastExitCode -ne 0) {
exit $lastExitCode
}
if($Target -eq "test") {
$mod = Get-InstalledModule -Name Pester -MinimumVersion 4.9.0 -MaximumVersion 4.99.99 -ErrorAction SilentlyContinue
if($null -eq $mod) {
$module = "c:\Program Files\WindowsPowerShell\Modules\Pester"
if(Test-Path $module) {
takeown /F $module /A /R
icacls $module /reset
icacls $module /grant Administrators:'F' /inheritance:d /T
Remove-Item -Path $module -Recurse -Force -Confirm:$false
}
Install-Module -Force -Name Pester -MaximumVersion 4.99.99
}
if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) {
$env:FOLDER = $builds[$Build]['Folder']
$env:VERSION = "$VersionTag"
Invoke-Pester -Path tests -EnableExit
Remove-Item env:\FOLDER
Remove-Item env:\VERSION
} else {
foreach($b in $builds.Keys) {
$env:FOLDER = $builds[$b]['Folder']
$env:VERSION = "$VersionTag"
Invoke-Pester -Path tests -EnableExit
Remove-Item env:\FOLDER
Remove-Item env:\VERSION
}
}
}
if($Target -eq "publish") {
if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) {
foreach($tag in $Builds[$Build]['Tags']) {
Write-Host "Publishing $Build => tag=$tag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $tag
Invoke-Expression $cmd
if($PushVersions) {
$buildTag = "$VersionTag-$tag"
if($tag -eq 'latest') {
$buildTag = "$VersionTag"
}
Write-Host "Publishing $Build => tag=$buildTag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag
Invoke-Expression $cmd
}
}
} else {
foreach($b in $builds.Keys) {
foreach($tag in $Builds[$b]['Tags']) {
Write-Host "Publishing $b => tag=$tag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $tag
Invoke-Expression $cmd
if($PushVersions) {
$buildTag = "$VersionTag-$tag"
if($tag -eq 'latest') {
$buildTag = "$VersionTag"
}
Write-Host "Publishing $Build => tag=$buildTag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag
Invoke-Expression $cmd
}
}
}
}
}
if($lastExitCode -ne 0) {
Write-Error "Build failed!"
} else {
Write-Host "Build finished successfully"
}
exit $lastExitCode