8

I'm getting an error deploying to Elastic Beanstalk, because there is no git on the instance. One of the dependencies in my package.json is dependant on a git repository and needs to git clone. Git is not installed on the instances. I tried installing it through .ebextensions .conf file while deploying, through yum, but when I ssh into the instance it's not there.

Question is: what is the correct way to install and have git on a Linux instance running on Elastic Beanstalk before npm install is called on that instance?

Here's the log showing the error:

[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.
Nick Pestov
  • 571
  • 5
  • 15
  • 1
    Have a look [here](http://stackoverflow.com/questions/13642171/elastic-beanstalk-ruby-rails-need-to-install-git-so-bundle-install-works-but-i). – Tim Biegeleisen Apr 19 '15 at 01:50
  • 1
    ...and [here](https://github.com/npm/npm/issues/5967) – Tim Biegeleisen Apr 19 '15 at 01:52
  • Thanks @TimBiegeleisen, I have tried including git as a yum package in the .ebextensions con file, tried the second approach with the dependencies as well, still the same. – Nick Pestov Apr 19 '15 at 02:07
  • 1
    Can you try installing Git directly on your Linux instance? – Tim Biegeleisen Apr 19 '15 at 02:48
  • Yes. It works that way. But I need git to be there if the EB instance is recreated or when new ones are created in that autoscaling group, which I thought could be achieved through .ebextensions – Nick Pestov Apr 19 '15 at 02:56
  • Don't you have git already installed on the AMI? – Guy Apr 19 '15 at 09:20
  • No, there's no git installed on the AMI. I can use custom AMIs with git on them, but the question still stands: what is the right way to install git on the default Elastic Beanstalk EC2 instances? – Nick Pestov Apr 19 '15 at 14:34
  • 2
    My elasticbeanstalk group just started failing to NPM install because no git was found. First error in a almost 6 months, no code changes anywhere - frozen version numbers. Maybe a bug on AWS side? – Adrian Seeley Apr 19 '15 at 16:06

2 Answers2

23

If you put a config file in your .ebextensions folder like this:

packages:
  yum:
    git: []

Make sure the git package is in a config file with a higher execution index then one that actually requires git. It is common to have it in a first config file named: 00-packages.config.

North-Pole
  • 610
  • 4
  • 13
ddtraveller
  • 1,029
  • 12
  • 18
  • 1
    this is what I'm using and it works. [aws doc](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-packages) – Raju Aug 30 '17 at 15:01
3

I can think of three ways you could ensure git(or any dependency) is installed on the system before npm install is run.

  1. Define a preinstall script in your package.json that installs git if required.
  2. You can add a script(file), using ebextensions in either the pre-appdeploy hooks directory, or the preinit hooks directory. I would suggest the preinit hook, as that's where the hook for installing packages is. Just set the path of your script to /opt/ebextensions/hooks/preinit/99_install_git.sh, or if you want to do in pre-appdeploy, /opt/ebextensions/hooks/appdeploy/pre/99_install_git.sh, and make the file executable by using the mode field.
  3. Using ebextensions to install a package.

For your use case, I think #3 is the best option. Kinda late, but I hope you find it useful

elssar
  • 5,651
  • 7
  • 46
  • 71
  • This is helpful, thanks! But the OP says he included git as a yum package in a ```.elasticbeanstalk/*.config``` --which should do what you suggest in #3, correct? So why does EB ignore it? – ericpeters0n Mar 08 '16 at 07:42
  • @ericpeters0n I have no idea. I've always found beanstalk to be a fickle beast. Could be an intermittent issue with the instance. – elssar Mar 11 '16 at 12:19