Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RubyConfBr 2015 - ChatOps in Ruby

RubyConfBr 2015 - ChatOps in Ruby

While DevOps is greatly misunderstood by most modern startups and big cloud companies and ChatOps may even seem alien, it is in reality a simple and straightforward way to tackle complicated operational problems. It's very developer friendly, and can be done from the convenience of your company’s internal chat solution.

With ChatOps complex deployments can be triggered by anyone with the right permission, even designers, in a lower risk environment.

You will learn how ChatOps can help you and your company do Ops better, using Ruby and backed by RSpec tests.

Gabriel Mazetto

September 19, 2015
Tweet

More Decks by Gabriel Mazetto

Other Decks in Technology

Transcript

  1. $ gem install lita Successfully installed lita-4.6.1 Parsing documentation for

    lita-4.6.1 Installing ri documentation for lita-4.6.1 Done installing documentation for lita after 1 seconds 1 gem installed
  2. $ lita --help Commands: lita adapter NAME # Generates a

    new Lita adapter lita extension NAME # Generates a new Lita extension lita handler NAME # Generates a new Lita handler lita help [COMMAND] # Describe available commands or one specific command lita new NAME # Generates a new Lita project (default name: lita) lita start # Starts Lita lita version # Outputs the current version of Lita
  3. $ cat Gemfile source "https://rubygems.org" gem "lita" # Uncomment to

    use the HipChat adapter # gem "lita-hipchat" # Uncomment to use the IRC adapter # gem "lita-irc" # Add handlers to give Lita new functionality. # For example: # gem "lita-google-images" # gem "lita-karma"
  4. $ cat lita_config.rb Lita.configure do |config| # The name your

    robot will use. config.robot.name = "ConfBot" # The locale code for the language to use. # config.robot.locale = :en # The severity of messages to log. Options are: # :debug, :info, :warn, :error, :fatal # Messages at the selected level and above will be logged. config.robot.log_level = :info ...
  5. $ bundle install Fetching gem metadata from https://rubygems.org/........... Resolving dependencies...

    Using multipart-post 2.0.0 Using bundler 1.7.6 Using i18n 0.7.0 Using rb-readline 0.5.2 Using ice_nine 0.11.1 Using multi_json 1.11.0 Using redis 3.2.1 Using thor 0.19.1 Using faraday 0.9.1 Using redis-namespace 1.5.2 Installing rack 1.6.1 ...
  6. $ lita start Type "exit" or "quit" to end the

    session. ConfBot > ConfBot help ConfBot: help - Lists help information for terms and command the robot will respond to. ConfBot: help COMMAND - Lists help information for terms or commands that begin with COMMAND. ConfBot: info - Replies with the current version of Lita. ConfBot: users find SEARCH_TERM - Find a Lita user by ID, name, or mention name. ConfBot > tem alguem ai? ConfBot >
  7. $ lita handler rubyconf create lita-rubyconf/lib/lita/handlers/rubyconf.rb create lita-rubyconf/lib/lita-rubyconf.rb create lita-rubyconf/spec/lita/handlers/rubyconf_spec.rb

    create lita-rubyconf/spec/spec_helper.rb create lita-rubyconf/locales/en.yml create lita-rubyconf/templates/.gitkeep create lita-rubyconf/Gemfile create lita-rubyconf/lita-rubyconf.gemspec create lita-rubyconf/.gitignore create lita-rubyconf/Rakefile create lita-rubyconf/README.md
  8. module Lita module Handlers class Rubyconf < Handler route(/keynote$/i, :next_keynote,

    command: true, help: {"keynote" => "Display the next keynote"}) def next_keynote(message) keynote = Keynote.get_next message.reply "Next keynote will be: #{keynote.title}" end end Lita.register_handler(Rubyconf) end end
  9. module Lita module Handlers class Rubyconf < Handler route(/keynote$/i, :next_keynote,

    command: true, help: {"keynote" => "Display the next keynote"}) def next_keynote(message) keynote = Keynote.get_next message.reply "Next keynote will be: #{keynote.title}" end end Lita.register_handler(Rubyconf) end end
  10. module Lita module Handlers class Rubyconf < Handler route(/keynote$/i, :next_keynote,

    command: true, help: {"keynote" => "Display the next keynote"}) def next_keynote(message) keynote = Keynote.get_next message.reply "Next keynote will be: #{keynote.title}" end end Lita.register_handler(Rubyconf) end end
  11. module Lita module Handlers class Rubyconf < Handler route(/status ci

    (.+)$/i, :check_ci, command: true, help: {"status ci" => "Display build status of informed branch"}) def check_ci(message) ci = XundaCI.get_status(message.match_data[1]) response.reply "Status do build: #{ci.status}" end end Lita.register_handler(Rubyconf) end end
  12. module Lita module Handlers class Rubyconf < Handler route(/status ci

    (.+)$/i, :check_ci, command: true, help: {"status ci" => "Display build status of informed branch"}) def check_ci(message) ci = XundaCI.get_status(message.match_data[1]) response.reply "Status do build: #{ci.status}" end end Lita.register_handler(Rubyconf) end end
  13. module Lita module Handlers class Rubyconf < Handler route(/status ci

    (.+)$/i, :check_ci, command: true, help: {"status ci" => "Display build status of informed branch"}) def check_ci(message) ci = XundaCI.get_status(message.match_data[1]) response.reply "Status do build: #{ci.status}" end end Lita.register_handler(Rubyconf) end end
  14. module Lita module Handlers class Rubyconf < Handler route(/deploy (\w*)

    (\w*)$/i, :deploy_branch, command: true, help: {"deploy [repo] [branch]" => "Deploys code according to informed params"}) def deploy_branch(message) repo, branch = message.match_data[1], message.match_data[2] github.create_deployment(repo, branch) response.reply "Started deploying #{repo}/#{branch}!" end # continua... end Lita.register_handler(Rubyconf) end end
  15. module Lita module Handlers class Rubyconf < Handler route(/deploy (\w*)

    (\w*)$/i, :deploy_branch, command: true, help: {"deploy [repo] [branch]" => "Deploys code according to informed params"}) def deploy_branch(message) repo, branch = message.match_data[1], message.match_data[2] github.create_deployment(repo, branch) response.reply "Started deploying #{repo}/#{branch}!" end # there is more... end Lita.register_handler(Rubyconf) end
  16. module Lita module Handlers class Rubyconf < Handler # more

    here :) config :token, type: String, required: true def github @github ||= Octokit::Client.new(access_token: config.token) end end Lita.register_handler(Rubyconf) end end
  17. $ lita start Type "exit" or "quit" to end the

    session. ConfBot > ConfBot deploy xunda-app/xunda-branch ConfBot: Started deploying xunda-app/xunda-branch! ConfBot >