2.2. 将 Node.js 应用程序部署到 Openshift
要将 Node.js 应用部署到 OpenShift,将 nodeshift 添加到应用,配置 package.json 文件,然后使用 nodeshift 部署。
2.2.1. 为 OpenShift 部署准备 Node.js 应用程序 复制链接链接已复制到粘贴板!
要为 OpenShift 部署准备 Node.js 应用程序,您必须执行以下步骤:
-
将
nodeshift添加到应用程序。 -
在
package.json文件中添加openshift和start条目。
先决条件
-
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。注意通用基础镜像和 RHEL 镜像可用于 Node.js。有关镜像名称的更多信息,请参阅 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