我的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"
},
当我部署到Elastic Beanstalk时,我想运行postinstall
,但是显然它没有这样做。 好的没问题。
我创建了一个名为.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
但是,这似乎也没有运行。 我做错了什么?
我想出了解决此问题的方法。 EB实例上的npm
二进制文件位于/opt/elasticbeanstalk/node-install/node-{version}
。 您应该先确保它出现在PATH
。
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
如您所见,我将附加到.bash_profile
并将PATH
添加到当前shell。 前者应足以满足您的目的。 我在package.json
的脚本中使用npm
命令时添加了第二个脚本,似乎这些脚本在同一shell中运行。 TL / DR:您现在应该可以在两个地方使用npm
了。
至于您的npm脚本,请尝试使用prestart
而不是postinstall
。
一些建议: