It got better

We’ve been running automated deployments for about 4 weeks now and they’ve greatly reduced the amount of time we spend pushing code out for testing. Powershell turned out to be a bit more of a pain-in-the-asslearning curve than I expected. Discovering Scott Guthrie’s blog post about app_offline.htm simplified another issue of ours, maintenance pages during the release.

Our Xml Updater utility is done. Our TFSDeployer scripts are a bit more modular now. We decided to just deploy everything rather than cherry-picking changes (it only takes about 4 minutes to deploy anyhow). The only thing we can’t do yet is automatically apply database changes and deploy to web servers with file sharing disabled.

Incorporating the app_offline.htm functionality to take the site down before deploying, we ended up with a basic code block of:


function Deploy-Directory
{
param([string] $appSourcePath, [string] $appDestinationPath)

# create our destination if it's not already there
new-item -force -path $appDestinationPath -itemtype "directory" | out-null

# create app_offline.htm to take destination offline for maintenance
Offline-App $appDestinationPath

# delete everything from destination, except the offline page.
get-childitem $appDestinationPath -exclude "app_offline.htm" | remove-item -force –recurse

# copy the published website to our destination
get-childitem $appSourcePath | copy-item -force -recurse -destination $appDestinationPath

# remove app_offline.htm
Online-App $appDestinationPath

# create a build indicator
$buildFile = $appDestinationPath + "CurrentBuild.txt"
$TfsDeployerBuildData.BuildNumber + " deployed on " + $(get-date).ToString() > $buildFile
}

# Creates an app_offline.htm file to let everyone know the websites's down.
function Offline-App
{
param([string] $appDestinationPath)

$offlineFile = $appDestinationPath + "app_offline.htm"

$output = "<HTML>" +
"<HEAD><TITLE>App down for maintenance</TITLE></HEAD>" +
"<BODY>This website is temporarily offline while Build " + $TfsDeployerBuildData.BuildNumber + " is being deployed. " +
"Please try again in a few minutes. " +
"<!-- " +
" Adding additional hidden content so that IE Friendly Errors don't prevent" +
" this message from displaying (note: it will show a friendly 404" +
" error if the content isn't of a certain size)." +
"-->" +
"</BODY>" +
"</HTML>"

$output > $offlineFile
}

Leave a Reply

Your email address will not be published. Required fields are marked *