Run Grunt Build before OpenShift Build Run Grunt Build before OpenShift Build jenkins jenkins

Run Grunt Build before OpenShift Build


The fundamental issue here is the openshift-origin-cartridge-nodejs and furthermore npm_global_module_list doesn't include grunt/grunt-cli in the global npm modules.

I opened openshift/origin-server/issues/4069 as an RFE to get this in the default cartridge.

In the meantime, I've been working on engineersamuel/openshift-origin-cartridge-nodejs which includes bower and Grunt support.

My cartridge runs grunt prod if a Gruntfile.js is found. By default grunt is not on the path, this is easily fixed by prefixing the command with the node_modules.

# If there is a grunt file, run $ grunt prodif [ -f "${OPENSHIFT_REPO_DIR}"/Gruntfile.js ]; then    (cd "${OPENSHIFT_REPO_DIR}"; node_modules/grunt-cli/bin/grunt prod)fi

The ./bin/control also checks for a bower.json file and installs the corresponding packages.

You can quickly and easily test out this custom cartridge with the cartridge reflector with the following command:

rhc create-app nodejstest "http://cartreflect-claytondev.rhcloud.com/reflect?github=engineersamuel/openshift-origin-cartridge-nodejs"


Although this is an old question, I just discovered an answer to this issue that is current.

First, now you can add grunt-cli to you dependencies (npm install grunt-cli --save) and Openshift will add those that are commonly installed using the -g flag to the path automatically.

From the Openshift site:

Command line utilities that are usually installed using the -g or --global flag will be automatically be added to the system $PATH, as long as they are included in the dependencies or devDependencies sections of the project’s package.json file.

Inside .openshift/action_hooks/build you need to first reset the home directory to be the repo directory, then run grunt build then switch the home directory back to the original.

#!/bin/bashOLD_HOME=$HOMEcd $OPENSHIFT_REPO_DIRexport HOME=$OPENSHIFT_REPO_DIRgrunt buildexport HOME=$OLD_HOME

Now grunt will be able to find your Gruntfile.js and run whatever tasks you need.


One possibility is to use the postinstall phase to execute your grunt task. First, install grunt-cli in a way you're not supposed to:

npm install grunt-cli --save-dev

Then, update your package.json to execute grunt prod in the postinstall phase:

{  ...  "scripts" : {    ...    "postinstall": "node_modules/.bin/grunt prod",    ...  }  ...}

Now when you deploy to OpenShift, and after your dependencies are installed, your grunt task should run.

This solution is not what I would consider perfect, but should get the job done so you can get something up and running while you're building a custom cartridge, like @Samuel has done.