Ned Ned - 1 year ago 138
Node.js Question

Deploying NodeJS application to Openshift

I have working SailsJS app that I want to deploy to Openshift, but as usual it doesn't go smoothly.
Here's what I did so far:

rhc app create myApp nodejs-0.10
rhc cartridge add mongodb-2.4

After these two, I can see that app is created and when I visit given URL, I got Welcome page.

I installed RockMongo, and I see that I can visit my mongodb as well.

Since I already have code, I proceed with following:

git remote add openshift -f <openshift-git-repo-url>
git merge openshift/master -s recursive -X ours
git push openshift HEAD

After I merge my existing code with remote openshift (like in commands above), things start to go wrong.

When I visit url to application, I receive 503 Service temporarily unavailable. If I visit RockMongo and try to login with given credentials, I receive

Unable to connect MongoDB, please check your configurations.
MongoDB said:Failed to connect to: Transport endpoint is not connected.

Also, in Applications Panel, status of my application is building (and stays like that for hours). After pushing code to openshift, application stopped, and after rebuilding it (automatically) I receive some errors, where the last one is

remote: An error occurred executing 'gear postreceive' (exit code: 34)
remote: Error message: CLIENT_ERROR: Failed to execute: 'control build' for /var/lib/openshift/538f1c205004461655000227/nodejs

Does anyone has idea what's going on?

Maybe I didn't set up ports, application url, db url properly? But then again, why RockMongo stopped working?


Here's my mongo config:

mongo: {
module: 'sails-mongo',
user: 'admin',
password: '********',
url: process.env.OPENSHIFT_MONGODB_DB_URL + 'surge'

Do I need to set up
server_port = process.env.OPENSHIFT_NODEJS_PORT
server_ip_address = process.env.OPENSHIFT_NODEJS_IP
as well?
I have some server.js file in root of my application, and I see that these variables are used here.

Here's what I get if I run
env | grep NODEJS


and here's what I get for
env | grep mongo


Ned Ned
Answer Source

Just in case someone else stumbles upon this problem, here is what I had to do.

I created separate file config/application.js, and there I placed

module.exports = {
  port: process.env.OPENSHIFT_NODEJS_PORT,
  host: process.env.OPENSHIFT_NODEJS_IP,
  environment: 'production'

Also I found what was the problem with application not starting. Post-install was failing (bower install did not finish successfully). To fix it, one should add to scripts section of package.json

"postinstall": "export HOME=/var/lib/openshift/[instance-id]/app-root/runtime/repo; ./node_modules/bower/bin/bower install"