All Projects → phallstrom → Slackistrano

phallstrom / Slackistrano

Licence: mit
Slack integration for Capistrano deployments.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Slackistrano

Workbase Server
Slack alternative, email integrated, build with Meteor
Stars: ✭ 284 (-23.24%)
Mutual labels:  slack
Action Slack
Provides the function of slack notification to GitHub Actions.
Stars: ✭ 310 (-16.22%)
Mutual labels:  slack
Slack
Slack API in Go - community-maintained fork created by the original author, @nlopes
Stars: ✭ 3,744 (+911.89%)
Mutual labels:  slack
Cdk Constructs
A collection of higher-level aws cdk constructs: slack-approval-workflow, #slack & msteams notifications, chatops, blue-green-container-deployment, codecommit-backup, OWASP dependency-check, contentful-webhook, github-webhook, stripe-webhook, static-website, pull-request-check, pull-request-approval-rule, codepipeline-merge-action, codepipeline-check-parameter-action...
Stars: ✭ 282 (-23.78%)
Mutual labels:  slack
Python Slack Sdk
Slack Developer Kit for Python
Stars: ✭ 3,307 (+793.78%)
Mutual labels:  slack
Slack Meme
A Meme Bot for Slack.
Stars: ✭ 322 (-12.97%)
Mutual labels:  slack
Vagas Java
Mural de vagas para desenvolvedores Java
Stars: ✭ 276 (-25.41%)
Mutual labels:  slack
Tfnotify
A CLI command to parse Terraform execution result and notify it to GitHub
Stars: ✭ 353 (-4.59%)
Mutual labels:  slack
Yetibot
🤖 Extreme chatops bot for Slack and IRC 🔧 New contributors welcome 🏗
Stars: ✭ 311 (-15.95%)
Mutual labels:  slack
Themer Gui
A graphical UI for themer. Replaced by Progressive Web App at https://themer.dev.
Stars: ✭ 337 (-8.92%)
Mutual labels:  slack
Terraform Aws Notify Slack
Terraform module which creates SNS topic and Lambda function which sends notifications to Slack
Stars: ✭ 290 (-21.62%)
Mutual labels:  slack
Slack Emojinator
Bulk upload emoji into Slack
Stars: ✭ 296 (-20%)
Mutual labels:  slack
Rigel
🌌 Colorscheme for vim, terminal, vscode and slack - based on the star Rigel ✨.
Stars: ✭ 324 (-12.43%)
Mutual labels:  slack
Slack History Export
A NPM module that allows slack users export their history
Stars: ✭ 284 (-23.24%)
Mutual labels:  slack
Chronos
📊 📊 📊 Monitors the health and web traffic of servers, microservices, and containers with real-time data monitoring and receive automated notifications over Slack or email.
Stars: ✭ 347 (-6.22%)
Mutual labels:  slack
Yonce
👑 Queen Bey-inspired themes for all your favs.
Stars: ✭ 280 (-24.32%)
Mutual labels:  slack
Kube Slack
Kubernetes Slack Monitoring
Stars: ✭ 321 (-13.24%)
Mutual labels:  slack
Bottender
⚡️ A framework for building conversational user interfaces.
Stars: ✭ 3,803 (+927.84%)
Mutual labels:  slack
Intelligo
🤖 Chatbot Framework for Node.js.
Stars: ✭ 347 (-6.22%)
Mutual labels:  slack
Slack Cleaner
delete slack messages and files. An improved version is at:
Stars: ✭ 329 (-11.08%)
Mutual labels:  slack

Slackistrano

Gem Version Code Climate Build Status

Send notifications to Slack about Capistrano deployments.

Requirements

  • Capistrano >= 3.8.1
  • Ruby >= 2.0
  • A Slack account

Installation

  1. Add this line to your application's Gemfile:

    gem 'slackistrano'
    
  2. Execute:

    $ bundle
    
  3. Require the library in your application's Capfile:

    require 'slackistrano/capistrano'
    

Configuration

You have two options to notify a channel in Slack when you deploy:

  1. Using Incoming WebHooks integration, offering more options but requires one of the five free integrations. This option provides more messaging flexibility.
  2. Using Slackbot, which will not use one of the five free integrations.

Incoming Webhook

  1. Configure your Slack's Incoming Webhook.

  2. Add the following to config/deploy.rb:

    set :slackistrano, {
      channel: '#your-channel',
      webhook: 'your-incoming-webhook-url'
    }
    

Slackbot

  1. Configure your Slack's Slackbot (not Bot).

  2. Add the following to config/deploy.rb:

    set :slackistrano, {
      channel: '#your-channel',
      team: 'your-team-name',
      token: 'your-token'
    }
    

Optional Configuration & Overrides

By default Slackistrano will use a default icon and username. These, can be overriden if you are using the default messaging class (ie. have not specified your own).

  1. Configure per instructions above.

  2. Add the following to config/deploy.rb:

    set :slackistrano, {
     ...
     username: 'Foobar the Deployer',
     icon_emoji: '👍', # takes precedence over icon_url
     icon_url: 'https://avatars2.githubusercontent.com/u/16705?v=4&s=40',
     ...
    }
    

Test your Configuration

Test your setup by running the following command. This will post each stage's message to Slack in turn.

$ cap production slack:deploy:test

Usage

Deploy your application like normal and you should see messages in the channel you specified.

Customizing the Messaging

You can customize the messaging posted to Slack by providing your own messaging class and overriding several methods. Here is one example:

if defined?(Slackistrano::Messaging)
   module Slackistrano
     class CustomMessaging < Messaging::Base

       # Send failed message to #ops. Send all other messages to default channels.
       # The #ops channel must exist prior.
       def channels_for(action)
         if action == :failed
           "#ops"
         else
           super
         end
       end

       # Suppress starting message.
       def payload_for_starting
         nil
       end

       # Suppress updating message.
       def payload_for_updating
         nil
       end

       # Suppress reverting message.
       def payload_for_reverting
         nil
       end

       # Fancy updated message.
       # See https://api.slack.com/docs/message-attachments
       def payload_for_updated
         {
           attachments: [{
             color: 'good',
             title: 'Integrations Application Deployed 💥‼️',
             fields: [{
               title: 'Environment',
               value: stage,
               short: true
             }, {
               title: 'Branch',
               value: branch,
               short: true
             }, {
               title: 'Deployer',
               value: deployer,
               short: true
             }, {
               title: 'Time',
               value: elapsed_time,
               short: true
             }],
             fallback: super[:text]
           }],
           text: "<!here> Application Deployed!"
         }
       end

       # Default reverted message.  Alternatively simply do not redefine this
       # method.
       def payload_for_reverted
         super
       end

       # Slightly tweaked failed message.
       # See https://api.slack.com/docs/message-formatting
       def payload_for_failed
         payload = super
         payload[:text] = "OMG 🔥 #{payload[:text]}"
         payload
       end

       # Override the deployer helper to pull the best name available (git, password file, env vars).
       # See https://github.com/phallstrom/slackistrano/blob/master/lib/slackistrano/messaging/helpers.rb
       def deployer
         name = `git config user.name`.strip
         name = nil if name.empty?
         name ||= Etc.getpwnam(ENV['USER']).gecos || ENV['USER'] || ENV['USERNAME']
         name
       end
     end
   end
end

The output would look like this: Custom Messaging

To set this up:

  1. Add the above class to your app, for example lib/custom_messaging.rb.

  2. Require the library after the requiring of Slackistrano in your application's Capfile.

    require_relative 'lib/custom_messaging'
    
  3. Update the slackistrano configuration in config/deploy.rb and add the klass option.

    set :slackistrano, {
      klass: Slackistrano::CustomMessaging,
      channel: '#your-channel',
      webhook: 'your-incoming-webhook-url'
    }
    
  4. If you come up with something that you think others would enjoy submit it as an issue along with a screenshot of the output from cap production slack:deploy:test and I'll add it to the Wiki.

Disabling posting to Slack

You can disable deployment notifications to a specific stage by setting the :slackistrano configuration variable to false instead of actual settings.

set :slackistrano, false

TODO

  • Notify about incorrect configuration settings.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].