I have been hacking around with the VCAP project for a month or so now and as a Ruby developer (and also now as a VMWare employee who’s role it is to support the community using the project) I wanted to start building up a set of tools for Ruby devs to use to make life a little easier / quicker.
Just after starting with VMWare I was given a work laptop and I wanted to set it up in a different way to my previous machine. As a massive fan of VCAP already, I knew I wanted developing stuff on that laptop to center around using an instance of VCAP on a VM. So, I have VMWare fusion running Ubuntu Server 12 running VCAP, this is where I will run all my services from, MySQL, MongoDB, PostgreSQL and the like.
The standard install of VCAP is configured to use the vcap.me domain which I didn’t realise until recently is set to resolve to… you guessed it 127.0.0.1, the loopback interface. This is great as it means that if you have an instance of VCAP running locally you can use any cname domain name to refer to said instance. So the first problem to overcome was forwarding all HTTP traffic on port 80 from my laptop to the VM. Now I can’t speak for other virtual machine apps but VMWare Fusion has a very handy way of doing this. I have the VM set to use NAT networking which means there is a private IP range that only my laptop and the VM share. There is a config file for NAT located in /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf, under the “incomingtcp” section add “80 =
So now, I have a platform I can provision web apps on and view using the vcap.me domain. So, the last thing left was to ease the process of developing Ruby apps using services provisioned on the VM. So, I have started a small project with (soon to be) a selection of rake tasks for doing exactly that. The first task (currently specific to Rails) is to make it easy to create a datasource, reconfigure the database.yml configuration and then open a tunnel. vcap:db_connect does exactly that, if a service doesn’t exist on the VCAP instance with the same name as the Rails application it creates one, prompting the user for the type of service, it modifies the database.yml file of the project for the current environment and then creates a tunnel to the service.
So to paint a picture of the average Rails + VCAP developement story, it goes something like this;
1 2 3 4 5
Add ‘vmc’, ‘caldecott’ and a adapter for your data source to Gemfile
1 2 3
1 2 3 4
At this point you would leave this console window open and use another for running a Rails console, rake tasks etc. I have a lot of tidying up to do but it works and I also need to add adapter names for anything else other than MySQL!