-
Notifications
You must be signed in to change notification settings - Fork 62
/
common.psm1
54 lines (45 loc) · 1.55 KB
/
common.psm1
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
function Make() {
[CmdletBinding()]
Param(
[Parameter(Position=1)]
[String] $Target = "build",
[String] $Group = 'jenkins',
[String] $Prefix = 'jnlp-agent',
[String] $Suffix = [string]((Get-Location) -split '\\' | Select-Object -Last 1)
)
#
# This is the root module for ensuring that the containers are all built
# properly
# To use this module, do:
# Import-Module -Force -DisableNameChecking -ArgumentList $args ..\common.psm1 ; Make @args
# GROUP can be overridden in the environment to root the docker images under
# different registry namespace
if(![System.String]::IsNullOrWhiteSpace($env:GROUP)) {
$Group = $env:GROUP
}
# PREFIX defaults to `jnlp-agent` and can be changed to compute different image
# names
if(![System.String]::IsNullOrWhiteSpace($env:PREFIX)) {
$Prefix = $env:PREFIX
}
$NAME="${Group}/${Prefix}-${Suffix}:windows"
function Build() {
Get-ChildItem -Path * -Include "Dockerfile.windows*" -File | ForEach-Object {
$fullName='{0}{1}' -f $NAME,[System.IO.Path]::GetExtension($_.FullName).Replace(".windows", "")
docker build -t $fullName -f $_ .
}
}
function Push() {
Get-ChildItem -Path * -Include "Dockerfile.windows*" | ForEach-Object {
$fullName='{0}-{1}' -f $NAME,[System.IO.Path]::GetExtension($_.FullName).Replace(".windows", "").TrimStart('-')
$fullName = $fullName.Trim('-')
Write-Host "Pushing $fullName"
docker push $fullName
}
}
switch -wildcard ($Target) {
"build" { Build }
"push" { Push }
default { Write-Error "No target '$Target'" ; Exit -1 }
}
}