AWS – 通过npm install来安装bower组件

我想使用git aws.push方法启动一个node.js服务器

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.sdlc.html

类似于这个解决scheme,我试图运行'bower install',虽然我的解决scheme有点不同:

https://developer.ibm.com/answers/questions/16594/how-to-install-packages-on-nodejs/

我的实现:

“scripts”:{“postinstall”:“bower install -F”},

这工作正常本地-npm安装也运行凉亭安装没有问题。 当我部署到aws,npm运行良好 – 我知道我的服务器启动正常,因为我可以看到在日志中的消息,但是当我尝试启动客户端时没有任何凉亭组件。

我正在使用节点v0.10.26,我相信,我没有在我的本地机器上全局安装凉亭。 我已经试过这两个有和没有在我的package.json的依赖部分包括凉亭。

有任何想法吗? 并提前感谢。

的package.json

{ "name": "smf", "version": "0.1.0", "dependencies": { "aws-sdk": "~2.0.0-rc.14", "base64-js": "0.0.6", "bookshelf": "~0.6.10", "bower": "*", "change-case": "~2.1.1", "crypto-js": "~3.1.2-3", "geojson": "~0.1.5", "handlebars": "~2.0.0-alpha.2", "js-base64": "~2.1.5", "lodash": "~2.4.1", "mathjs": "~0.21.0", "minify": "~0.5.1", "moment": "~2.6.0", "newrelic": "~1.5.3", "node-cryptojs-aes": "~0.4.0", "node-highcharts": "0.0.2", "node-uuid": "~1.4.1", "passport": "~0.2.0", "passport-http": "~0.2.2", "passport-local": "~1.0.0", "password-hash": "~1.2.2", "pg": "~3.0.3", "restify": "~2.7.0", "should": "~3.3.1", "socket.io": "~0.9.16", "sqlite3": "~2.2.3", "util": "~0.10.3", "when": "~3.1.0" }, "devDependencies": { "grunt": "~0.4.2", "grunt-contrib-jshint": "^0.10.0", "grunt-mocha-test": "~0.9.0", "mocha-phantomjs": "~3.3.1" }, "scripts": { "postinstall": "bower install -F" }, "engines": { "node": ">=0.6" } } 

日志文件

整个日志太长了,但是如果需要的话,我会把它粘贴在多个注释中。 以下是唯一提到凉亭的部分。

如果我尝试访问该网站,我可以获取访问日志,指出凉亭组件丢失。

似乎没有任何凉亭安装发生的执行。


/var/log/directory-hooks-executor.log

underscore.string@2.3.3 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string esprima@1.0.4 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / configstore / node_modules / js-yaml / node_modules / esprima object-assign@0.3.1 / tmp / deployment / application / node_modules / bower / node_modules / update- notifier / node_modules / configstore / node_modules / object-assign uuid@1.4.1 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / configstore / node_modules / uuid latest-version@0.2.0 / tmp /部署/应用程序/ node_modules / bower / node_modules / update-notifier / node_modules / latest-version package-json@0.2.0 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / latest-version / node_modules / package-json got@0.3.0 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_m odules / latest-version / node_modules / package-json / node_modules / got object-assign@0.3.1 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / latest-version / node_modules / package -json / node_modules / got / node_modules / object-assign registry-url@0.1.1 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / latest-version / node_modules / package -json / node_modules / registry- url npmconf@2.0.2 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / latest-version / node_modules / package -json / node_modules / registry-url / node_modules / npmconf config-chain@1.1。 8 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / latest-version / node_modules / package -json / node_modules / registry-url / node_modules / npmconf / node_modules / config-chain proto-list@1.2 .3 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / latest-version / node_modules / package-json / node_m odules / registry-url / node_modules / npmconf / node_modules / config-chain / node_modules / proto-list ini@1.2.1 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / latest-version / node_modules / package-json / node_modules / registry-url / node_modules / npmconf / node_modules / ini inherits@2.0.1 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / latest-version / node_modules / package- json / node_modules / registry-url / node_modules / npmconf / node_modules / inherits mkdirp@0.3.5 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / latest-version / node_modules / package -json / node_modules / registry-url / node_modules / npmconf / node_modules / mkdirp once@1.3.0 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / latest-version / node_modules / package -json / node_modules / registry- url / node_modules / npmconf / node_modules / once uid-number@0.0.5 / tmp / deployment / application / node_modules / bower / node_module s / update-notifier / node_modules / latest-version / node_modules / package -json / node_modules / registry-url / node_modules / npmconf / node_modules / uid-number semver-diff@0.1.0 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / semver-diff string-length@0.1.2 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules /string长度strip-ansi@0.2.2 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / string-length / node_modules / strip-ansi ansi-regex@0.1.0 / tmp / deployment / application / node_modules / bower / node_modules / update-notifier / node_modules / string-length / node_modules / strip-ansi / node_modules / ansi-regex which@1.5.5 / tmp / deployment / application / node_modules / bower / node_modules / which

凉亭可能没有安装在全球(如果是的话,请告诉我如何做到这一点在弹性beanstalk:D)。 你应该在node_modules文件夹中指向bower的bin(这是我们用来做的)。 我们已经摆脱了这个解决scheme(考虑500个实例的规模),并且正在检查bower_components进入回购。

 "scripts": { "postinstall": "node_modules/bower/bin/bower install -F" }, 

将.config文件添加到.ebextensions目录以安装Bower组件有所帮助。 不幸的是,node和npm默认没有添加到path中,所以你需要find最新的节点实例并创build一个符号链接。 我真的不是以root用户身份安装bower组件的粉丝,但是这样做会起作用:

 commands: 01_get_sudo: command: echo Defaults:root \!requiretty >> /etc/sudoers 02_node_path: command: "sudo ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /usr/bin/node" 03_npm_path: command: "sudo ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /usr/bin/npm" container_commands: 01_bower_install: command: "sudo ./node_modules/bower/bin/bower install --allow-root" 

使用$NODE_HOME ,例如

 container_commands: 01_bower_install: command: "export PATH=$PATH; $NODE_HOME/bin/node ./node_modules/bower/bin/bower install --allow-root &>> /tmp/01_bower_install.log" 

head -1不一定会使用nodenpm最新版本。

例如…

 $ ls -td /opt/elasticbeanstalk/node-install/node-* | head -1 /opt/elasticbeanstalk/node-install/node-v4.3.0-linux-x64 

ls显示v5.6.0实际上是最近的:

 $ ls -td /opt/elasticbeanstalk/node-install/node-* /opt/elasticbeanstalk/node-install/node-v4.3.0-linux-x64 /opt/elasticbeanstalk/node-install/node-v0.10.42-linux-x64 /opt/elasticbeanstalk/node-install/node-v5.6.0-linux-x64 /opt/elasticbeanstalk/node-install/node-v0.8.28-linux-x64 /opt/elasticbeanstalk/node-install/node-v0.12.10-linux-x64 

即使这样做,这可能不是你想要的。

你可以通过sorting来解决这个问题,但是你仍然可能想使用与环境相同的节点版本,可以通过$NODE_HOME访问。