Complete guide to deployment automation of DotNetNuke websites

Introduction

In this article we will show how Appveyor can be used to increase the productivity of DotNetNuke developers by establishing an automated, robust and repeatable deployment process of DotNetNuke websites.

CMS and e-commerce websites is a special group of ASP.NET applications and finding a proper deployment solution might be a challenge:

  • Database is a core of such websites and moving database along with its initial data must be a part of the deployment process. SQL scripting approach does not work for moving large databases. Once deployed to staging or production the database is getting filled with real data and you are at risk of getting “locked” and not being able to easily pull down or export the data (“data gravity” problem).
  • In existing release management or continuous integration solutions deployment is usually a part of build process, but in case of CMS your primary work is not making an app from scratch by compiling it from sources, but rather authoring content, customizing appearance (styles, skins) and extending functionality of existing app with modules.

Appveyor is a cloud-based deployment automation system for ASP.NET apps trying to address these challenges. Simple command-line interface and build-in support for SQL databases makes it a perfect choice for deploying CMS and e-commerce websites.

The article examines practical scenarios that are part of daily routine of web shops, design agencies and individual developers creating DotNetNuke websites and modules on professional basis and continuously deploying DotNetNuke websites to their own servers for UAT, staging and production.

In this guide

Demo environment

For this tutorial we will have an environment consisting of one developer machine with Windows 8 and two dedicated servers with Windows Server 2012 for staging and production:

demo-environment

In the end of tutorial we’ll see how to leverage Azure and AWS clouds for staging and production.

Installing DotNetNuke on developer machine

If you have already installed DotNetNuke on your developer machine you may skip this section.

Yet there are many great videos and tutorials on how to install DotNetNuke on your machine we will recap the steps required to install the latest DotNetNuke 7 on a clean Windows 8 machine.

The list of system requirements can be found here. In short, we need:

  1. .NET 4.0
  2. IIS 7 or above
  3. SQL Server 2008 or above

Install SQL Server 2012 Express

Download the latest SQL Server 2012 SP1 Express from the official download page.

We choose SQLEXPRWT_x64_ENU.exe (use SQLEXPRWT_x86_ENU.exe for 32-bit Windows). “WT” means “with tools” which includes SQL Server Management Studio. The installation wizard is mostly OK with default options, but the main point while installing SQL Express is enabling “mixed” security mode to allow connections from ASP.NET using SQL Server authentication and adding local “administrators” group to SQL Server admins:

installing-sql-server-security

If you already have SQL Server installed you may check this MSDN article to make sure “mixed” security mode is enabled.

Enable IIS

To install IIS go to Windows Start screen, type “features”, click “Settings” tab and then select “Turn Windows Features on or off”.

Tick “Internet Information Services”, then expand “World Wide Web Services/Application Development Features” and tick “ASP.NET 3.5” and “ASP.NET 4.5” items – that’s pretty much OK to leave other items as is:

windows-features-iis

Make sure IIS is installed by opening browser and navigating to http://localhost. You should see IIS 8 welcome screen. Turn on intranet settings if asked by IE.

Download DotNetNuke 7 CE

Go to DotNetNuke CodePlex page, click “Downloads” and download “7.0.x – New Install” in recommended downloads.

Open “Downloads” folder in Explorer, right-click downloaded ZIP and select “Properties”, click “Unblock” button and then “OK”.

Right-click DNN zip and select “Extract all…”, specify c:\websites\dotnetnuke7 as destination folder – this will be DNN website root.

Create DNN database

You can use SQL Server Management Studio to create DNN database with SQL user account, but here we will give you a faster way to do that using SQL Server command line.

In Explorer navigate to “c:\Program Files\Microsoft SQL Server\110\Tools\Binn” and open command prompt with elevated permissions (File → Open command prompt → Open command prompt as administrator).

Run interactive SQLCMD session connected to the local SQL Server instance:

sqlcmd -S .\SQLEXPRESS

Create new “dotnetnuke7” database:

> CREATE DATABASE [dotnetnuke7]
> GO

Create “dotnetnuke7” SQL user account (change password to your own):

> CREATE LOGIN [dotnetnuke7] WITH PASSWORD='P@ssw0rd!', CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
> GO

Set “dotnetnuke7” user account as db owner of “dotnetnuke7” database:

> USE [dotnetnuke7]
> GO
> CREATE USER dotnetnuke7 FOR LOGIN dotnetnuke7
> GO
> exec sp_addrolemember 'db_owner', dotnetnuke7
> GO

Done, the database is ready for DNN installation!

Create DotNetNuke website

Open IIS Manager (Windows Start → type “iis” and hit “ENTER”).

Right-click “Sites” node and select “Add Website…”. Specify “dotnetnuke7” as site name, then select “c:\websites\dotnetnuke7” as a site root and specify port 8007 for binding:

creating-dnn-website

Click “OK” to create a web site and application pool. Do not browse web site yet!

Open command prompt and grant “modify” permissions to “dotnetnuke7” app pool account on web site root folder:

icacls c:\websites\dotnetnuke7 /grant "iis apppool\dotnetnuke7":(OI)(CI)M

Configure DotNetNuke

Open c:\websites\dotnetnuke7\web.config in Notepad and update connection strings in two places. Replace the entire “connectionStrings” section with this fragment (change to your password):

<connectionStrings>
    <add name="SiteSqlServer" connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=dotnetnuke7;User ID=dotnetnuke7;Password=P@ssw0rd!" providerName="System.Data.SqlClient" />
</connectionStrings>

and put the same connection string into “appSettings” section:

<appSettings>
    <add key="SiteSqlServer" value="Data Source=(local)\SQLEXPRESS;Initial Catalog=dotnetnuke7;User ID=dotnetnuke7;Password=P@ssw0rd!" />
...

web-config-connection-strings

Save changes to web.config.

Open browser and navigate to http://localhost:8007. Specify host password and database password at the bottom of the form:

dnn-configuration-screen-cropped

DNN installation wizard completes in seconds and you are done! Do whatever you need to customize your DNN portal: install additional modules, modify skins, update content of existing pages and create new ones.

Preparing a server for DotNetNuke deployment

Appveyor supports deployments to Windows Server 2008 R2 and Windows Server 2012.

Install IIS 8

Login to your server by RDC and click “Server Manager” icon in the task bar. Select “Add roles and features” and tick “Web Server (IIS)” on Roles step:

windows-2012-install-web-server-role

On “Role Services” step expand “Application Development” node and select both “ASP.NET 3.5” and “ASP.NET 4.5”:

windows-2012-install-web-server-services

Make sure IIS is installed by opening browser and navigating to http://localhost. You should see IIS 8 welcome screen. Turn on intranet settings if asked by IE.

To avoid annoying popups while trying to download something in IE disable enhanced security configuration. On Server Manager click “Local Server” and then click “On” against IE Enhanced Security Configuration to change its value to “Off” for both users and administrators.

Install SQL Server 2012

The process of installing SQL Server is exactly the same as for developer machine.

In the end of this tutorial we’ll show how to preserve web server performance by moving database out to Azure SQL or Amazon RDS.

Install Appveyor Agent

Appveyor Agent is a lightweight service that must be installed on all machines you want to deploy to. Technically, it is a client using long-polling over SSL channel to receive commands from Appveyor cloud service. It does not listen on any TCP ports and thus does not require firewall modifications.

Sign-up with Appveyor. After signing in to Appveyor web console click “Install Appveyor PowerShell” button (or use direct link).

Open Appveyor PowerShell (Windows Start → then type “appveyor” and ENTER).

Use the following command to authenticate the current PowerShell session with your Appveyor account (you will be asked for password):

PS> Set-AppveyorConnection <your-email>

To install Appveyor Agent and register the server as deployment environment run the following command:

PS> New-LocalEnvironment Staging <server-ip>

where <server-ip> is a public/external IP of staging server. “Staging” will be a display name for the environment.

To verify an agent is installed and can connect to Appveyor open “Environments” page and click environment details. Appveyor should have detected installed services on that server:

web-ui-environment-details

The server is ready for deployment.

Knowledge base articles to read:

Deploying to staging

Now, when you done with customization of your DotNetNuke website it’s time to deploy the initial version to staging environment for review.

Install Appveyor PowerShell

Appveyor PowerShell which includes cmdlets for packaging and deploying applications must be installed on developer machine. Use this link to Install Appveyor PowerShell.

Package DotNetNuke website and deploy the package

Open Appveyor PowerShell and authenticate:

PS> Set-AppveyorConnection <your-email>

Navigate to the website root folder:

PS> cd c:\websites\dotnetnuke7

and run the following command to create package configuration file:

PS c:\websites\dotnetnuke7> New-App

powershell-new-app

A new file appveyor.config will appear in the root folder containing the application configuration for packaging and deploying. If you check the contents of appveyor.config you will see that by analyzing web.config and other files in the application directory Appveyor was able to detect correct .NET framework version required to run DNN and found SQL database defined in “connectionStrings” section.

“variable” declaration for “sqlDatabase” asset tells Appveyor the place where connection string can be taken to export the database and updated during the deployment. But there is another place where connection string must be updated to support legacy modules – “appSettings” section. To have appSettings correctly updated with connection string during the deployment modify “configurationSettings” element as following:

<configurationSettings>
   <variable name="SqlConnectionString" provider="Xml" path="web.config" query="/configuration/connectionStrings/add[@name='SiteSqlServer']/@connectionString" />
   <variable name="SqlConnectionString" provider="Xml" path="web.config" query="/configuration/appSettings/add[@key='SiteSqlServer']/@value" />
</configurationSettings>

Now, package the app and upload it to Appveyor by running the command:

PS c:\websites\dotnetnuke7> Push-App

After the command has completed you can see an app on “Applications” page of web console:

powershell-push-app

web-ui-applications

Highlight an app and click Deploy button:

web-ui-new-deployment

Select “Staging” environment to deploy to and specify DNS name for the application. For deployment name you can use notation like [project]-[version] – this will be used as a prefix for deployment URL.

Once the deployment is finished you can browse it using URL:

web-ui-deployment-staging-details

Congratulations, you have successfully deployed DotNetNuke website to the staging!

You can create a new deployment from command line as well:

PS> New-Deployment dotnetnuke7 1.0.0 -Environment Staging -Name dnn-demo-v1

Returned deployment object containg JobId. You can query the status of background job using Get-BackgroundJob cmdlet.

Knowledge base articles to read:

After the initial version of website has been deployed to staging one could start updating site content on the staging and another member of your team could customize portal skins on their development machine. Going further we will explain how to move a ready website from staging to production as well as apply updated skin to both staging and production.

Moving website from staging to production

Now, when initial website content is updated it’s time to move it to production.

Setup production server

The process of setting up a production server is completely the same as for staging:

At the end you should see another environment on Environments page:

web-ui-two-environments

Copying the deployment

For demo purposes we’ve modified a headline on the home page:

modified-dotnetnuke-staging

To copy website from staging to production open its deployment details page and click “Copy” button.

Select “Production” environment and specify deployment DNS name – we’ll just add “-prod” suffix to distinguish it from staging:

web-ui-copying-deployment-to-production

Once application deployment has been successfully copied we can browse it using URL.

modified-dotnetnuke-production

DotNetNuke website has been copied along with its database in a few seconds!

Copying deployment from command line:

PS> Copy-Deployment dnn7-demo-v1 -Environment Production -Name dnn7-demo-v1-prod

Assigning domain to production deployment

Now as everything is working using Appveyor URLs we’d like to assign a real domain to our production website.

To assign a new domain to the application deployment open its details page and click “Add domain”:

web-ui-new-domain

Note, that http://www.dnn7-demo.com and dnn7-demo.com are separate domains and must be added separately. Under the hood when you map a domain to the application deployment Appveyor updates IIS website host headers and provisions a new DNS zone (if your account quota is not reached).

Open domain details screen to see DNS instructions. You may choose to use cloud DNS service provided by Appveyor or keep your existing DNS service:

web-ui-domain-details

Adding a new domain from command line:

PS> New-Domain www.dnn7-demo.com
PS> Add-DeploymentDomain dnn7-demo-v1-prod www.dnn7-demo.com

Setting up SSL

Appveyor provides full-featured SSL management for the deployed applications.

You can import existing SSL certificate having its PFX file or RSA keys or generate a new certificate request to send to certificate authority (CA).

To generate new certificate request open domain details and click “Generate SSL certificate request”:

web-ui-ssl-request

After certificate request is generated you can copy it and submit to CA. After you receive the certificate in response message click “Complete certificate request” button to finish the procedure:

web-ui-ssl-request-complete

You can generate self-signed certificate that will be valid for 1 year and can be used for development and testing purposes.

To apply certificate to production website click “Unmap domain” and then “Map domain” again to the same application deployment:

web-ui-domain-map-domain-with-ssl

If you check production website bindings you will see that certificate was imported to the production server and SSL binding added:

production-website-bindings

Appveyor supports wildcard certificates which have been always tricky to manage in IIS Manager.

Deploying website changes to staging and production

On developer machine we’ve updated a default “Gravity” skin. In “\Portals\_default\Skins\Gravity\skin.css” we changed the color of links to green and image borders to black:

updated-dnn-skin

Now, we want to test our changes on staging first. To push update to Appveyor use this command:

PS c:\websites\dotnetnuke7> Update-App

Appveyor detects which files were updated, added or removed and pushes changes to the cloud repository. On Applications page you can see that the last “revision” digit of application package has been changed to 1:

web-ui-updated-app

We can spin off a new deployment of this new 1.0.0.1 version, but for now we will apply changes to the staging website to showcase customer/team our progress. On staging deployment details page you will see a message that new updates are available:

web-ui-staging-deployment-with-updates

Select update and click “Update” button. Refresh staging website and enjoy the results:

web-ui-updated-staging

After the change has been approved by your team or customer apply the same change to production web site!

Applying update from command line:

PS> Update-Deployment dnn7-demo-v1 1.0.0.1

Using snapshots for rollbacks and backups

Appveyor allows making application snapshots. Snapshot is full copy of all application files and its database stored in a cloud. You can use snapshots for rolling back after authoring mistakes or as website backups.

Let’s see how it works. Our production website is online and we are modifying its content on production.

Before doing a significant change on production web site we go to its deployment details and click “Create backup” button:

web-ui-new-backup

We give a meaningful label to this snapshot and click “Create backup” button. Now we login to production website and “accidentally” delete “About Us” page:

production-website-with-deleted-page

Restoring website from a snapshot

To restore from snapshot open production deployment details page and click “Deploy” against “before removing a page” backup.

Select “Production” environment and specify a new deployment name, say dnn7-demo-v1-prod-rest.

Now, to move domains to this new deployment unmap them from “dnn7-demo-v1-prod” deployment and then map to the restored one. Delete “broken” production deployment.

Done, our original website with “About Us” page is back online:

restored-production-website

There are cmdlets to automate backup and restore process. See the full Appveyor PowerShell reference for more details.

Downloading production website to developer machine for troubleshooting

The first step is to install Appveyor Agent on developer machine and register it as a new environment.

As it is Windows 8 with UAC enabled we run Appveyor PowerShell console “As administrator” in elevated context (to allow Windows Service installation).

To register developer machine as environment run this command:

PS> New-LocalEnvironment “Developer machine” 127.0.0.1

You should see it in the list of Environments:

web-ui-three-environments

Now, make a backup of production deployment and then deploy backup to “Developer machine” environment. We use “dnn7-demo-local-test” as deployment name.

When finished you can browse production website and explore its database locally. That’s right Appveyor DNS service works for local network deployments too (in our case it resolves to 127.0.0.1):

local-test-website

The root folder of locally deployed website is c:\Applications\dnn7-demo-local-test.appvyr.net\website

Deploying to Windows Azure

By providing automated provisioning of Azure virtual machines and transparent migration of application databases between SQL Server and Azure SQL Appveyor can facilitate adoption of Windows Azure cloud for your development and production needs.

In this section we will provision a new Azure Virtual machine and Azure SQL database and then deploy DotNetNuke website to Azure.

To start working with Azure you have to download Windows Azure publishing settings for your Azure account. It is an XML file with subscription ID and X509 certificate.

To register Azure cloud in Appveyor open “Clouds” page and click “New Azure cloud”:

web-ui-new-azure-cloud

Specify cloud display name and select your publishing settings file to upload.

To provision new Azure virtual machine as a new environment open “Environments” page and click “New Environment”, then select “Windows Azure → Application Server”:

web-ui-new-azure-vm-environment

At the moment Appveyor provides two VM images in “East US” and “West US” regions only. Those images are full Windows Server 2008 R2 stacks with IIS and SQL Server 2008 R2 installed. You can use your own images for provisioning new VMs.

Click “Create environment” to start VM provisioning.

Please be patient as creating a new VM could take sometime between 20-30 minutes.

To provision a new Azure SQL server click “New environment” and then select “Windows Azure → Azure SQL Database Server”:

web-ui-new-azure-sql-environment

Make sure you are creating Azure SQL server in the same region and click “Create environment”.

To deploy DotNetNuke website to Azure open “Applications” and then click “Deploy” button in application row. Select “azure-vm-1″ as “To environment” and “azure-sql1″ in “SQL databases to” field:

web-ui-new-azure-deployment

Congratulations, you’ve just deployed your DotNetNuke website to Azure!

You can do with Azure deployment all the same actions: copy, move, backup. Whenever you deploy app to Azure SQL or back to SQL Server the database schema is automatically adjusted for corresponding database engine.

Deploying to Amazon Web Services

In this section we will provision a new Amazon EC2 instance and RDS instance with SQL Server Express and then deploy DotNetNuke website to AWS.

To register AWS cloud you need “Access Key ID” and “Secret Access Key” for your AWS account. To see your account security credentials open AWS portal at http://aws.amazon.com and then select “My Account/Console → Security Credentials” in the top menu:

aws-security-credentials

To register AWS cloud in Appveyor open “Clouds” page and click “New AWS cloud”. Specify cloud display name, Access Key ID and Secret Access Key.

To provision new EC2 instance as a new environment open “Environments” page and click “New Environment”, then select “Amazon Web Services → Application Server”:

web-ui-new-aws-vm

At the moment Appveyor provides two AMIs in “US East” and “US West” regions only. Those AMIs are full Windows Server 2008 R2 stacks with IIS and SQL Server 2008 R2 installed.

Click “Create environment” to start instance provisioning.

To provision a new RDS instance to host application database click “New environment” and then select “Amazon Web Services → SQL Server RDS”:

web-ui-new-aws-rds

Make sure you are creating RDS instance in the same region and click “Create environment”.

To deploy DotNetNuke to AWS follow the same instructions as for deploying to Azure.

Conclusion

This article has explained how Appveyor can be used to completely automate deployment of DotNetNuke websites across your own, off-premise and cloud environments. Many practical scenarios were reviewed to help you get started with Appveyor.

Additional resources:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s