Gulp 任务不在弹性 beantalk 上运行

Posted

技术标签:

【中文标题】Gulp 任务不在弹性 beantalk 上运行【英文标题】:Gulp tasks not running on elastic beanstalk 【发布时间】:2015-07-02 09:18:37 【问题描述】:

我有一个关于 aws elastic beanstalk 服务和 gulp 的问题。 我在吞咽和弹性豆茎方面都很新,所以很抱歉这是一个愚蠢的问题......

我在根服务器文件夹中创建了一个 gulp 文件:

var gulp = require('gulp'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify');


gulp.task('scripts', function() 
    return gulp.src(['public/**/*.js'])
        .pipe(concat('scripts.js'))
        .pipe(gulp.dest('public/js'))
        .pipe(uglify(""))
        .pipe(gulp.dest('public/js'));
);

gulp.task('default', ['scripts'], function());

还有一个包含所有依赖项和脚本对象的 package.json 文件:

"scripts": 
    "test": "echo \"Error: no test specified\" && exit 1",
    "gulp": "gulp",
    "start": "npm run gulp && node server.js"
,

但是当我将应用程序部署到弹性弹性 beanstalk 时,服务器似乎没有运行 gulp 任务(在服务器上找不到文件 'public/js/scripts.js')。

根据要求,这些是来自服务器的最后 100 条日志(唯一似乎相关的部分):

-------------------------------------
/var/log/eb-activity.log
-------------------------------------
  decamelize@1.0.0 /tmp/deployment/application/node_modules/gulp-uglify/node_modules/uglify-js/node_modules/yargs/node_modules/decamelize
  window-size@0.1.0 /tmp/deployment/application/node_modules/gulp-uglify/node_modules/uglify-js/node_modules/yargs/node_modules/window-size
  wordwrap@0.0.2 /tmp/deployment/application/node_modules/gulp-uglify/node_modules/uglify-js/node_modules/yargs/node_modules/wordwrap
  uglify-to-browserify@1.0.2 /tmp/deployment/application/node_modules/gulp-uglify/node_modules/uglify-js/node_modules/uglify-to-browserify
  vinyl-sourcemaps-apply@0.1.4 /tmp/deployment/application/node_modules/gulp-uglify/node_modules/vinyl-sourcemaps-apply
  source-map@0.1.43 /tmp/deployment/application/node_modules/gulp-uglify/node_modules/vinyl-sourcemaps-apply/node_modules/source-map
  amdefine@0.1.0 /tmp/deployment/application/node_modules/gulp-uglify/node_modules/vinyl-sourcemaps-apply/node_modules/source-map/node_modules/amdefine
  Running npm install:  /opt/elasticbeanstalk/node-install/node-v0.10.31-linux-x64/bin/npm
  Running npm with --production flag
[2015-04-24T07:11:29.853Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage0/AppDeployPreHook/60config_generate.sh] : Starting activity...
[2015-04-24T07:11:50.652Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage0/AppDeployPreHook/60config_generate.sh] : Completed activity. Result:
  + /opt/elasticbeanstalk/containerfiles/ebnode.py --action generate-config
  Generating modifications to /etc/nginx/nginx.conf
  Generating reverse proxy settings
[2015-04-24T07:11:50.653Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage0/AppDeployPreHook] : Completed activity. Result:
  Successfully execute directory: /opt/elasticbeanstalk/hooks/appdeploy/pre.
[2015-04-24T07:11:50.653Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] : Starting activity...
[2015-04-24T07:11:54.361Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] : Completed activity.
[2015-04-24T07:11:54.361Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage0/InfraCleanEbextension] : Starting activity...
[2015-04-24T07:11:54.720Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage0/InfraCleanEbextension] : Completed activity. Result:
  Cleaned ebextensions subdirectories from /tmp/deployment/application.
[2015-04-24T07:11:54.720Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage0] : Completed activity. Result:
  Command CMD-AppDeploy stage 0 completed.
[2015-04-24T07:11:54.721Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1] : Starting activity...
[2015-04-24T07:11:54.721Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook] : Starting activity...
[2015-04-24T07:11:54.721Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/10stop.sh] : Starting activity...
[2015-04-24T07:12:09.244Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/10stop.sh] : Completed activity. Result:
  + /opt/elasticbeanstalk/containerfiles/ebnode.py --action stop-all
  nodejs stop/waiting
  nginx stop/waiting
  status: Unknown job: httpd
  status: Unknown job: httpd
  Job already stopped. Not stopping again.
  Job already stopped. Not stopping again.
  Did not find to find status of init job. Assuming stopped.
  Did not find to find status of init job. Assuming stopped.
[2015-04-24T07:12:09.244Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/20clean.sh] : Starting activity...
[2015-04-24T07:12:09.490Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/20clean.sh] : Completed activity. Result:
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_base_dir
  + EB_APP_BASE_DIR=/var/app
  + rm -rf /var/app
[2015-04-24T07:12:09.490Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/30app_deploy.sh] : Starting activity...
[2015-04-24T07:12:10.259Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/30app_deploy.sh] : Completed activity. Result:
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_base_dir
  + EB_APP_BASE_DIR=/var/app
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
  + EB_APP_STAGING_DIR=/tmp/deployment/application
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir
  + EB_APP_DEPLOY_DIR=/var/app/current
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_user
  + EB_APP_USER=nodejs
  + mkdir /var/app
  + mv /tmp/deployment/application /var/app/current
  + chown -R nodejs:nodejs /var/app/current
[2015-04-24T07:12:10.259Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/40config_deploy.sh] : Starting activity...
[2015-04-24T07:12:10.477Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/40config_deploy.sh] : Completed activity. Result:
  ++ /opt/elasticbeanstalk/bin/get-config container -k config_staging_dir
  + EB_CONFIG_STAGING_DIR=/tmp/deployment/config
  ++ ls /tmp/deployment/config
  + for i in '$(ls $EB_CONFIG_STAGING_DIR)'
  ++ sed -e 's/#/\//g'
  ++ echo '#etc#init#nginx.conf'
  + FILE_NAME=/etc/init/nginx.conf
  + /bin/cp /tmp/deployment/config/#etc#init#nginx.conf /etc/init/nginx.conf
  + for i in '$(ls $EB_CONFIG_STAGING_DIR)'
  ++ sed -e 's/#/\//g'
  ++ echo '#etc#init#nodejs.conf'
  + FILE_NAME=/etc/init/nodejs.conf
  + /bin/cp /tmp/deployment/config/#etc#init#nodejs.conf /etc/init/nodejs.conf
  + for i in '$(ls $EB_CONFIG_STAGING_DIR)'
  ++ sed -e 's/#/\//g'
  ++ echo '#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf'
  + FILE_NAME=/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
  + /bin/cp /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
  + for i in '$(ls $EB_CONFIG_STAGING_DIR)'
  ++ sed -e 's/#/\//g'
  ++ echo '#etc#nginx#nginx.conf'
  + FILE_NAME=/etc/nginx/nginx.conf
  + /bin/cp /tmp/deployment/config/#etc#nginx#nginx.conf /etc/nginx/nginx.conf
[2015-04-24T07:12:10.478Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/50start.sh] : Starting activity...
[2015-04-24T07:12:13.171Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/50start.sh] : Completed activity. Result:
  + /opt/elasticbeanstalk/containerfiles/ebnode.py --action start-all
  nodejs start/running, process 7307
  nginx start/running, process 7316
[2015-04-24T07:12:13.171Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook] : Completed activity. Result:
  Successfully execute directory: /opt/elasticbeanstalk/hooks/appdeploy/enact.
[2015-04-24T07:12:13.171Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployPostHook] : Starting activity...
[2015-04-24T07:12:13.172Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1/AppDeployPostHook] : Completed activity. Result:
  Successfully execute directory: /opt/elasticbeanstalk/hooks/appdeploy/post.
[2015-04-24T07:12:13.172Z] INFO  [6756]  - [CMD-AppDeploy/AppDeployStage1] : Completed activity. Result:
  Command CMD-AppDeploy stage 1 completed.
[2015-04-24T07:12:13.172Z] INFO  [6756]  - [CMD-AppDeploy/AddonsAfter] : Starting activity...
[2015-04-24T07:12:13.172Z] INFO  [6756]  - [CMD-AppDeploy/AddonsAfter] : Completed activity.
[2015-04-24T07:12:13.172Z] INFO  [6756]  - [CMD-AppDeploy] : Completed activity. Result:
  Command CMD-AppDeploy succeeded.
[2015-04-24T07:12:42.655Z] INFO  [7329]  - [CMD-TailLogs] : Starting activity...
[2015-04-24T07:12:43.083Z] INFO  [7329]  - [CMD-TailLogs/AddonsBefore] : Starting activity...
[2015-04-24T07:12:43.083Z] INFO  [7329]  - [CMD-TailLogs/AddonsBefore] : Completed activity.
[2015-04-24T07:12:43.083Z] INFO  [7329]  - [CMD-TailLogs/TailLogs] : Starting activity...
[2015-04-24T07:12:43.084Z] INFO  [7329]  - [CMD-TailLogs/TailLogs/TailLogs] : Starting activity...

我做错了什么? 谢谢

【问题讨论】:

不确定我们是否有足够的资源来帮助您...您在部署之前运行“脚本”命令吗? 实际上我让服务器在“node server.js”命令之前运行它,它在我的电脑上运行...... 你可以发送你运行它的方式吗?有错误的日志吗?谢谢。 添加了我认为与服务器相关的部分 【参考方案1】:

您应该提供 Elastic Beanstalk 尝试运行 npm start 后发生的情况的日志。您可以从命令行或控制台获取此信息,方法是转到 Logs > Request Logs > Last 100 Lines

离开您发布的内容,我将假设问题在于您没有在全局级别安装 Gulp。通过运行gulp,它将在您的 bin 中查找该可执行文件。即使您的package.json 中有gulp,该可执行文件也不会存在,因为package.json 仅在本地安装它。

如果您在启动命令之前运行npm install -g gulp 会怎样?您可以在启动命令中执行此操作或使用任何NPM's "scripts"。 preinstall 可能是要使用的。它看起来像这样:

"scripts": 
  "test": "echo \"Error: no test specified\" && exit 1",
  "gulp": "gulp",
  "preinstall": "npm install -g gulp",
  "prestart": "npm run gulp",
  "start": "node server.js"
,

我还将npm run gulp 移动到prestart 脚本,因为它应该在运行开始之前运行。

【讨论】:

预安装无效 - clarkie.io/nodejs/2015/06/25/…

以上是关于Gulp 任务不在弹性 beantalk 上运行的主要内容,如果未能解决你的问题,请参考以下文章

如何在弹性 beantalk 配置上运行 wget cron 命令

如何在 ec2 实例上运行元数据库(没有弹性 beantalk)

如何在同一个弹性beantalk实例上运行socket.io和表达?

使用 aws fargate 有啥缺点(缺点)以及为啥我的 laravel 应用程序在 Fargate 与弹性 beantalk 上运行缓慢?

botocore.exceptions.ProfileNotFound 当代码在AWS弹性beantalk上运行时,但在本地没问题

“npm install”在弹性 beantalk 上失败,但是手动执行有效