on
free OpenShift Online accounts:
github.com/ryanj/nodejs-custom-version-openshift
github.com/openshift/origin-server/pull/1624
https://github.com/openshift/rhc
sudo gem install rhc
rhc setup
Will automatically:
Setting a min and max scale from the command line
rhc cartridge-scale nodejs-0.6 -a nodeapp --min 3 --max 5
Adding and removing instances / scaling up and down
haproxy_ctld --up
haproxy_ctld --down
HAProxy on / off switches
haproxy_ctld_daemon start
haproxy_ctld_daemon stop
haproxy_ctld_daemon restart
These hooks are available on the command line within your gear, and via a REST API
http://$YOUR_APP_DNS/haproxy-status/
http://$YOUR_APP_DNS/haproxy-status/;csv
https://github.com/openshift-quickstart/irc-leaderboard-quickstart
rhc app create APP_NAME APP_CARTRIDGE CART_2 CART_3
rhc app create -s nodepdxbot nodejs-0.6 mongodb-2.2 --from-code=https://github.com/openshift-quickstart/irc-leaderboard-quickstart.git
Application Options
-------------------
Namespace: rjdemo
Cartridges: nodejs-0.6, mongodb-2.2
Source Code:
https://github.com/openshift-quickstart/openshift-meteorjs-quickstart.git
Gear Size: default
Scaling: no
Creating application 'instantappstore' ... done
Waiting for your DNS name to be available ... done
Downloading the application Git repository ...
Cloning into 'instantappstore'...
Your application code is now in 'instantappstore'
instantappstore @ http://intstantappstore-rjdemo.rhcloud.com/ (uuid: 5175981a5973ca7a69000501)
-------------------------------------------------------------
Created: 1:05 PM
Gears: 1 (defaults to small)
Git URL:
ssh://5175981a5973ca7a69000501@instantappstore-rjdemo.rhcloud.com/~/git/instantappstore.git/
Initial Git URL:
https://github.com/openshift-quickstart/openshift-meteorjs-quickstart.git
SSH: 5175981a5973ca7a69000501@instantappstore-rjdemo.rhcloud.com
nodejs-0.6 (Node.js 0.6)
------------------------
Gears: Located with mongodb-2.2
mongodb-2.2 (MongoDB NoSQL Database 2.2)
----------------------------------------
Gears: Located with nodejs-0.6
Connection URL:
mongodb://$OPENSHIFT_MONGODB_DB_HOST:$OPENSHIFT_MONGODB_DB_PORT/
Database Name: instantappstore
Password: PTk4cCetTj2w
Username: admin
RESULT:
Application instantappstore was created.
You should now have MongoDB and a basic node.js app running on OpenShift!
Your gear is now configured with:
Follow this git-based approach for porting your apps to OpenShift
https://gist.github.com/ryanj/5267357
Make sure that you bind to the correct IP_address and port number...
var ip_addr = process.env.OPENSHIFT_INTERNAL_IP || '127.0.0.1';
var port = process.env.OPENSHIFT_INTERNAL_PORT || 8000;
var hostname = process.env.OPENSHIFT_APP_DNS || 'localhost';
config-multipaas
is a config-chain
wrapper that provides a consistent naming scheme for cloud server configs (from OpenShift, Heroku)
npm install --save config-multipaas
Add your own configs using the config-chain
API
var cc = require('config-multipaas')
var config = cc({ additional_configs: "just like config-chain!" });
When cloud configs are not available, local development configs are returned
app.listen(config.get('PORT'), config.get('IP'), function () {
console.log( "Listening on " + config.get('IP') + ", port " + config.get('PORT') )
})
This command should make mongodb services avilable to your application if run from within your local application source folder
rhc cartridge add mongodb-2.2
For scalable applications, generate load from the command line to see automatic scaling in action:
while true ; do ab -n 10000 -c 400 https://nodepdxbot-rjdemo.rhcloud.com/ ; done
Run the above command from within an openshift gear to bypass wifi issues.
Connect to one of your OpenShift apps from the command line:
rhc ssh APP_NAME
Cluster sibling awareness now available in Nodejs:
Come hang out with us:
#openshift on freenode irc
More information about scaling with OpenShift:
https://www.openshift.com/blogs/step-by-step-nodejs-guide-for-realtime-monitoring-and-scaling
Thanks for following along! --ryanj