2016-09-20 98 views
0

我已經有了一個PHP應用程序的Elastic Beanstalk環境。我想在應用程序部署完成後運行npm installElastic Beanstalk上的「npm install」失敗,除非手動執行

nodenpm都安裝通過部署CONFIGS在服務器上。我已經定義了一個容器命令來簡單地cd到正確的目錄,然後運行npm install,但它的always失敗,出現相同的錯誤。

如果我手動執行npm install,一切都被完美地安裝。

我該如何去調試呢?

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

... 

90557 silly lifecycle [email protected]~install: no script for install, continuing 
90558 silly install [email protected] /var/app/ondeck/wp-content/themes/gift-certificates/node_modules/.staging/imagemin-gifsicle-836840bb 
90559 info lifecycle [email protected]~install: [email protected] 
90560 silly lifecycle [email protected]~install: no script for install, continuing 
90561 silly install [email protected] /var/app/ondeck/wp-content/themes/gift-certificates/node_modules/.staging/jpegtran-bin-6b358de8 
90562 info lifecycle [email protected]~install: [email protected] 
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: [email protected] 
90569 verbose stack Error: [email protected] 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 [email protected] 
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 [email protected] install: `node scripts/install.js` 
90580 error spawn ENOENT 
90581 error Failed at the [email protected] 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

... 

    | `-- [email protected] 
    +-- [email protected] 
    | +-- [email protected] 
    | +-- [email protected] 
    | | `-- [email protected] 
    | +-- [email protected] 
    | `-- [email protected] 
    +-- [email protected] 
    | +-- [email protected] 
    | | `-- [email protected] 
    | `-- [email protected] 
    +-- [email protected] 
    +-- [email protected] 
    `-- [email protected] 
    `-- [email protected] 
    `-- [email protected] 

    npm WARN optional Skipping failed optional dependency /chokidar/fsevents: 
    npm WARN notsup Not compatible with your operating system or architecture: [email protected] 
    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"} 
+0

你看到在日誌中的這些行: 'NPM WARN可選跳失敗可選的依賴/ chokidar/fsevents: NPM WARN notsup不與您的操作系統或架構兼容:fsevents @ 1.0.14' – rzymek

+0

是的,但是這只是一個「WARN」級別的日誌。我讀過的所有東西都可以忽略fsevents(儘管你可能比我更瞭解它) –

+0

嗯。另一名嫌疑人是「節點慘敗」。也許下面的鏈接可以幫助你https://github.com/sass/node-sass/issues/1504 – rzymek

回答

1

對於任何人遇到一個PHP彈性青苗例如這個問題,這裏就是幫助我度過這次難關:

1)如果你在Amazon Linux實例上運行,做一個yum install nodejs會給你一個超級老版本這很可能與許多事情不相容。我不得不在我的.ebextensions目錄中添加一個腳本,並從我的一個配置中執行它以安裝更新版本的nodejs。下面是該腳本的副本:

#!/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以通過此。

希望這可以幫助別人。

+1

謝謝! 2號爲我修好了。 – gmpatzer