Skip to content

Cloud Foundry CLI (VMC) Setup on Debian Squeeze

For the those of you who, like me, are new to Cloud Foundry and Ruby development, deploying your first Cloud Foundry Ruby application via VMC can be unnecessarily frustrating. The trouble stems mostly from sparse information scattered across the Internet and *especially* from incomplete and partially incorrect documentation provided by VMware when you sign up for a Cloud Foundry Beta account.

In this post, we aim accomplish the following things:

  1. Get your system ready with the pre-requisites for the Cloud Foundry CLI
  2. Install VMC (the CLI)
  3. Create and deploy a simple Ruby app
  4. Test and verify

1.) First, we need to install several packages prior to installing Ruby. Note: The VMWare documentation has a typo; there should be a space between “gcc” and “curl” as presented below.
sudo apt-get install gcc curl git-core build-essential libssl-dev libreadline5 libreadline5-dev zlib1g

2.) Next, let’s install RVM, the Ruby Version Manager. We’ll be using this to install Ruby instead of doing it via apt-get

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

Close your shell session after this step and start a new one! This is important.

3.) Next, let’s install Ruby 1.9.2

rvm pkg install zlib
rvm install 1.9.2 -C --with-zlib-dir=$rvm_path/usr 
rvm --default use 1.9.2

Note that in the VMWare doc, there are several errors here which you want to note. The first command syntax is “pkg” as noted above, instead of “package” which they have listed. You are also asked to make modifications to your .bashrc according to the prompts from the rvm installation script. No prompts are provided and no modifications to .bashrc are necessary. Finally, we need to include “–default” to the rvm use command. This ensures Ruby 1.9.2 will always be available at every shell login by default.

4.) Next, we should be able to install VMC with one simple command:

gem install vmc

5.) Now, let’s sign into CloudFoundry. I am using it atop of HP Cloud Services, so my target is tailored as such.

vmc target http://api.cloudfoundry.hpcloud.com
vmc login

(Enter your login credentials based on the service you will be using.)

6.) Now, we are ready to create our first Ruby App and push it to Cloud Foundry. Make a directory called “hello” in your home folder, and add a file called hello.rb inside with the contents below:

mkdir /home/[user]/hello
cd /home/[user]/hello
nano -w hello.rb
# Simple Ruby Example App
Bundler.setup
require "sinatra"
get "/" do
"Hello World!"
end

Now, it is important to note that the VMware document prompts you to deploy the above code without “Bundler.setup”. When you attempt to push the application without bundling, you will get the following error message during the “starting application” phase:

Error 306: Error retrieving file 'logs/startup.log'

You may then think to dig into what the error means by running the following command:

vmc logs hello --all

Good call. This supplies you with the following information:

====> logs/stderr.log <====
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- sinatra (LoadError) from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' from hello.rb:4

But that isn’t really all that helpful, either. It took me hours of googling to understand what it meant and what was wrong so it is my hope for those of you who are also searching for answers, you have found this post and can resolve it with ease.

So how do we fix this? We need to create a Gemfile bundle and its pretty easy to do so.

nano -w Gemfile
source "http://rubygems.org" 
gem 'sinatra'
bundle package
bundle install

Now we are ready to push the app to Cloud Foundry!

7.) Deploying the app and testing

vmc push hello

Selecting the defaults to each question by hitting “enter” is just fine here. Everything should complete successfully and we should now be able to view our app at: http://hello.cloudfoundry.hpcloud.com

Hopefully this post will save you some time. I also hope it has been a good prerequisite how-to for those of you viewing the Cloud Foundry on HP Cloud Services Demo video. Please let me know if you have questions. I’m happy to help however I can!

Categories: Cloud Computing, Linux.

Tags: , , , , ,