Class: Kamaze::DockerImage::Runner
- Inherits:
-
Object
- Object
- Kamaze::DockerImage::Runner
- Includes:
- Concern::Containers
- Defined in:
- lib/kamaze/docker_image/runner.rb
Overview
Runner provide methods to execute image related actions
Defined Under Namespace
Classes: Storage
Constant Summary collapse
- Command =
noinspection RubyConstantNamingConvention
Kamaze::DockerImage::Command
- ACTIONS =
Available actions
Actions registrable on
image. %i[restart start stop exec run build push rm rebuild].sort
Instance Attribute Summary collapse
-
#commands ⇒ Hash
readonly
protected
Get commands.
- #config ⇒ Hash readonly protected
Instance Method Summary collapse
- #actions ⇒ Array<Symbol>
-
#build(&block) ⇒ Object
Build image.
-
#command(name, extra = nil) ⇒ Command
protected
Generate command.
-
#containers(all: true) ⇒ Hash{String => Hash}
included
from Concern::Containers
protected
List containers.
-
#containers_maker ⇒ Proc
included
from Concern::Containers
protected
private
Add some methods on retrieved info.
- #exec(extra = nil, &block) ⇒ Object
-
#executable ⇒ String
included
from Concern::Executable
protected
Get executable.
-
#initialize(image) ⇒ Runner
constructor
A new instance of Runner.
-
#push(&block) ⇒ Object
Push image.
-
#rebuild(&block) ⇒ Object
Build image (do not use cache).
- #restart(&block) ⇒ Object
- #rm(&block) ⇒ Object
- #run(extra = nil, &block) ⇒ Object
-
#running? ⇒ Boolean
Denote container is running.
- #start(&block) ⇒ Object
-
#started? ⇒ Boolean
Denote container is started.
- #stop(&block) ⇒ Object
Constructor Details
#initialize(image) ⇒ Runner
Returns a new instance of Runner.
32 33 34 35 36 37 38 39 |
# File 'lib/kamaze/docker_image/runner.rb', line 32 def initialize(image) @config = image.to_h.reject! { |k| k == :commands }.freeze @commands = Storage[image.commands].tap do |store| store.config = @config end @commands.freeze end |
Instance Attribute Details
#commands ⇒ Hash (readonly, protected)
Get commands
114 115 116 |
# File 'lib/kamaze/docker_image/runner.rb', line 114 def commands @commands end |
#config ⇒ Hash (readonly, protected)
109 110 111 |
# File 'lib/kamaze/docker_image/runner.rb', line 109 def config @config end |
Instance Method Details
#actions ⇒ Array<Symbol>
86 87 88 |
# File 'lib/kamaze/docker_image/runner.rb', line 86 def actions ACTIONS end |
#build(&block) ⇒ Object
Build image
42 43 44 |
# File 'lib/kamaze/docker_image/runner.rb', line 42 def build(&block) command(:build).run(&block) end |
#command(name, extra = nil) ⇒ Command (protected)
Generate command.
121 122 123 124 125 |
# File 'lib/kamaze/docker_image/runner.rb', line 121 def command(name, extra = nil) command = commands.fetch(name.to_sym) Command.new(command, config, extra) end |
#containers(all: true) ⇒ Hash{String => Hash} (protected) Originally defined in module Concern::Containers
List containers.
Containers are indexed by name.
#containers_maker ⇒ Proc (protected) Originally defined in module Concern::Containers
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add some methods on retrieved info.
#exec(extra = nil, &block) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/kamaze/docker_image/runner.rb', line 60 def exec(extra = nil, &block) default = config.fetch(:exec_command) extra ||= default command(:exec, extra).run(&block) end |
#executable ⇒ String (protected) Originally defined in module Concern::Executable
Get executable
#push(&block) ⇒ Object
Push image
47 48 49 |
# File 'lib/kamaze/docker_image/runner.rb', line 47 def push(&block) command(:push).run(&block) end |
#rebuild(&block) ⇒ Object
Build image (do not use cache)
52 53 54 |
# File 'lib/kamaze/docker_image/runner.rb', line 52 def rebuild(&block) command(:rebuild).run(&block) end |
#restart(&block) ⇒ Object
79 80 81 82 83 |
# File 'lib/kamaze/docker_image/runner.rb', line 79 def restart(&block) stop(&block) rm(&block) start(&block) end |
#rm(&block) ⇒ Object
75 76 77 |
# File 'lib/kamaze/docker_image/runner.rb', line 75 def rm(&block) command(:rm).run(&block) if started? end |
#run(extra = nil, &block) ⇒ Object
56 57 58 |
# File 'lib/kamaze/docker_image/runner.rb', line 56 def run(extra = nil, &block) command(:run, extra).run(&block) end |
#running? ⇒ Boolean
Denote container is running.
101 102 103 104 |
# File 'lib/kamaze/docker_image/runner.rb', line 101 def running? # !fetch_containers(config.fetch(:run_as), :running).empty? config.fetch(:run_as).yield_self { |name| containers[name]&.running? } end |
#start(&block) ⇒ Object
67 68 69 |
# File 'lib/kamaze/docker_image/runner.rb', line 67 def start(&block) command(:start).run(&block) unless running? end |
#started? ⇒ Boolean
Denote container is started.
93 94 95 96 |
# File 'lib/kamaze/docker_image/runner.rb', line 93 def started? # !fetch_containers(config.fetch(:run_as)).empty? config.fetch(:run_as).yield_self { |name| !containers[name].nil? } end |
#stop(&block) ⇒ Object
71 72 73 |
# File 'lib/kamaze/docker_image/runner.rb', line 71 def stop(&block) command(:stop).run(&block) if started? end |