class Kamaze::DockerImage::Runner
Runner
provide methods to execute image related actions
@see actions
@see Kamaze::DockerImage::Concern::Setup#default_commands
Constants
- ACTIONS
Available actions
Actions registrable on “image“. @see
Runner#actions
- Command
Describe a command
Command
is able to run itself.
Attributes
commands[R]
Get commands
@return [Hash]
config[R]
@return [Hash]
Public Class Methods
new(image)
click to toggle source
@param [Kamaze::DockerImage] image
@see Kamaze::DockerImage::Concern::Setup#default_commands
# 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
Public Instance Methods
actions()
click to toggle source
@return [Array<Symbol>]
# File lib/kamaze/docker_image/runner.rb, line 86 def actions ACTIONS end
build(&block)
click to toggle source
Build image
# File lib/kamaze/docker_image/runner.rb, line 42 def build(&block) command(:build).run(&block) end
exec(extra = nil, &block)
click to toggle source
# 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
push(&block)
click to toggle source
Push image
# File lib/kamaze/docker_image/runner.rb, line 47 def push(&block) command(:push).run(&block) end
rebuild(&block)
click to toggle source
Build image (do not use cache)
# File lib/kamaze/docker_image/runner.rb, line 52 def rebuild(&block) command(:rebuild).run(&block) end
restart(&block)
click to toggle source
# File lib/kamaze/docker_image/runner.rb, line 79 def restart(&block) stop(&block) rm(&block) start(&block) end
rm(&block)
click to toggle source
# File lib/kamaze/docker_image/runner.rb, line 75 def rm(&block) command(:rm).run(&block) if started? end
run(extra = nil, &block)
click to toggle source
# File lib/kamaze/docker_image/runner.rb, line 56 def run(extra = nil, &block) command(:run, extra).run(&block) end
running?()
click to toggle source
Denote container is running.
@return [Boolean]
# 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)
click to toggle source
# File lib/kamaze/docker_image/runner.rb, line 67 def start(&block) command(:start).run(&block) unless running? end
started?()
click to toggle source
Denote container is started.
@return [Boolean]
# 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)
click to toggle source
# File lib/kamaze/docker_image/runner.rb, line 71 def stop(&block) command(:stop).run(&block) if started? end
Protected Instance Methods
command(name, extra = nil)
click to toggle source
Generate command.
@param [String|Symbol] name @param [String|nil] extra @return [Command]
# 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