CI with MVC4 and Linux? No Problem

There are a lot of tools out there that we can use to automate our awesomeness. One of those easy/free/fun tools is a continuous integration (CI) server. Since we are building in Windows and deploying to Linux, we can go ahead and upgrade a CI server from 'important' to essential. There are various products out there that can accomplish this; I'm going with what I know and that is TeamCity from JetBrains.

On our Ubuntu box, after we finish the easy as candy install, we're going to want to install Mono. Check out this previous post on how to do that and set it up in your /etc/environment.

Now that Mono is rocking, lets hop over to our CI install. At the time of this post, the latest version of TeamCity is 7.0.2a. Looking at the code below, we're going to install Java, pull down the latest version of the TeamCity linux tar, decompress it, switch directories and fire it up :

sudo apt-get install openjdk-7-jre
wget - http://download.jetbrains.com/teamcity/TeamCity-7.0.2a.tar.gz
tar xfz TeamCity-7.0.2a.tar.gz
cd Teamcity
sudo ./bin/runAll.bat start

Pretty easy right? Lets check out our web interface:TeamcityWelcome

Yay! Everything works! You're also at a ubiquitous web interface which will likely give the Softie in you some solace. There are tons of resources online for setting up your project in TeamCity to check it out, build it, run tests, deploy, yada yada yada. If you are just getting started, I highly recommend Troy Hunt's post. You can also install Ruby on this server and have a wonderfully awesome auto-deployment method via Capistrano. If you are interested in deploying with Capistrano, let me know I'll try to barf out a quick post on it. This is a pretty short and to the point post, if it needs more content with regards to project checkouts and stuff, let me know and I can barf that out as well.

Running ASP.NET MVC4 on Ubuntu 12.04

The single most question I get regarding our Hello Postgres series over Tekpub is "How are you running your app on Linux?" As much as I enjoy sending volleys of fragmented explanations over emails to people, I decided it might be in everyone's best interest if I just blog it out. Technology moves fast... like super fast. So instead of showing you how to deploy an old and busted MVC3 app to a "has been" Ubuntu 11.10, we're going to be going with MVC4 and Ubuntu 12.04. We're so bleeding edge you can call us cutters!

I'm not going to show you how to set up and install your Ubuntu Server, as there is a ton of internet out there that can handle that for you and the installer itself is pretty hard to mess up. What I will cover is what to do after that last reboot where it is just you and Bash, together... at last.

SSH into your fancy new Ubuntu box with Putty and Run this:
sudo apt-get update && sudo apt-get -y install git-core curl python-software-properties

This is going to let us add the ppa(think of this as a package location) to install a current nginx:
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update && sudo apt-get -y install nginx

Yes! We can now git things, we can curl things, and we can nginx things! Rawwrr!!! Let's kick some other processes to the curb... like that skank MySQL and that wet blanket Apache:
sudo update-rc.d mysql remove &&
sudo update-rc.d apache2 remove && mkdir mycoolapp

Now for the fun part, let's get Mono up and running. We really want the latest version of Mono, and like Nuget, not all packages in Ubuntu stay current. The fix for this in the mono world is to just grab this dudes install script and go have a drink because it takes a bit to finish:
mkdir mono-2.11
cd mono-2.11
wget --no-check-certificate https://github.com/nathanb/iws-snippets/raw/master/mono-install-scripts/ubuntu/install_mono-2.11.sh
chmod 755 install_mono-2.11.sh
./install_mono-2.11.sh

Now to check that we have the current version, we just run the following:
/opt/mono-2.11/bin/mono -V

Cool! We're current, but what we really need is to just be able to run "mono -V" anywhere we want. We can do that by modifying our /etc/environment file:
sudo nano /etc/environment
#then insert ":/opt/mono-2.11/bin" at the end of that path string. Log out, log in for it to take effect.

I don't now about you, but all this sys-admin crap is putting me to sleep and I want to code. Back on our Widows/Dev box, we're going to new up an empty MVC4 project (up to you to figure out how to get MVC4 going on your box, I used Web Platform Installer). After the project is new'ed up:

  • Add a controller
  • Add a view based on that controller
  • Hit F5 and make sure it works
  • Remove the EntityFramework.dll because we love our data and don't want to give our app a low self esteem
  • Once removed, hit F5 again

If everything is still running, then do a file system deploy to a local folder of your choice. Go check out what was just deployed, specifically the '/bin' folder. We want to remove the Web.Infrastructure.dll because Mono already has this built into its GAC. High Five Mono! With that out of the way, we are going to copy that deployment over to the 'mycoolapp' folder on our Linux server using WinsCP. While I don't have a WordPress plugin to read your mind, I hear you thinking "Rob, surely there are better ways to do this." and you are right. However, this post is long enough and that topic will likely go into its own post.

SSH back into your linux box, and 'cd mycoolapp'. "cd" into your "mycoolapp" directory, type in 'ls' to see the contents and make sure your app made it over. Once we see it, we can do a cassini like run of it by typeing out xsp4 and hitting enter. Try and hit your box on the port 8080 (xsp4 should tell you what it is running on) and see if you can see your app:

Yay! Our code works and we're so open source now that we can wear tight jeans at Starbucks and put Bon Iver on our ipod... just like those Rails wankers! As for nginx and running our site as a Mono service, we can just use some of the nice documentation over at the Mono site:

Nginx config:
http://www.mono-project.com/FastCGI_Nginx

Mono as a service:
http://yojimbo87.github.com/2010/03/14/mono-startup-script.html

Virtual Victory – AWS gives out a year of usage

Amazon has just done something amazing... Amazingness... They are essentially doing a conditional year free of their services. While I am a huge fan of VMWare, what Amazon is offering is something completely unmatched by VCloud or MS Azure.  (Please see Craig's comment as this claim has the possibility of being debunked. Thanks Craig!)

So what can I do with this you might ask? Here are some ideas: (I am doing these off the top of my head so feel free to criticize them by suggesting a better ideas)

1. If you have never played with Linux/Ruby or anything else, here is a good/free way to to dabble without the 'will this mess up my system' fear. Microsoft is continuing their adoption of features from these platforms and it can only benefit you to see these ideas they are using from Ruby(gems) or Apache(modularization). The more you know, the more you grow.

2. NOSQL? What is a NOSQL? Want a simple way to learn about NOSQL? Then try out Amazon's simpleDB. They have various demos and such you can run and play with and start trying to see what all the hype is about. Remember fellow fearful DBA's, NOSQL stands for "Not Only SQL" not for No - SQL as in SQL Void.

3. Embrace the awesome of Amazon S3. Ever wonder why Dropbox/JungleDisk and various other companies can give you so much storage for so cheap? Amazon S3 is pretty much the answer to that question. I typically use the cheapest hosting plans possible and S3 as a CDN to smoke/mirror performance.

4. SQL Server testing - Microsoft provides trial software for pretty much all their projects. If you are curious about ... say playing with some feature of replication or maybe wondering about online indexing ... Fire up 1 or more instances of EC2 and actually try it. You no longer have an excuse to put it off.

5. .Net testing or running a service - With shared hosting, I don't have a way of keeping an ongoing on demand service per say... So why not have a micro instance where you can deploy services and such. For example, say you need to add SMS services to your app.... Sign up for Twilio, create a little service, throw it on your free AWS EC2 instance and poll every hour or so. Most shared hosting sites don't really support SQL Server SSIS... so why not have an AWS EC2 instance that fires up at night and starts some SSIS packages?

Now, some of this isn't without a learning curve, but we are in the software development industry... if we can't navigate learning curves or don't even pursue learning to begin with we add more nails to our career coffin as well as start becoming the problem.

Installing MongoDB on Ubuntu

First step to getting started with toying around with NoSQL is getting it running. Currently, MongoDB is my choice in the land of learning. To get it going on my VM's I do the following after my Ubuntu server is installed.

Navigate to: /etc/apt/sources.list
Then: sudo pico sources.list
In your sources, add the following line: deb http://downloads.mongodb.org/distros/ubuntu 10.4 10gen
Save/exit the file, then add the key: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

Once that is done, you're ready to update and install.
Update: sudo apt-get update
Install: sudo apt-get install mongodb-stable

Well now what?
If you need to configure MongoDB further, then navigate to: /etc/mongodb.conf
If you need to add/remove/mess with the database, it lives in: /var/lib/mongodb
Want the logs? They are here: /var/log/mongodb/ (.log extension)