Part 3 : Publishing your Orchard 1.7.1 website to Windows Azure Cloud Services

Posted Wednesday, Nov 06, 2013 3:00 AM EST


Arra Derderian


With the advent of Orchard 1.7.1 we now have the ability to easily publish right to Azure Cloud Services via TFS in the cloud or Visual Studio. This is a great feature because being able to deploy Orchard to Azure is a huge benefit! It provides scalability so we can run Orchard across multiple web roles and also take advantage of shared caching for lightning fast speed. We have two options here that I will discuss.

First off, take a look at this thread. https://orchard.codeplex.com/discussions/461305 There is a file missing from the code assets that is most likely now fixed, but the 1.7.1 source did not have it included. Not having this file will cause your deploy to fail on publish. You can just add it in there or get the latest code from codeplex.

The Azure 1.7 SDK included in Orchard 1.7.1 allows for a new concept called Web Role Content folders along with it's new AddRoleContent build target. You can look at the Orchard.Azure.CloudService.ccproj in a text editor and see this target :

<Target Name="BeforeAddRoleContent">

</Target>

This contains all the steps that used to be in the old Azure.proj file that would ship with Orchard. Now we can get all the Modules and Themes up to Azure using the default tooling.

Utilizing the Visual Studio Publish Command (Requires Azure Account)

You can simply open the /src/Orchard.Azure.sln file from your Orchard source code package. This file contains the Orchard.Azure.CloudService proejct which details your Orchard Cloud Service Role. You will notice there is a ton of new settings in there that you will need to fill out. The Data Storage connection string have not been separated out into two configuration items called Orchard.Azure.Media.StorageConnectionString and Orchard.Azure.Settings.StorageConnectionString. This is most likely so you can use another storage account that may be replicated via CDN or owned by someone else for all your media. Next, you will notice all the cache settings that are apparent. You will need to use these with Cloud Services because the Azure SLA requires two web role instances. If you choose to use 1 web role then you risk your site going down for maintenance at times. The other piece of advice I would give is to utilize two small web role instances. Extra small just does not cut it with Orchard. 

Once your settings are updated, you will need to make sure any custom modules you needed are added to the modules Solution folder and also referenced in the Orchard.Azure.Web project so they are pulled in during publish. Next, you will need to right-click on the Orchard.Azure.CloudService project in the solution and choose "Publish". 

This will bring up the Visual Studio publish dialog. You can then click "Sign in to download credentals" to get your publish.settings file for you Azure account. Before doing this you would want to create a new Cloud Service and a SQL Azure instance to be used moving forward. Click "Next" to continue on. 

You will then be asked to choose your Cloud Service endpoint, the environment, the build configuration, and the service configuration. Also choose Enable Remote Desktop in case you need to troubleshoot any issues. These settings are important and if you have published to Azure before you should be familiar with them. If you have not, then you will need become familiar with the concept of Production/Staging slots in Azure and the Service Configurations. For the most part, since it is a new service you can choose Production and, Release, and Default.

Once you click "Next" again you will be brought to the summary screen. You will want to click the "Save" icon in the top left of the dialog in order to save a PUBXML file inside your project. This will be important as it saves your settings for next time, and when using TFS to publish in the next step. If you are ready, click Publish and away you will go. web.config tramsforms and building the solution will occur and then you will be publishing to Azure. 

Once complete, you can hit your cloud service endpoint and you should get the "Welcome To Orchard" screen. You will want to point your Orchard instance to an existing SQL Azure instance. I find that I need to create the database called "Orchard" in SQL Azure prior to running the install and using an admin account for everything to go smoothly. You can always modify the permissions later once the site is created. When creating a new site you will also get some new folders in your storage acount called "Media" and "Sites" similar to in your normal file system. 

You should then be ready to go!

Utilizing Team Foundation Services in Windows Azure Cloud (Requires TFS Preview Account)

Quick Note: I recommend performing the approach above first in order to make sure you get no build errors and flush out any build/publish/deployment problems before going to TFS.

Another great way to deploy Orchard 1.7.1 is using Team Foundation Services in the Azure Cloud. This is great because developers can check-in code and simply queue a build to be pushed out to Azure on the fly. You first need to take your source code and map it to the root directory of the Orchard Solution. This is reuired because you need all the files in source control for building purposes. This is specifically important with the /lib directory. TFS by default will not check-in dll files and they get left out. It is important that on the first checkin you take these files out of the "Excluded" dialog of Visual Studio and include them for check-in. Otherwise it is quite the manual process after that. Once you have the entire code base into source control you can move on.

You then begin by following all the steps in the above section except clicking the "Publish" button at the end. This leaves you with your new PUBXML file in the Cloud Service account and all your modified .cscfg files. Check those in to source control because your service will need them during build and deployment.

Next, login to the Azure Managment Portal and bring up your Cloud Service details and choose the "Integrate source control" option.
 

This will have you link your TFS instance to your Azure Cloud Service. Choose the repository you created for your Orchard CMS project and click connect. Once doing this, it will allow you to publish from TFS to your Cloud Service. 

You will next want to open your Orchard.Azure.sln file inside Visual Studio. Make sure you are bound to your source control repository by choosing "Team Explorer" from Visual Studio. If you are you should get the "Home" panel for your project and then choose "Builds". This should bring up a list of all your build definitions. As you see below I renamed mine, but you should now have a default one showing there.

Right-click on the builf definition and choose "Edit Build Definition". There are a series of menu items on the left hand side and you need to go through and perform the following changes :

General

1. Change the Queue Processing to "Enabled".

Trigger

1. Change to Manual. (Unless you want every check to trigger a build.)

Source Settings

None

Build Defaults

None

Process

1. Required : Solution To Build : /src/Orchard.Azure/Orchard.Azure.sln. You will need to browse to this file.

2. Basic : I turn off all the items related to testing and indexing source so Unit tests are not run.

3. Advanced : Analyze Test Impact = False, Disable Tests = True

4. Publishing -- General : Deployment Settings name = {Your Cloud Service Name}

5. Publishing -- Azure Cloud Service : Alternate Cloud Service Name = {Your Cloud Service Name}, Alternate Deployment Label = {Your Cloud Service Name}, Alternate Publish Profile : {Browse to your PUBXML file you checked into TFS inside the Cloud Service Project}, Alternate Storage Account Name = {Your Storage Account Name}.

Click Save!

You are now ready to queue a build. Right click, on your Build Definition in Visual Studio and choose "Queue A New Build". This will queue a new build in TFS. It will take about 15 minutes for a full build to be published out. You will recieve an email if you setup alerts in TFS, or you can wait for it in the Visual Studio window. Whatever happens you will have a log to view in the end to determine what happened. Most of the errors you will get are due to a missing file that was not checked in. Just check it in and re-build. This is why I recommend doing it from Visual Studio first, to flush out these issues.

You are now ready to be working in a great environment with Azure, TFS, and Orchard CMS. So powerful! Thanks to the Orchard Team for their hard work on this.

Add a Comment