什么是在OpenShift v2 push hook的最后一秒重置PATHvariables?

TL; DR:工作应用程序,克隆它,克隆不能从push hook正确启动(但是如果我在ssh中手动工作的很好) PATH有正确的Node版本添加到它,但是在最后一步正确的地方,版本再次被添加到PATH

path在这里是正确的:

 remote: PATH = /var/lib/openshift/.../app-root/data//node-v4.xx-linux-x64/bin:/var/lib/openshift/.../app-root/runtime/repo/node_modules/.bin:/var/lib/openshift/...//.node_modules/.bin:/opt/rh/nodejs010/root/usr/bin:/bin:/usr/bin:/usr/sbin 

然后不正确之后 ,在这里的某个地方:

 remote: Starting NodeJS cartridge remote: Tue Aug 22 2017 15:39:10 GMT-0400 (EDT): Starting application 'staging' ... 

那么在最后两行中或之前代表什么脚本和钩子呢? PATH不只是添加线条本身…


我有一个工作的OpenShift v2应用程序运行一个新的NodeJS版本, 足以支持胖箭头符号 。

看来它是在Openshift的每个自定义node.js版本上设置的,因为这个回购(用于使用标记文件)的脚本存在于.openshift

我使用rhc create --from-appbuild立了第二个基于工作rhc create --from-app ,重置回购,然后重新部署到它。 第二个工作很好,除了开始node的最后一步:

 remote: npm info ok remote: NOTE: The .openshift/action_hooks/build hook is not executable, to make it executable: remote: On Windows run: git update-index --chmod=+x .openshift/action_hooks/build remote: On Linux/OSX run: chmod +x .openshift/action_hooks/build remote: Preparing build for deployment remote: Deployment id is cedf7f51 remote: Activating deployment remote: NOTE: The .openshift/action_hooks/deploy hook is not executable, to make it executable: remote: On Windows run: git update-index --chmod=+x .openshift/action_hooks/deploy remote: On Linux/OSX run: chmod +x .openshift/action_hooks/deploy remote: remote: - pre_start_nodejs: Adding Node.js version 4.xx binaries to path remote: - PATH set to include custom node version (4.xx) from remote: /var/lib/openshift/.../app-root/data//node-v4.xx-linux-x64/bin remote: PATH = /var/lib/openshift/.../app-root/data//node-v4.xx-linux-x64/bin:/var/lib/openshift/.../app-root/runtime/repo/node_modules/.bin:/var/lib/openshift/...//.node_modules/.bin:/opt/rh/nodejs010/root/usr/bin:/bin:/usr/bin:/usr/sbin remote: Starting NodeJS cartridge remote: Tue Aug 22 2017 15:39:10 GMT-0400 (EDT): Starting application 'staging' ... remote: Waiting for application port (8080) become available ... 

(到目前为止,所有的东西都和在工作应用中一样,除了名字。)

 remote: Application 'staging' failed to start (port 8080 not available) remote: ------------------------- remote: Git Post-Receive Result: failure remote: Activation status: failure remote: Activation failed for the following gears: remote: ... (Error activating gear: CLIENT_ERROR: Failed to execute: 'control start' for /var/lib/openshift/.../nodejs remote: #<IO:0x00000001cd42d0> remote: #<IO:0x00000001cd4258> remote: ) remote: Deployment completed with status: failure remote: postreceive failed 

rhc envrhc app show显示的设置在所有方面都是相同的。

我从其他问题知道,上面的“8080端口”是红鲱鱼。 另外,如果我rhc ssh并手动node www.js ,它使用该端口就好了,我可以通过浏览器访问应用程序。

所以我调查使用rhc tail 。 我可以看到,由于胖箭头符号的缘故,反复启动失败:

 pg.on('error', (err) => { ^ SyntaxError: Unexpected token > at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) ... DEBUG: Program node ./www.js exited with code 8 DEBUG: Starting child process with 'node ./www.js' 

然而,如果我rhc ssh同一个服务器并运行node --version ,我会得到更新的版本(与其他服务器的版本相同,它们都从我部署的.openshift目录中的标记文件中.openshift )。

我猜不知什么推钩的最后一步是使用节点0.10,因为这是两个应用程序命名的墨盒。 但是,如果我检查添加到PATH ,实际上新的节点版本实际上居住在那里。

然而 ,这是事情变得有趣的地方。 上面报告的PATH (前缀4.xx) 不再是启动Node时的path 。 我改变了www.js只是吐出了process.env.PATH并比较了两者。 后者有这两条路join了开头!

 /opt/rh/nodejs010/root/usr/bin /opt/rh/v8314/root/usr/bin 

这是什么,我怎么能阻止它? 在这些产出方面甚至有机会呢?

 remote: PATH = /var/lib/openshift/.../app-root/data//node-v4.xx-linux-x64/bin:/var/lib/openshift/.../app-root/runtime/repo/node_modules/.bin:/var/lib/openshift/...//.node_modules/.bin:/opt/rh/nodejs010/root/usr/bin:/bin:/usr/bin:/usr/sbin remote: Starting NodeJS cartridge remote: Tue Aug 22 2017 15:39:10 GMT-0400 (EDT): Starting application 'staging' ... 

(为什么只是在我的第二个应用程序,当我用--from-app来创build它,所有其他设置似乎是相等的两个?)

在应用程序最初用于定制NodeJS版本的129个分支之一中,有一个问题解决了它的评论 :

添加一行到.openshift\lib\utils

 # Add the node binary path to the PATH. export OPENSHIFT_NODEJS_VERSION=0.6 ### this is the new line export PATH="$node_bin_path:${PATH}" 

“就像你提到的那样,重要的是它被设置为0.6,即使你没有运行0.6。

即使原始节点版本恢复到0.6也是很重要的,它被设置为0.6。 (我用0.10试过,没有运气,这里是0.6的魔术答案。)

Node.js (Latest)盒式磁带

@ hub.openshift:Node.js最新

默认情况下,Node.js版本是通过查询semver.io/node/stable来确定的。

可以通过NODE_VERSION_URL环境variables或通过在应用程序库中设置.openshift/NODE_VERSION_URL标记来指定不同的URL。

例如,通过将其放在NODE_VERSION_URLvariables或.openshift / NODE_VERSION_URL标记中,您将得到最新的0.10.x:

https://semver.io/node/resolve/0.10

如果您使用的是非默认的Node.js版本,并且您计划将应用程序跨越多个档位,则必须使用环境variables(请参阅此处了解原因) 。


其他可能的方法

pre_build 操作钩子解决方法:

 #!/bin/bash #NODE_VERSION_URL TARGET_NODE_VERSION=$(node -e "var p = require('$OPENSHIFT_REPO_DIR/package.json')||{engines:{}}; console.log(encodeURI(p.engines.node||''));") echo "https://semver.io/node/resolve/$TARGET_NODE_VERSION" > ${HOME}.env/user_vars/NODE_VERSION_URL #NPM_VERSION_URL TARGET_VERSION=$(node -e "var p = require('$OPENSHIFT_REPO_DIR/package.json')||{engines:{}}; console.log(encodeURI(p.engines.npm||''));") echo "https://semver.io/npm/resolve/$TARGET_VERSION" > ${HOME}.env/user_vars/NPM_VERSION_URL 

package.json engines解决方法:

从这个repo中添加.openshift文件夹可以让你使用package.json文件的引擎部分运行你需要的任何版本的nodejs (参见README的使用方法) :

 "engines": { "node": ">= 0.12.0" },