This is part 3 of 3 for Windows Azure Websites - Custom Deployments
- Part 1 - Introduction to custom deployment
- Part 2 - Custom script generator
- Part 3 - Custom deployment using the custom script generator sample
In previous posts I talked about Windows Azure Website’s custom deployment feature and the tool to easily generate a deployment script, in this post I’ll do a step by step guide on writing a custom deployment script.
Let’s say we have two websites in azure, one is a node.js website and the other is an mvc4 web application, both sites sources are in the same repository so we need a deployment script that handles differently based on which website it is deploying.
Full sample repository
- Assuming git is installed and the websites are in a local git repository.
- Install node.js.
- Install azure-cli by
running the following command:
npm install azure-cli -g
(a) First let’s generate a deployment script for the node.js website:
- Go to the root of the repository.
- Enter the following command:
azure site deploymentscript --node --sitePath nodejs
- Where “nodejs” is the path to the node.js website directory.
(b) Let’s generate a deployment script for the mvc4 web application:
At the root of the repository enter the command:
azure site deploymentscript --aspWAP mvc4\Mvc4WebApplication\Mvc4WebApplication.csproj -s mvc4\Mvc4WebApplication.sln
- Rename deploy.cmd to deploy.mvc4.cmd:
move deploy.cmd deploy.mvc4.cmd
NOTE: You can also edit this generated file (deploy.cmd) with any custom steps you have, you can also test it on your machine simply by running it, it will publish your website to %REPOSITORY_ROOT%\artifacts.
(c) To decide which script should run, based on the website we are currently deploying, we’ll use the “app settings” feature in windows azure websites:
- Create a deploy.cmd file under the root of the repository with the following:
(d) Now let’s try to push our repository to our Windows Azure Website:
git push WA master
We receive an error and the deployment fails since we still haven’t set the app setting yet, so let’s do that.
Go to the website on windows azure management portal and add under the CONFIGURATION tab under “app settings” a setting with name SITE_FLAVOR and value nodejs/mvc3 (based on the current site we’re configuring).
Click on the “Save” button.
Now we can either push our changes again (we’ll need a new commit, even an empty one, otherwise it’ll tell us that nothing has changed and the deployment won’t reinitiate).
- Or we can go to the DEPLOYMENTS tab in Windows Azure portal, select the last deployment which failed and push the RETRY button to retry the deployment.
That’s it, now we have a working mvc4/node.js website
NOTE: Another improvement we could do here is to store the repository on GitHub/Bitbucket and connect them to our 2 sites, now every time we push to GitHub/Bitbucket, both of our sites will be deployed.
The repository I’ve used can be cloned from here.