0

我試圖通過Elasticbeanstalk部署在EC2上運行的node.js服務器。 我遇到的問題是重建畫布npm模塊。 命令'[email protected]安裝:node-gyp rebuild'如下失敗:在elasticbeanstalk上安裝npm canvas - npm安裝錯誤

> [email protected] install /tmp/deployment/application/node_modules/canvas 
> node-gyp rebuild 

gyp ERR! clean error 
gyp ERR! stack Error: EACCES, unlink 'build' 
gyp ERR! System Linux 3.10.35-43.137.amzn1.x86_64 
gyp ERR! command "node" "/opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" 
gyp ERR! cwd /tmp/deployment/application/node_modules/canvas 
gyp ERR! node -v v0.10.26 
gyp ERR! node-gyp -v v0.12.2 
gyp ERR! not ok 

npm ERR! [email protected] install: `node-gyp rebuild` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] install script. 
npm ERR! This is most likely a problem with the canvas package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  node-gyp rebuild 
npm ERR! You can get their info via: 
npm ERR!  npm owner ls canvas 
npm ERR! There is likely additional logging output above. 

這個問題似乎是該npm install canvas命令沒有被具有適當特權運行。如果我手動ssh進入服務器並運行'sudo npm install canvas',一切正常。這告訴我,所有適當的依賴關係安裝正常(我遵循這些指示:https://github.com/Automattic/node-canvas/wiki/Installation---Amazon-Linux-AMI-(EC2))。這只是導致悲傷的elasticbeanstalk部署。

我試圖通過添加命令到config文件中.ebextensions使部署過程中的root訪問權限如下:

option_settings: 
    - namespace: aws:elasticbeanstalk:container:nodejs:staticfiles 
    option_name: /public 
    value: /public 
    - option_name: NODE_ENV 
    value: production 

commands: 
    01_enable_rootaccess: 
    command: echo Defaults:root \!requiretty >> /etc/sudoers 
    02_no-cert: 
    command: sudo /opt/elasticbeanstalk/node-install/node-v0.10.10-linux-x64/bin/npm config set ca "" 

,但它似乎沒有任何區別。

我在做什麼錯,我怎樣才能讓畫布在eb部署期間很好地安裝?

回答

3

您是否擁有畫布的所有依賴關係?爲了它爲我工作,我必須安裝以下內容:cairo,cairo-devel,libjpeg-devel,giflib-devel,libpng-devel(應該已經安裝)。

可以確保所有的這些都是通過添加下列之一安裝在您的.ebextensions

packages: 
    yum: 
     cairo: [] 
     cairo-devel: [] 
     libjpeg-devel: [] 
     giflib-devel: [] 
     libpng-devel: [] 

我想畫布可能會嘗試安裝的東西它沒有,它沒有權限對於。

試試看,讓我知道它是如何工作的。

+0

這應該放在:/.ebextensions/node.config - 正確嗎? – 2017-10-24 09:17:06