问题描述
我正在为nginx使用社区开发的OpenShift弹药筒.盒带的构建脚本(不做任何修改)运行良好;它使用我提供的配置文件启动nginx服务器.但是,我正在尝试修改构建脚本,以使其首先将目录更改到我的OpenShift存储库中,先运行npm install
,然后运行grunt build
来构建我创建的Angular应用程序.
I am working with a community-developed OpenShift cartridge for nginx. The cartridge's build script (without any modifications) works well; it starts the nginx server with the configuration file that I provide it. However, I am trying to modify the build script so that it first changes directory into my OpenShift repository, runs npm install
and then grunt build
to build an Angular application that I have created.
执行此操作时,脚本进入npm install
时,我不断收到错误EACCES, mkdir '/var/lib/openshift/xxxxxxxxxx/.npm'
.一些 OpenShift论坛帖子试图解决了问题,但似乎需要使用其他解决方案(至少就我而言).
When I do this, I continuously get the error EACCES, mkdir '/var/lib/openshift/xxxxxxxxxx/.npm'
when the script gets to npm install
. Some OpenShift forum posts have attempted to solve the issue, but it appears as though a different solution is required (at least in my case).
因此,我对是否可以通过这种方式使用npm,或者是否需要创建自己完成所有操作的墨盒感兴趣.
Thus, I am interested in whether or not it is possible to use npm in this way, or if I need to create a cartridge that does all of this myself.
推荐答案
由于我们通常没有创建~/.npm
所需的访问权限,因此我们必须找到移动npm缓存(通常为~/.npm
)和将npm用户配置(通常为~/.npmrc
)配置为可访问的文件夹,以使操作顺利进行.以下信息部分来自我就此问题提交给Redhat的错误报告
Since we do not typically have the access required to create ~/.npm
, we have to find ways of moving the npm cache (normally ~/.npm
) and the npm user configuration (normally ~/.npmrc
) to accessible folders to get things going. The following information comes partially from a bug report that I submitted to Redhat on this matter.
我们必须首先创建一个环境变量来控制.npmrc的位置.我在$OPENSHIFT_DATA_DIR
中创建了一个名为.env
的文件(可以通过外壳访问我的应用程序).在此文件中,我放置了:
We must begin by creating an environmental variable to control the location of .npmrc. I created a file (with shell access to my application) called .env
in $OPENSHIFT_DATA_DIR
. Within this file, I have placed:
export NPM_CONFIG_USERCONFIG=$OPENSHIFT_HOMEDIR/app-root/build-dependencies/.npmrc
这会将.npmrc
目录移动到我们有权读取/写入的位置.当然,我还必须在$OPENSHIFT_HOMEDIR/app-root/build-dependencies/
中创建目录.npmrc
.然后,在我的启动前webhook中/在构建脚本的早期,我放置了:
This moves the .npmrc
directory to a place where we have the privileges to read/write. Naturally, I have to also create the directory .npmrc
in $OPENSHIFT_HOMEDIR/app-root/build-dependencies/
. Then, in my pre-start webhook/early in my build script, I have placed:
touch $OPENSHIFT_DATA_DIR/.env
这确保了每次部署/构建时都可以访问配置.npmrc
位置的环境变量.现在我们可以移动npm缓存的位置了.首先在.env
文件上手动运行touch
,然后在$OPENSHIFT_HOMEDIR/app-root/build-dependencies/
中创建.npm
目录.运行以下命令以完成重新配置:
This ensures that the environmental variable that configures the location of .npmrc
will be accessible each time we deploy/build. Now we can move the location of the npm cache. Start by running touch
on the .env
file manually, and create the .npm
directory in $OPENSHIFT_HOMEDIR/app-root/build-dependencies/
. Run the following to complete the reconfiguration:
npm config set cache $OPENSHIFT_HOMEDIR/app-root/build-dependencies/.npm
现在,即使不使用NodeJS墨盒,每次部署NPM都应该可以访问.以上目录选择可以根据需要进行更改.
NPM should now be accessible each time we deploy, even if we are not using the NodeJS cartridge. The above directory choices may be changed as desired.
这篇关于OpenShift自定义墨盒和NPM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!