torquayish 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/docker_doctor.rb +58 -0
  3. metadata +59 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a4caea3d32d08cc02d450b6655bc4d18580265a
4
+ data.tar.gz: 172d66c888668447e16d84655a9c963cf6169cf3
5
+ SHA512:
6
+ metadata.gz: d03590357961a7828f20cd79aa9b3508e2ae47d1dace8cc9c58628c0ec8fd1bc83c0e04601765b3555ed40f35b969aeb7a62aed253ab5e3a50cbcddf0494f673
7
+ data.tar.gz: 8bead3c46803cf6c636cb83506d96606f8072ca1f48c17f652ee452ce128329c48878ecb800ab5f1a70f78ae962c2b7cc34f440b182ab7389f19d2c3d7bf3135
@@ -0,0 +1,58 @@
1
+ class DockerDoctor
2
+ def initialize
3
+ require 'docker'
4
+ Docker.options = { :write_timeout => 300, :read_timeout => 300 }
5
+ Docker.validate_version!
6
+ @host = {
7
+ :host_ip => get_host_ip,
8
+ :ports => {}
9
+ }
10
+ @container = nil
11
+ @image = nil
12
+ end
13
+
14
+ def get_host_ip
15
+ # Let the crazy one-liner definition begin:
16
+ # Docker.url.split(':')[1][2..-1]
17
+ # Docker.url = tcp://192.168.123.205:2375
18
+ # split(':') = ["tcp", "//192.168.123.205", "2375"]
19
+ # [1] = "//192.168.123.205"
20
+ # [2..-1] = "192.168.123.205"
21
+ # This last bit prunes the leading //
22
+ url = Docker.url
23
+ case url.split(':')[0]
24
+ when 'unix'
25
+ ip = "127.0.0.1"
26
+ when 'tcp'
27
+ ip = url.split(':')[1][2..-1]
28
+ end
29
+ ip
30
+ end
31
+
32
+ def provision(name, dockerfile_path)
33
+ dockerfile = IO.read(dockerfile_path)
34
+ @image = Docker::Image.build(dockerfile)
35
+ @container = Docker::Container.create({
36
+ 'Image' => @image.id,
37
+ 'Hostname' => "#{name}-#{image.id}",
38
+ })
39
+
40
+ @container.start({"PublishAllPorts" => true, "CapAdd" => "NET_ADMIN"})
41
+ @host[:ports] = @container.json["NetworkSettings"]["Ports"]
42
+ end
43
+
44
+ def cleanup
45
+ if @container
46
+ @container.stop
47
+ @container.delete
48
+ end
49
+ if @image
50
+ @image.remove(:force => true)
51
+ end
52
+ end
53
+
54
+ attr_reader :host
55
+ attr_reader :container
56
+ attr_reader :image
57
+ end
58
+
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: torquayish
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Tal Levy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docker-api
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.21'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.21'
25
+ prerelease: false
26
+ type: :runtime
27
+ description: Utility class for managing Docker containers and images, wrapping docker-api
28
+ email: tal@elastic.co
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/docker_doctor.rb
34
+ homepage: https://github.com/talevy/docker-doctor
35
+ licenses:
36
+ - apache-2.0
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.4.5
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Wrapper utility functions around Docker image creation and maintenance
58
+ test_files: []
59
+ has_rdoc: