Cloud Foundry Tutorial : Taking a PaaS on the hard stuff - Part 2
Deploying an application
There are a few ways to get started. The easiest, perhaps, is to sign up on the public site and create an account there. As development becomes more involved, you may decide you’d like to iterate quicker and work with a cloud that’s running locally. For this very specific use case, consider the Micro Cloud Foundry (MCF). MCF is a virtual machine image that runs in VMware Player on Linux and Windows, and VMware Fusion on OSX (Player is free, but Fusion has a nominal price attached to it.) You can sign up for an account and download the image for free from the MCF website then simply follow the setup guide. For our purposes, let’s simply work with the online site.
There are a few tools we need to effectively work with any Cloud Foundry instance: the vmc command line tool, and – if you’re a developer working with the JVM (Spring, Grails, Scala, regular applications, etc.) – the Eclipse support for Cloud Foundry.
There are many ways to interact with Cloud Foundry. Cloud Foundry’s public facing endpoint, called the cloud controller, is a RESTful API through which all commands pass and eventually effect some sort of response from one of the components in the cloud’s architecture itself. While you manipulate Cloud Foundry using this RESTful API itself, it’s easier to use language and client-specific integrations. The vmc command line tool provides a great way to interact with Cloud Foundry for those more comfortable banging around in the shell; the Eclipse support provides a WTP-connector view of Cloud Foundry; both the Grails and Roo RAD frameworks provide add-ons, and there is support for deploying applications with a Maven plug-in.
Signing up for a CloudFoundry.com account
Signing up is easy. While the project’s in beta, accounts on CloudFoundry.com are free. Go to the Cloud Foundry registration page and follow the steps.
Working with vmc
The instructions are presented here, but they may change in time, so be sure to consult the official documentation section for the latest and greatest, if anything is in doubt. The vmc command line tool is written in Ruby. So, first, you need to install Ruby on your operating system. At the moment, in the second quarter of 2012, Ruby versions 1.9.2 (or later) and 1.8.7 (or later) are supported. On Linux, you can use your operating system’s package manager to install Ruby (if it’s not already installed). If you’re on Windows, you can use the Ruby installer from RubyInstaller.org. On OSX, things are less rosy. The built-in Ruby is fragile. It’s easier to install something like the Ruby Version Manager (rvm) which lets you maintain multiple concurrent installations of Ruby on a given machine. The setup for Ruby, with rvm, looks like this:
$ bash -s stable <<(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
$ rvm install 1.9.2
$ rvm use 1.9.2
Once you have Ruby installed, getting the vmc command line tool’s a snap! Ruby comes with a package management tool called gem, which it uses to manage dependencies. It’s akin to a Ruby-specific version of the yum, deb, or apt package management systems on various Linux flavors. To install vmc, you will use the gem command line tool, like this:
$ sudo gem install vmc
If you’re running on Windows, then remove the word sudo, which is used on Unix variants like OSX and Linux to obtain elevated privileges when invoking a command, and is unnecessary on Windows. Once vmc is installed, open a new shell to test some of the basics out. When working with Cloud Foundry instances, you need to follow some basic workflow steps.
First, you need to target the correct instance, since Cloud Foundry is not one cloud by one vendor, but a stack that anybody can run. This is similar to the way you work with Git and Subversion: You wouldn’t install the Git command and expect it to automatically know which host to clone the source code from, would you? As a good rule of thumb, targeting involves specifying the api URL for the Cloud Foundry instance. This is pretty consistent of the pattern api.foo.com, where foo.com is the host of your Cloud Foundry instance. Here’s my console session targeting CloudFoundry.com:
$ vmc target api.cloudfoundry.com
Successfully targeted to [http://api.cloudfoundry.com]
Then, you need to login. You only need to login once for a given session.
$ vmc login
Attempting login to [http://api.cloudfoundry.com]
Successfully logged into [http://api.cloudfoundry.com]