ruboty-docker 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9dc07d639ba26196caa6fddeea691e6164953ac6
4
+ data.tar.gz: e35d45c6917f2611d3f5fa1c1a2f2e01bba4e332
5
+ SHA512:
6
+ metadata.gz: 7a6bbcb2989a80fbabd94f32fe80277c507a865502dc473fec9cf91616c909238e326ebb2dfd6932b4631a69b219258974f657aeaf81111fa2bcc66bc55393ce
7
+ data.tar.gz: 2ef5cba6d9d414269e2ad99b5d03dcf99c146adea59ab025ebe4cfc6ba1c7364f833ecbe8a1a0743296553dfe0fa08f808b1b4f81471895417a24e938e7beabc
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # Environment variable
12
+ .env
data/.pryrc ADDED
@@ -0,0 +1,4 @@
1
+ require 'ruboty'
2
+ require 'ruboty-docker'
3
+ require 'docker'
4
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ sudo: false
5
+
6
+ script:
7
+ - bundle exec rake spec
8
+ notifications:
9
+ email: false
10
+ slack:
11
+ secure: XsHJia8JIg9hDoCf/kj4dXqn4KA+Uu/fwIexjR9hC0yHRWRcTrXE8jKFAvp9AWXDnoeCHMUryEj25b8O5jgtZO7+/nASoP2q+Ejlp6/Symgd3g8rHTWA4K6+pQg0vB0sqsHtglweZWj4wQGx6ybV+OHcXogo7wTy4slgt4gWTTI=
12
+ addons:
13
+ code_climate:
14
+ repo_token:
15
+ secure: MQ9tK0Lt8r/mcF4NU3qhxUuBndO/zyFGVTlbDkMpCHzW+AtHocQgiQc9HplY7GA4byUzUEIAASQpnDZS9vb2SvZL4yMGQvIvReLepiCtDd/cUGxuqT5NySNj2sIcNBdmzdwJT/JYvcm2mPtWiygvxi/6mTGUlj10u8yfRJRff38=
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-docker.gemspec
4
+ gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
7
+ gem 'coveralls', require: false
8
+ gem 'ruboty-slack'
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard :shell do
2
+ watch(%r{lib/ruboty/handlers/.*\.rb$}) do |m|
3
+ `echo #{m.first} was reloaded`
4
+ end
5
+ end
6
+
7
+ guard :bundler do
8
+ watch('Gemfile')
9
+ watch(/^.+\.gemspec/)
10
+ end
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ [![Build Status](https://travis-ci.org/zchee/ruboty-docker.svg?branch=master)](https://travis-ci.org/zchee/ruboty-docker) [![Circle CI](https://circleci.com/gh/zchee/ruboty-docker.svg?style=svg)](https://circleci.com/gh/zchee/ruboty-docker) [![Code Climate](https://codeclimate.com/github/zchee/ruboty-docker/badges/gpa.svg)](https://codeclimate.com/github/zchee/ruboty-docker) [![Dependency Status](https://gemnasium.com/zchee/ruboty-docker.svg)](https://gemnasium.com/zchee/ruboty-docker)
2
+ # Ruboty::Docker
3
+
4
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruboty/docker`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+
6
+ TODO: Delete this and the text above, and describe your gem
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'ruboty-docker'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install ruboty-docker
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( https://github.com/[my-github-username]/ruboty-docker/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/circle.yml ADDED
@@ -0,0 +1,9 @@
1
+ machine:
2
+ timezone:
3
+ Asia/Tokyo
4
+ ruby:
5
+ version: 2.2.2
6
+
7
+ test:
8
+ post:
9
+ - bundle exec rake
@@ -0,0 +1,26 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Base
5
+ NAMESPACE = 'docker'
6
+
7
+ attr_reader :message
8
+
9
+ def initialize(message)
10
+ @message = message
11
+ end
12
+
13
+ private
14
+
15
+ def filesize_to_human(n)
16
+ count = 0
17
+ while n >= 1000 and count < 4
18
+ n /= 1000.0
19
+ count += 1
20
+ end
21
+ format('%.2f', n) + %w(B KB MB GB TB)[count]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Build < Base
5
+ def call
6
+ message_args = message[:code].to_s.split("\n", 2)
7
+ repo_name = message_args[0].split(':')[0]
8
+ tag = message_args[0].split(':')[1]
9
+ dockerfile = message_args[1].to_s[4..-5]
10
+
11
+ message.reply('Building this Dockerfile...')
12
+ message.reply(dockerfile, code: true)
13
+ build = ::Docker::Image.build(dockerfile).tag(repo: repo_name, tag: tag)
14
+ ap build
15
+ ap repo_name
16
+ ap dockerfile
17
+ message.reply('Done')
18
+ rescue => e
19
+ value = [e.class.name, e.message, e.backtrace].join("\n")
20
+ message.reply value
21
+ ensure
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Events < Base
5
+ def call
6
+ ::Thread.new {
7
+ ::Docker::Event.stream do |event|
8
+ response = ['docker event response', event.status, event.id, event.from, event.time].join("\s")
9
+ message.reply response
10
+ end
11
+ }
12
+ message.reply('Start real time events stream watch thread')
13
+ rescue => e
14
+ value = [e.class.name, e.message, e.backtrace].join("\n")
15
+ message.reply value
16
+ ensure
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Images < Base
5
+ def call
6
+ images = ::Docker::Image.all
7
+ rows = []
8
+ message.reply images if message[:debug] == ' -D '
9
+ images.each do |image|
10
+ repository = image.info['RepoTags'].to_s.split(':').first
11
+ tag = image.info['RepoTags'].to_s.split(':').last
12
+ id = image.info['id'].to_s.scan(/.{1,#{12}}/)
13
+ size = filesize_to_human(image.info['VirtualSize'])
14
+ rows.push [repository[2..100], tag[0..-3], id[0], size]
15
+ end
16
+ table = ::Terminal::Table.new headings: ['REPOSITORY', 'TAG', 'IMAGE ID', 'VIRTUAL SIZE'], rows: rows
17
+ table.style = { :padding_left => 0, :border_x => '', :border_y => ' ', :border_i => '' }
18
+ message.reply(table, code: true)
19
+ rescue => e
20
+ value = [e.class.name, e.message, e.backtrace].join("\n")
21
+ message.reply value
22
+ ensure
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,53 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Info < Base
5
+ def call
6
+ info = ::Docker.info
7
+ message.reply(info, code: true) if message[:debug] == ' -D '
8
+ rows = []
9
+ rows.push ['Containers', info['Containers']]
10
+ rows.push ['Debug', info['Debug']]
11
+ rows.push ['DockerRootDir', info['DockerRootDir']]
12
+ rows.push ['Driver', info['Driver']]
13
+ rows.push ['DriverStatus', '']
14
+ rows.push [' Root Dir', info['DriverStatus'][0][1]]
15
+ rows.push [' Backing Filesystem', info['DriverStatus'][1][1]]
16
+ rows.push [' Dirs', info['DriverStatus'][2][1]]
17
+ rows.push [' Dirperm1 Supperted', info['DriverStatus'][3][1]]
18
+ rows.push ['ExecutionDriver', info['ExecutionDriver']]
19
+ rows.push ['ID', info['ID']]
20
+ rows.push ['IPv4Forwarding', info['IPv4Forwarding']]
21
+ rows.push ['Images', info['Images']]
22
+ rows.push ['IndexServerAddress', info['IndexServerAddress']]
23
+ rows.push ['InitPath', info['InitPath']]
24
+ rows.push ['InitSha1', info['InitSha1']]
25
+ rows.push ['KernelVersion', info['KernelVersion']]
26
+ rows.push ['Labels', info['Labels'].to_s[2..-3]]
27
+ rows.push ['MemTotal', info['MemTotal']]
28
+ rows.push ['MemoryLimit', info['MemoryLimit']]
29
+ rows.push ['NCPU', info['NCPU']]
30
+ rows.push ['NEventsListener', info['NEventsListener']]
31
+ rows.push ['NFd', info['NFd']]
32
+ rows.push ['NGoroutines', info['NGoroutines']]
33
+ rows.push ['Name', info['Name']]
34
+ rows.push ['OperatingSystem', info['OperatingSystem'].to_s.split(':')[0]]
35
+ # rows << ['RegistryConfigs', info['RegistryConfigs']]
36
+ # rows << ['IndexName', info['RegistryConfigs'][0][0]]
37
+ # rows << ['Mirrors', info['RegistryConfigs']['IndexConfigs']['docker.io']['Mirrors']]
38
+ # rows << ['Official', info['RegistryConfigs']['IndexConfigs']['docker.io']['Official']]
39
+ # rows << ['Secure', info['RegistryConfigs']['IndexConfigs']['docker.io']['Secure']]
40
+ rows.push ['SwapLimit', info['SwapLimit']]
41
+ rows.push ['SystemTime', info['SystemTime']]
42
+ table = ::Terminal::Table.new title: 'DOCKER INFO', rows: rows
43
+ table.style = { :padding_left => 0, :border_x => '', :border_y => ' ', :border_i => '' }
44
+ message.reply(table, code: true)
45
+ rescue => e
46
+ value = [e.class.name, e.message, e.backtrace].join("\n")
47
+ message.reply value
48
+ ensure
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,48 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Inspect < Base
5
+ def call
6
+ images = ::Docker::Image.get(message[:target_name])
7
+ info = images.instance_variable_get(:@info)
8
+ message.reply(info, code: true) if message[:debug] == ' -D '
9
+ rows = []
10
+ rows.push ['ID', images.instance_variable_get(:@id)]
11
+ rows.push ['Architecture', info['Architecture']]
12
+ rows.push ['Author', info['Author']]
13
+ rows.push ['Command', info['Config']['Cmd']]
14
+ unless info['Config']['Env'].nil?
15
+ info['Config']['Env'].each_index do |n|
16
+ if n == 0
17
+ rows.push ['Env', info['Config']['Env'][n]]
18
+ else
19
+ rows.push ['', info['Config']['Env'][n]]
20
+ end
21
+ end
22
+ end
23
+ unless info['Config']['OnBuild'].nil?
24
+ info['Config']['OnBuild'].each_index do |n|
25
+ if n == 0
26
+ rows.push ['OnBuild', info['Config']['OnBuild'][n]]
27
+ else
28
+ rows.push ['', info['Config']['OnBuild'][n]]
29
+ end
30
+ end
31
+ end
32
+ rows.push ['Port Specs', info['Config']['PortSpecs']]
33
+ rows.push ['User', info['Config']['User']]
34
+ rows.push ['Volumes', info['Config']['Volumes']]
35
+ rows.push ['Working Dir', info['Config']['WorkingDir']]
36
+
37
+ table = ::Terminal::Table.new title: 'DOCKER INSPECT', rows: rows
38
+ table.style = { :padding_left => 0, :border_x => '', :border_y => ' ', :border_i => '' }
39
+ message.reply(table, code: true)
40
+ rescue => e
41
+ value = [e.class.name, e.message].join("\n")
42
+ message.reply value
43
+ ensure
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,33 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Ps < Base
5
+ def call
6
+ containers = ::Docker::Container
7
+ rows = []
8
+ message.reply(containers.all(:all => true), code: true) if message[:debug] == ' -D '
9
+ containers.all(:all => true).each do |c|
10
+ command = [c.instance_variable_get(:@info)['Command']].to_s[2..16]
11
+ created = [c.instance_variable_get(:@info)['Created']].to_s[2..-3]
12
+ image = [c.instance_variable_get(:@info)['Image']].to_s[2..-3]
13
+ label = [c.instance_variable_get(:@info)['Labels']].to_s[2..-3]
14
+ names = [c.instance_variable_get(:@info)['Names']].to_s[4..-4]
15
+ # TODO: Depth variable. and private & public ports.
16
+ # ports = [c.instance_variable_get(:@info)['Ports']].to_s[2..-3]
17
+ status = [c.instance_variable_get(:@info)['Status']].to_s[2..-3]
18
+ id = [c.instance_variable_get(:@info)['id'].to_s[0..12]].to_s[2..-3]
19
+
20
+ rows.push [id, image, command, created, status, names, label]
21
+ end
22
+ table = ::Terminal::Table.new headings: ['CONTAINER ID', 'IMAGE', 'COMMAND', 'CREATED', 'STATUS', 'NAMES'], rows: rows
23
+ table.style = { :padding_left => 0, :border_x => '', :border_y => ' ', :border_i => '' }
24
+ message.reply(table, code: true)
25
+ rescue => e
26
+ value = [e.class.name, e.message, e.backtrace].join("\n")
27
+ message.reply value
28
+ ensure
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,50 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Pull < Base
5
+ def call
6
+ image_name = message[:image_name]
7
+ message.reply("Pulling from #{image_name}...")
8
+ image = ::Docker::Image.create('fromImage' => image_name)
9
+ message.reply("Status: Downloaded newer image for #{image_name}")
10
+ message.reply(image.json, code: true) if message[:debug] == ' -D '
11
+ rows = []
12
+ rows.push ['IMAGE NAME', image_name]
13
+ rows.push ['IMAGE ID', image.json['Id']]
14
+ rows.push ['VirtualSize', filesize_to_human(image.json['VirtualSize'])]
15
+ rows.push ['OS', image.json['Os']]
16
+ unless image.json['Config']['Env'].nil?
17
+ image.json['Config']['Env'].each_index do |n|
18
+ if n == 0
19
+ rows.push ['Env', image.json['Config']['Env'][n]]
20
+ else
21
+ rows.push ['', image.json['Config']['Env'][n]]
22
+ end
23
+ end
24
+ end
25
+ unless image.json['Config']['OnBuild'].nil?
26
+ image.json['Config']['OnBuild'].each_index do |n|
27
+ if n == 0
28
+ rows.push ['OnBuild', image.json['Config']['OnBuild'][n]]
29
+ else
30
+ rows.push ['', image.json['Config']['OnBuild'][n]]
31
+ end
32
+ end
33
+ end
34
+ rows.push ['Cmd', image.json['ContainerConfig']['Cmd']]
35
+ rows.push ['WorkingDir', image.json['ContainerConfig']['WorkingDir']]
36
+ rows.push ['Created', image.json['Created']]
37
+ rows.push ['DockerVersion', image.json['DockerVersion']]
38
+
39
+ table = ::Terminal::Table.new title: 'PULLED IMAGE INFO', rows: rows
40
+ table.style = { :padding_left => 0, :border_x => '', :border_y => ' ', :border_i => '' }
41
+ message.reply(table, code: true)
42
+ rescue => e
43
+ value = [e.class.name, e.message, e.backtrace].join("\n")
44
+ message.reply value
45
+ ensure
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,19 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Rm < Base
5
+ def call
6
+ container = message[:container_name]
7
+
8
+ @rm_thread = ::Thread.new { ::Docker::Container.get(container).remove
9
+ message.reply("Delete #{container}")
10
+ }
11
+ rescue => e
12
+ value = [e.class.name, e.message, e.backtrace].join("\n")
13
+ message.reply value
14
+ ensure
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Rmi < Base
5
+ def call
6
+ image_name = message[:image_name]
7
+ message.reply("Deleting from #{image_name}...")
8
+ image = ::Docker::Image.get(image_name).remove(force: true)
9
+ message.reply(image, code: true) if message[:debug] == ' -D '
10
+ message.reply image
11
+ rescue => e
12
+ value = [e.class.name, e.message, e.backtrace].join("\n")
13
+ message.reply value
14
+ ensure
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,58 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Run < Base
5
+ def call
6
+ image_name = message[:image_name]
7
+
8
+ args = message[:args].gsub(/\"/) { $1 }.split('-')
9
+ args.each do |a|
10
+ if /^v/ === a
11
+ set_volumes(a)
12
+ elsif /^e/ === a
13
+ set_env(a)
14
+ elsif /^link/ === a
15
+ set_link(a)
16
+ elsif /^net/ === a
17
+ set_net(a)
18
+ else
19
+ set_command(a)
20
+ end
21
+ end
22
+ image = ::Docker::Container.create('Image' => image_name, 'Binds' => @volume, 'Env' => @env, 'Cmd' => @command)
23
+ message.reply("Start running the #{image_name}...")
24
+ ::Thread.new { image.tap(&:start).attach do |stream, chunk|
25
+ message.reply stream
26
+ message.reply chunk
27
+ end }
28
+ rescue => e
29
+ value = [e.class.name, e.message, e.backtrace].join("\n")
30
+ message.reply value
31
+ ensure
32
+ end
33
+
34
+ private
35
+
36
+ def set_volumes(a)
37
+ @volume = [] << a.sub('v') { $1 }.gsub(' ') { $1 }
38
+ end
39
+
40
+ def set_env(a)
41
+ @env = a.chop.sub(/e /) { $1 }.split(', ')
42
+ end
43
+
44
+ def set_link(a)
45
+ @link = [] << a.sub(/link /) { $1 }.gsub(/\s/) { $1 }
46
+ end
47
+
48
+ def set_net(a)
49
+ @net = [] << a.sub(/net /) { $1 }
50
+ end
51
+
52
+ def set_command(a)
53
+ @command = a.split('/\s/')
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,19 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Start < Base
5
+ def call
6
+ container = message[:container_name]
7
+
8
+ @start_thread = ::Thread.new { ::Docker::Container.get(container).start
9
+ message.reply("Start #{container}")
10
+ }
11
+ rescue => e
12
+ value = [e.class.name, e.message, e.backtrace].join("\n")
13
+ message.reply value
14
+ ensure
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Stop < Base
5
+ def call
6
+ container = message[:container_name]
7
+
8
+ @stop_thread = ::Thread.new { ::Docker::Container.get(container).stop
9
+ message.reply("Stop #{container}")
10
+ }
11
+ rescue => e
12
+ value = [e.class.name, e.message, e.backtrace].join("\n")
13
+ message.reply value
14
+ ensure
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Thread < Base
5
+ def call
6
+ thread = ::Thread
7
+ current = thread::current
8
+ thread::list.each do |t|
9
+ t != current ? message.reply('--------------------------------------------------') : message.reply('--------------- Current Thread ---------------')
10
+ message.reply(t)
11
+ message.reply(t.status)
12
+ message.reply(t.inspect)
13
+ end
14
+ rescue => e
15
+ value = [e.class.name, e.message, e.backtrace].join("\n")
16
+ message.reply value
17
+ ensure
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ module Ruboty
2
+ module Docker
3
+ module Actions
4
+ class Top < Base
5
+ def call
6
+ container = message[:container_name]
7
+ top = ::Docker::Container.get(container).top
8
+ rows = []
9
+ top.each do |t|
10
+ rows.push [t['PID'], t['USER'], t['COMMAND']]
11
+ end
12
+ table = ::Terminal::Table.new title: 'CONTAINER TOP', headings: ['PID', 'USER', 'COMMAND'], rows: rows
13
+ table.style = { :padding_left => 0, :border_x => '', :border_y => ' ', :border_i => '' }
14
+ message.reply(table, code: true)
15
+ rescue => e
16
+ value = [e.class.name, e.message].join("\n")
17
+ message.reply value
18
+ ensure
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Docker
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ require 'awesome_print'
2
+ require 'docker'
3
+ require 'pp'
4
+ require 'terminal-table'
5
+
6
+ require 'ruboty/docker/version'
7
+ require 'ruboty/docker/actions/base'
8
+ require 'ruboty/docker/actions/build'
9
+ require 'ruboty/docker/actions/events'
10
+ require 'ruboty/docker/actions/images'
11
+ require 'ruboty/docker/actions/info'
12
+ require 'ruboty/docker/actions/inspect'
13
+ require 'ruboty/docker/actions/ps'
14
+ require 'ruboty/docker/actions/pull'
15
+ require 'ruboty/docker/actions/rm'
16
+ require 'ruboty/docker/actions/rmi'
17
+ require 'ruboty/docker/actions/run'
18
+ require 'ruboty/docker/actions/start'
19
+ require 'ruboty/docker/actions/stop'
20
+ require 'ruboty/docker/actions/thread'
21
+ require 'ruboty/docker/actions/top'
22
+ require 'ruboty/handlers/docker'
@@ -0,0 +1,80 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class Docker < Base
4
+ NAMESPACE = 'docker'
5
+
6
+ ::Docker.url = ENV['RUBOTY_DOCKER_HOST'] || 'unix:///var/run/docker.sock'
7
+
8
+ on /docker build (?<code>.+)/m, name: 'docker_build', description: 'Build an image form a code'
9
+ on /docker events\z/, name: 'docker_events', description: 'Start real time events stream watch thread'
10
+ on /docker(?<debug>.+?)images\z/m, name: 'docker_images', description: 'List images'
11
+ on /docker(?<debug>.+?)info\z/m, name: 'docker_info', description: 'Display system-vide information'
12
+ on /docker(?<debug>.+?)inspect (?<target_name>.+)/m, name: 'docker_inspect', description: 'Return low-level information on a contaitner or image'
13
+ on /docker(?<debug>.+?)ps\z/m, name: 'docker_ps', description: 'List containers'
14
+ on /docker(?<debug>.+?)pull (?<image_name>.+)/m, name: 'docker_pull', description: 'Pull an image or a repository from a Docker registry server'
15
+ on /docker rm (?<container_name>.+)/, name: 'docker_rm', description: 'Remove one or more containers'
16
+ on /docker rmi(?<debug>.+?)(?<image_name>.+)/m, name: 'docker_rmi', description: 'Remove one or more images'
17
+ on /docker run (?<image_name>.+?) \[(?<args>.+?)\] (?<command>.+)/m, name: 'docker_run', description: 'Run a command in a nemw container'
18
+ on /docker start (?<container_name>.+)/, name: 'docker_start', description: 'Start a stopped container'
19
+ on /docker stop (?<container_name>.+)/, name: 'docker_stop', description: 'Stop a running container'
20
+ on /docker thread\z/, name: 'docker_thread', description: 'Check current Ruby thread'
21
+ on /docker top (?<container_name>.+)/, name: 'docker_top', description: 'Stop a running container'
22
+
23
+ def docker_events(message)
24
+ Ruboty::Docker::Actions::Events.new(message).call
25
+ end
26
+
27
+ def docker_build(message)
28
+ Ruboty::Docker::Actions::Build.new(message).call
29
+ end
30
+
31
+ def docker_images(message)
32
+ Ruboty::Docker::Actions::Images.new(message).call
33
+ end
34
+
35
+ def docker_info(message)
36
+ Ruboty::Docker::Actions::Info.new(message).call
37
+ end
38
+
39
+ def docker_inspect(message)
40
+ Ruboty::Docker::Actions::Inspect.new(message).call
41
+ end
42
+
43
+ def docker_ps(message)
44
+ Ruboty::Docker::Actions::Ps.new(message).call
45
+ end
46
+
47
+ def docker_pull(message)
48
+ Ruboty::Docker::Actions::Pull.new(message).call
49
+ end
50
+
51
+ def docker_rm(message)
52
+ Ruboty::Docker::Actions::Rm.new(message).call
53
+ end
54
+
55
+ def docker_rmi(message)
56
+ Ruboty::Docker::Actions::Rmi.new(message).call
57
+ end
58
+
59
+ def docker_run(message)
60
+ Ruboty::Docker::Actions::Run.new(message).call
61
+ end
62
+
63
+ def docker_start(message)
64
+ Ruboty::Docker::Actions::Start.new(message).call
65
+ end
66
+
67
+ def docker_stop(message)
68
+ Ruboty::Docker::Actions::Stop.new(message).call
69
+ end
70
+
71
+ def docker_thread(message)
72
+ Ruboty::Docker::Actions::Thread.new(message).call
73
+ end
74
+
75
+ def docker_top(message)
76
+ Ruboty::Docker::Actions::Top.new(message).call
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/docker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruboty-docker'
8
+ spec.version = Ruboty::Docker::VERSION
9
+ spec.authors = ['zchee']
10
+ spec.email = ['zcheeee@gmail.com']
11
+
12
+ spec.summary = %q{Management Docker Container via Ruboty ChatOps}
13
+ spec.description = %q{Management Docker Container via Ruboty ChatOps}
14
+ spec.homepage = 'https://github.com/zchee/ruboty-docker'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'docker-api', '~> 1.21'
22
+ spec.add_runtime_dependency 'ruboty', '~> 1.2'
23
+ spec.add_runtime_dependency 'terminal-table', '~> 1.4'
24
+ spec.add_development_dependency 'awesome_print'
25
+ spec.add_development_dependency 'bundler', '~> 1.9'
26
+ spec.add_development_dependency 'ci_reporter'
27
+ spec.add_development_dependency 'codeclimate-test-reporter'
28
+ spec.add_development_dependency 'coveralls'
29
+ spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'simplecov'
33
+ spec.add_development_dependency 'simplecov-rcov'
34
+ end
metadata ADDED
@@ -0,0 +1,257 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-docker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - zchee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docker-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.21'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.21'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruboty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: terminal-table
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: awesome_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ci_reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '10.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '10.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov-rcov
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description: Management Docker Container via Ruboty ChatOps
196
+ email:
197
+ - zcheeee@gmail.com
198
+ executables: []
199
+ extensions: []
200
+ extra_rdoc_files: []
201
+ files:
202
+ - ".coveralls.yml"
203
+ - ".gitignore"
204
+ - ".pryrc"
205
+ - ".rspec"
206
+ - ".ruby-version"
207
+ - ".travis.yml"
208
+ - Gemfile
209
+ - Guardfile
210
+ - README.md
211
+ - Rakefile
212
+ - circle.yml
213
+ - lib/ruboty/docker.rb
214
+ - lib/ruboty/docker/actions/base.rb
215
+ - lib/ruboty/docker/actions/build.rb
216
+ - lib/ruboty/docker/actions/events.rb
217
+ - lib/ruboty/docker/actions/images.rb
218
+ - lib/ruboty/docker/actions/info.rb
219
+ - lib/ruboty/docker/actions/inspect.rb
220
+ - lib/ruboty/docker/actions/ps.rb
221
+ - lib/ruboty/docker/actions/pull.rb
222
+ - lib/ruboty/docker/actions/rm.rb
223
+ - lib/ruboty/docker/actions/rmi.rb
224
+ - lib/ruboty/docker/actions/run.rb
225
+ - lib/ruboty/docker/actions/start.rb
226
+ - lib/ruboty/docker/actions/stop.rb
227
+ - lib/ruboty/docker/actions/thread.rb
228
+ - lib/ruboty/docker/actions/top.rb
229
+ - lib/ruboty/docker/version.rb
230
+ - lib/ruboty/handlers/docker.rb
231
+ - ruboty-docker.gemspec
232
+ homepage: https://github.com/zchee/ruboty-docker
233
+ licenses:
234
+ - MIT
235
+ metadata: {}
236
+ post_install_message:
237
+ rdoc_options: []
238
+ require_paths:
239
+ - lib
240
+ required_ruby_version: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - ">="
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ required_rubygems_version: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - ">="
248
+ - !ruby/object:Gem::Version
249
+ version: '0'
250
+ requirements: []
251
+ rubyforge_project:
252
+ rubygems_version: 2.4.5
253
+ signing_key:
254
+ specification_version: 4
255
+ summary: Management Docker Container via Ruboty ChatOps
256
+ test_files: []
257
+ has_rdoc: