Beanstalk:Node.js部署-由于权限被拒绝,node-gyp失败 [英] Beanstalk: Node.js deployment - node-gyp fails due to permission denied
问题描述
将Node.js应用程序(节点6,npm 5)部署到Beanstalk失败,
Deployment of a Node.js application (Node 6, npm 5) to Beanstalk fails with:
gyp错误!堆栈错误:EACCES:权限被拒绝,mkdir '/tmp/deployment/application/node_modules/heapdump/build'
gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/heapdump/build'
尽管该错误不是特定于软件包的,但是任何node-gyp调用都会失败.
though the error is not package-specific, any node-gyp call fails.
AWS控制台中的ERROR事件显示为:
The ERROR event in the AWS Console reads:
[Instance:i-12345]命令在实例上失败.返回 代码:1输出: (已截断).../opt/elasticbeanstalk/containerfiles/ebnode.py",行 180,在npm_install中引发e子进程.CalledProcessError:命令 '['/opt/elasticbeanstalk/node-install/node-v6.10.0-linux-x64/bin/npm', '--production','install']'返回非零退出状态1.挂钩 /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh失败.欲了解更多 详细信息,请使用控制台或EB CLI检查/var/log/eb-activity.log.
[Instance: i-12345] Command failed on instance. Return code: 1 Output: (TRUNCATED).../opt/elasticbeanstalk/containerfiles/ebnode.py", line 180, in npm_install raise e subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v6.10.0-linux-x64/bin/npm', '--production', 'install']' returned non-zero exit status 1. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
和eb-activity.log
包含上述npm错误.
and eb-activity.log
contained the aforementioned npm error.
通过上载不包含node_modules
的.zip文件来手动部署该应用程序. IE.它不是通过eb
命令行工具进行部署的.
The application was deployed manually by uploading a .zip file that did not include node_modules
. I.e. it was not deployed via the eb
command-line tool.
推荐答案
解决方案
解决方案是将文件.npmrc
添加到具有以下内容的应用程序中:
Solution
The solution is to add the file .npmrc
to the application with the content:
# Force npm to run node-gyp also as root, preventing permission denied errors in AWS with npm@5
unsafe-perm=true
(或以其他任何方式配置npm.(尽管/opt/elasticbeanstalk/env.vars
中的npm_config_unsafe_perm=true
设置对我不起作用.)
(Or configuring npm so in any other way. (Though setting npm_config_unsafe_perm=true
in /opt/elasticbeanstalk/env.vars
did not work for me.)
npm install
由root用户运行,但它为某些软件包触发的node-gyp
进程由默认用户ec2-user
运行.该用户无法访问由npm install运行创建并由root拥有的/tmp/deployment/application/node_modules/
目录. (而且它可能也无法访问由同一个对象创建的/tmp/.npm
和/tmp/.config
.)通过启用unsafe-perm
,我们强制npm也以root用户身份运行node-gyp,从而避免了该问题.
npm install
is run by the root user but the node-gyp
process it triggers for some packages is run by the default user ec2-user
. This user lacks access to the /tmp/deployment/application/node_modules/
directory created by the npm install run and owned by root. (And it likely also lacks access to /tmp/.npm
and /tmp/.config
created by the same.) By enabling unsafe-perm
we force npm to run node-gyp also as root, avoiding the problem.
(就我个人而言,我宁愿将它们全部作为ec2-user
而不是root
来运行,但我想这会涉及更多的问题:-))
(Personally I would prefer to run all as ec2-user
rather than root
but I guess that would be more involved :-))
这篇关于Beanstalk:Node.js部署-由于权限被拒绝,node-gyp失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!