Monday, May 20, 2013

Sitecore Continuos Deployment: From Zero to Hero (Part 1: Build)

During the past year I've learned a lot about importance of Continuous Integration for project success. Besides of quality and robustness improvements, automated builds and deployment simply make developers happier, as there is now much less stress / annoying tasks, and more time for fun stuff.

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.


This blog post is a part of the series:


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.


Let's start from Build. This is the first and the most important part of our Build-Deploy-Test (BDT) workflow.

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:

The following tasks are needed to create website package:

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.


Compile 
Then compile the project using msbuild. We can do that as Sitecore DLL's referenced by project are already in place.


Courier 
Let's create a package from serialized items and save it into \sitecore\admin\Packages folder


Zip
And finally move the files around and package everything


Variables from above scripts were defined as:

It seems unbelievable, but at this stage we already can create a package with all website files, items and databases by running the script. By the way, to run the script, I usually use the following snippet (which can be copy-pasted to TeamCity later, but let's talk about it a little bit later)

Where do you find the complete script? Check out this GitHub repository: https://github.com/adoprog/Sitecore-Build-Playground. It contains both build and deployment scripts, as well as a copy of LaunchSitecore website with serialized items. By the way, PSake build framework also outputs execution summary to console:


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.