"npm install"除非手动执行,否则在Elastic Beanstalk上失败 [英] "npm install" on Elastic Beanstalk fails unless manually executed

查看:113
本文介绍了"npm install"除非手动执行,否则在Elastic Beanstalk上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有PHP应用程序的Elastic Beanstalk环境.我想在部署应用程序后只运行npm install.

I've got an Elastic Beanstalk environment with a PHP application. I'd like to just run npm install after my application has been deployed.

nodenpm都通过deploy configs安装在服务器上.我已经定义了一个容器命令,将其简单地CD到正确的目录中,然后运行npm install,但它always失败,并出现相同的错误.

node and npm are both installed on the server via deploy configs. I've defined a container command to simply cd into the proper directory and then run npm install, but it always fails with the same errors.

如果我手动执行npm install,则一切都将完美安装.

If I manually execute npm install, everything gets installed perfectly.

我该如何调试呢?

deploy.config

commands:
    01_mkdir_webapp_dir:
      # use the test directive to create the directory
      # if the mkdir command fails the rest of this directive is ignored
      test: 'mkdir /home/webapp'
      command: 'ls -la /home/webapp'
    02_chown_webapp_dir:
      command: 'chown webapp:webapp /home/webapp'
    03_chmod_webapp_dir:
      command: 'chmod 700 /home/webapp'
    04_node_install:
        cwd: /tmp
        test: '[ ! -f /usr/bin/node ] && echo "node not installed"'
        command: 'yum install -y nodejs --enablerepo=epel'
    05_npm_install:
        cwd: /tmp
        test: '[ ! -f /usr/bin/npm ] && echo "npm not installed"'
        command: 'curl -L http://npmjs.org/install.sh | sh'
    06_node_update:
        cwd: /tmp
        test: '[ ! -f /usr/bin/n ] && echo "node not updated"'
        command: 'npm install -g n && n stable'

# These commands will be run just before the application is started
container_commands:
    01_npm_build:
        cwd: '/var/app/ondeck/wp-content/themes/gift-certificates'
        command: 'npm install && npm run build'

npm-debug.log

tail of npm-debug.log

...

90557 silly lifecycle gifsicle@3.0.4~install: no script for install, continuing
90558 silly install imagemin-gifsicle@4.2.0 /var/app/ondeck/wp-content/themes/gift-certificates/node_modules/.staging/imagemin-gifsicle-836840bb
90559 info lifecycle imagemin-gifsicle@4.2.0~install: imagemin-gifsicle@4.2.0
90560 silly lifecycle imagemin-gifsicle@4.2.0~install: no script for install, continuing
90561 silly install jpegtran-bin@3.1.0 /var/app/ondeck/wp-content/themes/gift-certificates/node_modules/.staging/jpegtran-bin-6b358de8
90562 info lifecycle jpegtran-bin@3.1.0~install: jpegtran-bin@3.1.0
90563 silly rollbackFailedOptional Finishing
90564 silly runTopLevelLifecycles Starting
90565 silly runTopLevelLifecycles Finishing
90566 silly install printInstalled
90567 warn optional Skipping failed optional dependency /chokidar/fsevents:
90568 warn notsup Not compatible with your operating system or architecture: fsevents@1.0.14
90569 verbose stack Error: node-sass@3.10.0 install: `node scripts/install.js`
90569 verbose stack spawn ENOENT
90569 verbose stack     at errnoException (child_process.js:1011:11)
90569 verbose stack     at Process.ChildProcess._handle.onexit (child_process.js:802:34)
90570 verbose pkgid node-sass@3.10.0
90571 verbose cwd /var/app/ondeck/wp-content/themes/gift-certificates
90572 error Linux 4.4.15-25.57.amzn1.x86_64
90573 error argv "node" "/usr/local/bin/npm" "install"
90574 error node v6.6.0
90575 error npm  v3.10.3
90576 error file sh
90577 error code ELIFECYCLE
90578 error errno ENOENT
90579 error syscall spawn
90580 error node-sass@3.10.0 install: `node scripts/install.js`
90580 error spawn ENOENT
90581 error Failed at the node-sass@3.10.0 install script 'node scripts/install.js'.
90581 error Make sure you have the latest version of node.js and npm installed.
90581 error If you do, this is most likely a problem with the node-sass package,
90581 error not with npm itself.
90581 error Tell the author that this fails on your system:
90581 error     node scripts/install.js
90581 error You can get information on how to open an issue for this project with:
90581 error     npm bugs node-sass
90581 error Or if that isn't available, you can get their info via:
90581 error     npm owner ls node-sass
90581 error There is likely additional logging output above.
90582 verbose exit [ 1, true ]

eb-commandprocessor.log

tail of eb-commandprocessor.log

  ...

  | `-- osenv@0.0.3
  +-- chalk@0.5.1
  | +-- ansi-styles@1.1.0
  | +-- has-ansi@0.1.0
  | | `-- ansi-regex@0.2.1
  | +-- strip-ansi@0.3.0
  | `-- supports-color@0.2.0
  +-- glob@4.5.3
  | +-- inflight@1.0.5
  | | `-- wrappy@1.0.2
  | `-- once@1.4.0
  +-- lodash@2.4.2
  +-- propprop@0.3.1
  `-- through2@0.6.5
  `-- readable-stream@1.0.34
  `-- isarray@0.0.1

  npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
  npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.14
  npm ERR! Linux 4.4.15-25.57.amzn1.x86_64
  npm ERR! argv "node" "/usr/local/bin/npm" "install"
  npm ERR! node v6.6.0
  npm ERR! npm  v3.10.3

  npm ERR! Callback called more than once.
  npm ERR!
  npm ERR! If you need help, you may report this error at:
  npm ERR!     <https://github.com/npm/npm/issues>

  npm ERR! Please include the following file with any support request:
  npm ERR!     /var/app/ondeck/wp-content/themes/gift-certificates/npm-debug.log
   (ElasticBeanstalk::ExternalInvocationError)


[2016-09-20T17:38:57.831Z] ERROR [4286]  : Command CMD-AppDeploy failed!
[2016-09-20T17:38:57.837Z] INFO  [4286]  : Command processor returning results:
{"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"(TRUNCATED)...\nnpm ERR! If you need help, you may report this error at:\nnpm ERR!     <https://github.com/npm/npm/issues>\n\nnpm ERR! Please include the following file with any support request:\nnpm ERR!     /var/app/ondeck/wp-content/themes/gift-certificates/npm-debug.log. \ncontainer_command 01_npm_build in .ebextensions/deploy.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI","returncode":1,"events":[]}],"truncated":"true"}

推荐答案

对于在PHP Elastic Beanstalk实例上遇到此问题的其他人,这是帮助我解决此问题的方法:

For anyone else experiencing this issue on a PHP Elastic Beanstalk instance, here's what helped me get through this:

1)如果您正在Amazon Linux实例上运行,则执行yum install nodejs将为您提供一个超级旧版本,该旧版本很可能与许多东西不兼容.我必须将脚本添加到我的.ebextensions目录中,并从我的一个配置中执行该脚本,以安装Nodejs的更新版本.这是该脚本的副本:

1) If you're running on an Amazon Linux instance, doing a yum install nodejs will give you a super old version that will most likely be incompatible with a number of things. I had to add a script to my .ebextensions dir and execute it from one of my configs to install an updated version of nodejs. Here is a copy of that script:

#!/bin/bash

hash_file="/tmp/nodejshash"

check_if_npm_packages_has_to_be_installed () {
    if [ -f $hash_file ]; then
        check_if_same_hash
    else
        return 0
    fi
}

check_if_same_hash () {
    hash_new="$(md5sum .ebextensions/bin/install-nodejs.sh 2> /dev/null | cut -d ' ' -f 1)"
    hash_current="$(cat "$hash_file" 2> /dev/null | cut -d ' ' -f 1)"

    if [ $hash_new == $hash_current ]; then
        return 1
    else
        return 0
    fi
}

install_node () {
    if hash nodejs 2> /dev/null; then
        echo 'nodejs install, add more processing if needed' > /dev/null
    else
        curl -sL https://rpm.nodesource.com/setup_6.x | bash -
        yum install -y nodejs
    fi
}

install_npm_packages () {
    npm install -g bower
    npm install -g gulp
}

update_current_hash () {
    echo $hash_new > $hash_file
}

install_node

if check_if_npm_packages_has_to_be_installed; then
    install_npm_packages
    update_current_hash
fi

2)如果默认情况下使用的是微型实例,则node-sass软件包的构建时间很长,最终超时.我将实例大小增加到t2.small来解决这个问题.

2) If you're on a micro instance by default, the node-sass package was taking a very long time to build and eventually timed out. I increased my instance size to a t2.small to get past this.

希望这可以帮助其他人.

Hope this helps someone else out.

这篇关于"npm install"除非手动执行,否则在Elastic Beanstalk上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆