Deploying ASP.NET Web applications

& Trade Me

By Richard Simes / @rdsimes

Why do I have to give this talk?

This should be easy?
All we need is a git push
There are lots of really cool deploy tools out there.
Most arent .NET specific.

	
	From: richard.simes@trademe.co.nz
	To: DevTeam@trademe.co.nz
	Subject: Reminder - run the unit tests
	----------------------------------------------------

	Hey guys,
	Just a reminder....
	Please remember to run the unit tests before you deploy.
	For those of you this isn't already obvious to, please 
	dont deploy anything if they fail?

	Cheers,
	Richard
	
					

	From: richard.simes@trademe.co.nz
	To: DevTeam@trademe.co.nz
	Subject: Reminder - update from VSS before deploying
	----------------------------------------------------

	Hey guys,
	Just a reminder....
	Please remember to get the latest from VSS before you 
	deploy anything.

	Cheers,
	Richard

					

What do we need in a deployment tool

  1. Deploy from source control
  2. Multi servers
  3. Control
  4. Zero downtime
  5. Testable, deployable
  6. Fast rollback

Options

  • Publish from Visual Studio
  • Web Deployment Projects
  • ms web deploy
  • Chuck Norris
  • Roll-your-own

Web deploy

Not a bad option. Probably.
Where is the documentation?

Chuck Norris/Dropkick


Define(settings =>
{
    DeploymentStepsFor(Db,
	   s =>
	   {
	       s.RoundhousE()
	           .ForEnvironment(settings.Environment)
	           .OnDatabase(settings.DbName)
	           .WithScriptsFolder(settings.DbSqlFilesPath)
	           .WithDatabaseRecoveryMode(settings.DbRecovery)
	           .WithRestorePath(settings.DbRestorePath)
	           .WithRepositoryPath("somewhereoutthere")
	           .WithVersionFile("_BuildInfo.xml")
	           .WithRoundhousEMode(settings.RoundhousEMode)
	           ;
	   });

    DeploymentStepsFor(Web,
       s =>
       {
           s.CopyDirectory("..\_PublishedWebSites\WebAppName").To("{{WebsitePath}}").DeleteDestinationBeforeDeploying();

           s.CopyFile(@"..\environment.files\{{Environment}}\{{Environment}}.web.config").ToDirectory(@"{{WebsitePath}}").RenameTo(@"web.config");

           s.Security(securityOptions =>
           {
               securityOptions.ForPath(settings.WebsitePath, fileSecurityConfig => fileSecurityConfig.GrantRead(settings.WebUserName));
               securityOptions.ForPath(Path.Combine(settings.WebsitePath, "logs"), fs => fs.GrantReadWrite(settings.WebUserName));
               securityOptions.ForPath(@"~\C$\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files", fs => fs.GrantReadWrite(settings.WebUserName));
               if (Directory.Exists(@"~\C$\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files"))
               {
                   securityOptions.ForPath(@"~\C$\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files", fs => fs.GrantReadWrite(settings.WebUserName));
               }
           });
       });
Dropkick example

Rolling your own

Maybe not such a bad option
It can be a lot of work
Please open source it

Deploying from source control

Continuous Integration - Team City
Source control - mercurial

Nuget, NUnit, JS/css minification

web.config

  • Transformations can suck
  • Config changes require a deploy?
  • Why use for settings?
  • Maybe I just hate XML

Push the button

Deploying to web

Take a backup
Copy the build in parallel, to all servers
Copy to a temporary location
Incremental changes?

Database deploy

We have ~20 database servers.
Get a list of updated stored procs & UDFs
Look up all their targets (some may have multiple)

Control


alter table auction alter column auctionid bigint; /* Hmmm? */
					

Scott Gu's worst post?

Downtime

Deploy all the time
Smaller deploys
Sessions will be lost

OK: SQL Server Mode
Better: Don't use sessions
You'll find other things that break
Deploy often and fix quickly

Fast rollback

When things go wrong, recover fast
Keep the previous version on every server
Monitor everything
Rollback in seconds, not minutes

Yep, Database rollback too...
but you probably need to test that

ABORT!

Summary

  • Tools do exist!
  • Deploy from source
  • Automate almost everything
  • Deploy frequently
  • Rollback fast

Thanks! Questions?

Richard Simes
@rdsimes

Links

Troy Hunt - You're deploying it wrong
Chuck Norris - Dropkick
Chuck Norris - RoundhousE