Class: Ruboty::Docker::Actions::Run

Inherits:
Base
  • Object
show all
Defined in:
lib/ruboty/docker/actions/run.rb

Constant Summary

Constants inherited from Base

Base::NAMESPACE

Instance Attribute Summary

Attributes inherited from Base

#message

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Ruboty::Docker::Actions::Base

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruboty/docker/actions/run.rb', line 5

def call
    image_name = message[:image_name]

    args = message[:args].gsub(/\"/) { $1 }.split('-')
    args.each do |a|
        if /^v/ === a
            set_volumes(a)
        elsif /^e/ === a
            set_env(a)
        elsif /^link/ === a
            set_link(a)
        elsif /^net/ === a
            set_net(a)
        else
            set_command(a)
        end
    end
    image = ::Docker::Container.create('Image' => image_name, 'Binds' => @volume, 'Env' => @env, 'Cmd' => @command)
    message.reply("Start running the #{image_name}...")
    ::Thread.new { image.tap(&:start).attach do |stream, chunk|
        message.reply stream
        message.reply chunk
    end }
rescue => e
    value = [e.class.name, e.message, e.backtrace].join("\n")
    message.reply value
ensure
end