在 elastic beanstalk 的 container_commands 中执行命令时没有路径

No path when executing commands in elastic beanstalk's container_commands

我正在尝试在 AWS Elastic Beanstalk 上部署应用程序。我在 .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"

基本上,我想要 运行 grunt prod,这将下载 bower 依赖项,编译我的 coffeescript,minify/concat 我的 js 和其他一些东西。 git、nodejs、g运行t、coffee 和 bower 安装工作正常(我可以 ssh 并确认命令可用并且在路径上)。但是,如果我在调用 bower 时不包括 export PATH=/usr/local/bin:/bin:/usr/bin; 部分,我会得到:

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

我尝试调试并添加 which git &>> /tmp/deploy.log 但得到 which: no git in ((null))。但是,如果我这样做 echo $PATH &>> /tmp/deploy.log 我会得到一条好看的路径:/usr/local/bin:/bin:/usr/bin

问题是:为什么调用bower时需要指定路径?

经过大量调试,似乎设置了 PATH 但没有导出。我只需要在调用 grunt:

之前添加 export PATH=$PATH;
container_commands:
  01_grunt:
    command: "export PATH=$PATH; grunt prod &>> /tmp/deploy.log"

请注意,您必须在同一个 command: 内执行 PATH=$PATH

这行不通...

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

失败...

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

注意:由于 container_command 是以 root 身份执行的,因此您必须使用 bower install --allow-root