Class: Conjure::Service::DockerHost

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

Instance Method Summary collapse

Constructor Details

#initialize(server_name) ⇒ DockerHost

Returns a new instance of DockerHost.



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

def initialize(server_name)
  @server_name = server_name
end

Instance Method Details

#command(command, options = {}, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/conjure/service/docker_host.rb', line 41

def command(command, options = {}, &block)
  full_command = "#{docker_path} #{command}"
  full_command = "nohup #{full_command}" if options[:nohup]
  full_command = "echo '#{shell_escape options[:stdin]}' | #{full_command}" if options[:stdin]
  Log.debug "   [scp] #{options[:files].inspect}" if options[:files]
  result = server.run full_command, :stream_stdin => options[:stream_stdin], :files => options[:files], &block
  raise "Docker error: #{result.stdout} #{result.stderr}" unless result.status == 0
  result.stdout
end

#containersObject



63
64
65
# File 'lib/conjure/service/docker_host.rb', line 63

def containers
  ContainerSet.new :host => self
end

#docker_pathObject



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

def docker_path
  @docker_path ||= existing_docker_path
  @docker_path ||= new_docker_path
end

#ensure_host_directory(dir) ⇒ Object



51
52
53
# File 'lib/conjure/service/docker_host.rb', line 51

def ensure_host_directory(dir)
  server.run "mkdir -p #{dir}"
end

#existing_docker_pathObject



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

def existing_docker_path
  path = server.run("which docker").stdout.to_s.strip
  path = nil if path == ""
  Log.info "[docker] Using installed #{path}" if path
  path
end

#imagesObject



59
60
61
# File 'lib/conjure/service/docker_host.rb', line 59

def images
  ImageSet.new self
end

#ip_addressObject



14
15
16
# File 'lib/conjure/service/docker_host.rb', line 14

def ip_address
  @server.ip_address
end

#new_docker_pathObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/conjure/service/docker_host.rb', line 18

def new_docker_path
  Log.info "[docker] Installing docker"
  server.run "dd if=/dev/zero of=/root/swapfile bs=1024 count=524288"
  server.run "mkswap /root/swapfile; swapon /root/swapfile"
  server.run "curl https://get.docker.io/gpg | apt-key add -"
  server.run "echo 'deb https://get.docker.io/ubuntu docker main' >/etc/apt/sources.list.d/docker.list"
  server.run "apt-get update"
  server.run "DEBIAN_FRONTEND=noninteractive apt-get install -y linux-image-extra-`uname -r` lxc-docker"
  existing_docker_path
end

#serverObject



10
11
12
# File 'lib/conjure/service/docker_host.rb', line 10

def server
  @server ||= Service::CloudServer.new @server_name
end

#shellObject



67
68
69
# File 'lib/conjure/service/docker_host.rb', line 67

def shell
  DockerShell.new :docker_host => self
end

#shell_escape(text) ⇒ Object



55
56
57
# File 'lib/conjure/service/docker_host.rb', line 55

def shell_escape(text)
  text.gsub "'", "'\"'\"'"
end