Posts tagged ASP.NET MVC
The release candidate repository
Jan 19th
This post is a part of automated deployment story
I am sorry you have to wait so long for a new episode of the story. The truth is, this episode was written a week ago and saved as a draft. Just before publishing I got an e-mail from the IT department that the solution I proposed (using SharePoint site) is not acceptable from the security point of view. They are not going to allow any access to the site from an automated process accounts. Period. So the blog post went to trash but not the idea. Here it is, reborn, better than ever!
Release candidate repository
I’ve taken the idea of release candidate repository from the Continuous Delivery book. The idea is, release candidate is not a term describing a binary package generate just before releasing, waiting for final tests and go-live flag. Instead, a Release candidate is every binary that passes unit tests (or commit stage tests how book authors tend to call them). The candidate then goes through various stages of the deployment pipeline, passing (or failing) integration tests, automated user acceptance tests, load tests, usability tests etc. During this journey, a candidate is deployed to various environments. Finally, a successful candidate ends up being deployed to production. As you probably expect, I was in desperate need of a tool that could track my RCs from the very beginning to the end of their lifetime. Buying an expensive and have-it-all tool was, of course, not an option.
Release Candidate Tracker
It took me one afternoon to hack a quick and dirty solution. As always, you can download it from github. Please don’t complain about the code quality. I know it’s not the cleanest code on the planet, but it works (or sort-of). RCT uses an embedded RavenDB database to store information. The database files are stored in the App_Data folder. If I understand Raven’s license correctly, you can use RCT anywhere you want, also in commercial environment.
Workflow
Here’s the workflow describing the typical usage scenario of RCT. First, the build script (MSBuild in my case) creates a release candidate after successfully running unit (commit stage) tests. To achieve this, it uses curl tool to call RCT API.
$id = .\curl -s --data "State=${state}&VersionNumber=${version}&ProductName=${product}" "${server}/ReleaseCandidate/Create"
if ($id -ne $null) {
.\curl -s --upload-file $scipt_file "${server}/ReleaseCandidate/AttachScript/${id}"
}
The first call creates a RC entity while the second one attaches a generated deployment bootstrap script. At this point, a candidate is in initial UnitTestsPassed state. You can see it on the release candidate list
The subsequent stages exercise the candidate using various test suites: integration, user acceptance and so on. However, before the candidate can be tested, it has to be deployed to a suitable test environment. Here comes another feature of RCT — the deployment bootstrap script. You can download it simply by clicking a ‘Deploy’ link on the candidate list. If you want, you can even associate the .ps1 extension with PowerShell so that it will be automatically executed. The script (which will be covered in detail in later episodes) starts the deployment process. Eventually, a deployment script completes the deployment and updates the state of the candidate. There’s another API call and another script that does this
.\curl -s --data "Environment=${environment}&VersionNumber=${version}" "${server}/ReleaseCandidate/MarkAsDeployed"
After executing the tests, the state of the candidate needs to be updated to reflect the result. Here’s a script for this task
.\curl -s --data "State=${state}&VersionNumber=${version}" "${server}/ReleaseCandidate/UpdateState"
Eventually, is the candidate manages to successfully pass all the tests, it can be potentially deployed to production. Of course not every successful candidate ends up on production. Each change of candidate state is reflected on its detail view page
Any contributions to RCT are, of course, more than welcome. Happy deploying!
Building an embedded MVC server
Feb 4th
During yesterday’s blog reading session I came across two interesting posts. First one was about building a web server using WCF. The other one was about testing ASP.NET MVC as a whole, not only controllers, by hosting ASP.NET in process.
I realized that by combining these two not very common usages of these technologies I can build an even more uncommon one. I could use WCF to receive requests and send response and ASP.NET MVC to generate content. The goal would be to get it to the state, when I could reference an assembly (a class library) containing controllers and views and start a web server using these in my console application or Windows service.
Now, probably, you want to ask, why on earth would I need such a feature? Isn’t IIS the place to host your web applications? My scenario, which I think is quite interesting, it to add HTTP/HTML based diagnostics to a Windows service. Want to check in log paths are OK? Just connect to it using browser. Want to run some diagnostics against disk share paths or database table permissions? Just write some code to generate a report and make it accessible via a controller.
I encountered some interesting challenges I want to share with you. First of all, how ASP.NET MVC is quite dependent on ASP.NET infrastructure. Some request/context related classes are not a big problem thanks to System.Web.Abstractions dll. The case if far worse with default view engine (aspx/ascx) which uses directly System.Web. I wasn’t able to find out how could I use the compilation feature without starting ASP.NET runtime in AppDomain, so I decided to give up and start the ASP.NET.
(I am not very happy with this solution and I will try to use another view engine to check whether there are other hard ASP.NET dependencies. If not, I will happily get rid of it, since it complicates stuff, a lot — read on)
ASP.NET runtime could be started only in a brand new AppDomain to which you don’t have to access before it starts. It is a big problem because when you start the runtime, you pass it a custom type which is instantiated ‘on the other side’ and lets you configure and manipulate the domain. By default ASP.NET searches for dll in the bin subdirectory of main app directory, so if you want to run it in context of console application, you have to create bin directory where you have your dlls and put there one containing that aforementioned ‘integration’ type. At least it works and this is the trick this article uses.
Mine was to add assembly load directives to web config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;"/>
</assemblyBinding>
</runtime>
The ‘;’ character is critical. Because of it this private path means ’search in bin subdirectory of application base dir and in the application base dir‘. The latter is represented by an empty string, ‘;’ is just a separator.
Other elements of solution include custom virtual path provided (using aspx/ascx files embedded in an assembly) and some hackyish code I am not very proud of. But remember, that is only a very quick and very dirty proof-of-concept.
You can download the code here. It requires ASP.NET MVC 1.0 to run. If you have any ideas (besides that code is horrible
), please leave a comment.





