Class: Kamaze::DockerImage
- Inherits:
-
Object
- Object
- Kamaze::DockerImage
- Includes:
- Concern::Executable, Concern::ReadableAttrs, Concern::Setup
- Defined in:
- lib/kamaze/docker_image.rb,
lib/kamaze/docker_image/version.rb
Overview
Describe a docker image
Defined Under Namespace
Modules: Concern Classes: Command, Loader, Runner, SSH
Constant Summary collapse
- VERSION =
Kamaze::Version.new.freeze
Instance Attribute Summary collapse
-
#commands ⇒ Hash
Get commands.
-
#docker_bin ⇒ String
Executable path or name for
docker. -
#exec_command ⇒ String
Get default command for
exec. -
#name ⇒ String
Get image name.
- #path ⇒ Pathname
-
#run_as ⇒ String
Get name used to run container.
- #runner ⇒ Runner readonly protected
-
#ssh ⇒ Hash|nil
Config related to ssh.
-
#tasks_load ⇒ Object
Returns the value of attribute tasks_load.
-
#tasks_ns ⇒ String|Symbol|nil
Get namespace used for tasks.
- #verbose ⇒ Object writeonly protected
-
#version ⇒ String
Get version.
Instance Method Summary collapse
-
#available_commands ⇒ Array<Symbol>
Get name of available commands.
- #called_from(locations = caller_locations) ⇒ Pathname included from Concern::Setup private
-
#default_commands ⇒ Hash
included
from Concern::Setup
protected
Get default commands.
-
#executable ⇒ String
included
from Concern::Executable
protected
Get executable.
-
#id ⇒ String?
Get image id (through docker command).
-
#initialize(&block) ⇒ DockerImage
constructor
A new instance of DockerImage.
- #method_missing(method, *args, &block) ⇒ Object
-
#readable_attrs ⇒ Array<Symbol>
included
from Concern::ReadableAttrs
Get readable attributes.
-
#readable_attrs_values ⇒ Array<Array>
included
from Concern::ReadableAttrs
protected
Get readable attributes with values.
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
-
#running? ⇒ Boolean
Denote image is running?.
-
#setup(locations, &block) ⇒ self
included
from Concern::Setup
protected
Setup.
-
#setup_attr(attr, val) ⇒ Object
included
from Concern::Setup
private
Set given attr with given value.
- #setup_block {|Config| ... } ⇒ Config included from Concern::Setup protected
-
#setup_defaults(locations) ⇒ self
included
from Concern::Setup
protected
Setup atttributes with default values.
-
#started? ⇒ Boolean
Denote image is started.
-
#tag ⇒ String
(also: #to_s)
Get tag.
-
#tasks_load! ⇒ Object
protected
Load tasks.
- #tasks_load? ⇒ Boolean
- #to_h ⇒ Hash
- #verbose? ⇒ Boolean
Constructor Details
#initialize(&block) ⇒ DockerImage
Returns a new instance of DockerImage.
84 85 86 87 88 89 90 |
# File 'lib/kamaze/docker_image.rb', line 84 def initialize(&block) setup(caller_locations, &block) @runner = Runner.new(self) @ssh = SSH.new(self).freeze tasks_load! if tasks_load? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
163 164 165 |
# File 'lib/kamaze/docker_image.rb', line 163 def method_missing(method, *args, &block) respond_to_missing?(method) ? runner.public_send(method, *args, &block) : super end |
Instance Attribute Details
#commands ⇒ Hash
Get commands
Commands as run by runner
26 27 28 |
# File 'lib/kamaze/docker_image.rb', line 26 def commands @commands end |
#docker_bin ⇒ String
Executable path or name for docker
56 57 58 |
# File 'lib/kamaze/docker_image.rb', line 56 def docker_bin @docker_bin end |
#exec_command ⇒ String
Get default command for exec
65 66 67 |
# File 'lib/kamaze/docker_image.rb', line 65 def exec_command @exec_command end |
#name ⇒ String
Get image name
31 32 33 |
# File 'lib/kamaze/docker_image.rb', line 31 def name @name end |
#path ⇒ Pathname
158 159 160 |
# File 'lib/kamaze/docker_image.rb', line 158 def path Pathname.new(@path) end |
#run_as ⇒ String
Get name used to run container
46 47 48 |
# File 'lib/kamaze/docker_image.rb', line 46 def run_as @run_as end |
#runner ⇒ Runner (readonly, protected)
217 218 219 |
# File 'lib/kamaze/docker_image.rb', line 217 def runner @runner end |
#ssh ⇒ Hash|nil
Config related to ssh.
51 52 53 |
# File 'lib/kamaze/docker_image.rb', line 51 def ssh @ssh end |
#tasks_load ⇒ Object
Returns the value of attribute tasks_load.
58 59 60 |
# File 'lib/kamaze/docker_image.rb', line 58 def tasks_load @tasks_load end |
#tasks_ns ⇒ String|Symbol|nil
Get namespace used for tasks
41 42 43 |
# File 'lib/kamaze/docker_image.rb', line 41 def tasks_ns @tasks_ns end |
#verbose=(value) ⇒ Object (writeonly, protected)
184 185 186 |
# File 'lib/kamaze/docker_image.rb', line 184 def verbose=(value) @verbose = value end |
#version ⇒ String
Get version
36 37 38 |
# File 'lib/kamaze/docker_image.rb', line 36 def version @version end |
Instance Method Details
#available_commands ⇒ Array<Symbol>
Get name of available commands.
125 126 127 |
# File 'lib/kamaze/docker_image.rb', line 125 def available_commands commands.clone.reject { |_k, args| args.nil? }.to_h.keys.sort end |
#called_from(locations = caller_locations) ⇒ Pathname (private) Originally defined in module Concern::Setup
#default_commands ⇒ Hash (protected) Originally defined in module Concern::Setup
Get default commands
#executable ⇒ String (protected) Originally defined in module Concern::Executable
Get executable
#id ⇒ String?
Get image id (through docker command).
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/kamaze/docker_image.rb', line 95 def id # docker image list --format "{{json .ID}}" image_name:image_version [ self.to_h[:docker_bin] || executable ].concat(['image', 'list', '--format', '{{json .ID}}', self.to_s]).yield_self do |command| Open3.capture3(*command).tap do |stdout, _, status| return nil unless status.success? return stdout.lines.empty? ? nil : JSON.parse(stdout.lines.first) end end end |
#readable_attrs ⇒ Array<Symbol> Originally defined in module Concern::ReadableAttrs
Get readable attributes
#readable_attrs_values ⇒ Array<Array> (protected) Originally defined in module Concern::ReadableAttrs
Get readable attributes with values
#respond_to_missing?(method, include_private = false) ⇒ Boolean
167 168 169 170 171 |
# File 'lib/kamaze/docker_image.rb', line 167 def respond_to_missing?(method, include_private = false) # rubocop:disable Style/RedundantParentheses (runner&.actions).to_a.include?(method.to_sym) || super(method, include_private) # rubocop:enable Style/RedundantParentheses end |
#running? ⇒ Boolean
Denote image is running?.
118 119 120 |
# File 'lib/kamaze/docker_image.rb', line 118 def running? runner.running? end |
#setup(locations, &block) ⇒ self (protected) Originally defined in module Concern::Setup
Setup
#setup_attr(attr, val) ⇒ Object (private) Originally defined in module Concern::Setup
Set given attr with given value
#setup_block {|Config| ... } ⇒ Config (protected) Originally defined in module Concern::Setup
#setup_defaults(locations) ⇒ self (protected) Originally defined in module Concern::Setup
Setup atttributes with default values
#started? ⇒ Boolean
Denote image is started.
111 112 113 |
# File 'lib/kamaze/docker_image.rb', line 111 def started? runner.started? end |
#tag ⇒ String Also known as: to_s
Get tag
tag has the following format: #{name}:#{version}
134 135 136 |
# File 'lib/kamaze/docker_image.rb', line 134 def tag "#{name}:#{version}" end |
#tasks_load! ⇒ Object (protected)
Load tasks
220 221 222 |
# File 'lib/kamaze/docker_image.rb', line 220 def tasks_load! self.tap { Loader.new(self).call } end |
#tasks_load? ⇒ Boolean
153 154 155 |
# File 'lib/kamaze/docker_image.rb', line 153 def tasks_load? !!self.tasks_load end |
#to_h ⇒ Hash
141 142 143 144 145 |
# File 'lib/kamaze/docker_image.rb', line 141 def to_h readable_attrs_values .to_h.tap { |h| h.merge!(tag: tag) } .sort.to_h end |
#verbose? ⇒ Boolean
148 149 150 |
# File 'lib/kamaze/docker_image.rb', line 148 def verbose? !!@verbose end |