简体   繁体   中英

Deploy existing Node.js source on OpenShift

I have created a Node.js app on my Windows PC. Now I want to deploy this app on Openshift.

I have installed the rhc and set my SSH key .

After many attempts I failed to deploy my app on Openshift.

I have created an app on Openshift for Node.js in this address:
http://webalves-javalinuxcode.rhcloud.com/

I have a webapp hosted in Openshift using NodeJS and Postgres. To deploy it I use Openshift git repository, which triggers the deploy on every commit.

Here's the documentation about Openshift deploy .

Once you have the rhc installed and the SSH key already set, I believe the steps bellow can help you to deploy it.

  1. Clone the git repository created by Openshift for you project: rhc git-clone <app_name> OR create manually your git remote pointing to Openshift repository

  2. Remove all files that are not needed in the folder creted as your local repository (Openshift may create some default files for your project)

  3. Unzip the source from you project inside the git repository folder

  4. Commit all your sources: git add . , then git commit -am "Your commit message"

  5. Push the code to Openshift: git push -f

Doing so it must trigger the deploy process and you will see it in the console, as explained in the documentation link I've inserted above.

As an additional information, you have also to make a few changes in your source code. For database access, as any other resource, Openshift has many environment variables you can access. So, if you need to run your HTTP server implemented in NodeJS in Openshift, you will need to make some changes, like this:

package.json

"scripts": {
    "start": "node server.js"
}

server.js

var serverPort = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var serverIpAaddress = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';

var server = app.listen(serverPort, serverIpAaddress, function() {
    logger.info("Starting application");
    logger.info("Starting HTTP server - port %s", server.address().port);
});

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM