nodejs-custom-version-openshift icon indicating copy to clipboard operation
nodejs-custom-version-openshift copied to clipboard

Bcrypt Module Issue

Open funseiki opened this issue 13 years ago • 11 comments

It seems as though 'git push'-ing doesn't seem to install the Node bcrypt module SSH-ing in running npm list from the REPO_DIR shows that bcrypt did not install.

Running 'npm install' from this directory seems to resolve the issue, though.

It isn't clear to me why this happens with bcrypt. Is this a permission issue regarding access to OpenSSL?

funseiki avatar Jun 10 '13 17:06 funseiki

Looks like its because node-gyp is not installed on OpenShift + the node version it has is v0.6 -- which is about 1.5 years + old now. You should really bug OpenShift to update the version of Node.js ...

In any case, b*ching aside, what you need to do is add/modify these lines in your package.json: "dependencies": { "express": "", "node-gyp": "", "bcrypt": "" },

Basically add node-gyp as a dependency + of course bcrypt. Aside: express is there because my sample app is an express app.

HTH

ramr avatar Jun 12 '13 04:06 ramr

Ah, I see. Thanks for that. Yeah, I was hoping they might with the new update.

funseiki avatar Jun 12 '13 04:06 funseiki

So I tried adding node-gyp, but bcrypt still didn't seem to like it. Looking at the top of the npm log, I see:

"info using [email protected]" which is not correct as I should be running 0.8.21 (this is the version that appears when I run "node -v").

Any idea as to what might be causing the problem?

Note: The error appears to be the same, but after adding node-gyp, that build process after a push takes significantly longer (not sure if this is to be expected).

funseiki avatar Jun 12 '13 19:06 funseiki

I received a similar error when trying to deploy my node js app with a custom version of 0.10.1

I think its a problem with the v2 cartridges.

When I ssh into the gear and do a "node -v" i see the version as 0.10.1

But I too get "info using [email protected]"

So is there any workaround? Or since now custom cartridges are supported, could a custom NodeJS v0.8 or v0.10 Cartridge be created?

tsjamm avatar Jun 12 '13 19:06 tsjamm

Hmm @funseiki and @tsjamm, I just created a new app (followed these instructions https://github.com/ramr/nodejs-custom-version-openshift/blob/master/README.md) and added node-gyp and bcrypt to package.json and it works fine for me.

Do you have a npm-shrinkwrap.json by any chance? Try deleting that and see if it works. Or are you doing something custom in the action hooks? Make sure to source the custom node env in those hooks. Something like:
source "$OPENSHIFT_REPO_DIR/.openshift/lib/setup_custom_nodejs_env"

FYI, as an example to test this out, here's the steps I followed:

rhc app create -a node10 -t nodejs-0.6  
cd node10  
git remote add upstream -m master    \
     git://github.com/ramr/nodejs-custom-version-openshift.git  
git pull -s recursive -X theirs upstream master   
echo 0.10.10 >> .openshift/markers/NODEJS_VERSION  
git commit . -m 'use Node version 0.10.10'  
vi package.json   #  and added node-gyp and bcrypt to the dependencies.   
git commit package.json -m 'add node-gyp + bcrypt'   
node -e "require('./package.json')"    #  or  python -m json.tool package.json   
git push   

And then ssh into your app and:

[node10-ramr.rhcloud.com ~]\>   cd $OPENSHIFT_REPO_DIR   
[node10-ramr.rhcloud.com repo]\>  node -e "require('bcrypt').hash('node10', 8, \
       function(err, hash) { console.log(hash); });"  
$2a$08$/4Sdm.AJiPvILYWDUeeX5OBBhMeDep8mCQO1pJP6dcpoDXFk9KWZy 

And that works as you'd want it to.

ramr avatar Jun 13 '13 05:06 ramr

Perhaps this was because I was using an existing repo. So my steps look as follows:

1) Create a node.js app using web console
2) cd my_repo_dir
3) git remote add openshift <openshift git repo>
4) git clone git://github.com/ramr/nodejs-custom-version-openshift.git ../another/directory
5) cp ../another/directory/.openshift 
6) Set NODE_ENV=production in the pre_start script (see below)
7) git push -f openshift my_local_branch:master

I realize this is definitely not a carbon copy of the steps you outlined, but I feel like the above should work (it obviously does not). Again, SSHing into my openshift app and running npm install from $OPENSHIFT_REPO_DIR "fixes" the problem, but I then have to go back and run "rhc app start". Not the most ideal setup.

Here is how I set NODE_ENV to production in the pre_start_nodejs-0.6 action hook script

#  Source utility functions.
...

# Set NODE_ENV
echo ""
echo " - pre_start_nodejs: Setting the NODE_ENV variable"
NODE_ENV=production
export NODE_ENV
echo "NODE_ENV: $NODE_ENV"

#  Setup path to include the custom Node[.js] version.
...

Thanks for all the quick responses, by the way - I really appreciate all the help.

funseiki avatar Jun 13 '13 17:06 funseiki

Also, this hopefully shouldn't be a huge issue, but my "main" file is "app.js" and not "server.js" so I have this snippet in my package.json:

"scripts" :
{
    "start": "node $OPENSHIFT_REPO_DIR/app.js"
},

funseiki avatar Jun 13 '13 17:06 funseiki

The package.json file having a script shouldn't matter as the app is started via 'npm start', so that should be ok.

In your pre_start_nodejs* action hook, can you add a node -v and see what the node version is? And if its not 0.10, then add a

source "$OPENSHIFT_REPO_DIR/.openshift/lib/setup_custom_nodejs_env" 

line in there. See if that works. Alternatively is it the case that the script is not being called?
Do you see that NODE_ENV: production in the git push output?

One other option is to try and rename the hook to pre_start_nodejs (drop the -0.6) or symlink to the 0.6 hook ala (ln -s pre_start_nodejs-0.6 pre_start_nodejs) and git add/commit/push and see if that works? If that works I can push a fix out. Thanks.

ramr avatar Jun 14 '13 03:06 ramr

Also am curious, if you create a new app + add the quickstart + add your code - does that work?

FYI, I also just pushed a fix https://github.com/ramr/nodejs-custom-version-openshift/commit/b99acf40eff4bb67f9bd8d1464fefd9e0a9ec930 where renamed the action hooks and symlinked to them for older code - maybe that will help - I dunno - it shouldn't but ...

ramr avatar Jun 14 '13 04:06 ramr

Hi ramr, I think the script is failing in the pre_build phase, since I don't see NODE_ENV: production.

If I go in manually and run npm install, though, and then an rhc app start -a <app name>, I do see NODE_ENV: production.

It also may be that I might have broken something while SSHing into the server. I'll continue tinkering and post a solution if I find one.

I'll be trying your solutions as well - was in the middle of creating an entirely new app the way your README describes and pulling in my own changes (the reverse of my current setup).

funseiki avatar Jun 18 '13 00:06 funseiki

Hmm, ok does adding a set -x in the pre_build hook tell you more? Let me know if you find something more. Thanks.

ramr avatar Jun 19 '13 07:06 ramr