docker_map 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f73aa467d659f7bfd367997ac18bd54e05d389d8
4
+ data.tar.gz: c8b5dacd6be0f9b9cc824c44e7bce245455abc9d
5
+ SHA512:
6
+ metadata.gz: 3faaeaef723535e0d2fa54f07f79a0c1bc61a3f33fc01172b17d58b03f922d7c6d9c77bdc45a775939ade7051f870c5f2c0b4c703a94d59efc3ff916116791e6
7
+ data.tar.gz: f1c083b2e8041727ab93540bba1be3a71299f91e7a78c16ee3f950be03610737251a97c6e1f6a65dc6988ca54437df92a80ea5087828fd2afa3f691f21a0d819
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in docker-map.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Mike Williams
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Docker::Map
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'docker-map'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install docker-map
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/docker-map/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ task "default" => "spec"
6
+
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.pattern = 'spec/**/*_spec.rb'
9
+ t.rspec_opts = ["--colour", "--format", "documentation"]
10
+ end
11
+
@@ -0,0 +1,86 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path("../../lib", __FILE__)
4
+
5
+ require "clamp"
6
+ require "docker"
7
+ require "docker_image_map/image_set"
8
+ require "term/ansicolor"
9
+
10
+ Excon.defaults[:ssl_verify_peer] = false
11
+
12
+ C = Term::ANSIColor
13
+
14
+ Clamp do
15
+
16
+ option ["-C", "--compact"], :flag, "compact output"
17
+
18
+ def execute
19
+ load_images
20
+ image_set.roots.each do |root|
21
+ display_image(root)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def image_set
28
+ @image_set ||= DockerImageMap::ImageSet.new
29
+ end
30
+
31
+ def load_images
32
+ Docker::Image.all(:all => true).each do |image|
33
+ info = image_set[image.id]
34
+ parent_id = image.info.fetch('ParentId')
35
+ parent_id = nil if parent_id == ""
36
+ if parent_id
37
+ parent = image_set[parent_id]
38
+ info.parent = parent
39
+ parent.children << info
40
+ end
41
+ info.date = Time.at(image.info["Created"])
42
+ info.size = (image.info["VirtualSize"].to_f / 1024 / 1024).round(1)
43
+ image.info.fetch('RepoTags').each do |tag|
44
+ info.tags << tag unless tag == '<none>:<none>'
45
+ end
46
+ end
47
+ end
48
+
49
+ def display_image(image, prefix = "", collapsed = 0)
50
+ if compact? && image.children.size == 1 && image.tags.empty?
51
+ display_image(image.children.first, prefix, collapsed + 1)
52
+ else
53
+ puts (prefix + image_line(image, collapsed))
54
+ prefix = prefix + " " + (" " * collapsed)
55
+ image.tags.to_a.sort.each do |tag|
56
+ puts (prefix + tag_line(tag))
57
+ end
58
+ image.children.each do |child|
59
+ display_image(child, prefix)
60
+ end
61
+ end
62
+ end
63
+
64
+ def image_line(image, collapsed)
65
+ "".tap do |s|
66
+ if collapsed > 0
67
+ s << ("." * collapsed)
68
+ end
69
+ s << image.id[0..11]
70
+ s << " "
71
+ s << C.cyan
72
+ s << "("
73
+ s << image.date.strftime("%F")
74
+ s << ", "
75
+ s << image.size.to_s
76
+ s << ")"
77
+ s << C.reset
78
+ end
79
+ end
80
+
81
+ def tag_line(tag)
82
+ "#{C.yellow}- #{tag.inspect}#{C.reset}"
83
+ end
84
+
85
+ end
86
+
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'docker_image_map/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "docker_map"
7
+ spec.version = DockerImageMap::VERSION
8
+ spec.authors = ["Mike Williams"]
9
+ spec.email = ["mdub@dogbiscuit.org"]
10
+ spec.summary = %q{Visualize docker image history}
11
+ spec.homepage = ""
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_runtime_dependency "clamp", ">= 0.6.4"
20
+ spec.add_runtime_dependency "docker-api"
21
+ spec.add_runtime_dependency "term-ansicolor"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.2"
26
+ spec.add_development_dependency "rspec-collection_matchers"
27
+
28
+ end
@@ -0,0 +1,22 @@
1
+ require "set"
2
+
3
+ module DockerImageMap
4
+
5
+ class ImageInfo
6
+
7
+ def initialize(id)
8
+ @id = id
9
+ @tags = Set.new
10
+ @children = []
11
+ end
12
+
13
+ attr_reader :id
14
+ attr_accessor :size
15
+ attr_accessor :date
16
+ attr_accessor :parent
17
+ attr_reader :children
18
+ attr_reader :tags
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,23 @@
1
+ require "docker_image_map/image_info"
2
+
3
+ module DockerImageMap
4
+
5
+ class ImageSet
6
+
7
+ def initialize
8
+ @images = {}
9
+ end
10
+
11
+ attr_reader :images
12
+
13
+ def [](id)
14
+ @images[id] ||= ImageInfo.new(id)
15
+ end
16
+
17
+ def roots
18
+ @images.values.select { |i| i.parent.nil? }
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ module DockerImageMap
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'spec_helper'
2
+
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ require 'docker_image_map/image_set'
4
+
5
+ RSpec.describe DockerImageMap::ImageSet do
6
+
7
+ subject(:image_set) { described_class.new }
8
+
9
+ context "new" do
10
+
11
+ it "has no images" do
12
+ expect(image_set.images).to be_empty
13
+ end
14
+
15
+ end
16
+
17
+ context "after referencing an image" do
18
+
19
+ context "with no parent" do
20
+
21
+ before do
22
+ image_set["abc123"]
23
+ end
24
+
25
+ it "remembers the image" do
26
+ expect(image_set.images).to have(1).entry
27
+ expect(image_set["abc123"].id).to eq("abc123")
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1 @@
1
+ require 'rspec/collection_matchers'
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docker_map
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: clamp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: docker-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: term-ansicolor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-collection_matchers
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - mdub@dogbiscuit.org
114
+ executables:
115
+ - docker-image-map
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/docker-image-map
126
+ - docker_image_map.gemspec
127
+ - lib/docker_image_map/image_info.rb
128
+ - lib/docker_image_map/image_set.rb
129
+ - lib/docker_image_map/version.rb
130
+ - spec/docker_image_map/image_info_spec.rb
131
+ - spec/docker_image_map/image_set_spec.rb
132
+ - spec/spec_helper.rb
133
+ homepage: ''
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.2.2
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Visualize docker image history
157
+ test_files:
158
+ - spec/docker_image_map/image_info_spec.rb
159
+ - spec/docker_image_map/image_set_spec.rb
160
+ - spec/spec_helper.rb