Class: Dapp::Image::Docker
- Inherits:
-
Object
- Object
- Dapp::Image::Docker
- Defined in:
- lib/dapp/image/docker.rb
Overview
Docker
Direct Known Subclasses
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Class Method Summary collapse
- .cache ⇒ Object
- .cache_reset(name = '') ⇒ Object
- .image_config_option(image_id:, option:) ⇒ Object
- .image_name?(name) ⇒ Boolean
- .image_name_format ⇒ Object
- .tag!(id:, tag:) ⇒ Object
Instance Method Summary collapse
- #cache_reset ⇒ Object
- #created_at ⇒ Object
- #id ⇒ Object
-
#initialize(name:, project:, from: nil) ⇒ Docker
constructor
A new instance of Docker.
- #pull! ⇒ Object
- #push! ⇒ Object
- #size ⇒ Object
- #tagged? ⇒ Boolean
- #untag! ⇒ Object
Constructor Details
#initialize(name:, project:, from: nil) ⇒ Docker
Returns a new instance of Docker.
10 11 12 13 14 |
# File 'lib/dapp/image/docker.rb', line 10 def initialize(name:, project:, from: nil) @from = from @name = name @project = project end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
6 7 8 |
# File 'lib/dapp/image/docker.rb', line 6 def from @from end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/dapp/image/docker.rb', line 7 def name @name end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
8 9 10 |
# File 'lib/dapp/image/docker.rb', line 8 def project @project end |
Class Method Details
.cache ⇒ Object
86 87 88 |
# File 'lib/dapp/image/docker.rb', line 86 def cache @cache ||= (@cache = {}).tap { cache_reset } end |
.cache_reset(name = '') ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/dapp/image/docker.rb', line 90 def cache_reset(name = '') cache.delete(name) Project.shellout!("docker images --format='{{.Repository}}:{{.Tag}};{{.ID}};{{.CreatedAt}};{{.Size}}' --no-trunc #{name}").stdout.lines.each do |l| name, id, created_at, size = l.split(';') cache[name] = { id: id, created_at: created_at, size: size } end end |
.image_config_option(image_id:, option:) ⇒ Object
55 56 57 58 |
# File 'lib/dapp/image/docker.rb', line 55 def self.image_config_option(image_id:, option:) output = Project.shellout!("docker inspect --format='{{json .Config.#{option.to_s.capitalize}}}' #{image_id}").stdout.strip output == 'null' ? [] : JSON.parse(output) end |
.image_name?(name) ⇒ Boolean
77 78 79 |
# File 'lib/dapp/image/docker.rb', line 77 def image_name?(name) !(/^#{image_name_format}$/ =~ name).nil? end |
.image_name_format ⇒ Object
71 72 73 74 75 |
# File 'lib/dapp/image/docker.rb', line 71 def image_name_format separator = '[_.]|__|[-]*' tag = "[[:alnum:]][[[:alnum:]]#{separator}]{0,127}" "#{DockerRegistry.repo_name_format}(:(?<tag>#{tag}))?" end |
Instance Method Details
#cache_reset ⇒ Object
60 61 62 |
# File 'lib/dapp/image/docker.rb', line 60 def cache_reset self.class.cache_reset(name) end |
#created_at ⇒ Object
45 46 47 48 |
# File 'lib/dapp/image/docker.rb', line 45 def created_at raise Error::Build, code: :image_not_exist, data: { name: name } unless tagged? cache[:created_at] end |
#id ⇒ Object
16 17 18 |
# File 'lib/dapp/image/docker.rb', line 16 def id cache[:id] end |
#pull! ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/dapp/image/docker.rb', line 33 def pull! return if tagged? project.log_secondary_process(project.t(code: 'process.image_pull', data: { name: name })) do project.shellout!("docker pull #{name}", log_verbose: true) end cache_reset end |
#push! ⇒ Object
26 27 28 29 30 31 |
# File 'lib/dapp/image/docker.rb', line 26 def push! raise Error::Build, code: :image_not_exist, data: { name: name } unless tagged? project.log_secondary_process(project.t(code: 'process.image_push', data: { name: name })) do project.shellout!("docker push #{name}", log_verbose: true) end end |
#size ⇒ Object
50 51 52 53 |
# File 'lib/dapp/image/docker.rb', line 50 def size raise Error::Build, code: :image_not_exist, data: { name: name } unless tagged? cache[:size] end |
#tagged? ⇒ Boolean
41 42 43 |
# File 'lib/dapp/image/docker.rb', line 41 def tagged? !!id end |