Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

ChatOps in Ruby

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Operations and Performance Team

Slide 6

Slide 6 text

# /etc/init.d/daemon stop

Slide 7

Slide 7 text

Some Numbers...

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

deploys per day 10+

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

What is ChatOps?

Slide 13

Slide 13 text

Doing Operations in a chat

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Using your chat as an automated CLI

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Conversation Driven Development

Slide 18

Slide 18 text

Forget TDD, BDD It's all about CDD!

Slide 19

Slide 19 text

Just kidding! Keep testing, please!

Slide 20

Slide 20 text

Conversation Driven Development

Slide 21

Slide 21 text

It's about Communicating what, when, why

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Reinforces organizational culture!

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Empowering Non Ops it should be easy...

Slide 26

Slide 26 text

Everybody deploys even designers

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Lita Robot companion in ruby

Slide 29

Slide 29 text

Eventmachine based

Slide 30

Slide 30 text

Plugins are rubygems too

Slide 31

Slide 31 text

Redis as your datastore

Slide 32

Slide 32 text

Integrated Webserver for webhooks

Slide 33

Slide 33 text

Rspec Integration so you can test, seriously!

Slide 34

Slide 34 text

and first steps How to Install

Slide 35

Slide 35 text

$ 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

Slide 36

Slide 36 text

$ 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

Slide 37

Slide 37 text

$ lita new confbot create confbot create confbot/Gemfile create confbot/lita_config.rb

Slide 38

Slide 38 text

$ 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"

Slide 39

Slide 39 text

$ 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 ...

Slide 40

Slide 40 text

$ 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 ...

Slide 41

Slide 41 text

running it on the terminal

Slide 42

Slide 42 text

$ 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 >

Slide 43

Slide 43 text

Creating a plugin

Slide 44

Slide 44 text

$ 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

Slide 45

Slide 45 text

module Lita module Handlers class Rubyconf < Handler end Lita.register_handler(Rubyconf) end end

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

Checking Status Continuous Integration

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

Automating code deployment

Slide 54

Slide 54 text

Github Deployment Flow Heaven + Heroku

Slide 55

Slide 55 text

github.com/atmos/heaven

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

$ 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 >

Slide 61

Slide 61 text

github.com/brodock @brodock blog.gabrielmazetto.eti.br shipit.resultadosdigitais.com.br Questions?