Some time ago I've published one part of Build-Deploy-Test workflow, called PowerCore Deployment Framework, and now I'd like to bring it all together - describe how to setup automated build, deploy, and testing for any Sitecore website. And of course there will be another playground with complete source code - Build Playground.
I'll use LaunchSitecore website as an example and guide you through the Continuous Deployment setup from scratch.
- Sitecore Continuos Deployment: From Zero to Hero (Part 1: Build)
- Sitecore Continuos Deployment: From Zero to Hero (Part 2: Deploy)
The final goal can be described as following: on each commit to repository, I want test website to be created from scratch with the latest changes, as well as to be able to deploy the same package to production.
The Tools
First of all, we might need a build framework. Ideally, PowerShell-based... and there is a one called PSake. I'd like to highlight that it is not mandatory to use it but it makes build script much easier to use and maintain.
Also we'll need a Courier for package generation and a PowerCore for deployment. Yep, that's all. To sum it up:
How the PSake looks like from above? Here's the sample scripts that will give you brief overview:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
properties { | |
$buildFolder = Resolve-Path .. | |
$revision = "100500" | |
$buildNumber = "15" | |
} | |
task Package -depends Init, Upt, Zip | |
task Init { | |
# Copy Sitecore DLL's, etc. | |
} | |
task Upt { | |
# Create UPT package | |
} | |
task Zip { | |
# Zip the results | |
} |
Init
At this stage we will prepare Sitecore files to be copied to the solution folder (I guess you know that the best practice is not to add standard Sitecore files to the repository).
In my implementation, first I extract Sitecore files to some temporary storage (if they were not extracted before), and copy them to the project folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task Init { | |
if (-not (Test-Path $localStorage)) { | |
New-Item $localStorage -type directory -Verbose | |
} | |
if (-not (Test-Path $zipFile)) { | |
Copy-Item $distributivePath $zipFile -Verbose | |
} | |
if (-not (Test-Path $localStorage\$distributiveName)) { | |
sz x -y "-o$localStorage" $zipFile "$distributiveName/Website" | |
sz x -y "-o$localStorage" $zipFile "$distributiveName/Data" | |
sz x -y "-o$localStorage" $zipFile "$distributiveName/Databases" | |
} | |
if (Test-Path "$buildFolder\output") { | |
Remove-Item -Recurse -Force "$buildFolder\Output" | |
} | |
New-Item "$buildFolder\Output" -type directory | |
robocopy $localStorage\$distributiveName $buildFolder /E /XC /XN /XO | |
robocopy $localStorage\$distributiveName\Website\bin $buildFolder\Buildscript\Tools\Courier /E /XC /XN /XO | |
} |
Compile
Then compile the project using msbuild. We can do that as Sitecore DLL's referenced by project are already in place.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task Compile { | |
exec { msbuild $buildFolder\Website\LaunchSitecore.sln /p:Configuration=Release /t:Clean } | |
exec { msbuild $buildFolder\Website\LaunchSitecore.sln /p:Configuration=Release /t:Build } | |
} |
Courier
Let's create a package from serialized items and save it into \sitecore\admin\Packages folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task Courier { | |
New-Item $buildFolder\Data\serialization_empty -type directory -force | |
& "$buildFolder\Buildscript\Tools\Courier\Sitecore.Courier.Runner.exe" /source:$buildFolder\Data\serialization_empty /target:$buildFolder\Data\serialization /output:$buildFolder\Website\sitecore\admin\Packages\LaunchSitecoreItems.update | |
} |
Zip
And finally move the files around and package everything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task Zip { | |
$outputPath = "$buildFolder\output\LaunchSitecore.Build.$buildNumber.zip" | |
Copy-Item "$buildFolder\website\bin_Net4\*" "$buildFolder\website\bin\" | |
sz a $outputPath "$buildFolder\data" -xr!serialization* -mx1 | |
sz a $outputPath "$buildFolder\website" -mx1 | |
sz a $outputPath "$buildFolder\databases" -xr!*\Oracle\* -mx1 | |
} |
Variables from above scripts were defined as:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scriptRoot = Split-Path (Resolve-Path $myInvocation.MyCommand.Path) | |
if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) {throw "$env:ProgramFiles\7-Zip\7z.exe needed"} | |
set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" | |
properties { | |
$distributivePath = "C:\Sitecore 6.6.0 rev. 130404.zip" | |
$localStorage = "C:\LocalStorage" | |
$distributiveName = [System.IO.Path]::GetFileNameWithoutExtension($distributivePath) | |
$zipFile = "$localStorage\$distributiveName.zip" | |
$buildFolder = Resolve-Path .. | |
$buildNumber = "12345" | |
$tag_dir = "$localStorage\LiveSite" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clear-Host | |
remove-module [p]sake | |
import-module .\Tools\psake\psake.psm1 | |
$psake.use_exit_on_error = $true | |
Invoke-psake .\buildscript.ps1 Package -properties @{ buildNumber = '12345'; } |
Only 16 seconds total to build the package for deploying website from scratch! And I can tell you that with things like RAMDisk, this stuff can run in a few seconds - here's the real lightspeed.
What's next? Deploy it - Sitecore Continuos Deployment: From Zero to Hero (Part 2: Deploy).
No comments:
Post a Comment