[英]How can I run an npm script for an AWS Elastic Beanstalk Deployment?
My package.json
has: 我的
package.json
具有:
"scripts": {
"start": "node_modules/.bin/coffee server.coffee",
"test": "NODE_ENV=test node test/runner.js",
"coverage": "NODE_ENV=test COVERAGE=1 node test/runner.js -R html-cov test/ > ./test/coverage.html",
"testw": "fswatch -o test src | xargs -n1 -I{} sh -c 'coffeelint src server.coffee ; npm test'",
"db:drop": "node scripts/drop-tables.js",
"encryptConfig": "node_modules/.bin/coffee config/encrypt.coffee",
"decryptConfig": "node_modules/.bin/coffee config/decrypt.coffee",
"postinstall": "npm run decryptConfig"
},
When I deploy to Elastic Beanstalk, I'd like to run the postinstall
, but apparently it doesn't do that. 当我部署到Elastic Beanstalk时,我想运行
postinstall
,但是显然它没有这样做。 Okay, no problem. 好的没问题。
I created a file called .ebextensions/00.decrypt.config
which has: 我创建了一个名为
.ebextensions/00.decrypt.config
的文件,该文件具有:
commands:
00-add-home-variable:
command: sed -i 's/function error_exit/export HOME=\/root\n\nfunction error_exit/' /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh
container_commands:
02-decrypt-config:
command: $NODE_HOME/bin/npm run decryptConfig
However this doesn't seem to run either. 但是,这似乎也没有运行。 What am I doing incorrectly?
我做错了什么?
I figured out a workaround for this issue. 我想出了解决此问题的方法。 The
npm
binary on an EB instance is located in /opt/elasticbeanstalk/node-install/node-{version}
. EB实例上的
npm
二进制文件位于/opt/elasticbeanstalk/node-install/node-{version}
。 You should make sure this is present in your PATH
first. 您应该先确保它出现在
PATH
。
00_setpath.config 00_setpath.config
commands:
01_set_path:
command: echo 'export PATH=$PATH:`ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin' >> /root/.bash_profile
02_set_path:
command: export PATH=$PATH:`ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin
As you can see I am appending to .bash_profile
and also adding PATH
to the current shell. 如您所见,我将附加到
.bash_profile
并将PATH
添加到当前shell。 The former should be sufficient for your purpose. 前者应足以满足您的目的。 I added the second one as I'm using the
npm
command within a script in my package.json
, and it seems these scripts are run inside the same shell. 我在
package.json
的脚本中使用npm
命令时添加了第二个脚本,似乎这些脚本在同一shell中运行。 TL/DR: You should now be able to use npm
in both places. TL / DR:您现在应该可以在两个地方使用
npm
了。
As for your npm scripts, try using prestart
instead of postinstall
. 至于您的npm脚本,请尝试使用
prestart
而不是postinstall
。
A few suggestions: 一些建议:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.