Cirych / openshift-cartridge-nodejs

Custom cartridge for OpenShift providing the lastest version of Node.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Node.js cartridge for OpenShift

nodejs-openshift

This is a custom Node.js cartridge that takes care of auto-updating the Node.js and NPM versions on each build.

Why

Because the standard OpenShift cartridge never gets updated to the latest Node.js version.

When to use

When you need a quick and unsofisticated solution to run your application on the latest Node.js version.

How to (web console)

Go to Choose a type of application in your OpenShift Online account, paste the URL below into "Code Anything" textbox at the bottom of the page, click "Next", then set your public URL and click "Create Application".

http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-nodejs

How to (command line)

Assuming you have rhc installed (see here), run:

rhc app create -t http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-nodejs -a appname

...where appname is the name of your application.

See output of rhc app create --help for information on additional options.

Customizing the Node.js and npm versions

Node.js

By default, the Node.js version is determined by querying semver.io/node/stable.

A different URL can be specified either via NODE_VERSION_URL environment variable or by setting .openshift/NODE_VERSION_URL marker in your application repository. For instance, you'd get the latest 0.10.x (0.10.41 as of Jan 24, 2015) by putting this in NODE_VERSION_URL variable or .openshift/NODE_VERSION_URL marker:

https://semver.io/node/resolve/0.10

If you're using a non-default Node.js version and you're planning to scale the application across multiple gears, you must use the environment variable (learn here why).

npm

By default, the npm version is determined by running npm view npm version.

A different npm version can be specified either via NPM_VERSION_URL environment variable or by setting .openshift/NPM_VERSION_URL marker in your application repository. For instance, you'd get the latest 2.x (2.14.16 as of Jan 24, 2016) by putting this in NPM_VERSION_URL variable or .openshift/NPM_VERSION_URL marker:

https://semver.io/npm/resolve/2

Features

  • The cartridge build script is using this function to check for the latest Node.js and npm versions and installs them if necessary;
  • This cartridge can be scaled;
  • This cartridge does not (yet?) have a hot-deploy strategy.

Notes

  • Can't guarantee this cartridge is production-ready. Some people use it though (on their own responsibility).
  • This is a lean cartridge. No unnecessary modules are installed. Which means that - unlike the standard Node.js cartridge - it won't install supervisor for you. You'll have to implement your own logic to auto-restart on errors. The provided application template is using cluster for that.
  • The cartridge emulates the execution of npm start to start your application, so make sure your application entrypoint is defined in your start script of your package.json file. See package.json in the provided template or read the npm docs for more information.
  • Due to OpenShift's outdated gcc (4.4.7 as of Jan 4 2016), native modules (such as pg-native) won't compile on Node.js > 4.x. They'll only work on Node.js 0.10 and 0.12. See this issue for more info.
  • Upon cartridge initialization, the Node.js binary package is downloaded and installed, which may take a while, depending on OpenShift server and network load. 2 - 3 minutes is quite often, but 5 - 10 minutes is not uncommon, especially for scalable multi-gear setups (if you specified "Scale with web traffic").

FAQ

Q: I'm getting the error Cannot download, must be smaller than 20480 bytes while trying to deploy the cartridge to OpenShift. What am I doing wrong?

A: You're probably trying to use the URL https://github.com/icflorescu/openshift-cartridge-nodejs instead of http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-nodejs. A common mistake for people not paying sufficient attention while trying to use a custom cartridge for the first time.


Q: The latest Node.js version is 5.3.0, but the cartridge installs 5.1.1. Isn't it supposed to install the latest?

A: By default, the Node.js version is determined by querying semver.io/node/stable (see the top of this README). For reasons which escape me, semver.io is not updating instantly the latest version, but you can force the cartridge to install it by putting, for instance, https://semver.io/node/resolve/5.3.x in .openshift/NODE_VERSION_URL.


Q: Sometimes, git push fails with:

remote: CLIENT_MESSAGE: Stopping Node.js application...
remote: CLIENT_RESULT: Warning! Could not stop Node.js application!
remote: An error occurred executing 'gear prereceive' (exit code: 1)
remote: Error message: CLIENT_ERROR: Failed to execute: 'control stop' for /var/lib/openshift/[...]/nodejs
remote:
remote: For more details about the problem, try running the command again with the '--trace' option.
To ssh://[...].git/
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'ssh://[...].git/'

What's wrong?

A: Your application may take longer than 60 seconds to shutdown. Try to git push again until it works.

Related

Since you're here, chances are you might also be interested in this custom MongoDB cartridge.

Credits

See contributors here.

If you find this repo useful, don't hesitate to give it a star and spread the word.

License

The ISC License.

About

Custom cartridge for OpenShift providing the lastest version of Node.js.

License:ISC License


Languages

Language:Shell 44.9%Language:JavaScript 27.5%Language:HTML 17.1%Language:CSS 10.5%