How many times have you seen something like this:

Deployment instructions for Acme website XYZ:

1 - Grab the files from the latest CI build and copy to server

2 - Open SQL Server Management Studio

3 - Execute the CreateDatabase.sql script

4 - Execute the SeedDatabase.sql script

5 - Open IIS manager and create a new website called MyGreatWebsite.

6 - Create a new .Net 4.0 app pool, MyAppPool

7 - Add a web app App1 in MyGreatWebsite pointing at the copied files, running in MyAppPool.

8 - some other manual steps (eg. web.config changes, etc.)

Usually the database, website, etc will be created on the first install to a server and then, inevitably, "tweeked" over time (ie. people will semi-randomly mess with settings). So subsequent releases consist of just copying the files and modifying web.configs, etc.

There are a number of things wrong here...

You might have missed something

These instructions were probably written while the first deployment was being done and it would be quite easy to miss a step or configuration option. So when someone follows these instructions to commission a new test server 2 months later, they can't figure out why it's not working.

Configuration changes will get lost

When (not if) somebody realises the app pool needs to run as a different user, or the site bindings need to change, or whatever, they have to remember that the deployment instructions also need updating. Trust me, they won't (well, not all of them).

Manually following a set of instructions wastes time

I don't know about you, but my time could be much better spent writing code than following instructions like these. And, to put it into a business context, how long would it take you to setup a completely new server from scratch if, say, your main data-centre went offline and you had to setup a backup? How much money would the company lose in that time? And how confident would you be that the new setup was actually correct.

Don't write instructions, write scripts

All of the instructions in the list above can be scripted in batch files, powershell scripts, etc. Here are some useful tools:

  • robocopy - robust file copy, xcopy++
  • sqlcmd - SQL Server command line tool: run scripts, etc. from the command line
  • appcmd - IIS command line administration tool
  • Web Deploy - very powerful web site/app deployment tool

Make everything repeatable

You need to be starting from scratch every time, so make sure you have an equivalent teardown script to delete the database, website, etc. Then, when you run your deploy script you can be confident you've captured every step necessary to rebuild everything. When you've got to this point your deployments are not only simple to do (just run DeployAll.bat) but you won't have that nagging doubt in the back of your mind that you forgot to do step 24...

This obviously gets more complicated when you have changes to live databases (you can't just delete the DB and start again) - but you can either create matching update/rollback scripts or use DB projects in Visual Studio to handle these for you.

Script machine configurations too

Ideally you should also be automating the setup of your servers too using something like Chef or Puppet. But even if not, you can still automate installation of prerequisites such as the .Net runtime, etc. just using simple batch files.

Remember...

Humans are fallible but these computer things are really good at following sets of simple instructions - lets put them to work.