在Elastic Beanstalk上通过.ebextensions安装git

我收到了部署到Elastic Beanstalk的错误,因为实例上没有git。 我的package.json中的一个依赖依赖于一个git仓库,需要git clone 。 Git没有安装在实例上。 我尝试通过.ebextensions .conf文件进行安装,同时通过yum进行部署,但是当我将ssh移入实例时,它不在那里。

问题是:在该实例上调用npm install之前,在Elastic Beanstalk上运行的Linux实例上安装和运行git的正确方法是什么?

以下是显示错误的日志:

 [2015-04-18T09:00:02.815Z] ERROR [1777] : Command execution failed: Activity failed. (ElasticBeanstalk::ActivityFatalError) caused by: + /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install npm WARN package.json amity-api-v2@2.0.0 No repository field. npm WARN package.json amity-api-v2@2.0.0 No README data npm WARN `git config --get remote.origin.url` returned wrong result (https://github.com/awslabs/dynamodb-document-js-sdk) undefined npm WARN `git config --get remote.origin.url` returned wrong result (https://github.com/awslabs/dynamodb-document-js-sdk) undefined npm ERR! git clone https://github.com/awslabs/dynamodb-document-js-sdk undefined npm ERR! git clone https://github.com/awslabs/dynamodb-document-js-sdk undefined npm ERR! Linux 3.14.35-28.38.amzn1.x86_64 npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v0.12.0-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v0.12.0-linux-x64/bin/npm" "--production" "install" npm ERR! node v0.12.0 npm ERR! npm v2.5.1 npm ERR! code ENOGIT npm ERR! not found: git npm ERR! npm ERR! Failed using git. npm ERR! This is most likely not a problem with npm itself. npm ERR! Please check if you have git installed and in your PATH. 

我可以想到三种方法可以确保在npm install之前在系统上安装git (或任何依赖项)。

  1. package.json中定义一个preinstall脚本,在需要时安装git
  2. 您可以在pre-appdeploy挂钩目录或preinit挂钩目录中使用ebextensions来添加脚本(文件) 。 我会build议preinit挂钩,因为这是安装包的挂钩。 只需将脚本的path设置为/opt/ebextensions/hooks/preinit/99_install_git.sh ,或者如果您想在预先appdeploy中执行/opt/ebextensions/hooks/appdeploy/pre/99_install_git.sh ,并使文件可通过使用mode字段执行。
  3. 使用ebextensions来安装一个包 。

对于你的用例,我认为#3是最好的select。 有点晚了,但我希望你觉得它有用

如果你把你的.ebextensions文件夹中的configuration文件如下所示:

 packages: yum: git: [] 

确保git包在一个configuration文件中具有更高的执行索引,然后实际上需要git。 在第一个名为00-packages.configconfiguration文件中使用它是很常见的。