class Kamaze::DockerImage

Describe a docker image

Constants

VERSION

Attributes

commands[RW]

Get commands

Commands as run by runner

@see Kamaze::DockerImage::Runner#command @see Kamaze::DockerImage::Concern::Setup#default_commands

@return [Hash]

docker_bin[RW]

Executable path or name for “docker“

@return [String]

exec_command[RW]

Get default command for “exec“

@see Runner#exec

@return [String]

name[RW]

Get image name

@return [String]

path[W]

@see Concern::Setup#setup_defaults @type [String]

run_as[RW]

Get name used to run container

@return [String]

runner[R]

@return [Runner]

ssh[RW]

Config related to ssh.

@return [Hash|nil]

tasks_load[RW]
tasks_ns[RW]

Get namespace used for tasks

@return [String|Symbol|nil]

verbose[W]

@see Concern::Setup#setup_defaults @type [Boolean]

version[RW]

Get version

@return [String]

Public Class Methods

new(&block) click to toggle source
# 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

Public Instance Methods

available_commands() click to toggle source

Get name of available commands.

@return [Array<Symbol>]

# File lib/kamaze/docker_image.rb, line 125
def available_commands
  commands.clone.reject { |_k, args| args.nil? }.to_h.keys.sort
end
id() click to toggle source

Get image id (through docker command).

@return [String, nil]

# 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
method_missing(method, *args, &block) click to toggle source

@see Runner#actions

Calls superclass method
# 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
path() click to toggle source

@return [Pathname]

# File lib/kamaze/docker_image.rb, line 158
def path
  Pathname.new(@path)
end
respond_to_missing?(method, include_private = false) click to toggle source
Calls superclass method
# 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?() click to toggle source

Denote image is running?.

@return [Boolean]

# File lib/kamaze/docker_image.rb, line 118
def running?
  runner.running?
end
started?() click to toggle source

Denote image is started.

@return [Boolean]

# File lib/kamaze/docker_image.rb, line 111
def started?
  runner.started?
end
tag() click to toggle source

Get tag

tag has the following format: “#{name}:#{version}“

@return [String]

# File lib/kamaze/docker_image.rb, line 134
def tag
  "#{name}:#{version}"
end
Also aliased as: to_s
tasks_load?() click to toggle source

@return [Boolean]

# File lib/kamaze/docker_image.rb, line 153
def tasks_load?
  !!self.tasks_load
end
to_h() click to toggle source

@return [Hash]

# 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
to_s()
Alias for: tag
verbose?() click to toggle source

@return [Boolean]

# File lib/kamaze/docker_image.rb, line 148
def verbose?
  !!@verbose
end

Protected Instance Methods

tasks_load!() click to toggle source

Load tasks

# File lib/kamaze/docker_image.rb, line 220
def tasks_load!
  self.tap { Loader.new(self).call }
end