forked from OneIdentity/safeguard-ps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoke-docker-build.ps1
36 lines (28 loc) · 1.18 KB
/
invoke-docker-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
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,Position=0)]
[string]$ImageType = "alpine",
[Parameter(Mandatory=$false,Position=1)]
[string]$Version
)
if (-not $PSBoundParameters.ContainsKey("ErrorAction")) { $ErrorActionPreference = "Stop" }
if (-not $PSBoundParameters.ContainsKey("Verbose")) { $VerbosePreference = $PSCmdlet.GetVariableValue("VerbosePreference") }
Import-Module -Name "$PSScriptRoot\docker\docker-include.psm1" -Scope Local -Force
$ImageType = $ImageType.ToLower()
$SafeguardDockerFile = (Get-SafeguardDockerFile $ImageType)
Write-Host $SafeguardDockerFile
if (-not (Get-Command "docker" -EA SilentlyContinue))
{
throw "Unabled to find docker command. Is docker installed on this machine?"
}
if ($Version)
{
$Version = "$Version-"
}
if (Invoke-Expression "docker images -q oneidentity/safeguard-ps:$ImageType")
{
Write-Host "Cleaning up the old image: oneidentity/safeguard-ps:$ImageType ..."
& docker rmi --force "oneidentity/safeguard-ps:$ImageType"
}
Write-Host "Building a new image: oneidentity/safeguard-ps:$ImageType ..."
& docker build --no-cache -t "oneidentity/safeguard-ps:$Version$ImageType" -f "$SafeguardDockerFile" "$PSScriptRoot"