Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing git through .ebextensions on Elastic Beanstalk

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 [email protected] No repository field.
  npm WARN package.json [email protected] 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.
like image 334
Nick Pestov Avatar asked Apr 19 '15 01:04

Nick Pestov


People also ask

What is .ebextensions in AWS Elastic Beanstalk?

You can add AWS Elastic Beanstalk configuration files ( . ebextensions ) to your web application's source code to configure your environment and customize the AWS resources that it contains. Configuration files are YAML- or JSON-formatted documents with a . config file extension that you place in a folder named .


2 Answers

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.

like image 177
ddtraveller Avatar answered Sep 22 '22 07:09

ddtraveller


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

like image 29
elssar Avatar answered Sep 23 '22 07:09

elssar