2.2. 将 Node.js 应用程序部署到 Openshift
要将 Node.js 应用部署到 OpenShift,请将 nodeshift 添加到应用,配置 package.json 文件,然后使用 nodeshift 进行部署。
2.2.1. 为 OpenShift 部署准备 Node.js 应用 复制链接链接已复制到粘贴板!
要为 OpenShift 部署准备 Node.js 应用程序,您必须执行以下步骤:
-
将
nodeshift添加到应用程序。 -
将
openshift和start条目添加到package.json文件。
先决条件
-
安装了
npm。
步骤
将
nodeshift添加到应用程序中。$ npm install nodeshift --save-dev将
openshift和start条目添加到package.json中的scripts部分。{ "name": "myApp", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "openshift": "nodeshift --expose --dockerImage=registry.access.redhat.com/rhscl/ubi8/nodejs-12", "start": "node app.js", ... } ... }openshift脚本使用nodeshift将应用部署到 OpenShift。注意Node.js 提供了通用基础镜像和 RHEL 镜像。有关镜像名称的更多信息,请参阅 Node.js 发行注记。
可选 :在
package.json中添加一个files部分。{ "name": "myApp", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { ... }, "files": [ "package.json", "app.js" ] ... }files部分告知nodeshift在部署到 OpenShift 时要包含哪些文件和目录。nodeshift使用node-tar模块根据您在files部分中列出的文件和目录创建 tar 文件。nodeshift将应用部署到 OpenShift 时使用此 tar 文件。如果没有指定files部分,nodeshift将发送整个当前目录,不包括:-
node_modules/ -
.git/ tmp/建议您在
package.json中包含files部分,以避免在部署到 OpenShift 时包括不必要的文件。
-
2.2.2. 将 Node.js 应用部署到 OpenShift 复制链接链接已复制到粘贴板!
您可以使用 nodeshift 将 Node.js 应用部署到 OpenShift。
先决条件
-
安装了
ocCLI 客户端。 -
安装了
npm。 - 在配置路由时,请确保应用程序使用的所有端口都被正确公开。
步骤
使用
oc客户端登录到您的 OpenShift 实例。$ oc login ...使用
nodeshift将应用部署到 OpenShift。$ npm run openshift