In this blog post we deploy a simple “hello world” app to our Cloud Foundry installation.
[2014-10-19 this blog post has been updated to reflect Cloud Foundry CLI version 6.6.1]
We have already set up Cloud Foundry:
- World’s Smallest IaaS, Part 1 describes installing VMware ESXi and VMware vCenter on an Apple Mac Pro
- World’s Smallest IaaS, Part 2 describes installing Cloud Foundry’s Ops Manager and deploying BOSH to the ESXi/vCenter
- World’s Smallest IaaS, Part 3: the PaaS describes installing Elastic Runtime (i.e. Cloud Foundry)
Install Cloud Foundry CLI
Test for a successful install by bringing up a terminal and querying the version of the CLI: 
cf --version cf version 6.6.1-b2cdb2b-2014-09-23T23:07:17+00:00
Let’s point the CLI to our installation:
cf api --skip-ssl-validation api.cf.nono.com
Let’s log in. We’ll use the UAA admin credentials (these credentials can be retrieved from Ops Manager; here is a description of how to retrieve the credentials). We’ll target the “CF Engineering” organization, which we created at the end of Part 3:
cf login -u admin -p a723936f2102e4xxxxxx # Use admin login API endpoint: https://api.cf.nono.com Authenticating... OK Select an org (or press enter to skip): 1. system 2. CF Engineering Org> 2 Targeted org CF Engineering Targeted space development API endpoint: https://api.cf.nono.com (API version: 2.13.0) User: admin Org: CF Engineering Space: development
Let’s create our first app, a simple app, a “hello world” app. Let’s create a directory where we’ll do our work:
mkdir -p ~/workspace/hello-world cd ~/workspace/hello-world
Create a file,
Gemfile, with the following contents (a Gemfile is a file that describes the Ruby libraries (i.e. “gems”) upon which your application depends). The gem we’re using, Sinatra, is a Ruby-based webserver (though its authors may argue that it’s a DSL (domain specific language) for creating web applications in Ruby).
# Gemfile source "http://rubygems.org" gem "sinatra"
Now let’s write a very simple Ruby/Sinatra program,
# hello.rb require 'sinatra' get '/' do "hello world\n" end
Next we create
config.ru, a file which is a configuration file for Rack-based applications (or, in this case, Sinatra, which is a Rack-based web framework):
# config.ru require './hello' run Sinatra::Application
Let’s make sure we’ve installed Bundler (
sudo is not necessary if you’re using rvm, rbenv, or chruby) (if unsure, use
sudo gem install bundler bundle
Now let’s push:
cf push hello-world Creating app hello-world in org CF Engineering / space development as admin... OK Creating route hello-world.cf.nono.com... OK Binding hello-world.cf.nono.com to hello-world... OK Uploading hello-world... Uploading app files from: /Users/cunnie/workspace/hello-world Uploading 892, 4 files OK Starting app hello-world in org CF Engineering / space development as admin... OK -----> Downloaded app package (4.0K) -----> Compiling Ruby/Rack -----> Using Ruby version: ruby-2.0.0 -----> Installing dependencies using 1.6.3 Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment Fetching gem metadata from http://rubygems.org/.......... Using bundler 1.6.3 Installing tilt 1.4.1 Installing rack 1.5.2 Installing rack-protection 1.5.3 Installing sinatra 1.4.5 Your bundle is complete! Gems in the groups development and test were not installed. It was installed into ./vendor/bundle Bundle completed (4.41s) Cleaning up the bundler cache. ###### WARNING: You have not declared a Ruby version in your Gemfile. To set your Ruby version add this line to your Gemfile: ruby '2.0.0' # See https://devcenter.heroku.com/articles/ruby-versions for more information. ###### WARNING: No Procfile detected, using the default web server (webrick) https://devcenter.heroku.com/articles/ruby-default-web-server -----> Uploading droplet (13M) 1 of 1 instances running App started Showing health and status for app hello-world in org CF Engineering / space development as admin... OK requested state: started instances: 1/1 usage: 1G x 1 instances urls: hello-world.cf.nono.com state since cpu memory disk #0 running 2014-10-19 12:57:21 PM 0.0% 34.4M of 1G 45M of 1G
Now we test: let’s browse to https://hello-world.cf.nono.com/:
We have successfully tested our Cloud Foundry installation by installing our first app, which is merely a hint of things to come.
The ‘hello world’ example was pulled from internal Cloud Foundry documentation.
2 If you see
command not found, then /usr/local/bin is unlikely to be in your PATH. A simple workaround is to invoke the CLI by typing
/usr/local/bin/cf rather than