docker-doctor 0.0.1

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: 2da035fc867d237438e955e9bef4a406a07dbfe7
4
+ data.tar.gz: f142fb49264e6403a2443f149bb4b7c5a86740fa
5
+ SHA512:
6
+ metadata.gz: df5110b2b549dfde6006c6b368e93e35c0d8a366618a57102387131eef49bc1f68fb83923ac6f0b7041a1aa782b7bbadf07a87f7c07a0ac3f002b72f077d62c8
7
+ data.tar.gz: 7ac15f1475498eb054fab57025693ab02c346f47e89b22a110c38ba46e3372b3c0615e03c3809f79e4d95fe6879d99e6c055c58055bee7ffcb326068bd6fc8fb
@@ -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})
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: docker-doctor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tal Levy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-04 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: