-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUp.ps1
77 lines (62 loc) · 2.72 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
[CmdletBinding(DefaultParameterSetName = "no-arguments")]
Param (
[Parameter(HelpMessage = "Name of the CM instance, used as prefix in the hostname. 'cm' is used by default.")]
[string]$CMName = "cm",
[Parameter(HelpMessage = "Name of the ID instance, used as prefix in the hostname. 'id' is used by default.")]
[string]$IDName = "id",
[Parameter(HelpMessage = "Domain name used for the hostnames and certificates. 'examples.local' is used by default.")]
[string]$EnvironmentDomain = "examples.local",
[Parameter(HelpMessage = "Path to the .env file to use. '.\.env.user' is used by default.")]
[string]$EnvFilePath = ".\.env.user",
[Parameter(HelpMessage = "Determines whether there will be docker-compose build or not.")]
[Switch]$SkipBuild,
[Parameter(HelpMessage = "Determines whether there will be a dotnet sitecore ser push + publish or not.")]
[Switch]$SkipPush
)
$ErrorActionPreference = "Stop";
$CMHost = "{0}.{1}" -f $CMName, $EnvironmentDomain
$IDHost = "{0}.{1}" -f $IDName, $EnvironmentDomain
# Double check whether init has been run
if (-not (Test-Path $EnvFilePath -PathType Leaf)) {
throw "There is no '$EnvFilePath' file. Did you run 'Init.ps1'?"
}
# Build the containers
if (-not $SkipBuild) {
docker-compose --env-file $EnvFilePath build
}
# Start the Sitecore instance
Write-Host "Starting Sitecore environment..." -ForegroundColor Green
docker-compose --env-file $EnvFilePath 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."
}
if (-not $SkipPush) {
dotnet sitecore login --cm "https://$CMHost/" --auth "https://$IDHost/" --allow-write true
if ($LASTEXITCODE -ne 0) {
Write-Error "Unable to log into Sitecore, did the Sitecore environment start correctly? See logs above."
}
Write-Host "Pushing latest items to Sitecore..." -ForegroundColor Green
dotnet sitecore ser push
if ($LASTEXITCODE -ne 0) {
Write-Error "Serialization push failed, see errors above."
}
dotnet sitecore publish
if ($LASTEXITCODE -ne 0) {
Write-Error "Item publish failed, see errors above."
}
}
Write-Host "Sitecore is online and ready." -ForegroundColor Green