Skip to content

Commit 79ade28

Browse files
authored
* Add SXA * Define tag in .env file * Add SXA Solr cores * Use Nuke.Build
1 parent dc3d01b commit 79ade28

18 files changed

+808
-83
lines changed

.env

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
SQL_SA_PASSWORD=my_Sup3rSecret!!
2-
SQL_DB_PREFIX=Sitecore
3-
4-
SOLR_HOST_NAME=solr
5-
SOLR_PORT=8983
6-
SOLR_SERVICE_NAME=Solr-6
1+
# Variables that are used in docker-compose files
2+
IMAGE_PREFIX=sitecore-docker_
3+
TAG=9.0.2
74

8-
XCONNECT_SITE_NAME=xconnect
9-
XCONNECT_SOLR_CORE_PREFIX=xp0
5+
SQL_SA_PASSWORD=my_Sup3rSecret!!
106

117
SITECORE_SITE_NAME=sitecore
12-
SITECORE_SOLR_CORE_PREFIX=Sitecore
13-
14-
CONFIG_PACKAGE=XP0 Configuration files 9.0.2 rev. 180604.zip
15-
SITECORE_PACKAGE=Sitecore 9.0.2 rev. 180604 (OnPrem)_single.scwdp.zip
16-
XCONNECT_PACKAGE=Sitecore 9.0.2 rev. 180604 (OnPrem)_xp0xconnect.scwdp.zip
17-
18-
SITECORE_LICENSE_FILE=license.xml

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
build/bin
2+
build/obj
3+
cores
4+
databases
15
files
26
logs
7+
tmp
8+
.tmp

.nuke

Whitespace-only changes.

CopyCores.ps1

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Script to copy Solr cores
2+
# Start and stop the Solr container and run this script.
3+
[CmdletBinding()]
4+
param(
5+
[Parameter(Mandatory=$false)]
6+
[string]$Container = 'sitecore-docker_solr_1',
7+
[Parameter(Mandatory=$false)]
8+
[string]$FromCoresFilePath = 'C:\solr\solr-6.6.2\server\solr',
9+
[Parameter(Mandatory=$false)]
10+
[string]$ToCoresFilePath = 'cores/'
11+
)
12+
13+
mkdir -Force -Path ${ToCoresFilePath}
14+
15+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_fxm_master_index ${ToCoresFilePath}
16+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_fxm_web_index ${ToCoresFilePath}
17+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_marketingdefinitions_master ${ToCoresFilePath}
18+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_marketingdefinitions_web ${ToCoresFilePath}
19+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_marketing_asset_index_web ${ToCoresFilePath}
20+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_marketing_asset_index_master ${ToCoresFilePath}
21+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_suggested_test_index ${ToCoresFilePath}
22+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_testing_index ${ToCoresFilePath}
23+
24+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_core_index ${ToCoresFilePath}
25+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_master_index ${ToCoresFilePath}
26+
docker cp ${Container}:${FromCoresFilePath}\Sitecore_web_index ${ToCoresFilePath}
27+
28+
docker cp ${Container}:${FromCoresFilePath}\xp0_xdb ${ToCoresFilePath}
29+
docker cp ${Container}:${FromCoresFilePath}\xp0_xdb_rebuild ${ToCoresFilePath}
30+
31+
# LCOW mount binds do not yet support locking
32+
# Replace native locking by simple locking
33+
gci ${ToCoresFilePath} -recurse -filter "solrconfig.xml" | ForEach { (Get-Content $_.PSPath | ForEach {$_ -replace "solr.lock.type:native", "solr.lock.type:simple"}) | Set-Content $_.PSPath }
34+
35+
# Fix wrong path configuration
36+
gci ${ToCoresFilePath} -recurse -filter "core.properties" | ForEach { (Get-Content $_.PSPath | ForEach {$_ -replace "config=conf\\solrconfig.xml", "config=solrconfig.xml"}) | Set-Content $_.PSPath }
37+
38+
# Remove all lock files
39+
Remove-Item -Recurse -Path ${ToCoresFilePath} -include *.lock

CopyDatabases.ps1

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[CmdletBinding()]
2+
param(
3+
[Parameter(Mandatory=$false)]
4+
[string]$Container = 'sitecore-docker_mssql_1',
5+
[Parameter(Mandatory=$false)]
6+
[string]$FromDatabaseFilePath = 'C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA',
7+
[Parameter(Mandatory=$false)]
8+
[string]$ToDatabaseFilePath = 'databases/'
9+
)
10+
11+
mkdir -Force -Path ${ToDatabaseFilePath}
12+
13+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Core_Primary.mdf ${ToDatabaseFilePath}
14+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Core_Primary.ldf ${ToDatabaseFilePath}
15+
16+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_ExperienceForms_Primary.mdf ${ToDatabaseFilePath}
17+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_ExperienceForms_Primary.ldf ${ToDatabaseFilePath}
18+
19+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_MarketingAutomation_Primary.mdf ${ToDatabaseFilePath}
20+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_MarketingAutomation_Primary.ldf ${ToDatabaseFilePath}
21+
22+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Master_Primary.mdf ${ToDatabaseFilePath}
23+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Master_Primary.ldf ${ToDatabaseFilePath}
24+
25+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Processing.Pools_Primary.mdf ${ToDatabaseFilePath}
26+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Processing.Pools_Primary.ldf ${ToDatabaseFilePath}
27+
28+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Processing.Tasks_Primary.mdf ${ToDatabaseFilePath}
29+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Processing.Tasks_Primary.ldf ${ToDatabaseFilePath}
30+
31+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_ReferenceData_Primary.mdf ${ToDatabaseFilePath}
32+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_ReferenceData_Primary.ldf ${ToDatabaseFilePath}
33+
34+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Master_Primary.mdf ${ToDatabaseFilePath}
35+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Master_Primary.ldf ${ToDatabaseFilePath}
36+
37+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Reporting_Primary.mdf ${ToDatabaseFilePath}
38+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Reporting_Primary.ldf ${ToDatabaseFilePath}
39+
40+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Web_Primary.mdf ${ToDatabaseFilePath}
41+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Web_Primary.ldf ${ToDatabaseFilePath}
42+
43+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Xdb.Collection.Shard0.mdf ${ToDatabaseFilePath}
44+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Xdb.Collection.Shard0_log.ldf ${ToDatabaseFilePath}
45+
46+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Xdb.Collection.Shard1_Primary.mdf ${ToDatabaseFilePath}
47+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Xdb.Collection.Shard1_Primary.ldf ${ToDatabaseFilePath}
48+
49+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Xdb.Collection.ShardMapManager.mdf ${ToDatabaseFilePath}
50+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Xdb.Collection.ShardMapManager_log.ldf ${ToDatabaseFilePath}
51+
52+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Messaging_Primary.mdf ${ToDatabaseFilePath}
53+
docker cp ${Container}:${FromDatabaseFilePath}\Sitecore_Messaging_Primary.ldf ${ToDatabaseFilePath}

README.md

+50-26
Original file line numberDiff line numberDiff line change
@@ -4,75 +4,99 @@ Run Sitecore 9 (with XConnect) using Docker and Windows containers.
44
This repository contains experimental code that we use in development setups. We do not consider the current code in this repository ready for production.
55
Hopefully this will help you to get up and running with Sitecore and Docker. By no means we consider ourselves Docker experts and thus expect these images to still contain a lot of bugs. Great help for creating this setup was provided by the [sitecoreops](https://github.com/sitecoreops/sitecore-images) and [sitecore-nine-docker](https://github.com/pbering/sitecore-nine-docker) repos. Please feel free to provide feedback by creating an issue, PR, etc.
66

7+
78
# Requirements
89
- Windows 10 update 1709 (with Hyper-V enabled)
910
- Docker for Windows (version 1712 or better): https://docs.docker.com/docker-for-windows/
1011
- Visual Studio 15.5.3
1112
- Sitecore installation files
13+
- [Nuke.build](https://nuke.build)
14+
1215

1316
# Build
1417
As Sitecore does not distribute Docker images, the first step is to build the required Docker images.
15-
For this you need the Sitecore installation files and a Sitecore license file. What files to use are set by environment variables (interpreted by docker-compose); download all the packages that are defined by variables in the `.env` file and place them in the `files` directory.
18+
19+
## Pre-build steps
20+
For this you need the Sitecore installation files and a Sitecore license file.
21+
What files to use are set in the [build configuration](./build/Build.cs).
1622

1723
The xp0 Sitecore topology requires SSL between the services, for this we need self signed certificates for the
1824
xConnect and SOLR roles. You can generate these by running the `./Generate-Certificates.ps1` script (note that this requires an Administrator elevated powershell environment and you may need to set the correct execution policy, e.g. `PS> powershell.exe -ExecutionPolicy Unrestricted`).
1925

20-
Next, modify the `.env` file and change the build parameters if needed:
21-
22-
| Field | Description |
23-
| ------------------------- | ------------------------------------------------ |
24-
| SQL_SA_PASSWORD | The password to use for the SQL sa user |
25-
| SQL_DB_PREFIX | Prefix to use for all DB names |
26-
| SOLR_HOST_NAME | Host name to use for the SOLR instance |
27-
| SOLR_PORT | Port to use for the SOLR instance |
28-
| SOLR_SERVICE_NAME | Name of the SOLR Windows service |
29-
| XCONNECT_SITE_NAME | Host name of the Xconnect site |
30-
| XCONNECT_SOLR_CORE_PREFIX | Prefix to use for the XConnect SOLR cores |
31-
| SITECORE_SITE_NAME | Host name of the Sitecore site |
32-
| SITECORE_SOLR_CORE_PREFIX | Prefix to use for the Sitecore SOLR cores |
33-
34-
Now perform the Docker build step:
26+
## Build
27+
Build all images using:
28+
```
29+
PS> nuke
3530
```
36-
PS> docker-compose build
37-
```
3831

3932
The build results in the following Docker images:
4033
- sitecore: IIS + ASP.NET + Sitecore
4134
- mssql: MS SQL + Sitecore databases
4235
- solr: Apache Solr
4336
- xconnect: IIS + ASP.NET + XConnect
4437

45-
As final step build all Solr indexes (populate and re-build indexes) from Sitecore (reachable at https://sitecore/sitecore), and perform a Docker commit for the Solr image to persist the changes (otherwise you will have to redo this step each time):
38+
and two SXA images:
39+
- sitecore-sxa
40+
- mssql-sxa
41+
42+
### Push images
43+
Push the Docker images to your repository, e.g:
4644
```
47-
PS> docker commit sitecoredocker_solr_1 sitecoredocker_solr:latest
45+
PS> nuke push
4846
```
4947

48+
5049
# Run
5150
Docker compose is used to start up all required services.
5251

5352
Place the Sitecore source files in the `.\wwwroot\sitecore` directory.
5453

54+
Create a webroot directory:
55+
```
56+
PS> mkdir -p wwwroot/sitecore
57+
```
58+
5559
Create the log directories which are mounted in the Docker compose file:
5660
```
5761
PS> ./CreateLogDirs.ps1
5862
```
5963

60-
Create a webroot directory:
64+
To start Sitecore;
6165
```
62-
PS> mkdir -p wwwroot/sitecore
66+
PS> docker-compose up
6367
```
6468

65-
To start Sitecore:
69+
or to start Sitecore with SXA:
6670
```
67-
PS> docker-compose up
71+
PS> docker-compose -f docker-compose.yml -f docker-compose.sxa.yml up
6872
```
6973

74+
Run-time parameters can be modified using the `.env` file:
75+
76+
| Field | Description |
77+
| ------------------------- | ------------------------------------------------ |
78+
| SQL_SA_PASSWORD | The password to use for the SQL sa user |
79+
| SITECORE_SITE_NAME | Host name of the Sitecore site |
80+
| IMAGE_PREFIX | The Docker image prefix to use |
81+
| TAG | The version to tag the Docker images with |
82+
83+
7084
## DNS
7185
To set the Docker container service names as DNS names on your host edit your `hosts` file.
7286
A convenient tool to automatically do this is [whales-names](https://github.com/gregolsky/whales-names).
7387

74-
## Log files
75-
Logging is set up to log on the host under the logs folder of this repository.
88+
## (Optionally) Obtain Solr cores
89+
Stop the `solr` container and copy the cores to your the `cores` directory:
90+
```
91+
PS> ./CopyCores.ps1
92+
```
93+
94+
## (Optionally) Obtain database files from images
95+
Stop the `mssql` container and copy the databases to the `databases` directory:
96+
```
97+
PS> ./CopyDatabases.ps1
98+
```
99+
76100

77101
# Known issues
78102
Docker for Windows can be unstable at times, some troubleshooting tips are listed below.

build.ps1

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[CmdletBinding()]
2+
Param(
3+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
4+
[string[]]$BuildArguments
5+
)
6+
7+
Write-Output "Windows PowerShell $($Host.Version)"
8+
9+
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { exit 1 }
10+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
11+
12+
###########################################################################
13+
# CONFIGURATION
14+
###########################################################################
15+
16+
$BuildProjectFile = "$PSScriptRoot\build\_build.csproj"
17+
$TempDirectory = "$PSScriptRoot\\.tmp"
18+
19+
$DotNetGlobalFile = "$PSScriptRoot\\global.json"
20+
$DotNetInstallUrl = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1"
21+
$DotNetChannel = "Current"
22+
23+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
24+
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
25+
$env:NUGET_XMLDOC_MODE = "skip"
26+
27+
###########################################################################
28+
# EXECUTION
29+
###########################################################################
30+
31+
function ExecSafe([scriptblock] $cmd) {
32+
& $cmd
33+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
34+
}
35+
36+
# If global.json exists, load expected version
37+
if (Test-Path $DotNetGlobalFile) {
38+
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
39+
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
40+
$DotNetVersion = $DotNetGlobal.sdk.version
41+
}
42+
}
43+
44+
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
45+
if ((Get-Command "dotnet" -ErrorAction SilentlyContinue) -ne $null -and `
46+
(!(Test-Path variable:DotNetVersion) -or $(& dotnet --version) -eq $DotNetVersion)) {
47+
$env:DOTNET_EXE = (Get-Command "dotnet").Path
48+
}
49+
else {
50+
$DotNetDirectory = "$TempDirectory\dotnet-win"
51+
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
52+
53+
# Download install script
54+
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
55+
md -force $TempDirectory > $null
56+
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
57+
58+
# Install by channel or version
59+
if (!(Test-Path variable:DotNetVersion)) {
60+
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
61+
} else {
62+
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
63+
}
64+
}
65+
66+
Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"
67+
68+
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false }
69+
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }

build.sh

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
echo $(bash --version 2>&1 | head -n 1)
4+
5+
set -eo pipefail
6+
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
7+
8+
###########################################################################
9+
# CONFIGURATION
10+
###########################################################################
11+
12+
BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj"
13+
TEMP_DIRECTORY="$SCRIPT_DIR//.tmp"
14+
15+
DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
16+
DOTNET_INSTALL_URL="https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh"
17+
DOTNET_CHANNEL="Current"
18+
19+
export DOTNET_CLI_TELEMETRY_OPTOUT=1
20+
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
21+
export NUGET_XMLDOC_MODE="skip"
22+
23+
###########################################################################
24+
# EXECUTION
25+
###########################################################################
26+
27+
function FirstJsonValue {
28+
perl -nle 'print $1 if m{"'$1'": "([^"\-]+)",?}' <<< ${@:2}
29+
}
30+
31+
# If global.json exists, load expected version
32+
if [ -f "$DOTNET_GLOBAL_FILE" ]; then
33+
DOTNET_VERSION=$(FirstJsonValue "version" $(cat "$DOTNET_GLOBAL_FILE"))
34+
if [ "$DOTNET_VERSION" == "" ]; then
35+
unset DOTNET_VERSION
36+
fi
37+
fi
38+
39+
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
40+
if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version) == "$DOTNET_VERSION") ]]; then
41+
export DOTNET_EXE="$(command -v dotnet)"
42+
else
43+
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
44+
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
45+
46+
# Download install script
47+
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
48+
mkdir -p "$TEMP_DIRECTORY"
49+
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
50+
chmod +x "$DOTNET_INSTALL_FILE"
51+
52+
# Install by channel or version
53+
if [ -z ${DOTNET_VERSION+x} ]; then
54+
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
55+
else
56+
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
57+
fi
58+
fi
59+
60+
echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)"
61+
62+
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false
63+
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"

0 commit comments

Comments
 (0)