I am working with a community-developed OpenShift cartridge for nginx. The cartridge's build script (without any modifications) works well; it starts the nginx server with the configuration file that I provide it. However, I am trying to modify the build script so that it first changes directory into my OpenShift repository, runs npm install
and then grunt build
to build an Angular application that I have created.
When I do this, I continuously get the error EACCES, mkdir '/var/lib/openshift/xxxxxxxxxx/.npm'
when the script gets to npm install
. Some OpenShift forum posts have attempted to solve the issue, but it appears as though a different solution is required (at least in my case).
Thus, I am interested in whether or not it is possible to use npm in this way, or if I need to create a cartridge that does all of this myself.
You do not have write access to the ~/.npm directory in your gear. You might try reviewing how the native node.js cartridge is setup (https://github.com/openshift/origin-server/tree/master/cartridges/openshift-origin-cartridge-nodejs) and see if you can apply it to your custom cartridge.
Since we do not typically have the access required to create
~/.npm
, we have to find ways of moving the npm cache (normally~/.npm
) and the npm user configuration (normally~/.npmrc
) to accessible folders to get things going. The following information comes partially from a bug report that I submitted to Redhat on this matter.We must begin by creating an environmental variable to control the location of .npmrc. I created a file (with shell access to my application) called
.env
in$OPENSHIFT_DATA_DIR
. Within this file, I have placed:This moves the
.npmrc
directory to a place where we have the privileges to read/write. Naturally, I have to also create the directory.npmrc
in$OPENSHIFT_HOMEDIR/app-root/build-dependencies/
. Then, in my pre-start webhook/early in my build script, I have placed:This ensures that the environmental variable that configures the location of
.npmrc
will be accessible each time we deploy/build. Now we can move the location of the npm cache. Start by runningtouch
on the.env
file manually, and create the.npm
directory in$OPENSHIFT_HOMEDIR/app-root/build-dependencies/
. Run the following to complete the reconfiguration:NPM should now be accessible each time we deploy, even if we are not using the NodeJS cartridge. The above directory choices may be changed as desired.