I had, what I thought, was a simple job to do; but it took over two weeks of discovery to find out it actually was easy, but not quite in the way I was planning to do it.
I had two web services that I needed to host in Azure. For a temporary measure, I create a single Azure instance and this had a simple elevated start up task that installed required run-times and then downloaded 7zip file from Azure storage and then extracted this file.
I then connected to the instance via remote desktop, launched IIS Manager and created the web applications there. I also manually started a back end process.
The next step was to try and automate the deployment of this process using two instances. I moved the required database into SQL Azure which worked fine.
Next I created a new C# Azure project with an ASP.net web role and added the tasks to install the runtime and also looked up the commands required to add the website applications.
I hit a problem that I never really managed to solve where the installation of the C++ 10 runtime would just hang the start-up task. After spending around three days trying to diagnose what had happened I decided to start again from scratch.
I created a new VB Azure project with an ASP.net web role. I added the same task which ran a batch file. This time round the run-times installed with no problem. (I guess I’ll never know what went wrong with that one)
The next part of the script was to download and extract the 7zip archive file. (To download from storage I used the Azure Command Line tools from Rob Blackwell/Two10 Degrees: https://github.com/RobBlackwell/AzureCommandLineTools)
I then extracted the archive using 7zip command line tools (http://www.7-zip.org/download.html)
It was when I came to run AppCmd.exe to add the extracted web applications, I learned about the order that Tasks etc. are run in Azure. (After a day or so of tracking things down)
The following article helped clarify this a lot. (I’ve borrowed the picture from the article below) http://msdn.microsoft.com/en-us/library/windowsazure/hh127476.aspx
So basically, any start-up tasks would not be able to run scripts that try to modify the website (Like adding the web applications). I abandoned that idea.
Now there is an Elevated Simple task which installs the required run-times and downloads and extracts the files required.
Then there is an Elevated Foreground task which starts the back end process.
All that was left to do was get the web applications (Which were extracted by the Simple Task onto the C: drive)
After a lot more web searching I decided to modify the service definition file for the website and added the virtual applications to this file. (As described in this article: http://msdn.microsoft.com/en-us/library/windowsazure/gg433110.aspx )
I pointed the physical directory to where the application will be extracted to on the C drive of the instance. This caused a build error saying it couldn’t find the directories. I created these directories on the C drive of the machine I was publishing from which allowed the publish to complete.
Unfortunately the deployment got stuck in busy until I deleted it. (Waited a good few hours and tried a couple of times just in case of a “Glitch”).
As a last resort, I extracted the web applications and added the files to the web role’s project folder and then included them into the project. Next I modified the physical directory to a relative directory pointing to the included application directories.
Published and to my great surprise it actually work. Phew!
Took a few weeks but was a great learning process (If a bit frustrating at times )