Skip to content

Yak Shaving Hello World! ;)

From the Alameda County (first) Hackathon

Ren & Stimpy Yak Shaving

Barebones Cloud Foundry Youtube Post #2.5 (Ruby)

It’s pretty easy to get started with Cloud Foundry, but here’s also a 10 min barebones version we shared at the Alameda County Hackathon 2012 (record is 7 mins!)

This is a “half project” because I have not changed any of the instructions from the Barebones Hello World in Ruby.

require 'rubygems'
require 'sinatra'

get '/' do

def youtube_embed(youtube_url)

if youtube_url
[/youtu\.be\/([^\?]*)/]
youtube_id = $1

else

# Regex from # http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url/4811367#4811367
youtube_url
[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
youtube_id = $5

end
%Q{
<iframe title="YouTube video player" width="560" height="315" src="http://www.youtube.com/embed/#{ youtube_id }" frameborder="0" allowfullscreen></iframe>}
end

"<
h1>Bacon Pancakes from Cloud Foundry</h1>"+youtube_embed('youtu.be/zalYJacOhpo')
end

I just changed the Ruby app code to post a youtube link. You can copy and paste this code into your Ruby app too!

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

(Thanks to http://stackoverflow.com/users/13831/douglas-f-shearer for his post on stackoverflow)

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

Barebones Cloud Foundry Hello World #2 (using Spring Tool Suite)

It’s pretty easy to get started with Cloud Foundry, but here’s also a 10 min barebones version we shared at JavaOne and will be sharing at Devoxx 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 If using your own laptop, make sure that you have Spring Tool Suite or Eclipse installed: http://www.springsource.org/sts (The instructions below are for STS)
  2. Install the Cloud Foundry plugin, Select Help > Dashboard, Click the Extensions tab, at the bottom left, type in “Cloud” in the Find field, then choose Cloud Foundry and click the Install button. Click on the prompted buttons until you are prompted to restart STS. Restart.
  3. Once you restart STS, in the Servers window where it says “No servers available. Define a new server from the …” click on the “new server wizard” link. (If you don’t see a Servers window, go to Window>Show View>Servers or Other>Servers)
  4. From the list of folders, open VMware, choose Cloud Foundry, and click Next.
  5. You should be in the Account Information page where you will log in to your Cloud Foundry account. If you just created a Cloud Foundry account, check your email for your temporary password.
    If you cannot remember your password, recover it here https://my.cloudfoundry.com/passwd
  6. Enter your account email address and password and click on the Validate Account button (We recommend copying and pasting both your email (ID) and your password – This is where a lot of people get stuck). Doubleclick on your VMware Cloud Foundry server and make sure
  7. If prompted to create security questions for the new Master Password, follow those steps.
  8. If the center screen in STS is not on the Dashboard, click the Dashboard tab. (If you don’t see it at all, go to Help>Dashboard)
    Under Create in the top left, choose Spring Template Project.
  9. In the Template Selection window, select Spring MVC Project, click Next.
  10. Create a Project Name (eg. my-first-hello) and specify the top-level package (eg. com.mydotcom.hello01).
    Click Finish.
  11. You will now see your new folder listed in the Package Explorer at the left. (If you don’t see Package Explorer, go to Window>Show View>Package Explorer)
    If you seen no alerts or X’s on your package, drag it down and drop into your VMware Cloud Foundry server listed in the bottom left Server window. (If it won’t drop onto the server, delete the app and create a new one).
  12. Once the app window opens, choose Next. For the Deployed URL, you need to create a unique URL prefix (eg. pusheeninspired – no periods or spaces) Click Next, make sure that your memory allocation is at least 512 or 1024, then click Finish and wait for the app to deploy.
  13. Once you see the word “Deployed” next to your app in the Servers list, right click on the app and choose
    Open Home Page to test. Your Hello World sample app should appear. (If you see 404, doublecheck the console to make sure your app has fully deployed. If you see 404 after full deployment, click on your app on the server and increase the memory allocation).
  14. If you want to do something more fun, you can edit your home.jsp file (in app name>src>main>webapp>WEB-INF>views>home.jsp

You can add something like this into your home.jsp file:

<html>
<head>
<title>Pusheen Inspired</title>
</head>
<body>
<h1>
Hello world! Be inspired!
</h1>
<img src=http://25.media.tumblr.com/tumblr_m7jhivE7DP1qhy6c9o5_250.gif>
<P>  The time on the server is ${serverTime}. </P>
</body>
</html>

If you make changes, then save and drag the changed app to the Cloud Foundry server again. If you succeed, you will see something like this: pusheeninspired.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

Barebones Cloud Foundry Hello World #1 (Ruby)

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

Preshavedyak grazing toward the end of Silicon Valley Code Camp 2012

A preshavedyak hoodie went home to our youngest member at SV Code Camp!

Everyone pushed an app to Cloud Foundry for the preshavedyak hoodie! This was our youngest member of the day to become a proud owner of a hoodie.

Fun in the sun at the SV Code Camp!

 

Follow

Get every new post delivered to your Inbox.