There are many options to choose from to automate deployment. On my first web app, I used Github together with Windows Azure. In this post I will highlight the problems I faced and how I got over them. The first, and most important lesson I learned was this –
I’m not sure if every developer once made the mistake of putting private stuff in source control, I sure did and it bit me bad. When I found out I checked in a private connection string a couple of days after the fact, my response was to delete my repository. I’m pretty sure there is a way to untrack and remove a file from Github. I didn’t bother to research about it during that time though, perhaps I was in panic mode.
Here is what I found out on Azure. Your connection strings in web.config will get updated by what you have written in a configuration section at Azure portal. Here is a screenshot
Its found in the Application Settings section of your App Service. Just make sure the Name or the Key you write in Azure Portal matches the Name/Key of the setting in your development machine. Azure will then use the Value you wrote in Azure Portal (the private area) when you publish. Just put a dummy value on your development machine’s settings before you check in to Github. Please note that I haven’t tried using a different name on my Dev machine and on Azure configuration section to see if it’ll still work.
If you have complete control of your server, which you won’t have in an Azure App Service, you can save a configuration file that contains the private data on your server. You can then reference the file on your web.config. By the way, you can have a unique extension for these external files so you’ll know they have secret stuff.
For connection strings, use the configSource property to reference the file:
<connectionStrings configSource="secretStuff.config"><br /> <connectionStrings/>
For app settings, use the file property:
<appSettings file="secretStuff.config"><br /> <appSettings/>
The settings you have on the external file will then get merged on runtime.
This one took me some time to figure out. I kept getting deployment errors on Windows Azure. You set this up in the Deployment Options section of your App Service.
By the way Kudu is this nifty little tool that I just found out about while trying to fix the deployment errors I kept getting. I tried republishing the Web App, disconnecting and redeploying from Github, recreating the database and a couple of other things – trial and error – to fix the deployment problems. Then I found out simply deleting the repository folder and the wwwroot on Kudu’s debug console, then setting up deployment again fixes my issue. You can access Kudu by adding scm to your site url – _yoursite.scm.azurewebsites.net – _or by clicking Advanced Tools on the Development Tools of your App Service.
If you encounter this error – Azure: The system cannot find the path specified. There’s a quick fix I found on the Github forum, while on Kudu console you do these commands:
Go to – local/temp/webcompiler.[version]
Run – cmd /c prepare.cmd
That’s it! I hope this could help someone who wants to automate deployment using Github and Windows Azure.