-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild.ps1
executable file
·131 lines (107 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
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
#!/usr/bin/env pwsh
# =============================================================================
# build.ps1: build script for SteeltoeOSS Docker images
# =============================================================================
# -----------------------------------------------------------------------------
# help
# -----------------------------------------------------------------------------
<#
.SYNOPSIS
Build Steeltoe Docker images
.DESCRIPTION
Builds a specified Steeltoe Docker image.
By default, the image will be tagged using the name '<image>:[<version>[-<rev>]]' where:
image the specified Image name
version the value of 'IMAGE_VERSION' if specified in Dockerfile
rev the value of 'IMAGE_REVISION' if specified in Dockerfile
.PARAMETER Help
Print this message.
.PARAMETER List
List available images.
.PARAMETER Name
Docker image name.
.PARAMETER Tag
Override the image tag.
.PARAMETER Registry
Set the container registry. Defaults to dockerhub under steeltoeoss.
#>
# -----------------------------------------------------------------------------
# args
# -----------------------------------------------------------------------------
param (
[Switch] $Help,
[Switch] $List,
[String] $Name,
[String] $Tag,
[String] $Registry
)
# -----------------------------------------------------------------------------
# impl
# -----------------------------------------------------------------------------
if ($Registry)
{
$DockerOrg = $Registry
}
else
{
$DockerOrg = "steeltoeoss"
}
if ($Help)
{
Get-Help $PSCommandPath -Detailed
return
}
if ($Name -And $List)
{
throw "-Name and -List are mutually exclusive"
}
$ImagesDirectory = Split-Path -Parent $PSCommandPath
if ($List)
{
Get-Childitem -Path $ImagesDirectory -Directory | Where-Object { !$_.Name.StartsWith(".") } | Select-Object Name
return
}
if (!$Name)
{
throw "Name not specified; run with -Help for help"
}
$ImageDirectory = Join-Path $ImagesDirectory $Name
if (!(Test-Path $ImageDirectory))
{
throw "Unknown image $Name; run with -List to list available images"
}
if (!(Get-Command "docker" -ErrorAction SilentlyContinue))
{
throw "'docker' command not found"
}
$Dockerfile = Join-Path $ImageDirectory Dockerfile
if (!(Test-Path $Dockerfile))
{
throw "No Dockerfile for $Name (expected $Dockerfile)"
}
if (!$Tag)
{
if (Test-Path "$ImageDirectory/metadata")
{
$Tag = "-t $DockerOrg/$Name"
$Version = Get-Content "$ImageDirectory/metadata/IMAGE_VERSION"
$Tag += ":$Version"
$Revision = Get-Content "$ImageDirectory/metadata/IMAGE_REVISION"
if ($Revision)
{
$Tag += "-$Revision"
}
$Tag += " $(Get-Content $ImageDirectory/metadata/ADDITIONAL_TAGS | ForEach-Object { $_.replace("$Name","$DockerOrg/$Name") })"
}
else
{
throw "No metadata found for $Name"
}
}
else
{
Write-Host "Tag value set by script parameter:" $Tag
}
$docker_command = "docker build $Tag $ImageDirectory"
Write-Host $docker_command
Invoke-Expression $docker_command