让 Capistrano 运行 shell 任务的问题(nodejs 部署)
我正在使用 capistrano 部署 node.js 应用程序,并且有一个 设置 shell 任务时出现问题。 例如,我认为我已经安装了 npm,但失败了:
运行“npm install”
未找到 npm
,当我使用
run "/opt/nvm/'cat /opt/nvm/alias/default'/bin/npm install"
错误是找不到节点
部署由特殊用户进行部署管理。
您能告诉我什么可能导致这个问题以及如何解决它吗?
I am using capistrano to deploy a node.js application, and have a
problem with setting the shell tasks.
For instance, thought I have npm installed this fails:
run "npm install"
npm not found
and when I use
run "/opt/nvm/'cat /opt/nvm/alias/default'/bin/npm install"
the error is node not found
The deploy is managed by a special user for deploy.
Could you please tell what might cause this problem and how to solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通过
bash
运行命令并首先获取nvm.sh
文件,使用 NVM 和 Capistrano 对我来说很有效。我的 NVM 安装在
/opt/nvm
中,因此npm install
任务可能如下所示:因此无需通过读取别名来手动设置二进制文件的路径来自 NVM 的文件。
Using NVM and Capistrano is working for me by running the command through
bash
and sourcing thenvm.sh
file first.My NVM is installed in
/opt/nvm
, so thenpm install
task could look something like this:So no need of manually setting the path to the binaries by reading the alias file from NVM.
听起来 npm/node 可执行文件不在执行 Capistrano 脚本的远程用户的 $PATH 上。
您应该仔细检查 Capistrano 正在运行的用户以及 $PATH 是什么(并根据需要进行更正)
Sounds like the npm/node executables are not on the $PATH for the remote user that is executing the Capistrano script.
You should double check which user Capistrano is running as and what the $PATH is (and correcting as required)
我最终将其添加到我的
Capfile
中I ended up adding this to my
Capfile
我能够通过在我的 capistrano 部署脚本中添加如下行来影响节点版本更改:
其中
vOLDER_VERSION
是选择的版本。它的工作方式是它获取 nvm,将其设置为使用指定版本,并将该版本设置为默认版本。然后,它会在 npm 步骤运行后恢复这些更改。这样部署的其他部分或其他部署仍然可以使用最新版本。
如果您不关心其他部署,您只需为部署者用户运行该步骤一次:
I was able to affect node version changes by adding lines like the following to my capistrano deploy scripts:
Where
vOLDER_VERSION
is the version of choice.The way this works is it sources nvm, sets it to use the specified version, and sets that version as default. It then reverts those changes after the npm steps have been run. This way other parts of the deploy or other deploys still get to use the latest version.
If you don't care about other deploys you could just run that step once for your deployer user:
与此同时(一年多前)我创建了一个 Capistrano 扩展,以便轻松使用 nvm: https: //github.com/koenpunt/capistrano-nvm
该扩展默认会映射
node
和npm
,但您可以添加任何需要 nvm 运行的可执行文件到它(例如咕噜声
)。通过将以下内容添加到您的
deploy.rb
中即可进行基本设置:In the meantime (more than a year back tho) I've created a Capistrano extension for easy nvm usage: https://github.com/koenpunt/capistrano-nvm
The extension will map
node
andnpm
by default, but you can add any executable that needs nvm to run to it (eg.grunt
).A basic setup would work by adding the following to your
deploy.rb
: