forked from OneIdentity/SafeguardDevOpsService
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoke-docker-run.ps1
59 lines (47 loc) · 1.94 KB
/
invoke-docker-run.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
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,Position=0)]
[string]$ImageType = "alpine",
[Parameter(Mandatory=$false)]
[int]$Port = 443,
[Parameter(Mandatory=$false)]
[ValidateScript({[bool]($_ -as [IPAddress])})]
[string]$IPAddress,
[Parameter(Mandatory=$false)]
[switch]$DebugContainer
)
if (-not $PSBoundParameters.ContainsKey("ErrorAction")) { $ErrorActionPreference = "Stop" }
if (-not $PSBoundParameters.ContainsKey("Verbose")) { $VerbosePreference = $PSCmdlet.GetVariableValue("VerbosePreference") }
if (-not $IPAddress)
{
Write-Host "Determining Host IP address..."
$IPAddress = (Get-NetIPConfiguration | Where-Object {$_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.status -ne "Disconnected"}).IPv4Address.IPAddress
Write-Host -ForegroundColor Green $IPAddress
}
Import-Module -Name "$PSScriptRoot\docker\docker-include.psm1" -Scope Local -Force
$ImageType = $ImageType.ToLower()
Get-SafeguardDockerFile $ImageType # Make sure the ImageType exists
if (-not (Get-Command "docker" -EA SilentlyContinue))
{
throw "Unable to find docker command. Is docker installed on this machine?"
}
$ImageName = "oneidentity/safeguard-devops:$ImageType"
$ContainerName = "safeguard-devops-runtime"
Write-Host "Rebuilding the image: $ImageName ..."
& "$PSScriptRoot/invoke-docker-build.ps1" $ImageType
Write-Host "Clean up any old container named $ContainerName ..."
$Exists = (& docker ps -a -f name=$ContainerName -q)
if ($Exists)
{
docker rm $ContainerName
}
Write-Host "Using Docker host IP address: $IPAddress"
if ($DebugContainer)
{
& docker run --name "$ContainerName" -p "${Port}:4443" --env DOCKER_HOST_IP=$IPAddress --cap-add=NET_ADMIN -it "$ImageName" "/bin/bash"
}
else
{
Write-Host "Running interactive container ($ContainerName) for $ImageName on port $Port ..."
& docker run --name "$ContainerName" -p "${Port}:4443" --env DOCKER_HOST_IP=$IPAddress --cap-add=NET_ADMIN -it "$ImageName"
}