Module: Mcrain::ContainerController
- Included in:
- Base, Riak::Node
- Defined in:
- lib/mcrain/container_controller.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #add_volume_options(r, path_on_container, path_on_host) ⇒ Object
- #build_docker_options ⇒ Object
- #container ⇒ Docker::Container
- #container_image ⇒ Object
- #find_portno ⇒ Object
- #host ⇒ Object
- #info ⇒ Object
- #ip ⇒ Object
- #name ⇒ Object
- #port ⇒ Object
- #ssh_uri ⇒ Object
- #url ⇒ Object
Class Method Details
.included(klass) ⇒ Object
5 6 7 |
# File 'lib/mcrain/container_controller.rb', line 5 def self.included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#add_volume_options(r, path_on_container, path_on_host) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/mcrain/container_controller.rb', line 73 def (r, path_on_container, path_on_host) r['Volumes'] ||= {} r['Volumes'][path_on_container] = {} r['HostConfig']['Binds'] ||= [] r['HostConfig']['Binds'] << "#{path_on_host}:#{path_on_container}" self end |
#build_docker_options ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mcrain/container_controller.rb', line 62 def { 'Image' => container_image, 'HostConfig' => { 'PortBindings' => { "#{self.class.port}/tcp" => [{ 'HostPort' => port.to_s }] } } } end |
#container ⇒ Docker::Container
29 30 31 32 33 34 35 36 |
# File 'lib/mcrain/container_controller.rb', line 29 def container unless @container = Mcrain.logger.info("#{self.class.name}#container Docker::Container.create(#{.inspect})") @container = Docker::Container.create() end @container end |
#container_image ⇒ Object
38 39 40 |
# File 'lib/mcrain/container_controller.rb', line 38 def container_image self.class.container_image or raise "No container_image for #{self.class.name}" end |
#find_portno ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/mcrain/container_controller.rb', line 46 def find_portno # 未使用のポートをシステムに割り当てさせてすぐ閉じてそれを利用する tmpserv = TCPServer.new(0) portno = tmpserv.local_address.ip_port tmpserv.close portno end |
#host ⇒ Object
42 43 44 |
# File 'lib/mcrain/container_controller.rb', line 42 def host @host ||= URI.parse(ENV["DOCKER_HOST"] || "tcp://localhost").host end |
#info ⇒ Object
81 82 83 |
# File 'lib/mcrain/container_controller.rb', line 81 def info container.json end |
#ip ⇒ Object
89 90 91 |
# File 'lib/mcrain/container_controller.rb', line 89 def ip info["NetworkSettings"]["IPAddress"] end |
#name ⇒ Object
85 86 87 |
# File 'lib/mcrain/container_controller.rb', line 85 def name info["Name"] # .sub(/\A\//, '') end |
#port ⇒ Object
54 55 56 |
# File 'lib/mcrain/container_controller.rb', line 54 def port @port ||= find_portno end |
#ssh_uri ⇒ Object
93 94 95 |
# File 'lib/mcrain/container_controller.rb', line 93 def ssh_uri "ssh://root@#{ip}:22" end |
#url ⇒ Object
58 59 60 |
# File 'lib/mcrain/container_controller.rb', line 58 def url @url ||= "#{self.class.server_name}://#{host}:#{port}" end |