Updated Deltacloud VirtualBox Driver

Sunday September 19 2010

The SteamCannon project uses Deltacloud to abstract away the details of specific cloud providers when launching instances. For local development, it's nice to be able to launch a cluster of virtual machines in VirtualBox instead of actually starting and stopping instances on a public cloud like Amazon EC2.

Michal Fojtik created a deltacloud-virtualbox-driver many months ago to add VirtualBox support to Deltacloud. However, Deltacloud has evolved quite a bit since it was initially released and that driver no longer works with the current implementation.

I've taken Michal's great start and updated it to work with the latest Deltacloud release, giving it a few other changes in the process.

  • Switched to the excellent virtualbox gem which uses the VirtualBox COM API instead of shelling out to the VBoxManage process. The COM API is substantially faster and should allow this driver to work on Windows instead of just Linux/Mac (but it hasn't been tested on Windows).

  • Networking settings of the launched instance are now copied from the parent image instead of being hardcoded to a specific value.

  • The driver now works under JRuby. There are still some optimizations to be made in the code based on which environment it's running in, but it will at least run in JRuby and MRI.

Installing the VirtualBox Driver

The driver is very new and still needs to mature a bit before I submit it to the upstream Deltacloud project. Until then, if you're comfortable living on the edge, read below for installation instructions.

  • Install VirtualBox 3.2.x (might work with 3.1.x but has not been tested) - http://www.virtualbox.org/wiki/Downloads

  • Install bbrowning-virtualbox gem (temporary fork of upstream implementing some missing features)

      $ gem install bbrowning-virtualbox --pre
    
  • Install bbrowning-deltacloud-core gem

      $ gem install bbrowning-deltacloud-core
    
  • Launch deltacloud-core with the VirtualBox driver

      $ deltacloudd -i virtualbox
    

If all goes well, you should be able to go to http://localhost:3001 in your browser and see the Deltacloud web interface. Clicking the Images link should display all virtual machines you have setup inside VirtualBox - if you don't see any, try creating a new virtual machine in VirtualBox and then come back to play around.

The instances launched from an image clone the hard drive of the image but any changes made in the instance are not reflected in the parent image. If you don't have a lot of free hard drive space, make sure to go to the Instances page and destroy stopped instances that you no longer need.

Enjoy!

Moving From GitHub Pages to Awestruct

Friday September 17 2010

I'm switching the site over from GitHub Pages to Awestruct. I was turned on to Awestruct by Bob McWhirter and am really digging the compass / blueprint integration and ease of writing extensions.

As part of the transition, I'm also switching web hosts. It should go pretty smoothly but because of a poor IntenseDebate implementation on my old site I'm having a hard time pulling all the previous blog comments over. There weren't many to begin with, but I apologize in advance if I can't get them all to show up on the new site.

TorqueBox Vagrant Box Updated to Beta20

Thursday July 08 2010

Hot on the heels of the TorqueBox Beta20 release, I've pushed an updated version of the TorqueBox Vagrant box. The box is now 1.6GB in size - I'm not entirely sure why it's larger than last time but if I figure it out I'll upload a smaller version.

Grab it here:

http://bbrowning-boxes.s3.amazonaws.com/torquebox-1.0.0.Beta20.box?torrent (bittorrent)

http://bbrowning-boxes.s3.amazonaws.com/torquebox-1.0.0.Beta20.box (direct download)

Refer to my previous post for details on getting started with TorqueBox and Vagrant.

Developing Rails Apps with TorqueBox and Vagrant

Sunday June 06 2010

The TorqueBox project does a great job of bringing together the best parts of Ruby, Rails, JBoss, and the JVM. However, I've recently started using Vagrant for all my development work and couldn't find anyone that had used the two together. So, after hacking around a bit, I've created a Vagrant box anyone can use to easily get up and running with TorqueBox.

The rest of this post assumes a basic level of familiarity with TorqueBox and Vagrant - things will make more sense if you browse some of their documention before reading further.

What's Included in the Box

  • Ubuntu 8.04
  • OpenJDK 1.6.0_0-b11
  • TorqueBox 1.0.0.Beta19

Because it contains a full TorqueBox binary and a Java runtime, the box is 1.2GB in size.

Creating Your First Project

  • Add the TorqueBox Box to Vagrant

    Preferred Method - Bittorrent

    Use your favorite Bittorrent client to download http://bbrowning-boxes.s3.amazonaws.com/torquebox.box?torrent and then run

      $ vagrant box add torquebox path_to_downloaded_file/torquebox.box 
    

    Alternate Method - Direct Download

    The direct download will be faster (but cost me more money) unless several nice people help me seed the torrent.

      $ vagrant box add torquebox http://bbrowning-boxes.s3.amazonaws.com/torquebox.box
    
  • Create and initialize a sample application

      $ mkdir sample_app
      $ cd sample_app
      $ vagrant init torquebox
    
  • Run the box

      $ vagrant up
    

    This step may take a few minutes.

  • Create a Rails project

    To simplify things, all rails/rake commands should be run from inside the TorqueBox VM.

    Log into the VM and cd to the shared vagrant folder.

      $ vagrant ssh
      $ cd /vagrant
    

    Follow the steps from the TorqueBox Rails documentation for creating our Rails application with the TorqueBox template:

      $ rails -m $TORQUEBOX_HOME/share/rails/template.rb .
    

    If you look on your host machine, you'll see the Rails application files were created in your sample_app directory. The /vagrant directory inside your VM is a bidirectional shared-folder with the sample_app directory on your host.

    After creating a new project, you'll need to redeploy your Rails app into TorqueBox. You only have to do this once - the VM will automatically pick up on the project the next time it's started.

      $ rake torquebox:rails:deploy
    

    Wait 15-30 seconds and point your browser to http://localhost:3000. You should see the familiar Rails "Welcome aboard" page.

Congratulations, you're now running a Rails application inside TorqueBox.

Next Steps

If you've made it this far, you've done the hard part. Use your favorite editor on your host machine to develop your Rails application like you always have. The only thing to remember is to run script/generate, rake db:migrate, etc from inside the Vagrant VM. If you try to run these on the host you most likely won't have the right version of Rails or JRuby installed.

Changes made to your Rails project should be visible on the next page refresh just like regular Rails development. To try this, generate a simple Posts scaffold.

$ ./script/generate scaffold post title:string body:text
$ rake db:migrate

Point your browser to http://localhost:3000/posts and your should see the scaffolded post index.

When you've finished working on this project or need to switch to another one, issue a vagrant halt or vagrant destroy from the sample_app directory on your host. The next time you need to work on this project again, issue a vagrant up to boot everything back up. See the Vagrant docs for more details on these commands.

Let's try it.

If you're still logged into the VM via ssh, log out.

$ exit

Destroy the VM

$ vagrant destroy

Now re-create the VM and start it back up (will take several minutes)

$ vagrant up

Wait 15-30 seconds for TorqueBox to start up and then point your browser to http://localhost:3000/posts - your app is back right where we left off.

If you have any feedback, requests, or problems with the TorqueBox box, contact me on Twitter (@bbrowning). Enjoy!