ContainerMgt/New-NCHNAVContainer.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
function New-NCHNAVContainer {
    <#
    .SYNOPSIS
    Installs a new container using the navcontainerhelper module (from Freddy) on a docker host.
     
    .DESCRIPTION
    Long description
     
    .PARAMETER ContainerName
    ContainerName
     
    .PARAMETER AdditionalParameters
    Additional Docker parameters
     
    .PARAMETER imageName
    The docker image
 
    .PARAMETER registryUserName
    Login username to login to the private registry that hosts the ContainerDockerImage
     
    .PARAMETER registryPwd
    Password to login to the private registry that hosts the ContainerDockerImage
     
    .PARAMETER LicenseFile
    The NAV License File
     
    .PARAMETER memoryLimit
    The memory the container is limited to use (Default: 3G)
     
    .PARAMETER Credential
    Credential for the container
     
    .PARAMETER alwaysPull
    Always pull a new version or not (switch)
         
    .PARAMETER DoNotInstallDependentModules
    Switch to avoid installing the Cloud.Ready.Software.* modules on the container
     
    .EXAMPLE
    Simply create a new container:
 
    New-NCHNAVContainer `
        -ContainerDockerImage $ContainerDockerImage `
        -ContainerName $Containername `
        -ContainerLicenseFile $ContainerLicenseFile `
        -ContainerCredential $ContainerCredential `
        -ContainerAlwaysPull `
        -ContainerAdditionalParameters $ContainerAdditionalParameters
    #>

    param(
        [Parameter(Mandatory = $true)]
        [String] $ContainerName,
        [Parameter(Mandatory = $false)]
        [String[]] $AdditionalParameters=@(), 
        [Parameter(Mandatory = $true)]
        [String] $imageName,        
        [Parameter(Mandatory = $false)]
        [String] $registryUserName, 
        [Parameter(Mandatory = $false)]
        [string] $registryPwd,         
        [Parameter(Mandatory = $true)]
        [String] $LicenseFile, 
        [Parameter(Mandatory = $false)]
        [String] $memoryLimit, 
        [Parameter(Mandatory = $true)]
        [System.Management.Automation.PSCredential] $Credential, 
        [Parameter(Mandatory = $false)]
        [Switch] $alwaysPull,
        [Parameter(Mandatory = $false)]
        [Switch] $accept_eula,
        [Parameter(Mandatory = $false)]
        [Switch] $DoNotInstallDependentModules,
        [Parameter(Mandatory = $false)]
        [Switch] $doNotExportObjectsToText
    )

    Write-Host -ForegroundColor Green "$($MyInvocation.MyCommand.Name) on $env:COMPUTERNAME"

    if ($registryUserName) {
        $registry = $imageName.Substring(0,$imageName.IndexOf('/'))
        Write-Host -ForegroundColor Gray "Connecting docker to $registry user: $registryUserName pwd: $registryPwd"
        docker login "$registry" -u "$registryUserName" -p "$registryPwd"
    }

    New-NavContainer `
        -accept_eula:$accept_eula `
        -containerName $ContainerName `
        -imageName $imageName `
        -licenseFile $LicenseFile `
        -additionalParameters $AdditionalParameters `
        -memoryLimit $memoryLimit `
        -alwaysPull:$alwaysPull `
        -Credential $Credential `
        -doNotExportObjectsToText:$doNotExportObjectsToText `
        -updateHosts `
        -auth NavUserPassword `
        -includeCSide `
        -Verbose

    if (!$DoNotInstallDependentModules){
        Install-NCHDependentModules `
            -ContainerName $ContainerName `
            -ContainerModulesOnly
    }

    Sync-NCHNAVTenant -containerName $ContainerName
}