docker-image-map 0.1.1

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: 1d64a32b617faaad5c05ba0cbb7985bab75e4302
4
+ data.tar.gz: 4fd34790d1f488d14e30ed804a9d970c6dd74fd1
5
+ SHA512:
6
+ metadata.gz: a6ad7797db91c9acb32071e2c3268df35130bab5bc4c47de83442426014df986e990c29c9184e1ced026350ea6f25844f9eb64a5dd22a623e95989a2b8394794
7
+ data.tar.gz: 4be390ef01b6efcd59c15108f2019d5e5bc3d4d877711ca49c2d4f88421d602b237689786b925481b98868a29eb4055639daa0b21034a15b316b64bbf34c7564
@@ -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,17 @@
1
+ # docker-image-map
2
+
3
+ Visualize docker image history.
4
+
5
+ ## Installation
6
+
7
+ gem install docker-image-map
8
+
9
+ ## Usage
10
+
11
+ docker-image-map
12
+
13
+ ![Sample output](screenshot.png "Sample output")
14
+
15
+ ## Contributing
16
+
17
+ * It's on [GitHub](https://github.com/mdub/docker_image_map)
@@ -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-image-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.1"
3
+ end
Binary file
@@ -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,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docker-image-map
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-01 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
+ - screenshot.png
131
+ - spec/docker_image_map/image_info_spec.rb
132
+ - spec/docker_image_map/image_set_spec.rb
133
+ - spec/spec_helper.rb
134
+ homepage: ''
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.5
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Visualize docker image history
158
+ test_files:
159
+ - spec/docker_image_map/image_info_spec.rb
160
+ - spec/docker_image_map/image_set_spec.rb
161
+ - spec/spec_helper.rb