Skip to content

Barebones Cloud Foundry Hello World #1 (Ruby)

by on October 26, 2012

It’s pretty easy to get started with Cloud Foundry, but here’s also a 10 min barebones version we shared at Code Camp 2012 (record is 7 mins!)
1. Sign up! If you do not have a Cloud Foundry account, sign up with this promo code: https://my.cloudfoundry.com/signup/preshavedyak
2. Install Ruby, Ruby Gems, & VMC:
— If you have Windows, there are a few steps you need to take: http://docs.cloudfoundry.com/frameworks/ruby/installing-ruby.html#windows
— If you have a Mac, Ruby is already installed, so it’s a little more streamlined (Version 10.5+ of Mac OS X Ruby and RubyGems installed) I’m going to show the updated Mac version here. (Make sure that you have Ruby 1.8.7 to 1.9.2 installed).
Click on the spotlight icon in the top right corner of your Mac OSX screen (it looks like a magnifying glass). Type in “Terminal” and choose the Terminal option that pops up.
3. To install VMC, at the prompt$ enter “sudo gem install vmc” and hit Return (and you will be prompted to enter your usual OS login password)
(If you get an error requiring updated ruby gems, at the prompt$ enter “sudo gem update –system” and hit Return; then try “sudo gem install vmc” again). Give it a couple of minutes.
4. To target VMC to cloudfoundry.com, at the prompt$ enter “vmc target api.cloudfoundry.com” and hit Return
5. Now you will log in to cloudfoundry.com If you just created a new Cloud Foundry account, check your email for your temporary password. If you already have an account but forgot your password, reset it here: https://my.cloudfoundry.com/passwd
To log in to cloudfoundry.com, at the prompt$ enter “vmc login” and hit Return.
It will ask you for your email and password.
*** This is where a lot of people get stuck! If you are using a temporary password, I recommend that you copy and paste both your email address and password, or change it to one you are sure will work. ***
6. Now you are ready to push a basic app. I have a fun one that you can use:

require 'rubygems'
require 'sinatra'

get '/' do
host = ENV['VMC_APP_HOST']
port = ENV['VMC_APP_PORT']
"<h1>Hello, yes this is CloudFoundry: #{host}:#{port}><img src=http://i0.kym-cdn.com/photos/images/newsfeed/000/217/040/48ACD.png>"
end

Save this code in a .rb file (eg. myrubyapp.rb)
[Note that if you copy and paste this code, there has been some issue with the formatting of the quotation marks because of wordpress (even though I used the code brackets). If you have issues, retype in all quotation marks.]

Save this in a folder (eg. a folder on your Desktop called myrubyapp)
7. To push your app, first make sure that you are in your myrubyapp folder. You can make sure that you are by entering at the prompt$ “cd ~/Desktop/myrubyapp” and hit Return. Type “ls” and hit Return to make sure that you see your myrubyapp.rb in that folder.
8. To push your app, enter “vmc push” and hit Return. You will now get a series of questions.
Would you like to deploy from the current directory? [Yn]:
If the “Y” is capitalized, hit Return.
Application Name: This is where you will enter a unique url prefix, so think of something that no one else has thought of before. (Eg. myfirstapp is probably taken …). Also, no periods, please.
For eg, here entered “dogspeaking”
Detected a Sinatra Application, is this correct? [Yn]:
If the “Y” is capitalized, hit Return.
Application Deployed URL [dogspeaking.cloudfoundry.com]:
This is a preview of how your url will look. Hit Return.
Memory reservation (128M, 256M, 512M, 1G, 2G) [128M]:
Hit Return.
How many instances? [1]:
Hit Return.
Create services to bind to ‘dogspeaking’? [yN]:
If the “N” is capitalized, hit Return. In the future, if you enter Y instead here, this is where it will ask you what services you want (eg. MongoDB, MySQL, RabbitMQ, etc)
Would you like to save this configuration? [yN]:
If the “N” is capitalized, hit Return.

9. Now VMC will create and upload my app:
Creating Application: OK
Uploading Application:
Checking for available resources: OK
Packing application: OK
Uploading (0K): OK
Push Status: OK
Staging Application ‘dogspeaking': OK
Starting Application ‘dogspeaking': OK

10. Once this process is complete, copy and paste your new url into a browser (eg. in my case it is dogspeaking.cloudfoundry.com)
Voila’! Bare bare bones Cloud Foundry app push completed.

NOTE: Yes, this is a very very limited case. If you encounter issues, please consult these resources:

http://docs.cloudfoundry.com/getting-started.html

http://support.cloudfoundry.com/home

http://stackoverflow.com/questions/tagged/cloudfoundry

About these ads
4 Comments
  1. skye young permalink

    Hi, my name is Skye. im 12 years old and in the seventh grade. my bestfriend Anna has a preshavedyak hoodie and for months shes writen me a neon stickynote saying “go to preshavedyak.com” and i finnally remebered to come! what i would like to know is how do you get a hoodie? i really like her hoodie and want one..thanks!!

    • Hi Skye! Sorry for the late reply. Glad that your friend loves her hoodie! I’ll email you and we will see what we can do.

  2. Copying and pasting sometimes produces incorrect quote and double quote characters. You may need to manually re-type the quote and double quote characters by hand if you have problems starting your app.

    • Thanks for the heads up. I tried adding more code brackets and tested it with a new rb file. It looks like it pushed to cloud foundry without issue this time. Thanks for the heads up!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: