Note: This was originally contributed by @mdunisch, @webintoit, and @cwramsey.
It may be moved back on to the Sails website at a future date; I'm just removing it until there's time to break down the "Hosting" section into individual pages. (If anyone's interested in helping w/ that, please send a PR to sails-docs!)
-mike
To deploy to OpenShift, you'll need to make some minor modifications to your configuration:
Open up config/local.js in your app folder. In here, you'll need to add the following lines.
port: process.env.OPENSHIFT_NODEJS_PORT,
host: process.env.OPENSHIFT_NODEJS_IP,You will also need to install grunt-cli with npm i --save grunt-cli.
After doing that, create the file .openshift/action_hooks/pre_start_nodejs with the following contents. (source)
This action_hook tells OpenShift's supervisor to run all 'prod' grunt tasks, before Sails lifted.
#!/bin/bash
export NODE_ENV=production
if [ -f "${OPENSHIFT_REPO_DIR}"/Gruntfile.js ]; then
(cd "${OPENSHIFT_REPO_DIR}"; node_modules/grunt-cli/bin/grunt prod)
fiThen disable Sails Grunt integration hook.
To do this set the grunt property to false in .sailsrc hooks like this:
{
"hooks": {
"grunt": false
}
}Do not remove Gruntfile.js to disable Grunt hook, this file still using by OpenShift's supervisor.
Then create the file /supervisor_opts with the following contents. This tells OpenShift's supervisor to ignore Sails' .tmp directory for the hot reload functionality. (source)
-i .tmpThis deployment guide was based on Openshift's "SCALABLE" gears, with nodejs v0.10. If you're using non-scalable gear, the
/supervisor_optsfile will be ignored and Sails will not lift on it.
You can now git add . && git commit -a -m "your message" && git push to deploy to OpenShift.
--
Click here for more Sails/Node.js tutorials, best practices, and recommended support options.