4

I am trying to deploy an application on AWS Elastic Beanstalk. I have the following file in .ebextensions:

commands:
  01-install-git:
    command: "yum install -y git &>> /tmp/deploy.log"
  02-install-nodejs-npm:
    command: "yum install -y --enablerepo=epel nodejs npm &>> /tmp/deploy.log"
  03-install-grunt:
    command: "npm install -g grunt-cli &>> /tmp/deploy.log"
  04-install-coffee:
    command: "npm install -g coffee-script &>> /tmp/deploy.log"
  05-install-bower:
    command: "npm install -g bower &>> /tmp/deploy.log"
container_commands:
  01_grunt:
    command: "export PATH=/usr/local/bin:/bin:/usr/bin; grunt prod &>> /tmp/deploy.log"

Basically, I want to run grunt prod and that will download bower dependencies, compile my coffeescript, minify/concat my js and some other stuff. The git, nodejs, grunt, coffee, and bower installation works fine (I can ssh and confirm that the commands are available and on the path). However, if I don't include the export PATH=/usr/local/bin:/bin:/usr/bin; part when calling bower, I get:

Running "bower:install" (bower) task
Fatal error: git is not installed or not in the PATH

I tried to debug and add which git &>> /tmp/deploy.log but got which: no git in ((null)). However if I do echo $PATH &>> /tmp/deploy.log I get a good looking path: /usr/local/bin:/bin:/usr/bin

Question is: why do I need to specify the path when calling bower?

Manuel Darveau
  • 4,585
  • 5
  • 26
  • 36

2 Answers2

7

After a lot of debugging, it seems like the PATH is set but not exported. I only needed to add export PATH=$PATH; before calling grunt:

container_commands:
  01_grunt:
    command: "export PATH=$PATH; grunt prod &>> /tmp/deploy.log"
Manuel Darveau
  • 4,585
  • 5
  • 26
  • 36
  • The syntax `command: PATH=$PATH grunt prod &>> /tmp/deploy.log` also works, as the variable definition command also allows running a command after setting the variable with the variable exported. If you already have a multi-line command, though, you will need the `export PATH=$PATH; ...` syntax. – Logan Pickup Jul 06 '16 at 04:16
0

Note that you must execute the PATH=$PATH within the same command:.

This does not work...

container_commands:
  01_path:
    command: "export PATH=$PATH; echo $PATH &>> /tmp/01_path.log"
    ignoreErrors: true
  02_bower_install:
    command: "$NODE_HOME/bin/node ./node_modules/bower/bin/bower install --allow-root &>> /tmp/02_bower_install.log"
    ignoreErrors: true

Fails with...

bower    no-home HOME environment variable not set. User config will not be loaded.
ENOGIT git is not installed or not in the PATH

NB: As container_command is executed as root, you must use bower install --allow-root

rmharrison
  • 4,730
  • 2
  • 20
  • 35