简体   繁体   English

使用capistrano部署Node.js项目时,如何成功通知Airbrake部署?

[英]How do I successfully notify Airbrake of a deployment when using capistrano to deploy a Node.js project?

This is a bit of an oddball question. 这有点奇怪的问题。

Capistrano 2.14.2 Capistrano 2.14.2

I'm using capistrano to deploy a couple of Node.js projects, and this works fine (from within the same rvm and gemset Ruby installation). 我正在使用capistrano来部署一些Node.js项目,这很好(从同一个rvm和gemset Ruby安装中)。 However, I'd like to have Airbrake be notified of these deployments. 但是,我希望Airbrake得到有关这些部署的通知。

Using the 'airbrake' Node.js module, and calling 使用'airbrake'Node.js模块,并调用

airbrake.trackDeployment({repo: '...'}); 

works, but not sure how to reliably call this just once at deploy time. 工作,但不知道如何在部署时可靠地调用它一次。 If I call it within my server, then Airbrake is notified of a "deployment" every time my server starts, which is obviously not correct. 如果我在我的服务器内调用它,那么每次我的服务器启动时Airbrake都会收到“部署”的通知,这显然是不正确的。

Adding 添加

require 'airbrake/capistrano'

to deploy.rb definitely does not work. deploy.rb肯定不起作用。

How do others successfully use 其他人如何成功使用

airbrake.trackDeployment

?

You could create a simple js file you'd run locally (on your machine for example) that notifies airbrake as a last deploy task. 您可以创建一个简单的js文件,您可以在本地运行(例如在您的计算机上),通知airbrake作为最后一次部署任务。 You could for example use the backtick operator to run a task: 例如,您可以使用反引号运算符来运行任务:

deploy.task :notify_airbrake do
    `node notify_airbrake.js`
end

If you don't have node installed locally, you could also pick one of the servers to run the notification script through ssh: 如果您没有在本地安装节点,您还可以选择其中一个服务器通过ssh运行通知脚本:

deploy.task :notify_airbrake do
    `ssh youserver "node notify_airbrake.js"`
end

Based on this solution http://dwradcliffe.com/2011/09/26/using-airbrake-with-node.html (which is clearly embedded in a Rails app.), I came up with the following, which depends solely on Javascript: 基于这个解决方案http://dwradcliffe.com/2011/09/26/using-airbrake-with-node.html (显然嵌入在Rails应用程序中),我提出了以下内容,这完全取决于使用Javascript:

In my Node.js root directory, create a deploy.js file, like so: 在我的Node.js根目录中,创建一个deploy.js文件,如下所示:

var airbrake = require('airbrake').createClient("AIRBRAKE_API_KEY");

var deployment = {rev: process.argv[2],
                  repo: process.argv[3],
                  env: process.argv[4],
                  user: process.argv[5]};

airbrake.trackDeployment(deployment, function(err, params) {
  if (err) {throw err}
  console.log('Tracked deployment of %s to %s', params.rev, params.env);
})

In config/deploy.rb, add 在config / deploy.rb中,添加

require 'airbrake/capistrano'

and

namespace :airbrake do
  desc "Notify Airbrake of a new deploy."
  task :deploy do
    system "node deploy.js #{current_revision} #{repository} #{stage} #{user}"
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何部署 Node.js 代码以在不超过免费部署层的情况下按时间间隔运行 - How do I deploy Node.js code to run on an interval without exceeding free deployment tiers 当我希望使用node.js与我的项目一起部署库时,应该包括哪些文件? - Which files should I include when I wish to deploy a library with my project using node.js? 如何将node.js应用程序部署到服务器? - How do I deploy my node.js app to a server? 如何在 node.js 服务器上部署 Angular 应用程序 - How do I deploy Angular app on node.js server 如何使用systemd将Node.js应用程序部署为单个可执行文件? - How do I deploy Node.js applications as a single executable file using systemd? 如何使用 Docker 映像将 Node.js HTTP/2 应用程序部署到 Google Compute Engine 上? - How do I deploy a Node.js HTTP/2 application onto Google Compute Engine using a Docker image? 我如何知道在Ubuntu 14.04上是否已成功安装Node.js和npm? - How do I know whether I have Node.js and npm successfully installed on Ubuntu 14.04? 如何在Node.js中运行复制的项目 - How do I run a copied project in Node.js 如何在WebStorm中为Node.js创建项目? - How do I create a project in WebStorm for Node.js? 成功编译自定义node.js模块我该如何使用 - successfully compiled custom node.js module how do I use it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM