-
Notifications
You must be signed in to change notification settings - Fork 152
/
up.ps1
186 lines (159 loc) · 8.28 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
# DEMO TEAM CUSTOMIZATION - Add ability to skip building the containers, and use pre-release versions
[CmdletBinding(DefaultParameterSetName = "no-arguments")]
Param (
[Parameter(HelpMessage = "Whether to skip building the Docker images.")]
[switch]$SkipBuild,
[Parameter(HelpMessage = "Whether to set up the environment with pre-release version of Sitecore products (internal only) .")]
[switch]$PreRelease
)
# END CUSTOMIZATION
$ErrorActionPreference = "Stop";
. .\upFunctions.ps1
Validate-LicenseExpiry
$envContent = Get-Content .env -Encoding UTF8
$xmCloudHost = $envContent | Where-Object { $_ -imatch "^CM_HOST=.+" }
$sitecoreDockerRegistry = $envContent | Where-Object { $_ -imatch "^SITECORE_DOCKER_REGISTRY=.+" }
$sitecoreVersion = $envContent | Where-Object { $_ -imatch "^SITECORE_VERSION=.+" }
$ClientCredentialsLogin = $envContent | Where-Object { $_ -imatch "^SITECORE_FedAuth_dot_Auth0_dot_ClientCredentialsLogin=.+" }
# DEMO TEAM CUSTOMIZATION - Removed reading the dynamic Sitecore API key. We use a static API key.
$xmcloudDockerToolsImage = ($envContent | Where-Object { $_ -imatch "^TOOLS_IMAGE=.+" }).Split("=")[1]
$xmCloudHost = $xmCloudHost.Split("=")[1]
$sitecoreDockerRegistry = $sitecoreDockerRegistry.Split("=")[1]
$sitecoreVersion = $sitecoreVersion.Split("=")[1]
$ClientCredentialsLogin = $ClientCredentialsLogin.Split("=")[1]
if ($ClientCredentialsLogin -eq "true") {
$xmCloudClientCredentialsLoginDomain = $envContent | Where-Object { $_ -imatch "^SITECORE_FedAuth_dot_Auth0_dot_Domain=.+" }
$xmCloudClientCredentialsLoginAudience = $envContent | Where-Object { $_ -imatch "^SITECORE_FedAuth_dot_Auth0_dot_ClientCredentialsLogin_Audience=.+" }
$xmCloudClientCredentialsLoginClientId = $envContent | Where-Object { $_ -imatch "^SITECORE_FedAuth_dot_Auth0_dot_ClientCredentialsLogin_ClientId=.+" }
$xmCloudClientCredentialsLoginClientSecret = $envContent | Where-Object { $_ -imatch "^SITECORE_FedAuth_dot_Auth0_dot_ClientCredentialsLogin_ClientSecret=.+" }
$xmCloudClientCredentialsLoginDomain = $xmCloudClientCredentialsLoginDomain.Split("=")[1]
$xmCloudClientCredentialsLoginAudience = $xmCloudClientCredentialsLoginAudience.Split("=")[1]
$xmCloudClientCredentialsLoginClientId = $xmCloudClientCredentialsLoginClientId.Split("=")[1]
$xmCloudClientCredentialsLoginClientSecret = $xmCloudClientCredentialsLoginClientSecret.Split("=")[1]
}
#set nuget version
$xmCloudBuild = Get-Content "xmcloud.build.json" | ConvertFrom-Json
# DEMO TEAM CUSTOMIZATION - Custom rendering host name.
$nodeVersion = $xmCloudBuild.renderingHosts.PlayWebsite.nodeVersion
if (![string]::IsNullOrWhitespace($nodeVersion)) {
# DEMO TEAM CUSTOMIZATION - Custom rendering host name.
Set-EnvFileVariable "NODEJS_VERSION" -Value $xmCloudBuild.renderingHosts.PlayWebsite.nodeVersion
}
# DEMO TEAM CUSTOMIZATION - Ensure the right NodeJs version is installed
$currentNodeJsVersion = node -v
$currentNodeJsVersion = $currentNodeJsVersion.substring(1)
if ($currentNodeJsVersion -ne $nodeVersion) {
Write-Warning "ERROR: You are currently running NodeJs $currentNodeJsVersion and this project requires a different version. Please switch to NodeJs $nodeVersion. Then delete the /src/rendering/node_modules folder. Then run this script again."
}
# END CUSTOMIZATION
# Double check whether init has been run
$envCheckVariable = "SITECORE_ADMIN_PASSWORD"
$envCheck = $envContent | Where-Object { $_ -imatch "^$envCheckVariable=.+" }
if (-not $envCheck) {
# DEMO TEAM CUSTOMIZATION - Auto run init.ps1 if not run.
if (Test-Path "C:\License") {
Write-Host "Initializing environment using default values" -ForegroundColor Yellow
& .\init.ps1 -InitEnv -AdminPassword b -LicenseXmlPath C:\License\license.xml
if ($PreRelease) {
& .\init-ci.ps1 -PreRelease
}
else {
& .\init-ci.ps1
}
}
else {
throw "$envCheckVariable does not have a value. Did you run 'init.ps1 -InitEnv'?"
}
# END CUSTOMIZATION
}
Write-Host "Keeping XM Cloud base image up to date" -ForegroundColor Green
docker pull "$($sitecoreDockerRegistry)sitecore-xmcloud-cm:$($sitecoreVersion)"
Write-Host "Keeping XM Cloud Tools image up to date" -ForegroundColor Green
docker pull "$($xmcloudDockerToolsImage):$($sitecoreVersion)"
# DEMO TEAM CUSTOMIZATION - Add ability to skip building the containers.
if (-not $SkipBuild) {
# 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."
}
}
# END CUSTOMIZATION
# Start the Sitecore instance
Write-Host "Starting Sitecore environment..." -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"
} catch {
if ($_.Exception.Response.StatusCode.value__ -ne "404") {
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."
}
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"
}
#####################################
Write-Host "Logging into Sitecore..." -ForegroundColor Green
if ($ClientCredentialsLogin -eq "true") {
dotnet sitecore cloud login --client-id $xmCloudClientCredentialsLoginClientId --client-secret $xmCloudClientCredentialsLoginClientSecret --client-credentials true
dotnet sitecore login --authority $xmCloudClientCredentialsLoginDomain --audience $xmCloudClientCredentialsLoginAudience --client-id $xmCloudClientCredentialsLoginClientId --client-secret $xmCloudClientCredentialsLoginClientSecret --cm https://$xmCloudHost --client-credentials true --allow-write true
}
else {
dotnet sitecore cloud login
dotnet sitecore connect --ref xmcloud --cm https://$xmCloudHost --allow-write true -n 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."
}
# DEMO TEAM CUSTOMIZATION - Moved index rebuild
Write-Host "Pushing Demo Items" -ForegroundColor Green
dotnet sitecore ser push
# DEMO TEAM CUSTOMIZATION - Added robustness check
if ($LASTEXITCODE -ne 0) {
Write-Error "Serialization push failed, see errors above."
}
# END CUSTOMIZATION
# DEMO TEAM CUSTOMIZATION - Restart CM after deserialization to clear the caches
Invoke-WebRequest https://$xmCloudHost/Utilities/Restart.aspx
# DEMO TEAM CUSTOMIZATION - Moved index rebuild here.
# Rebuild indexes
Write-Host "Rebuilding indexes ..." -ForegroundColor Green
# DEMO TEAM CUSTOMIZATION - Added robustness check
dotnet sitecore index rebuild
if ($LASTEXITCODE -ne 0) {
Write-Error "Rebuild indexes failed, see errors above."
}
# END CUSTOMIZATION
# DEMO TEAM CUSTOMIZATION - Removed setting the dynamic Sitecore API key and pushing it to Sitecore. We use a static API key.
if ($ClientCredentialsLogin -ne "true") {
Write-Host "Opening site..." -ForegroundColor Green
# DEMO TEAM CUSTOMIZATION - Custom hostnames
Start-Process https://$xmCloudHost/sitecore/
# DEMO TEAM CUSTOMIZATION - Open the website
Start-Process https://www.xmcloudcm.localhost/
}
Write-Host ""
Write-Host "Use the following command to monitor your Rendering Host:" -ForegroundColor Green
Write-Host "docker compose logs -f rendering"
Write-Host ""