forked from kine/NVRAppDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Init-ALEnvironment.ps1
180 lines (169 loc) · 7.54 KB
/
Init-ALEnvironment.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<#
.SYNOPSIS
Create container for the AL project
.DESCRIPTION
Create container for the AL project
.EXAMPLE
PS C:\> Read-ALConfiguration -Path <repopath> | Init-ALEnvironment
Read the config for the repo and create the environment
.Parameter ContainerName
Name of the container to create
.Parameter ImageName
Name of the docker image to use
.Parameter LicenseFile
Path of the .flf file to use
.Parameter Build
If specified, password will be taken from parameter and not asked from user
.Parameter Password
Password to use for creating the user inside the container
.Parameter RepoPath
Path to the repository - will be mapped as c:\app into the container
.Parameter RAM
Size of RAM for the container (e.g. '4GB')
.Parameter SkipImportTestSuite
Will not import test suite and it could be imported later through separate command
.Parameter optionalParameters
Array of optional Parameters for the container creation
#>
function Init-ALEnvironment
{
Param (
[Parameter(ValueFromPipelineByPropertyName=$True)]
$ContainerName,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$ImageName,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$LicenseFile,
[ValidateSet('','process','hyperv')]
[Parameter(ValueFromPipelineByPropertyName=$True)]
$Isolation,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$Build='',
[Parameter(ValueFromPipelineByPropertyName=$True)]
$Password='',
[Parameter(ValueFromPipelineByPropertyName=$True)]
$RepoPath='',
[Parameter(ValueFromPipelineByPropertyName=$True)]
$Username=$env:USERNAME,
[ValidateSet('Windows', 'NavUserPassword')]
[Parameter(ValueFromPipelineByPropertyName=$True)]
$Auth='Windows',
[Parameter(ValueFromPipelineByPropertyName=$True)]
$RAM='4GB',
[Parameter(ValueFromPipelineByPropertyName=$True)]
[String]$DockerHost,
[Parameter(ValueFromPipelineByPropertyName=$True)]
[PSCredential]$DockerHostCred,
[Parameter(ValueFromPipelineByPropertyName=$True)]
[bool]$DockerHostSSL,
[switch]$SkipImportTestSuite,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$optionalParameters,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$EnableSymbolLoading=$true,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$CreateTestWebServices=$true
)
if ($env:TF_BUILD) {
Write-Host "TF_BUILD set, running under agent, enforcing Build flag"
$Build = 'true'
}
Write-Host "Build is $Build"
$inclTestToolkit = $True
if ($SkipImportTestSuite) {
$inclTestToolkit = $False
}
if ($Build -ne 'true') {
if ($Password) {
Write-Host "Using passed password"
$PWord = ConvertTo-SecureString -String $Password -AsPlainText -Force
$User = $Username
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$PWord
} else {
if ($Auth -eq 'Windows') {
$credentials = Get-Credential -Message "Enter your WINDOWS password!!!" -UserName $Username
} else {
$credentials = Get-Credential -Message "Enter password you want to use" -UserName $Username
}
}
$myscripts = @(@{'MainLoop.ps1' = 'while ($true) { start-sleep -seconds 10 }'})
$additionalParameters = @("--volume ""$($RepoPath):C:\app""",
'-e CustomNavSettings=ServicesUseNTLMAuthentication=true'
)
if($optionalParameters) {
$additionalParameters += $optionalParameters
}
New-NavContainer -accept_eula `
-accept_outdated `
-containerName $ContainerName `
-imageName $ImageName `
-licenseFile $LicenseFile `
-isolation $Isolation `
-Credential $credentials `
-doNotExportObjectsToText `
-enableSymbolLoading:$EnableSymbolLoading `
-includeCSide `
-alwaysPull `
-includeTestToolkit:$inclTestToolkit `
-shortcuts "Desktop" `
-auth $Auth `
-additionalParameters $additionalParameters `
-memoryLimit $RAM `
-assignPremiumPlan `
-updateHosts `
-useBestContainerOS `
-myScripts $myscripts
} else {
if ((-not $Password) -or ($Password -eq '')) {
Write-Host 'Using fixed password and NavUserPassword authentication'
$PWord = ConvertTo-SecureString -String 'Pass@word1' -AsPlainText -Force
} else {
Write-Host "Using passed password and Windows authentication"
$PWord = ConvertTo-SecureString -String $Password -AsPlainText -Force
}
$User = $Username
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$PWord
$additionalParameters = @("--volume ""$($RepoPath):C:\app""",
'-e CustomNavSettings=ServicesUseNTLMAuthentication=true',
'-e usessl=N'
)
if($optionalParameters) {
$additionalParameters += $optionalParameters
}
New-NavContainer -accept_eula `
-accept_outdated `
-containerName $ContainerName `
-imageName $ImageName `
-licenseFile $LicenseFile `
-isolation $Isolation `
-Credential $credentials `
-auth $Auth `
-enableSymbolLoading:$EnableSymbolLoading `
-doNotExportObjectsToText `
-includeCSide `
-alwaysPull `
-includeTestToolkit:$inclTestToolkit `
-additionalParameters $additionalParameters `
-memoryLimit $RAM `
-assignPremiumPlan `
-shortcuts "None" `
-useBestContainerOS `
-updateHosts
# -myScripts @{"SetupWebClient.ps1"=''}
# -memoryLimit 4GB
}
if ($Build -eq '') {
Write-Host 'Extracting VSIX'
docker exec -t $ContainerName PowerShell.exe -Command {$targetDir = "c:\run\my\alc"; $vsix = (Get-ChildItem "c:\run\*.vsix" -Recurse | Select-Object -First 1);Add-Type -AssemblyName System.IO.Compression.FileSystem;[System.IO.Compression.ZipFile]::ExtractToDirectory($vsix.FullName, $targetDir) ;Write-Host "$vsix";copy-item $vsix "c:\run\my"}
$vsixExt = (Get-ChildItem "C:\ProgramData\NavContainerHelper\Extensions\$ContainerName\" -Filter *.vsix).FullName
Write-Host 'Installing vsix package'
code --install-extension $vsixExt
}
if ($inclTestToolkit -and $CreateTestWebServices) {
Write-Host 'Publishing CALTestResult (PAG130405) and CALCodeCoverageMap (PAG130408) Webservices'
Invoke-ScriptInNavContainer -containerName $ContainerName -scriptblock {
New-NAVWebService -ServerInstance NAV -ServiceName CALTestResults -ObjectType Page -ObjectId 130405 -Published $True
New-NAVWebService -ServerInstance NAV -ServiceName CALCodeCoverageMap -ObjectType Page -ObjectId 130408 -Published $True
}
}
}