My package.json
has:
"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
然而,这似乎也没有运行。我做错了什么?
我想出了解决这个问题的方法。这npm
EB 实例上的二进制文件位于/opt/elasticbeanstalk/node-install/node-{version}
。您应该确保它存在于您的PATH
first.
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
到当前外壳。前者应该足以满足您的目的。我添加了第二个,因为我正在使用npm
我的脚本中的命令package.json
,而且这些脚本似乎是在同一个 shell 内运行的。 TL/DR:您现在应该能够使用npm
在这两个地方。
至于你的 npm 脚本,请尝试使用prestart
代替postinstall
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)