Search code examples
node.jsgitopenshiftopenshift-cartridge

Why does pushing my locally created MEAN-Application to OpenShift not work?


I'm trying to push my MEAN-Application, which I created locally using express, to OpenShift. For that, I create a new application from the dashboard and add NodeJS as a cartridge. When I then add my Git-Repository-URL (Hosted on BitBucket) and create the application, I get the following error:

Error from the Openshift Dashboard

When I create a new application without entering the repository URL and then pull from Openshift, copy in my Project and Push again, I get a similar error:

Error from Git-Push

It seems to be some problem with port 8080 being unavailable but I cant resolve this myself as I'm new to this and couldn't find a solution on the web, so any help & advice is appreciated.

EDIT: when I say MEAN I actually mean EAN; I don't use MongoDB at the moment.

EDIT 2: after several hours I decided to try Heroku. It also didn't work on the first try but the Log contained far more useful information so I got everything up and running in about an hour (compared to like 4 hours of trying with OpenShift). After that I tried to push the exact same Project I pushed to Heroku to Openshift and got the following, new error:

New Openshift error log

Again, if somebody happens to know a quick fix for this please tell me as I would still like to use OpenShift.


Solution

  • What worked for me was the following:

    1. Create App on OpenSHift, leave Repo Url empty for now.
    2. Use git remote add openshift -f <openshift-git-repo-url (ssh://...something)> to add the Openshift-Repo as a remote Repo to your Project.
    3. Use git merge openshift/master -s recursive -X ours to merge the Openshift-Repo into your local Repo and keep your files if conflicts appear.
    4. (And this is the important step) Your main File (bin/www for me) has to look something like this (I tried everything to format this but it just didn't format properly):

      var app = require('../app'); var debug = require('debug')('CTW:server'); var http = require('http');

      /**

      • Get port from environment and store in Express. */ app.set('port', process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 3002); app.set('ip', process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1");

      /**

      • Create HTTP server. */

      var server = http.createServer(app);

      /**

      • Listen on provided port, on all network interfaces. */

      server.listen(app.get('port') ,app.get('ip'));

    5. git push openshift HEAD to push it to your Application Repo

    As it turns out, I had to set the IP.

    All credit goes to this and this questions answers.