Jak*_*olý 61 node.js amazon-elastic-beanstalk
将Node.js应用程序(节点6,npm 5)部署到Beanstalk失败了:
gyp ERR!堆栈错误:EACCES:权限被拒绝,mkdir'/ tmp/deployment/application/node_modules/heapdump/build'
虽然错误不是特定于包,但任何node-gyp调用都会失败.
AWS控制台中的ERROR事件显示:
[实例:i-12345]命令在实例上失败.返回码:1输出:(TRUNCATED).../opt/elasticbeanstalk/containerfiles/ebnode.py",第180行,在npm_install中提升e subprocess.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.
并eb-activity.log包含上述npm错误.
通过上载不包含的.zip文件手动部署应用程序node_modules.即它不是通过eb命令行工具部署的.
Jak*_*olý 174
解决方案是将文件添加.npmrc到具有以下内容的应用程序:
# Force npm to run node-gyp also as root, preventing permission denied errors in AWS with npm@5
unsafe-perm=true
Run Code Online (Sandbox Code Playgroud)
(或配置NPM所以在任何其他方式.(虽然设置npm_config_unsafe_perm=true在/opt/elasticbeanstalk/env.vars我没有工作.)
npm install由root用户运行,但node-gyp它为某些包触发的进程由默认用户运行ec2-user.该用户无法访问/tmp/deployment/application/node_modules/由npm安装运行创建并由root拥有的目录.(它可能也无法获得/tmp/.npm与/tmp/.config由同一个创建的.)通过使unsafe-perm我们强迫NPM也运行节点GYP为根,以避免这个问题.
(就个人而言,我宁愿全部运行ec2-user而不是,root但我想这会更多涉及:-))
通过覆盖初始化服务的脚本中的一些配置,我和我的团队能够在Amazon NodeJS机器上实现此功能。这实际上使用完全相同的脚本和几个额外的命令覆盖了包含的aws节点运行配置。这是您要放置的文件.ebextensions
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
#==============================================================================
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Amazon Software License (the "License"). You may not use
# this file except in compliance with the License. A copy of the License is
# located at
#
# http://aws.amazon.com/asl/
#
# or in the "license" file accompanying this file. This file is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or
# implied. See the License for the specific language governing permissions
# and limitations under the License.
#==============================================================================
chmod 777 -R /tmp
set -xe
sudo /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14239 次 |
| 最近记录: |