Monday, April 18, 2011

The World Is Your Oyster: Installing and Using Cloud Foundry on Windows

CloudFoundry is an incredibly cool way to build and deploy cloud apps to any target cloud using very simple commands.

The basic api has just three commands:
  1. vmc target cloud.url //select cloud provider
  2. vmc login // login to cloud
  3. vmc push app.name // run cloud app
Three commands and the (cloud) world is your oyster! Very cool.

This may be just me but I found it difficult to follow the install guide for Cloud Foundry on my windows machine. For those of us trapped behind corporate firewalls and proxy servers, things got even more complicated.

After scurrying around the cloud foundry forums and stackoverflow, here are my slightly revised notes for getting Cloud Foundry running on a Windows machine using a proxy server:

1. Apply for a Cloud Foundry account at www.cloudfoundry.com you will be notified by email when your account is activated

2. Install Ruby from www.rubyinstaller.org. The Cloud Foundry cloud controller command line is built in Ruby so this is required. As the installer runs, make sure to check the boxes to add the ruby directory to your command path
















3. Start the Windows command line client on windows by typing "run cmd" in start menu

4. Install the Cloud Controller software. Type:
gem install vmc

If you are behind a firewall, you will get a nasty error message:

ERROR: Could not find a valid gem 'vmc' (>=0) in any repository

5. Install vmc gem through a proxy server, type:

gem install --http-proxy http://proxy.vmware.com:3128 vmc






Congratulations! The Cloud Foundry Cloud Controller is now installed. From here on, you can type Cloud Foundry commands into the Windows command window.

6. Tell Cloud Foundry which cloud you want to connect to. Type:

vmc target api.cloudfoundry.com

Again, if you are benhind a firewall, you will get the error message

Host is not valid: 'http://api.cloudfoundry.com

7. To communicate with Cloud Foundry through a proxy server, set the environment variable "http_proxy". In the command window, type

set http_proxy=http://proxy.vmware.com:3128
vmc target api.cloudfoundry.com

8. Login to Cloud Foundry

vmc login

Enter your email address and password

9. Create a simple Ruby application.

cd \
mkdir hello
cd hello

The above commands create a "C:\hello" directory. Using a text editor type the following and save the file as "hello.rb"

require 'sinatra'
get '/' do
"Hello from Cloud Foundry +VMware and may I add you look dashing today?"
end

11. Publish the application to the cloud. Type:

vmc push

The following prompts will appear :

Would you like to deploy from the current directory? [Yn]
Assuming that you are in the hello directory hit enter (this answers Yes)

Application Name: hello_username
NOTE: use a unique name for your application best to concat your user name and "hello"

Application Deployed URL: ‘hello_username.cloudfoundry.com’?
Press enter to accept default

Detected a Sinatra Application, is this correct? [Yn]
Press enter to accept default

Memory Reservation [Default:128M] (64M, 128M, 256M, 512M, 1G or 2G)
Press enter to accept default (128MB)

Creating Application: OK...
Would you like to bind any services to ‘hello’ [yN]:
Press enter, you don’t want to bind any services for this example

12. Launch a web browser and go to your Application Deployment URL.






Now wasn't that easy?

Troubleshooting Problems With CloudFoundry

In deploying or updating an application, you may get the following error:

Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (2M): OK
Error (JSON 500):

The workaround for this is to make sure that the application is stopped (vmc stop foo) before you update the application (vmc update foo).


2 comments:

Coach Craig said...

Thanks Chris. You got me past the proxy issue. Cheers.
Craig

Christopher Keene said...

@craig - happy to help. Those proxy issues are nasty because the way you figure out that there is a problem is that nothing happens ;-)