views:

250

answers:

2

So I have an ASP.NET MVC website I am developing and never had a decent deployment strategy so making changes, especialy database scheme ones can involve a lot of steps and time.

Here are the steps I am looking todo and would like suggestions on how to do it or tools (preferably free). Feel free to point out any missing steps or things I am doing wrong.

Edit: I will list tools I have used to solve each stage

  1. Check out all code from source control (perforce)
  2. Build debug and relese version. Release version needs different connection strings in web.config. (MSBUILD)
  3. Run all unit tests
  4. For each page (aspx) combine all referenced JS files and inline code into one file. Same with css
  5. Minify said JS and CSS files.
  6. Backup live database schema and data
  7. deploy database schema changes to live server
  8. upload all files that are new or have changed to the server.
  9. Backup all code and my source control depository to external drive and possibly online.

I have it lucky that my site won't have any visitors between 1am and 4pm so all this can be done without the need for staging servers etc?

I know my question is long but this would probably help a lot of people.

+2  A: 

MSBuild (or likely any other build technology) is probably your best bet for accomplishing all these tasks automatically.

You can use MSBuild to do 1 through 4 with no problems. We update our web configs with MSBuild using an XMLUpdate task, and we also run some awk scripts to augment some of our generated code using an Exec task.

For #5 and #6, you'd again probably want to use Exec to execute some script to get the backup files and run them against the production instances, however I'm not a SQL admin so I have no idea if that's the best way, or if there are already MSBuild tasks for this.

For actual file copying, there is the Copy task, and likely others, but you may need to resort to xcopy or a custom script.

Managing the build of your product is a big job, but it's the exact reason that technologies like MSBuild and Ant were created.

womp
A: 

I have tried the following for deployment on a production server, using NAnt to handle the logic:

1) Check folder with latest release build for revision number.

If a newer revision is available:

2) Fetch file with compiled web site and database scripts (see below).

3) Take web site offline (add app_offline.htm).

4) Apply database scripts (see below).

5) Put web site online (delete app_offline.htm).


Concerning deploying changes to the database schema, I've been inspired by some posts by K. Scott Allen. A short version of these is:

1) Script each new change to the database schema (tables, indexes, seed data), and store each new change in separate files (e.g. schema-001.0001.sql, schema-001.0002.sql, etc.). Keep these files in a separate folder, e.g. sql\schema.

2) Script misc. objects (stored procedure, functions, triggers, and views) in separate files in separate folders, e.g. sql\procedures\uspGetProducts.sql, sql\procedures\uspUpdateProduct.sql, sql\functions\, sql\triggers\, sql\views\

3) When deploying: a) Drop all misc. objects from part 2, b) apply the schema changes from part 1 that have not been applied previuously, c) and finally recreate all misc. objects from part 2.

These scripts can be deployed automatically by e.g. Nant scripts on the production server.

Ole Lynge