Class: Conjure::Service::DockerHost
- Inherits:
-
Object
- Object
- Conjure::Service::DockerHost
- Defined in:
- lib/conjure/service/docker_host.rb
Instance Method Summary collapse
- #command(command, options = {}, &block) ⇒ Object
- #containers ⇒ Object
- #docker_path ⇒ Object
- #ensure_host_directory(dir) ⇒ Object
- #existing_docker_path ⇒ Object
- #images ⇒ Object
-
#initialize(server_name) ⇒ DockerHost
constructor
A new instance of DockerHost.
- #ip_address ⇒ Object
- #new_docker_path ⇒ Object
- #server ⇒ Object
- #shell ⇒ Object
- #shell_escape(text) ⇒ Object
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, = {}, &block) full_command = "#{docker_path} #{command}" full_command = "nohup #{full_command}" if [:nohup] full_command = "echo '#{shell_escape [:stdin]}' | #{full_command}" if [:stdin] Log.debug " [scp] #{[:files].inspect}" if [:files] result = server.run full_command, :stream_stdin => [:stream_stdin], :files => [:files], &block raise "Docker error: #{result.stdout} #{result.stderr}" unless result.status == 0 result.stdout end |
#containers ⇒ Object
63 64 65 |
# File 'lib/conjure/service/docker_host.rb', line 63 def containers ContainerSet.new :host => self end |
#docker_path ⇒ Object
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_path ⇒ Object
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 |
#images ⇒ Object
59 60 61 |
# File 'lib/conjure/service/docker_host.rb', line 59 def images ImageSet.new self end |
#ip_address ⇒ Object
14 15 16 |
# File 'lib/conjure/service/docker_host.rb', line 14 def ip_address @server.ip_address end |
#new_docker_path ⇒ Object
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 |
#server ⇒ Object
10 11 12 |
# File 'lib/conjure/service/docker_host.rb', line 10 def server @server ||= Service::CloudServer.new @server_name end |
#shell ⇒ Object
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 |