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

RubyConfBr 2015 - ChatOps in Ruby

2c8545cf821ed984bae91dcda758e105?s=47 Gabriel Mazetto
September 19, 2015

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.

2c8545cf821ed984bae91dcda758e105?s=128

Gabriel Mazetto

September 19, 2015
Tweet

Transcript

  1. None
  2. ChatOps in Ruby

  3. @brodock github.com/brodock blog.gabrielmazetto.eti.br Gabriel Mazetto Full -Stack Developer

  4. None
  5. Operations and Performance Team

  6. # /etc/init.d/daemon stop

  7. Some Numbers...

  8. 10.1M+ requests 116.6M+ background transactions 120M+ e-mails delivered this month!

  9. 35K+ commits 3.2K+ closed PRs 2 bots 24/7 since 2012

  10. deploys per day 10+

  11. None
  12. What is ChatOps?

  13. Doing Operations in a chat

  14. None
  15. Using your chat as an automated CLI

  16. None
  17. Conversation Driven Development

  18. Forget TDD, BDD It's all about CDD!

  19. Just kidding! Keep testing, please!

  20. Conversation Driven Development

  21. It's about Communicating what, when, why

  22. None
  23. Reinforces organizational culture!

  24. None
  25. Empowering Non Ops it should be easy...

  26. Everybody deploys even designers

  27. None
  28. Lita Robot companion in ruby

  29. Eventmachine based

  30. Plugins are rubygems too

  31. Redis as your datastore

  32. Integrated Webserver for webhooks

  33. Rspec Integration so you can test, seriously!

  34. and first steps How to Install

  35. $ 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
  36. $ 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
  37. $ lita new confbot create confbot create confbot/Gemfile create confbot/lita_config.rb

  38. $ 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"
  39. $ 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 ...
  40. $ 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 ...
  41. running it on the terminal

  42. $ 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 >
  43. Creating a plugin

  44. $ 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
  45. module Lita module Handlers class Rubyconf < Handler end Lita.register_handler(Rubyconf)

    end end
  46. 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
  47. 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
  48. 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
  49. Checking Status Continuous Integration

  50. 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
  51. 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
  52. 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
  53. Automating code deployment

  54. Github Deployment Flow Heaven + Heroku

  55. github.com/atmos/heaven

  56. None
  57. 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
  58. 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
  59. 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
  60. $ 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 >
  61. github.com/brodock @brodock blog.gabrielmazetto.eti.br shipit.resultadosdigitais.com.br Questions?