Class: Image
Instance Attribute Summary collapse
-
#created ⇒ Object
Returns the value of attribute created.
-
#id ⇒ Object
Returns the value of attribute id.
-
#regexp_repo ⇒ Object
Returns the value of attribute regexp_repo.
-
#regexp_tag ⇒ Object
Returns the value of attribute regexp_tag.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#size ⇒ Object
Returns the value of attribute size.
-
#tag ⇒ Object
Returns the value of attribute tag.
Class Method Summary collapse
- .build(dockerfile, *tags) ⇒ Object
- .command ⇒ Object
- .create(line) ⇒ Object
- .find(keyword:, name:, tag:) ⇒ Object
- .headers ⇒ Object
- .launch(image_name, run_opts, command) ⇒ Object
- .pull(name) ⇒ Object
- .push(repo_name) ⇒ Object
- .tag(name, *as_names) ⇒ Object
Instance Method Summary collapse
- #del ⇒ Object
- #image_name ⇒ Object
-
#initialize(**params) ⇒ Image
constructor
A new instance of Image.
- #launch(run_opts, command) ⇒ Object
- #push ⇒ Object
- #to_a(*cols) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(**params) ⇒ Image
Returns a new instance of Image.
63 64 65 66 67 68 69 70 |
# File 'lib/models/image.rb', line 63 def initialize(**params) @repository = params[:repository] @tag = params[:tag] @id = params[:id] @created = params[:created] @size = params[:size] @raw = params[:raw] end |
Instance Attribute Details
#created ⇒ Object
Returns the value of attribute created.
3 4 5 |
# File 'lib/models/image.rb', line 3 def created @created end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/models/image.rb', line 3 def id @id end |
#regexp_repo ⇒ Object
Returns the value of attribute regexp_repo.
3 4 5 |
# File 'lib/models/image.rb', line 3 def regexp_repo @regexp_repo end |
#regexp_tag ⇒ Object
Returns the value of attribute regexp_tag.
3 4 5 |
# File 'lib/models/image.rb', line 3 def regexp_tag @regexp_tag end |
#repository ⇒ Object
Returns the value of attribute repository.
3 4 5 |
# File 'lib/models/image.rb', line 3 def repository @repository end |
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'lib/models/image.rb', line 3 def size @size end |
#tag ⇒ Object
Returns the value of attribute tag.
3 4 5 |
# File 'lib/models/image.rb', line 3 def tag @tag end |
Class Method Details
.build(dockerfile, *tags) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/models/image.rb', line 22 def self.build(dockerfile, *) run 'docker', 'build', '--force-rm', '-f', dockerfile, '-t', .join(' -t '), '.' end |
.command ⇒ Object
14 15 16 |
# File 'lib/models/image.rb', line 14 def self.command 'docker images' end |
.create(line) ⇒ Object
57 58 59 60 61 |
# File 'lib/models/image.rb', line 57 def self.create(line) repository, tag, id, created, size = line.chomp.split(' ' * 2).reject(&:empty?).map(&:strip) ret = new(repository: repository, tag: tag, id: id, created: created, size: size, raw: line) ret end |
.find(keyword:, name:, tag:) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/models/image.rb', line 33 def self.find(keyword:, name:, tag:) return all unless keyword || name || tag ret = keyword ? search(keyword) : all if name regexp_repo = /#{name}/i ret = ret.select do |image| image.regexp_repo = regexp_repo regexp_repo.match image.repository end end if tag regexp_tag = /#{tag}/i ret = ret.select do |image| image.regexp_tag = regexp_tag regexp_tag.match image.tag end end ret end |
.headers ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/models/image.rb', line 4 def self.headers { repository: 'REPOSITORY', tag: 'TAG', id: 'IMAGE ID', created: 'CREATED', size: 'SIZE' } end |
.launch(image_name, run_opts, command) ⇒ Object
18 19 20 |
# File 'lib/models/image.rb', line 18 def self.launch(image_name, run_opts, command) ['docker', 'run', run_opts, image_name, command] end |
.pull(name) ⇒ Object
77 78 79 |
# File 'lib/models/image.rb', line 77 def self.pull(name) run("docker pull #{name}") end |
.push(repo_name) ⇒ Object
53 54 55 |
# File 'lib/models/image.rb', line 53 def self.push(repo_name) run("docker push #{repo_name}") end |
.tag(name, *as_names) ⇒ Object
85 86 87 |
# File 'lib/models/image.rb', line 85 def self.tag(name, *as_names) run("docker tag #{name} #{as_names.join(' ')}") end |
Instance Method Details
#del ⇒ Object
72 73 74 75 |
# File 'lib/models/image.rb', line 72 def del instance = /<none>/.match(image_name) ? id : image_name run("docker rmi -f #{instance}") end |
#image_name ⇒ Object
89 90 91 |
# File 'lib/models/image.rb', line 89 def image_name "#{repository}:#{tag || 'latest'}" end |
#launch(run_opts, command) ⇒ Object
93 94 95 |
# File 'lib/models/image.rb', line 93 def launch(run_opts, command) self.class.launch(image_name, run_opts, command) end |
#push ⇒ Object
81 82 83 |
# File 'lib/models/image.rb', line 81 def push self.class.push(image_name) end |
#to_a(*cols) ⇒ Object
97 98 99 100 101 |
# File 'lib/models/image.rb', line 97 def to_a(*cols) cols = Image.headers.keys if cols.empty? ret = cols.map { |col| send(col).strip } ret end |
#to_s ⇒ Object
103 104 105 106 107 108 |
# File 'lib/models/image.rb', line 103 def to_s @raw.gsub!(@regexp, &:yellow) if @regexp @raw.sub!(repository, repository.gsub(@regexp_repo, '\0'.red)) if @regexp_repo @raw.gsub!(/#{tag}$/) { |tag| tag.gsub(@regexp_tag, '\0'.blue) } if @regexp_tag @raw end |