node.js - 在 Elastic Beanstalk 上运行 npm install 时出现问题

标签 node.js laravel amazon-web-services deployment amazon-elastic-beanstalk

情况

我有一个 Laravel (5.4) 应用程序,它使用 npm、bower 和 gulp 作为前端。

我已在部署时成功配置了所有内容,但 npm installnpm install --product (在我的情况下是相同的)命令给我错误并导致部署失败。

问题

这是我运行 eb deploy 命令时 AWS 响应的“原因”。

Application update failed at 2017-06-07T17:08:38Z with exit status 1 and error: container_command 01-npm-install in .ebextensions/05-frontend-install.config failed.

npm WARN lifecycle npm is using /usr/bin/node but there is no node binary in the current PATH. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@1.0.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs@1.2.3: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
npm WARN prefer global node-gyp@3.6.2 should be installed with -g
npm WARN prefer global marked@0.3.6 should be installed with -g

> node-sass@3.13.1 install /var/app/ondeck/node_modules/node-sass
> node scripts/install.js

npm ERR! file sh
npm ERR! path sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn sh
npm ERR! node-sass@3.13.1 install: `node scripts/install.js`
npm ERR! spawn sh ENOENT
npm ERR!
npm ERR! Failed at the node-sass@3.13.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-06-07T17_08_38_740Z-debug.log.
Incorrect application version "app-5d9c-170607_190633" (deployment 40). Expected version "app-0466-170606_110037" (deployment 31).

.ebextensions/05-frontend-install.config 文件具有以下内容

container_commands:
  00-npm-upgrade:
    command: "npm install -g npm@latest"
  01-npm-install:
    command: "npm install --production"
  02-gulp-install:
    command: "sudo npm install gulp"
  03-bower-install:
    command: "sudo npm install bower"
  04-bower-deploy:
    command: "sudo bower install --allow-root"
  05-gulp-deploy:
    command: "sudo npm run prod"

最佳答案

通过 EB HOOK 实现!

我通过使用自定义弹性beanstalk部署后解决了我的问题 platform hook (听起来不错吧?)

我的04-nodenpm.config 文件包含以下内容:

container_commands:
  00-entersudoi:
    command: "sudo -i"
  01-removeoldnode:
    command: " yum remove -y nodejs npm"
  02-get-noderpm:
    command: " curl --silent --location https://rpm.nodesource.com/setup_7.x | bash -"
  03-ensurecggmake:
    command: " yum install -y gcc-c++ make"
  04-installnodenpm:
    command: " yum install -y nodejs"
  05-exitsudoi:
    command: "exit"

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/99npminstall.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      cd /var/app/current/
      sudo npm install -g gulp bower laravel-elixir
      sudo bower install --allow-root
      sudo gulp --production

解决问题的部分位于 files: 下,我手动添加 /opt/elasticbeanstalk/hooks/appdeploy/post/99npminstall.sh 文件,其中 content:作为部署后操作使npm install ...以及我想要的所有东西。

TL;博士:

npm 似乎在container_commands 上不完全可用。使用部署后 Hook 来触发这些 npm 安装命令。

引用文献和有用的链接:

http://www.eq8.eu/blogs/29-aws-elasticbeanstalk-deployment-hooks https://forums.aws.amazon.com/thread.jspa?threadID=137136

关于node.js - 在 Elastic Beanstalk 上运行 npm install 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44419064/

相关文章:

JQuery 无法与 Node.js 一起使用

javascript - Heroku 错误 : ENOENT: no such file or directory, 打开 '.env'

laravel - 更改 Laravel Migrations 的执行顺序

php - Controller 和路由 - Laravel 8

ruby-on-rails - 如何在 Elastic Beanstalk 启动时守护 Rails Rake 任务

javascript - 从任何地方在 Windows 命令中执行单个 Node.js 文件

node.js - NodeJS 中同步操作面临的问题

jquery clone() 不做任何事情

amazon-web-services - Terraform:如何提供使用一个资源 block 创建的资源的属性?

amazon-web-services - 创建额外服务时出现 AWS CloudFormation 错误