简体   繁体   English

在OpenShift上部署现有Node.js源

[英]Deploy existing Node.js source on OpenShift

I have created a Node.js app on my Windows PC. 我已经在Windows PC上创建了一个Node.js应用程序。 Now I want to deploy this app on Openshift. 现在,我想在Openshift上部署此应用程序。

I have installed the rhc and set my SSH key . 我已经安装了rhc并设置了SSH key

After many attempts I failed to deploy my app on Openshift. 经过多次尝试,我无法在Openshift上部署我的应用程序。

I have created an app on Openshift for Node.js in this address: 我已经在此地址的Openshift上为Node.js创建了一个应用程序:
http://webalves-javalinuxcode.rhcloud.com/ http://webalves-javalinuxcode.rhcloud.com/

I have a webapp hosted in Openshift using NodeJS and Postgres. 我有一个使用NodeJS和Postgres在Openshift中托管的Webapp。 To deploy it I use Openshift git repository, which triggers the deploy on every commit. 要部署它,我使用Openshift git存储库,它会在每次提交时触发部署。

Here's the documentation about Openshift deploy . 这是有关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. 一旦您安装了rhc并且已经设置了SSH key ,我相信下面的步骤可以帮助您进行部署。

  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 克隆由Openshift为您创建的git存储库: rhc git-clone <app_name>或手动创建指向Openshift存储库的git remote目录

  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) 删除creted文件夹中不需要的所有文件作为本地存储库(Openshift可能会为您的项目创建一些默认文件)

  3. Unzip the source from you project inside the git repository folder 从项目的git repository文件夹中解压缩源代码

  4. Commit all your sources: git add . 提交所有资源: git add . , then git commit -am "Your commit message" ,然后git commit -am "Your commit message"

  5. Push the code to Openshift: git push -f 将代码推送到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. 与其他资源一样,对于数据库访问,Openshift具有许多您可以访问的环境变量 So, if you need to run your HTTP server implemented in NodeJS in Openshift, you will need to make some changes, like this: 因此,如果您需要运行在Openshift的NodeJS中实现的HTTP服务器,则需要进行一些更改,如下所示:

package.json package.json

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

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. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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