【问题标题】:No path when executing commands in elastic beanstalk's container_commands在弹性beantalk的container_commands中执行命令时没有路径
【发布时间】:2015-04-04 19:07:23
【问题描述】:

我正在尝试在 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 依赖项、编译我的咖啡脚本、缩小/合并我的 js 和其他一些东西。 git、nodejs、grunt、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时需要指定路径?

【问题讨论】:

    标签: node.js amazon-web-services amazon-elastic-beanstalk


    【解决方案1】:

    请注意,您必须在同一个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

    【讨论】:

      【解决方案2】:

      经过大量调试,似乎 PATH 已设置但未导出。我只需要在调用 grunt 之前添加export PATH=$PATH;

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

      【讨论】:

      • 语法command: PATH=$PATH grunt prod &>> /tmp/deploy.log 也可以使用,因为变量定义命令还允许在使用导出的变量设置变量后运行命令。但是,如果您已经有一个多行命令,则需要 export PATH=$PATH; ... 语法。
      猜你喜欢
      • 2016-07-07
      • 2022-01-13
      • 2017-09-03
      • 2020-10-05
      • 1970-01-01
      • 2021-12-31
      • 2015-08-26
      • 2014-05-29
      • 2017-10-16
      相关资源
      最近更新 更多