In this blog post we deploy a simple “hello world” app to our Cloud Foundry installation.
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.2.0-c9d4aaa-2014-06-19T22:03:53+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 f1e25xxxxxxxxxxxxxxxx # use your admin password 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.2.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 893, 4 files OK Starting app hello_world in org CF Engineering / space development as admin... OK -----> Downloaded app package (4.0K) -----> Using Ruby version: ruby-1.9.3 -----> Installing dependencies using Bundler version 1.3.2 Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment Fetching gem metadata from http://rubygems.org/.......... Fetching gem metadata from http://rubygems.org/.. Installing rack (1.5.2) Installing rack-protection (1.5.3) Installing tilt (1.4.1) Installing sinatra (1.4.5) Using bundler (1.3.2) Your bundle is complete! It was installed into ./vendor/bundle Cleaning up the bundler cache. -----> WARNINGS: You have not declared a Ruby version in your Gemfile. To set your Ruby version add this line to your Gemfile:" ruby '1.9.3'" # See https://devcenter.heroku.com/articles/ruby-versions for more information." -----> Uploading droplet (23M) 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: 0/1 usage: 1G x 1 instances urls: hello-world.cf.nono.com state since cpu memory disk #0 running 2014-07-02 09:37:55 PM 0.0% 69.8M of 1G 52.2M 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.
1 For those of you lucky enough to have Homebrew-cask installed, you can use it to install the Cloud Foundry CLI:
brew cask install cloudfoundry-cli.