https://github.com/icflorescu/openshift-cartridge-nodejs
This is a custom Node.js cartridge that takes care of auto-updating the Node.js and NPM versions on each start.
By default, the Node.js version is determined by querying semver.io/node/stable.
A different URL can be specified in your application's repository, in the .openshift/NODE_VERSION_URL
file. For instance, you'd get the latest 0.10 (0.10.39 as of June 29, 2015) by putting this in .openshift/NODE_VERSION_URL
:
https://semver.io/node/resolve/0.10.x
Because the standard OpenShift cartridge never gets updated to the latest Node.js version.
The original cartridge by icflorescu is designed as a primary cartridge. Therefore you have to use an additional gear for it. In my case I want to use Node.js as a small background worker which would lead to a waste of my free gears.
This cartridge add the current Node.js version as a secondary server.
When you need a quick and unsofisticated solution to run your application on the latest Node.js version.
How to (web console)
To install this cartridge in your existing OpenShift application, go to "See the list of cartridges you can add", paste the URL below in "Install your own cartridge" textbox at the bottom of the page and click "Next".
http://cartreflect-claytondev.rhcloud.com/github/Rawi01/openshift-cartridge-nodejs
Assuming you have rhc
installed (see here), run:
rhc cartridge add -t http://cartreflect-claytondev.rhcloud.com/github/Rawi01/openshift-cartridge-nodejs -a appname
...where appname
is the name of your application.
See output of rhc cartridge add --help
for information on additional options.
- 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.
- 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 yourpackage.json
file. Seepackage.json
in the provided template or read thenpm
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").
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/Rawi01/openshift-cartridge-nodejs
instead of
http://cartreflect-claytondev.rhcloud.com/github/Rawi01/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.
Since you're here, chances are you might also be interested in this custom MongoDB cartridge.
See contributors here.
If you find this repo useful, don't hesitate to give it a star and spread the word.
The MIT License.