Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to run side-by-side Sitecore XP0s #69

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Briefly, here's what you'll find in this repo:
* Example for running an out of the box Sitecore instance (see `getting-started`).
* Example solution for creating custom Sitecore images, with recommended folder structure for container development (see `custom-images`).
* Sample PowerShell scripts for container-based Sitecore instance preparation (`init.ps1`) and cleanup (`clean.ps1`).
* Docker compose file for running side-by-site XP0 instances with different versions of Sitecore (see `sitecore-compare`).
* Docker compose files for building Sitecore instances in various topologies (see `custom-images`).

Please refer to the [Sitecore Containers documentation](https://doc.sitecore.com/xp/en/developers/latest/developer-tools/containers-in-sitecore-development.html) for complete details, including running the examples and recommended usage.
Expand Down
42 changes: 42 additions & 0 deletions sitecore-compare/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
COMPOSE_PROJECT_NAME=sitecore-compare
SITECORE_DOCKER_REGISTRY=scr.sitecore.com/sxp/
SITECORE_VERSION_1=10.3.1-ltsc2022
SITECORE_VERSION_2=10.4.0-ltsc2022
SITECORE_ADMIN_PASSWORD=Password12345
SQL_SA_PASSWORD=Password12345
TELERIK_ENCRYPTION_KEY=
SITECORE_IDSECRET=
SITECORE_ID_CERTIFICATE=
SITECORE_ID_CERTIFICATE_PASSWORD=
SITECORE_LICENSE=
CM_HOST_1=xp103cm.localhost
CM_HOST_2=xp104cm.localhost
ID_HOST_1=xp103id.localhost
ID_HOST_2=xp104id.localhost
TRAEFIK_IMAGE=traefik:v2.2.0-windowsservercore-1809
TRAEFIK_ISOLATION=hyperv
ISOLATION=default
SOLR_CORE_PREFIX_NAME_1=Sitecore103
SOLR_CORE_PREFIX_NAME_2=Sitecore104
# You should change the shared secret to a random string and not use the default value
MEDIA_REQUEST_PROTECTION_SHARED_SECRET=

SOLR_PORT=8984
HTTPS_PORT=443
TRAEFIK_MANAGEMENT_PORT=8079
MSSQL_PORT=14330
XCONNECT_PORT_1=8081
XCONNECT_PORT_2=8082

SQL_SERVER=mssql
SQL_SA_LOGIN=sa
SQL_CUSTOM_DATABASE_PREFIX_UPDATE_FROM=
SQL_DATABASE_PREFIX_1=Sitecore103
SQL_DATABASE_PREFIX_2=Sitecore104

SITECORE_GRAPHQL_UPLOADMEDIAOPTIONS_ENCRYPTIONKEY=
SITECORE_GRAPHQL_ENABLED=true
SITECORE_GRAPHQL_EXPOSEPLAYGROUND=true

LOG_LEVEL_VALUE=INFO
EXTERNAL_IMAGE_TAG_SUFFIX=ltsc2022
13 changes: 13 additions & 0 deletions sitecore-compare/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/mssql-data/*
!/mssql-data/.gitkeep
/solr-data/*
!/solr-data/.gitkeep

/traefik/certs/*
!/traefik/certs/.gitkeep

/device-detection-data_1/*
!/device-detection-data_1/.gitkeep

/device-detection-data_2/*
!/device-detection-data_2/.gitkeep
5 changes: 5 additions & 0 deletions sitecore-compare/clean.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Clean data folders
Get-ChildItem -Path (Join-Path $PSScriptRoot "\mssql-data") -Exclude ".gitkeep" -Recurse | Remove-Item -Force -Recurse -Verbose
Get-ChildItem -Path (Join-Path $PSScriptRoot "\solr-data") -Exclude ".gitkeep" -Recurse | Remove-Item -Force -Recurse -Verbose
Get-ChildItem -Path (Join-Path $PSScriptRoot "\device-detection-data_1") -Exclude ".gitkeep" -Recurse | Remove-Item -Force -Recurse -Verbose
Get-ChildItem -Path (Join-Path $PSScriptRoot "\device-detection-data_2") -Exclude ".gitkeep" -Recurse | Remove-Item -Force -Recurse -Verbose
Empty file.
Empty file.
479 changes: 479 additions & 0 deletions sitecore-compare/docker-compose.yml

Large diffs are not rendered by default.

152 changes: 152 additions & 0 deletions sitecore-compare/init.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[string]
[ValidateNotNullOrEmpty()]
$LicenseXmlPath,

# We do not need to use [SecureString] here since the value will be stored unencrypted in .env,
# and used only for transient local example environment.
[string]
$SitecoreAdminPassword = "Password12345",

# We do not need to use [SecureString] here since the value will be stored unencrypted in .env,
# and used only for transient local example environment.
[string]
$SqlSaPassword = "Password12345"
)

$ErrorActionPreference = "Stop";

if (-not (Test-Path $LicenseXmlPath)) {
throw "Did not find $LicenseXmlPath"
}
if (-not (Test-Path $LicenseXmlPath -PathType Leaf)) {
throw "$LicenseXmlPath is not a file"
}

# Check for Sitecore Gallery
Import-Module PowerShellGet
$SitecoreGallery = Get-PSRepository | Where-Object { $_.SourceLocation -eq "https://nuget.sitecore.com/resources/v2/" }
if (-not $SitecoreGallery) {
Write-Host "Adding Sitecore PowerShell Gallery..." -ForegroundColor Green
Register-PSRepository -Name SitecoreGallery -SourceLocation https://nuget.sitecore.com/resources/v2/ -InstallationPolicy Trusted
$SitecoreGallery = Get-PSRepository -Name SitecoreGallery
}
# Install and Import SitecoreDockerTools
$dockerToolsVersion = "10.2.7"
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
Write-SitecoreDockerWelcome

###############################
# Populate the environment file
###############################

Write-Host "Populating required .env file variables..." -ForegroundColor Green

# SITECORE_ADMIN_PASSWORD
Set-EnvFileVariable "SITECORE_ADMIN_PASSWORD" -Value $SitecoreAdminPassword

# SQL_SA_PASSWORD
Set-EnvFileVariable "SQL_SA_PASSWORD" -Value $SqlSaPassword

# TELERIK_ENCRYPTION_KEY = random 64-128 chars
Set-EnvFileVariable "TELERIK_ENCRYPTION_KEY" -Value "'$(Get-SitecoreRandomString 128)'"

# MEDIA_REQUEST_PROTECTION_SHARED_SECRET
Set-EnvFileVariable "MEDIA_REQUEST_PROTECTION_SHARED_SECRET" -Value "'$(Get-SitecoreRandomString 64)'"

# SITECORE_IDSECRET = random 64 chars
Set-EnvFileVariable "SITECORE_IDSECRET" -Value (Get-SitecoreRandomString 64 -DisallowSpecial)

# SITECORE_ID_CERTIFICATE
$idCertPassword = Get-SitecoreRandomString 12 -DisallowSpecial
Set-EnvFileVariable "SITECORE_ID_CERTIFICATE" -Value (Get-SitecoreCertificateAsBase64String -DnsName "localhost" -Password (ConvertTo-SecureString -String $idCertPassword -Force -AsPlainText))

# SITECORE_ID_CERTIFICATE_PASSWORD
Set-EnvFileVariable "SITECORE_ID_CERTIFICATE_PASSWORD" -Value $idCertPassword

# SITECORE_LICENSE
Set-EnvFileVariable "SITECORE_LICENSE" -Value (ConvertTo-CompressedBase64String -Path $LicenseXmlPath)

##################################
# Get host names from .env
##################################

$CM_HOST_1 = Get-EnvFileVariable CM_HOST_1 -Path (Resolve-Path .\.env)
$ID_HOST_1 = Get-EnvFileVariable ID_HOST_1 -Path (Resolve-Path .\.env)
$CM_HOST_2 = Get-EnvFileVariable CM_HOST_2 -Path (Resolve-Path .\.env)
$ID_HOST_2 = Get-EnvFileVariable ID_HOST_2 -Path (Resolve-Path .\.env)

##################################
# Configure TLS/HTTPS certificates
##################################

Push-Location traefik\certs
try {
$mkcert = ".\mkcert.exe"
if ($null -ne (Get-Command mkcert.exe -ErrorAction SilentlyContinue)) {
# mkcert installed in PATH
$mkcert = "mkcert"
} elseif (-not (Test-Path $mkcert)) {
Write-Host "Downloading and installing mkcert certificate tool..." -ForegroundColor Green
Invoke-WebRequest "https://github.com/FiloSottile/mkcert/releases/download/v1.4.1/mkcert-v1.4.1-windows-amd64.exe" -UseBasicParsing -OutFile mkcert.exe
if ((Get-FileHash mkcert.exe).Hash -ne "1BE92F598145F61CA67DD9F5C687DFEC17953548D013715FF54067B34D7C3246") {
Remove-Item mkcert.exe -Force
throw "Invalid mkcert.exe file"
}
}
Write-Host "Generating Traefik TLS certificates..." -ForegroundColor Green
& $mkcert -install
& $mkcert -cert-file "$CM_HOST_1.crt" -key-file "$CM_HOST_1.key" "$CM_HOST_1"
& $mkcert -cert-file "$CM_HOST_2.crt" -key-file "$CM_HOST_2.key" "$CM_HOST_2"
& $mkcert -cert-file "$ID_HOST_1.crt" -key-file "$ID_HOST_1.key" "$ID_HOST_1"
& $mkcert -cert-file "$ID_HOST_2.crt" -key-file "$ID_HOST_2.key" "$ID_HOST_2"

}
catch {
Write-Host "An error occurred while attempting to generate TLS certificates: $_" -ForegroundColor Red
}
finally {
Pop-Location
}

################################
# Update traefik dynamic config
################################

try {

Write-Host "Updating .\traefik\config\dynamic\certs_config.yaml `..." -ForegroundColor Green

(Get-Content .\traefik\config\dynamic\certs_config.yaml) `
-replace '##CM_HOST_1##', $CM_HOST_1 `
-replace '##CM_HOST_2##', $CM_HOST_2 `
-replace '##ID_HOST_1##', $ID_HOST_1 `
-replace '##ID_HOST_2##', $ID_HOST_2 | `
Set-Content .\traefik\config\dynamic\certs_config.yaml `
}
catch {
Write-Warning $Error[0]
Write-Host "An error occurred updating .\traefik\config\dynamic\certs_config.yaml" -ForegroundColor Red
}


################################
# Add Windows hosts file entries
################################

Write-Host "Adding Windows hosts file entries..." -ForegroundColor Green

Add-HostsEntry "$CM_HOST_1"
Add-HostsEntry "$CM_HOST_2"
Add-HostsEntry "$ID_HOST_1"
Add-HostsEntry "$ID_HOST_2"

Write-Host "Done!" -ForegroundColor Green
Empty file.
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions sitecore-compare/traefik/config/dynamic/certs_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tls:
certificates:
- certFile: C:\etc\traefik\certs\##CM_HOST_1##.crt
keyFile: C:\etc\traefik\certs\##CM_HOST_1##.key
- certFile: C:\etc\traefik\certs\##ID_HOST_1##.crt
keyFile: C:\etc\traefik\certs\##ID_HOST_1##.key
- certFile: C:\etc\traefik\certs\##CM_HOST_2##.crt
keyFile: C:\etc\traefik\certs\##CM_HOST_2##.key
- certFile: C:\etc\traefik\certs\##ID_HOST_2##.crt
keyFile: C:\etc\traefik\certs\##ID_HOST_2##.key