ql.io on Cloud Foundry

| Comments

Here are the steps to deploy ql.io on Cloud Foundry with node 0.6.x. This setup automatically spawns a cluster of node processes using node’s native cluster. A sample app to demonstrate these steps is on github - this includes an app.js and a package.json with all the dependencies.

Setup Cloud Foundry

Setup a working Cloud Foundry environment with matching architecture for development and deployment. ql.io relies non node-expat and hence npm modules installed on the development machine must be portable to your Cloud Foundry VM. This rules out using a Mac or Windows for development and Micro Cloud Foundry with Ubuntu for testing the deployment.

If you want to try on a Mac with Micro Cloud Foundry from Mac, use the Micro Cloud Foundry VM as the development machine. Here are the steps to use.

  • ssh vcap@<your Micro Cloud Foundry IP>
  • Install vmc.
  • Download and build node (0.6.x)
  • sudo apt-get install expat libexpat-dev

Upgrade nginx

Upgrae nginx on on the Cloud Foundry target machine. This step is required to let nginx correctly serve chunked encoded responses without Content-Length headers.

  • ssh vcap@<your Micro Cloud Foundry IP>
  • cd /tmp
  • su -
  • curl https://raw.github.com/gist/2187930/e081d925a881e51ef44f19bc5649b2918a1e86d4/mcf_nginx_11.sh | bash

Setup an App

git clone git@github.com:ql-io/ql.io-cloudfoundry.git cfapp

vmc failed for me when the directory name of the app had numbers and dots, and hence use a name without such characters for the app.

cd cfapp
npm install

Add tables and routes as usual.

Push the App

~/cfapp/vmc push --runtime=node06
Would you like to deploy from the current directory? [Yn]: y
Application Name: cfapp
Application Deployed URL [cfapp.xxx.cloudfoundry.me]: <use your deployment URL>
Detected a Node.js Application, is this correct? [Yn]:
Memory Reservation (64M, 128M, 256M, 512M, 1G) [64M]: 512M
Creating Application: OK
Would you like to bind any services to 'cfapp'? [yN]: n
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (160K): OK
Push Status: OK
Staging Application: OK
Starting Application: OK

Note that, using 512M or more is important - the default 64M is not sufficient for running a cluster of node instances with all ql.io modules, and vmc fails silently with the default.

Known Issues

Here is a summary of issues that I ran into while trying this out.

  1. Don’t forget to add --runtime=node06 to vmc push. By default, Cloud Foundry uses node 0.4.x.
  2. Reserve appropriate memory for the app. app.js spans n+1 node processes where n equals the number of the CPU threads on the VM.
  3. Don’t use characters like . and - in the name of the app.
  4. Cloud Foundry uses an L7 router and hence breaks ql.io’s console as it uses WebSocket API. If you would like to use the console on Cloud Foundry, use Safari.
  5. The app.js bundled with ql.io-cloudfoundry leaves the paths /console, and /q open for traffic. I don’t recommend this. In production, consider disabling these two and use routes in stead from client apps by changing the options in app.js to the following.