我才刚刚开始探索OpenShift Online 3
,看起来真的很棒。我正在尝试设置一个简单的HTTP服务器。这是我使用的步骤CLI
:
我当前的工作文件夹包含两个文件package.json
和server.js
。
Package.json
{
"name": "test",
"version": "0.0.1",
"description": "Node.js app for OpenShift 3",
"main": "server.js",
"dependencies": {
"express": "^4.13.4"
},
"engine": {
"node": "*",
"npm": "*"
},
"scripts": {
"start": "node server.js"
}
}
Server.js
const express = require('express')
const app = express()
const port = process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080
const ip = process.env.IP || process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0'
app.get('/', function (req, res) {
res.status(200).send({ message: 'OK' })
})
// error handling
app.use(function(err, req, res, next){
console.error(err.stack)
res.status(500).send('Something bad happened!')
})
app.listen(port, ip)
console.log('Server running on http://%s:%s', ip, port)
module.exports = app
这是控制台输出:
--> Creating resources ...
imagestream "olmeo-openshift" created
buildconfig "olmeo-openshift" created
deploymentconfig "olmeo-openshift" created
service "olmeo-openshift" created
--> Success
Build scheduled, use 'oc logs -f bc/olmeo-openshift' to track its progress.
Run 'oc status' to view your app.
构建完成后,Web控制台显示错误:
Environment:
DEV_MODE=false
NODE_ENV=production
DEBUG_PORT=5858
Launching via npm...
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm ERR! Linux 3.10.0-693.12.1.el7.x86_64
npm ERR! argv "/opt/rh/rh-nodejs6/root/usr/bin/node" "/opt/rh/rh-nodejs6/root/usr/bin/npm" "run" "-d" "start"
npm ERR! node v6.11.3
npm ERR! npm v3.10.9
npm ERR! path /opt/app-root/src/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/opt/app-root/src/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/opt/app-root/src/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /opt/app-root/src/npm-debug.log
显然,package.json
找不到。我想念什么?
如果您使用:
oc new-app .
在从远程托管的Git存储库中克隆的git工作区中,将建立构建以从托管的Git存储库中提取文件。这意味着,如果您进行本地更改,并且不将其添加/提交/推送到托管的Git存储库,则将永远不会使用它们。
如果要从本地目录工作而不使用托管的Git存储库,则需要使用二进制输入构建。为此,请首先运行:
oc new-build --binary --image-stream nodejs --name olmeo-openshift
然后运行以下命令开始构建:
oc start-build olmeo-openshift --from-dir=.
这将从本地目录上载文件。
构建第一个映像后,即可运行:
oc new-app olmeo-openshift
部署映像,并:
oc expose svc/olmeo-openshift
给它一个公共URL。
每次更改代码时,请再次运行:
oc start-build olmeo-openshift --from-dir=.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句