forked from Sitecore/XM-Cloud-Introduction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathup.ps1
144 lines (124 loc) · 5.89 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
[CmdletBinding(DefaultParameterSetName = "no-arguments")]
Param (
[Parameter(HelpMessage = "Switch to enable running against edge, this will only run Traefik and the host containers.",
ParameterSetName = "env-init")]
[switch]$UseEdge
)
$ErrorActionPreference = "Stop";
$envContent = Get-Content .env -Encoding UTF8
$xmCloudHost = $envContent | Where-Object { $_ -imatch "^CM_HOST=.+" }
$mvpHost = $envContent | Where-Object { $_ -imatch "^MVP_RENDERING_HOST=.+" }
$sugconeuHost = $envContent | Where-Object { $_ -imatch "^SUGCON_EU_HOST=.+" }
$sugconanzHost = $envContent | Where-Object { $_ -imatch "^SUGCON_ANZ_HOST=.+" }
$xmCloudDeployConfig = $envContent | Where-Object { $_ -imatch "^XMCLOUD_DEPLOY_CONFIG=.+" }
$sitecoreDockerRegistry = $envContent | Where-Object { $_ -imatch "^SITECORE_DOCKER_REGISTRY=.+" }
$sitecoreVersion = $envContent | Where-Object { $_ -imatch "^SITECORE_VERSION=.+" }
$xmCloudHost = $xmCloudHost.Split("=")[1]
$mvpHost = $mvpHost.Split("=")[1]
$sugconeuHost = $sugconeuHost.Split("=")[1]
$sugconanzHost = $sugconanzHost.Split("=")[1]
$xmCloudDeployConfig = $xmCloudDeployConfig.Split("=")[1]
$sitecoreDockerRegistry = $sitecoreDockerRegistry.Split("=")[1]
$sitecoreVersion = $sitecoreVersion.Split("=")[1]
# Double check whether init has been run
$envCheckVariable = "HOST_LICENSE_FOLDER"
$envCheck = $envContent | Where-Object { $_ -imatch "^$envCheckVariable=.+" }
if (-not $envCheck) {
throw "$envCheckVariable does not have a value. Did you run 'init.ps1 -InitEnv'?"
}
Write-Host "Keeping XM Cloud base image up to date" -ForegroundColor Green
docker pull "$($sitecoreDockerRegistry)sitecore-xmcloud-cm:$($sitecoreVersion)"
# Build all containers in the Sitecore instance, forcing a pull of latest base containers
Write-Host "Building containers..." -ForegroundColor Green
docker-compose build
if ($LASTEXITCODE -ne 0) {
Write-Error "Container build failed, see errors above."
}
if ($UseEdge) {
# Start the container using the edge override to only run traefik & host containers
Write-Host "Starting Sitecore hosts running againt edge..." -ForegroundColor Green
docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml -f .\docker-compose.edge.yml up -d
# Wait for Traefik to expose Rendering Host route
Write-Host "Waiting for MVP Rendering Host to become available..." -ForegroundColor Green
$startTime = Get-Date
do {
Start-Sleep -Milliseconds 100
try {
$status = Invoke-RestMethod "http://localhost:8079/api/http/routers/mvp-secure@docker"
}
catch {
if ($_.Exception.Response.StatusCode.value__ -ne "404") {
throw
}
}
} while ($status.status -ne "enabled" -and $startTime.AddSeconds(60) -gt (Get-Date))
if (-not $status.status -eq "enabled") {
$status
Write-Error "Timeout waiting for MVP Rendering Host to become available via Traefik proxy. Check mvp-rendering container logs."
}
Write-Host "Opening site..." -ForegroundColor Green
Start-Process https://$mvpHost
}
else {
# Start the Sitecore instance
Write-Host "Starting Sitecore environment, all roles running locally..." -ForegroundColor Green
docker-compose up -d
# Wait for Traefik to expose CM route
Write-Host "Waiting for CM to become available..." -ForegroundColor Green
$startTime = Get-Date
do {
Start-Sleep -Milliseconds 100
try {
$status = Invoke-RestMethod "http://localhost:8079/api/http/routers/cm-secure@docker" -TimeoutSec 600
}
catch {
if ($_.Exception.Response.StatusCode.value__ -ne "404") {
throw
}
}
} while ($status.status -ne "enabled" -and $startTime.AddSeconds(600) -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."
}
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"
}
# update XM Cloud Deploy plugin
$pluginJsonFiles = Get-ChildItem -path "$PSScriptRoot\.sitecore\package-cache\nuget\Sitecore.DevEx.Extensibility.XMCloud.*" -filter plugin.json -Recurse
$pluginJsonContent = Get-Content $xmCloudDeployConfig
foreach ($pluginJsonFile in $pluginJsonFiles) {
$pluginJsonContent | Set-Content -Path $pluginJsonFile.FullName
}
Write-Host "Logging into Sitecore..." -ForegroundColor Green
dotnet sitecore cloud login
# dotnet sitecore login --ref xmcloud --cm https://$xmCloudHost --allow-write true
dotnet sitecore connect -r xmcloud --cm https://$xmCloudHost --allow-write true --environment-name default
if ($LASTEXITCODE -ne 0) {
Write-Error "Unable to log into Sitecore, did the Sitecore environment start correctly? See logs above."
}
# 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
# Deploy the serialised content items
Write-Host "Pushing items to Sitecore..." -ForegroundColor Green
dotnet sitecore ser push
if ($LASTEXITCODE -ne 0) {
Write-Error "Serialization push failed, see errors above."
}
Write-Host "Opening site..." -ForegroundColor Green
Start-Process https://$xmCloudHost/sitecore/
Start-Process https://$mvpHost
Start-Process https://$sugconeuHost
Start-Process https://$sugconanzHost
}