-
Notifications
You must be signed in to change notification settings - Fork 19
/
init-ci.ps1
94 lines (84 loc) · 3.88 KB
/
init-ci.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
Param (
[Parameter(
HelpMessage = "Demo version used in image tagging.")]
[string]$DemoVersion = "latest"
,
[Parameter(
HelpMessage = "Internal ACR use by the demo team")]
[string]$DemoTeamRegistry = ""
,
[Parameter(
HelpMessage = "Internal Sitecore ACR")]
[string]$SitecoreRegistry = "scr.sitecore.com/"
,
[Parameter(
HelpMessage = "Process Isolation to use when building images")]
[string]$IsolationMode = "hyperv"
,
[Parameter(
HelpMessage = "Windows image version")]
[string]$WindowsVersion = "ltsc2019"
,
[Parameter(
HelpMessage = "Sitecore version")]
[string]$SitecoreVersion = "10.1.0"
)
$ErrorActionPreference = "Stop";
Write-Host "Preparing your Sitecore Containers environment!" -ForegroundColor Green
################################################
# Retrieve and import SitecoreDockerTools module
################################################
# Set correct TLS version
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Check for Sitecore Gallery
Import-Module PowerShellGet
$SitecoreGallery = Get-PSRepository | Where-Object { $_.Name -eq "SitecoreGallery" }
if (-not $SitecoreGallery) {
Write-Host "Adding Sitecore PowerShell Gallery..." -ForegroundColor Green
Register-PSRepository -Name SitecoreGallery -SourceLocation https://sitecore.myget.org/F/sc-powershell/api/v2 -InstallationPolicy Trusted -Verbose
$SitecoreGallery = Get-PSRepository -Name SitecoreGallery
}
else {
Write-Host "Updating Sitecore PowerShell Gallery url..." -ForegroundColor Yellow
Set-PSRepository -Name $SitecoreGallery.Name -Source "https://sitecore.myget.org/F/sc-powershell/api/v2"
}
#Install and Import SitecoreDockerTools
$dockerToolsVersion = "10.1.4"
Remove-Module SitecoreDockerTools -ErrorAction SilentlyContinue
if (-not (Get-InstalledModule -Name SitecoreDockerTools -RequiredVersion $dockerToolsVersion -ErrorAction SilentlyContinue)) {
Write-Host "Installing SitecoreDockerTools..." -ForegroundColor Green
Install-Module SitecoreDockerTools -RequiredVersion $dockerToolsVersion -Scope CurrentUser -Repository $SitecoreGallery.Name
}
Write-Host "Importing SitecoreDockerTools..." -ForegroundColor Green
Import-Module SitecoreDockerTools -RequiredVersion $dockerToolsVersion
###############################
# Populate the environment file
###############################
Write-Host "Populating required demo team .env file values..." -ForegroundColor Green
if ([string]::IsNullOrEmpty($DemoTeamRegistry)) {
# if it wasn't passed as a parameter, let's try to find it in environment
$DemoTeamRegistry = $env:DEMO_TEAM_DOCKER_REGISTRY
if ($null -eq $DemoTeamRegistry) {
# Environment variable not found. Try to set it using demo team function.
Set-DemoEnvironmentVariables
refreshenv
}
# Retry
$DemoTeamRegistry = $env:DEMO_TEAM_DOCKER_REGISTRY
if ($null -eq $DemoTeamRegistry) {
Write-Host "The DEMO_TEAM_DOCKER_REGISTRY environment variable is not set. Please:" -ForegroundColor Red
Write-Host " 1. Ensure you are using the team's PowerShell profile." -ForegroundColor Red
Write-Host " 2. From a new PowerShell window, re-run this command." -ForegroundColor Red
throw
}
}
$NanoserverVersion = $(if ($WindowsVersion -eq "ltsc2019") { "1809" } else { $WindowsVersion })
Set-DockerComposeEnvFileVariable "SITECORE_DOCKER_REGISTRY" -Value $SitecoreRegistry
Set-DockerComposeEnvFileVariable "REGISTRY" -Value $DemoTeamRegistry
Set-DockerComposeEnvFileVariable "DEMO_VERSION" -Value $DemoVersion
Set-DockerComposeEnvFileVariable "SMTP_CONTAINERS_COUNT" -Value 0
Set-DockerComposeEnvFileVariable "ISOLATION" -Value $IsolationMode
Set-DockerComposeEnvFileVariable "WINDOWSSERVERCORE_VERSION" -Value $WindowsVersion
Set-DockerComposeEnvFileVariable "NANOSERVER_VERSION" -Value $NanoserverVersion
Set-DockerComposeEnvFileVariable "SITECORE_VERSION" -Value $SitecoreVersion
Write-Host "Done!" -ForegroundColor Green