Git Product home page Git Product logo

capistrano-slack's Introduction

Capistrano Slack

Install

Best way to install Capistrano Slack intergration is via Bundler.

Add the following to your Gemfile, then run the bundle command to install the gem direct from the git repository

gem 'capistrano-slack', :git => 'https://github.com/j-mcnally/capistrano-slack.git'

Once installed you can use the settings below in your Capistrano deploy.rb to configure Slack.

Push deployment messages to Slack

#in deploy/shared.rb add
require 'capistrano/slack'

#in deploy.rb 
# required
set :slack_token, "webhook_token" # comes from inbound webhook integration
set :slack_room, "#general"
set :slack_subdomain, "kohactive" # if your subdomain is kohactive.slack.com


before 'deploy', 'slack:starting'
after 'deploy',  'slack:finished'


# optional
set :slack_application, "Rocketman"
set :slack_username, "Elton John"
set :slack_emoji, ":rocket:"
set :slack_deploy_defaults, false #gem provides the standard before and after callbacks deploy:starting and deploy:finished deploy of set to false and provide your own. 
#example slack:starting and slack:finished are the only defaults provided in the gem. 

You can obtain your webhook_token from the integrations section of the team page in Slack.

https://kohactive.slack.com/services/new/incoming-webhook (if your subdomain is kohactive.slack.com)

Add custom messages to callbacks

namespace :slack do
    namespace :migration do 
        task :start do 
            @migration_start_time = Time.now
            msg = "Running Migrations"
            slack_connect(msg)
        end
        task :end do 
            elapsed_time = Time.now.to_i - @migration_start_time.to_i   if @migration_start_time
            msg = "Migrations finished in #{elapsed_time} seconds"
            slack_connect(msg)
        end
    end
    before "deploy:migrate", "slack:migration:start"
    after  "deploy:migrate", "slack:migration:end"

capistrano-slack's People

Contributors

cromwellryan avatar dieterve avatar fullybaked avatar hannesvdvreken avatar joshpuetz avatar kirs avatar parkr avatar simaofreitas avatar stopdropandrew avatar technicalpickles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

capistrano-slack's Issues

Publish new gem version

I'm sharing capistrano recipes between projects from a custom gem and can't add the git dependency in the gem.

Thanks!

:slack_emoji is mandatory

Hi,

In the readme file, slack_emoji is in the optional section. But, if not defined, an error is raised:

  • 2014-03-17 16:59:05 executing slack:starting' /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/variables.rb:82:inblock in fetch': `slack_emoji' not found (IndexError)

EDIT:
The same happens with the other "optional" parameters

Deploy failing when can't connect to slack.com

When Slack.com is not available passing technical problems, my deploy fails.

/Users/wagnerpereira/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:879:in `initialize': Operation timed out - connect(2) for "unimedrj.slack.com" port 443 (Errno::ETIMEDOUT)

I think it should just warning that slack was unavailable.

Deployment raises error: "\xCC" on US-ASCII (Encoding::InvalidByteSequenceError)

Hi,

Here are my settings:

set :slack_token, "my key"
set :slack_room, "#channel-name"
set :slack_subdomain, "my-domain"

set :slack_application, "app name"
set :slack_username, "some random user name"
set :slack_emoji, ":rocket:"

When deploying, I get this:

2014-03-17 16:47:39 executing slack:starting' /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/bundler/gems/capistrano-slack-3ed328fd2eb0/lib/capistrano/slack.rb:47:inencode': "\xCC" on US-ASCII (Encoding::InvalidByteSequenceError)
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/bundler/gems/capistrano-slack-3ed328fd2eb0/lib/capistrano/slack.rb:47:in to_json' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/bundler/gems/capistrano-slack-3ed328fd2eb0/lib/capistrano/slack.rb:47:inblock (3 levels) in extended'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/execution.rb:138:in instance_eval' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/execution.rb:138:ininvoke_task_directly'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/callbacks.rb:25:in invoke_task_directly_with_callbacks' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/execution.rb:89:inexecute_task'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/execution.rb:101:in find_and_execute_task' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/callback.rb:38:incall'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/callbacks.rb:141:in block in trigger' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/callbacks.rb:141:ineach'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/callbacks.rb:141:in trigger' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/callbacks.rb:23:ininvoke_task_directly_with_callbacks'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/execution.rb:89:in execute_task' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/execution.rb:101:infind_and_execute_task'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/cli/execute.rb:46:in block in execute_requested_actions' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/cli/execute.rb:45:ineach'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/cli/execute.rb:45:in execute_requested_actions' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/cli/help.rb:19:inexecute_requested_actions_with_help'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/cli/execute.rb:34:in execute!' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/cli/execute.rb:14:inexecute'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/capistrano-2.15.5/bin/cap:4:in <top (required)>' from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/bin/cap:23:inload'
from /Users/simaofreitas/.rvm/rubies/ruby-2.0.0-p353/bin/cap:23:in <main>' from /Users/simaofreitas/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:ineval'
from /Users/simaofreitas/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `

'

Won't deploy with capistrano-slack

I've been trying to use capistrano-slack without success.

I get this:

$cap capistrano deploy
uninitialized constant Capistrano::Logger
.../.rvm/gems/ruby-1.9.3-p448@global/gems/capistrano-log_with_awesome-0.0.2/lib/capistrano/log_with_awesome.rb:4:in `<module:Capistrano>'
.../.rvm/gems/ruby-1.9.3-p448@global/gems/capistrano-log_with_awesome-0.0.2/lib/capistrano/log_with_awesome.rb:3:in `<top (required)>'
.../.rvm/gems/ruby-1.9.3-p448@global/gems/capistrano-slack-1.1.7/lib/capistrano/slack.rb:2:in `require'
.../.rvm/gems/ruby-1.9.3-p448@global/gems/capistrano-slack-1.1.7/lib/capistrano/slack.rb:2:in `<top (required)>'

also included the code (config/deploy.rb):

require 'capistrano/slack'
set :slack_token, "..." # comes from inbound webhook integration
set :slack_room, "#web-devs"
set :slack_subdomain, "..." # if your subdomain is kohactive.slack.com
...

Gemfile.lock:

 capistrano (3.0.0)
      i18n
      rake (>= 10.0.0)
      sshkit (>= 0.0.23)
    capistrano-log_with_awesome (0.0.2)
      capistrano (>= 2.5.14)
    capistrano-slack (1.1.7)
      capistrano
      capistrano-log_with_awesome (~> 0.0.2)

Does not work with Capistrano3

after fiddling with this version, i wrote this small file, that works with any capistrano version and is a bit more straightforward. Not configurable yet, just change variables in SlackNotifierWrapper. Hope that gives some directions for future improvements. :)

https://gist.github.com/mindreframer/da9b48a9b3afedd63f7a

# lib/capistrano/tasks/slack.rake

# install slack-notifier gem
# include this file into your lib/capistrano/tasks/ folder
# add this line to the end of your Capfile: 
#    Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
# deploy with: 
#    MSG='fixing that payment bug...' cap staging deploy 

class SlackNotifierWrapper

  require 'slack-notifier'

  def token
    'XXXXXXXXXXX'
  end

  def team
    "your-subdomain-on-slack"
  end

  def channel
    '#deployments'
  end

  def app
    "my-awesome-app"
  end

  def deployer
    ENV['GIT_AUTHOR_NAME'] || `git config user.name`.chomp
  end

  def reason
    raise "provice a reason with MSG=... !" unless ENV['MSG']
    ENV['MSG']
  end

  def notify(msg)
    notifier.ping(msg, icon_emoji: ":rocket:")
  end

  def notifier
    @notifier ||= ::Slack::Notifier.new(team, token, channel: channel, username: 'capistrano')
  end
end


namespace :slack do
  def wrapper
    @wrapper ||= SlackNotifierWrapper.new
  end

  def msg_prefix
    deployer   = wrapper.deployer
    app        = wrapper.app
    branch     = fetch(:branch, nil)
    stage      = fetch(:stage, 'production')
    app_string = branch ? "#{app}'s #{branch}" : app


    "#{deployer} / #{app_string} / #{stage}"
  end

  task :starting do
    msg = "#{msg_prefix} - started - #{wrapper.reason}"

    wrapper.notify(msg)
    set(:start_time, Time.now)
  end

  task :finished do
    begin
      start_time = fetch(:start_time)
      elapsed    = Time.now.to_i - start_time.to_i
      msg        = "#{msg_prefix} - finished - #{elapsed} seconds."
      wrapper.notify(msg)
    end
  end

  before 'deploy', 'slack:starting'
  after 'deploy',  'slack:finished'
end

uninitialized constant Capistrano::Slack::Faraday

While upgrading our application to Rails 4 we ran into this error:

capistrano-slack-35112edc71d3/lib/capistrano/slack.rb:73:in `rescue in block (3 levels) in extended': uninitialized constant Capistrano::Slack::Faraday (NameError)
  from capistrano-slack-35112edc71d3/lib/capistrano/slack.rb:66:in `block (3 levels) in extended'
  from capistrano-2.15.5/lib/capistrano/configuration/execution.rb:138:in `instance_eval'
  from capistrano-2.15.5/lib/capistrano/configuration/execution.rb:138:in `invoke_task_directly'

Other gems in our application rely on Faraday, but capistrano-slack doesn't, so it's understandable that this error would occur since Faraday hasn't actually been loaded.

Issue in receiving the notifications

Hello Guys,
First I would like to thank you for you creating this amazing Gem, but I did all the steps in my code and from the terminal when stating deploy to the server I saw in the terminal
slack:starting & slack:finished but actually didn't got the notification on slack !!
so what is missing in my deploy.rb file?!!
this is my deploy.rb credentials:

require 'capistrano/slack'

set :deployer do
  name = `git config user.name`.strip
  name = `whoami`.strip if name == ''
  name
end

set :slack_token, 'https://hooks.slack.com/services/............etc ' # comes from inbound webhook integration
set :slack_room, '#deploying' # room
set :slack_subdomain, 'astm' # if your subdomain is astm.slack.com
set :slack_emoji, ':shipit:' # ":rocket:"
set :slack_deploy_defaults, false
set :slack_application, "myApp"
set :slack_username, "Deploying on server"

namespace :slack do
  task :starting do
    slack_connect "#{fetch(:deployer)} *started* deploying to *#{fetch(:stage)}*. :rocket:"
  end

  task :finished do
    slack_connect "#{fetch(:deployer)} *finished* deploying to *#{fetch(:stage)}*. :star2:"
  end
end

before 'deploy:update_code', 'slack:starting'
after 'deploy:restart', 'slack:finished' 

And in my Gemfile I added & bundle install

group :development do
	# For Notifying slack
	gem 'capistrano-slack'
end

Project maintenance?

Hello, @j-mcnally.

My name is Andrey.
First of all, thank you. You've made a lot of work to create integration Capistrano with Slack. I enjoyed it very much on previous projects.

But in last few month project has not answered PR, outdated gems. It also does not support Capistrano 3 and new Slack API features and doesn't have tests.

So, do you have a plan to maintenance capistrano-slack and close above pointed bugs? If no, I'm ready to continue support and develop this gem because we use Capistrano and Slack in our projects actually.

ALL PRs WILL BE MERGED AFTER 7 DAYS

Notice, i am still getting PRs for this project, and thats fine. I will be merging all PRs that don't have down votes after 7 days, so do some community QA. If a PR is not mergeable please assume the responsibility to Rebase or it will be closed after 7 days.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.