Class: Conjure::Service::DockerShell

Inherits:
Object
  • Object
show all
Defined in:
lib/conjure/service/docker_shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DockerShell

Returns a new instance of DockerShell.



6
7
8
9
# File 'lib/conjure/service/docker_shell.rb', line 6

def initialize(options)
  @docker_host = options[:docker_host]
  @image = options[:image]
end

Instance Attribute Details

#docker_hostObject (readonly)

Returns the value of attribute docker_host.



4
5
6
# File 'lib/conjure/service/docker_shell.rb', line 4

def docker_host
  @docker_host
end

Instance Method Details

#command(*args, &block) ⇒ Object



18
19
20
# File 'lib/conjure/service/docker_shell.rb', line 18

def command(*args, &block)
  (@image || default_image).command *args, &block
end

#default_imageObject



37
38
39
# File 'lib/conjure/service/docker_shell.rb', line 37

def default_image
  @default_image ||= @docker_host.images.create(image_options)
end

#default_image_nameObject



41
42
43
# File 'lib/conjure/service/docker_shell.rb', line 41

def default_image_name
  "ubuntu"
end

#image_optionsObject



30
31
32
33
34
35
# File 'lib/conjure/service/docker_shell.rb', line 30

def image_options
  {
    :base_image => (@image || default_image_name),
    :host_volumes => (@image.host_volumes if @image),
  }
end

#prepare(options) ⇒ Object



11
12
13
14
15
16
# File 'lib/conjure/service/docker_shell.rb', line 11

def prepare(options)
  self.class.new(
    :docker_host => @docker_host,
    :image => @docker_host.images.create(image_options.merge options),
  )
end

#run(*args) ⇒ Object



22
23
24
# File 'lib/conjure/service/docker_shell.rb', line 22

def run(*args)
  (@image || default_image).run *args
end

#stop(*args) ⇒ Object



26
27
28
# File 'lib/conjure/service/docker_shell.rb', line 26

def stop(*args)
  (@image || default_image).stop *args
end