本文介绍了如何使用.ebextensions在Amazon Elastic Beanstalk中运行`npm install`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 eb deploy 命令将PHP应用程序部署在Amazon Elastic Beanstalk中.但是我的应用程序使用gulp来连接并最小化scss和js.

I want to deploy my PHP app in a Amazon Elastic Beanstalk with eb deploy command. But my app use gulp to concat and minify scss and js.

所以我尝试了这些命令到文件 .ebextensios/03npm.config

So I tried these commands to in the file .ebextensios/03npm.config

commands:
  01-install-node:
    command: "yum install nodejs npm --enablerepo=epel -y"

container_commands:
  01-install-dependencies:
    command: "npm install"
  02-build:
    command: "npm run build"

但是最后我收到了这个错误

But in the end I receive this error

[Instance: i-c7800103] Command failed on instance. Return code: 1 Output: (TRUNCATED)...ttps://registry.npmjs.org/acorn npm http 304 https://registry.npmjs.org/amdefine npm http 304 https://registry.npmjs.org/wrappy npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /var/app/ondeck/npm-debug.log npm ERR! not ok code 0. container_command 01-install-dependencies in .ebextensions/03npm.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

我不确定,但是 npm install 似乎从一个软件包中收到了一个错误,可以忽略,但它正在分派EB错误并停止整个过程.

I'm not sure but it appears that npm install receive an error from one package that could be ignored but it is dispatching the EB error and stopping the whole process.

我正在使用此计算机运行:运行PHP 5.6的64位Amazon Linux 2015.09 v2.0.4

I'm running with this machine: 64bit Amazon Linux 2015.09 v2.0.4 running PHP 5.6

有人知道我们如何解决这个问题吗?

Does anyone know how we can fix this?

推荐答案

直到现在,我已经有了这个难看的解决方案,但是它可以工作.我在package.json中创建了此脚本,该脚本按顺序进行了艰苦的工作.它创建一个新分支并提交已编译的文件,然后再将其部署到EB

Until now, I have this ugly solution, but it works. I created this script inside package.json that do the hard job in sequence. It create a new branch and commit the compiled files before deploy it to EB

package.json

package.json

{
  "scripts": {
    "production": "node ./node_modules/gulp/bin/gulp.js --production",
    "deploy": "git checkout -b deploy && npm run production && git add . && git commit -m \"build\" && eb deploy && git checkout master && git branch -D deploy"
  }
}

.elasticbeanstalk/config.yml

.elasticbeanstalk/config.yml

branch-defaults:
  deploy:
    environment: NAME_OF_ENVIRONMENT

这篇关于如何使用.ebextensions在Amazon Elastic Beanstalk中运行`npm install`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 07:32