-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
up.ps1
212 lines (168 loc) · 6.9 KB
/
up.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<#
.SYNOPSIS
Spins up the containers.
.PARAMETER SkipBuild
Specifies that the images should not be built prior to starting up.
.PARAMETER IncludeSps
Species that the Sitecore Publishing Service should be included.
.PARAMETER IncludeSpe
Specifies that the Sitecore PowerShell Extensions module should be included.
.PARAMETER IncludeSxa
Specifies that the Sitecore Exerience Accelerator modules should be included.
.PARAMETER IncludePackages
Specifies that custom packages should be included during the build and/or after startup.
Packages contained within .\docker\build\releases will be included in the built images.
Packages contained within .\docker\releases will be deployed after the containers startup.
#>
[CmdletBinding()]
param(
[switch]$IncludeSps,
[switch]$IncludeSpe,
[switch]$IncludeSxa,
[switch]$IncludePackages,
[switch]$SkipBuild,
[switch]$SkipIndexing
)
$releases = Join-Path -Path $PSScriptRoot -ChildPath "docker\releases"
$sat = Join-Path -Path $releases -ChildPath "sat"
if(-not (Test-Path -Path $sat)) {
New-Item -Path $sat -ItemType Directory > $null
}
$satConfig = Get-ChildItem -Path $releases -Filter "configuration.json" |
Get-Content | ConvertFrom-Json | Select-Object -ExpandProperty "SitecoreAzureToolkit"
$satPackage = Join-Path -Path $sat -ChildPath $satConfig.Filename
if(-not (Test-Path -Path $satPackage)) {
Get-ChildItem -Path $sat -Recurse | Remove-Item -Recurse
Write-Host "Downloading $($satConfig.Filename)"
$webClient = New-Object System.Net.WebClient
$webClient.Downloadfile($satConfig.Url, $satPackage)
Write-Host "Unblocking $($satConfig.Filename)"
Unblock-File -Path $satPackage
Expand-Archive -Path $satPackage -DestinationPath $sat
}
Import-Module -Name (Join-Path -Path $sat -ChildPath "tools\Sitecore.Cloud.Cmdlets.dll")
$packages = Get-ChildItem -Path $releases -Filter "*.zip" |
Where-Object { $_.Extension -ne ".scwdp.zip" } |
Select-Object -ExpandProperty FullName
$destination = "$($releases)\"
Add-Type -AssemblyName "System.IO.Compression"
Add-Type -AssemblyName "System.IO.Compression.FileSystem"
function Test-ValidModulePackage {
param(
[string]$Path
)
$isModulePackage = $false
$zip = [System.IO.Compression.ZipFile]::Open($Path, [System.IO.Compression.ZipArchiveMode]::Read)
$packageZipEntry = $zip.Entries | Where-Object { $_.Name -eq "package.zip" }
if($packageZipEntry) {
$isModulePackage = $true
}
$zip.Dispose()
$isModulePackage
}
foreach($package in $packages) {
if (-not (Test-ValidModulePackage -Path $package)) {
continue
}
$packageName = [System.IO.Path]::GetFileNameWithoutExtension($package)
Write-Host "Converting $($packageName)"
try {
$convertedFilename = Join-Path -Path $destination -ChildPath "$($packageName).scwdp.zip"
if (Test-Path -Path $convertedFilename) {
Remove-Item -Path $convertedFilename
}
$wdpPath = ConvertTo-SCModuleWebDeployPackage -Path $package -Destination $destination #-DisableDacPacOptions * -Force
} catch {
$PSItem.Exception
Write-Warning "Verify that Microsoft® SQL Server® Data-Tier Application Framework is installed."
Write-Host "Tip: Use Process Monitor to identify which libraries are missing."
Write-Host "https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0019579"
exit
}
Write-Host ""
}
if (-not (docker ps)) {
Write-Host "Please verify Docker is running and try again." -ForegroundColor Red
break
}
$composeArgs = @("compose", "-f", ".\docker-compose.yml")
if(Test-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath "docker-compose.override.yml")) {
$composeArgs += "-f"
$composeArgs += ".\docker-compose.override.yml"
}
if($IncludeSps) {
$composeArgs += "-f"
$composeArgs += ".\docker-compose.sps.yml"
}
if($IncludeSpe -or $IncludeSxa) {
$composeArgs += "-f"
$composeArgs += ".\docker-compose.spe.yml"
}
if($IncludeSxa) {
$composeArgs += "-f"
$composeArgs += ".\docker-compose.sxa.yml"
}
if(-not $SkipBuild) {
Write-Host "Build Sitecore images..." -ForegroundColor Green
$parameters = $PSBoundParameters
$parameters.Remove("SkipBuild") > $null
$parameters.Remove("SkipIndexing") > $null
& (Join-Path -Path $PSScriptRoot -ChildPath "build.ps1") @parameters
if ($LASTEXITCODE -ne 0) {
Write-Error "Container build failed, see errors above."
}
}
Write-Host "Starting Sitecore environment..." -ForegroundColor Green
docker $composeArgs up -d
Write-Host "Waiting for CM to become available..." -ForegroundColor Green
$startTime = Get-Date
do {
Start-Sleep -Milliseconds 300
try {
$status = Invoke-RestMethod "http://localhost:8079/api/http/routers/cm-secure@docker"
} catch {
if ($_.Exception.Response.StatusCode.value__ -ne "404") {
$containers = docker ps -a --format "table {{.Names}}"
$container = $containers | ConvertFrom-Csv | Where-Object { $_.NAMES -match "-cm" } | Select-Object -First 1 -ExpandProperty NAMES
docker exec $container curl http://cm
throw
}
}
} while ($status.status -ne "enabled" -and $startTime.AddSeconds(15) -gt (Get-Date))
if (-not $status.status -eq "enabled") {
$status
Write-Error "Timeout waiting for Sitecore CM to become available via Traefik proxy. Check CM container logs."
}
if($IncludePackages) {
& (Join-Path -Path $PSScriptRoot -ChildPath "deploy.ps1")
}
Write-Host "Restoring Sitecore CLI..." -ForegroundColor Green
dotnet tool restore
Write-Host "Installing Sitecore CLI Plugins..."
dotnet sitecore --help | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Error "Unexpected error installing Sitecore CLI Plugins"
}
Import-Module .\tools\DockerToolsLite
$envPath = Join-Path -Path $PSScriptRoot -ChildPath ".env"
$cmHost = Get-EnvFileVariable -Variable "CM_HOST" -Path $envPath
$idHost = Get-EnvFileVariable -Variable "ID_HOST" -Path $envPath
Write-Host "Logging into Sitecore..." -ForegroundColor Green
dotnet sitecore login --cm https://$cmHost --allow-write true --auth https://$idHost
if ($LASTEXITCODE -ne 0) {
Write-Error "Unable to log into Sitecore, did the Sitecore environment start correctly? See logs above."
}
if (-not $SkipIndexing) {
# Populate Solr managed schemas to avoid errors during item deploy
Write-Host "Populating Solr managed schema..." -ForegroundColor Green
dotnet sitecore index schema-populate
if ($LASTEXITCODE -ne 0) {
Write-Error "Populating Solr managed schema failed, see errors above."
}
# Rebuild indexes
Write-Host "Rebuilding indexes ..." -ForegroundColor Green
dotnet sitecore index rebuild
}
Write-Host "Good luck!" -ForegroundColor Green
Write-Host "Opening site..." -ForegroundColor Green
Start-Process "https://$($cmHost)/sitecore"