class Dapp::Dimg::Image::Stage
Attributes
dapp[R]
from[R]
name[R]
Public Class Methods
image_by_name(name:, **kwargs)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 12 def image_by_name(name:, **kwargs) images[name] ||= new(name: name, **kwargs) end
image_name?(name)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 32 def image_name?(name) !(/^#{image_name_format}$/ =~ name).nil? end
image_name_format()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 24 def image_name_format "#{DockerRegistry.repo_name_format}(:(?<tag>#{tag_format}))?" end
image_reset(name)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 16 def image_reset(name) images.delete(name) end
images()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 20 def images @images ||= {} end
load!(dapp, file_path, verbose: false, quiet: false)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 44 def load!(dapp, file_path, verbose: false, quiet: false) ruby2go_command(dapp, command: :load, options: { file_path: file_path }) end
new(name:, dapp:, built_id: nil, from: nil)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 57 def initialize(name:, dapp:, built_id: nil, from: nil) @built_id = built_id @bash_commands = [] @service_bash_commands = [] @options = {} @change_options = {} @service_change_options = {} @from = from @name = name @dapp = dapp end
ruby2go_command(dapp, command:, **options)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 48 def ruby2go_command(dapp, command:, **options) (options[:options] ||= {}).merge!(host_docker_config_dir: dapp.class.host_docker_config_dir) dapp.ruby2go_image({ command: command }.merge(options)).tap do |res| raise Error::Build, code: :ruby2go_image_command_failed_unexpected_error, data: { command: command, message: res["error"] } unless res["error"].nil? break res['data'] end end
save!(dapp, image_or_images, file_path, verbose: false, quiet: false)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 40 def save!(dapp, image_or_images, file_path, verbose: false, quiet: false) ruby2go_command(dapp, command: :save, options: { images: Array(image_or_images), file_path: file_path }) end
tag?(name)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 36 def tag?(name) !(/^#{tag_format}$/ =~ name).nil? end
tag_format()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 28 def tag_format '(?![-.])[a-zA-Z0-9_.-]{1,127}' end
Public Instance Methods
build!()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 128 def build! res = self.dapp.ruby2go_image(**ruby2go_image_build_options) if res["error"].nil? set_ruby2go_state_hash(JSON.load(res['data']['image'])) elsif res["error"].start_with? "container run failed" raise Error::Build, code: :ruby2go_image_command_failed, data: { command: "build" } else raise Error::Build, code: :ruby2go_image_command_failed_unexpected_error, data: { command: "build", message: res["error"] } end end
built?()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 75 def built? !built_id.nil? end
built_id()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 79 def built_id @built_id ||= id end
built_image_inspect()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 103 def built_image_inspect @built_image_inspect || image_inspect end
built_image_inspect!()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 99 def built_image_inspect! built_image_inspect end
created_at()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 91 def created_at built_image_inspect!["Created"] end
export!(name)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 157 def export!(name) ruby2go_command(:export, options: { name: name }) end
get_ruby2go_short_state_hash()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 232 def get_ruby2go_short_state_hash [ :name, :bash_commands, :service_bash_commands, :options, :change_options, :service_change_options, ].map do |name| [name, send(name)] end .compact .to_h end
get_ruby2go_state_hash()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 207 def get_ruby2go_state_hash [ :name, :from, :built_id, :built_image_inspect, :image_inspect, :bash_commands, :service_bash_commands, :options, :change_options, :service_change_options, ].map do |name| if name == :from [name, from.get_ruby2go_state_hash] unless from.nil? elsif name == :built_image_inspect && built_image_inspect.empty? elsif name == :image_inspect && image_inspect.empty? else [name, send(name)] end end .compact .to_h end
id()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 83 def id image_inspect["Id"] end
image_inspect()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 111 def image_inspect ruby2go_command(:inspect, short_image_option: true) if @image_inspect.nil? @image_inspect end
import!(name)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 165 def import!(name) ruby2go_command(:import, options: { name: name }) end
introspect!()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 153 def introspect! ruby2go_command(:introspect) end
labels()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 87 def labels built_image_inspect!.fetch('Config', {}).fetch('Labels', {}) || {} end
pull!()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 116 def pull! dapp.log_secondary_process(dapp.t(code: 'process.image_pull', data: { name: name })) do ruby2go_command(:pull) end end
push!()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 122 def push! dapp.log_secondary_process(dapp.t(code: 'process.image_push', data: { name: name })) do ruby2go_command(:push) end end
reset_image_inspect()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 107 def reset_image_inspect @image_inspect = nil end
ruby2go_command(command, short_image_option: false, options: {})
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 177 def ruby2go_command(command, short_image_option: false, options: {}) command_options = ruby2go_command_options(command, short_image_option: short_image_option).in_depth_merge(options: options) self.class.ruby2go_command(dapp, **command_options).tap do |data| set_ruby2go_state_hash(JSON.load(data['image'])) end end
ruby2go_command_options(command, short_image_option: false)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 184 def ruby2go_command_options(command, short_image_option: false) image = begin if short_image_option ruby2go_short_image_option else ruby2go_image_option end end { image: image, command: command, } end
ruby2go_image_build_options()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 139 def ruby2go_image_build_options { image: ruby2go_image_option, command: :build, options: { introspection: { before: dapp.introspect_before_error?, after: dapp.introspect_error? }, host_docker_config_dir: dapp.class.host_docker_config_dir, } } end
ruby2go_image_option()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 199 def ruby2go_image_option JSON.dump(get_ruby2go_state_hash) end
ruby2go_short_image_option()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 203 def ruby2go_short_image_option JSON.dump(get_ruby2go_short_state_hash) end
save_in_cache!()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 169 def save_in_cache! ruby2go_command(:save_in_cache) end
set_ruby2go_state_hash(state_hash)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 247 def set_ruby2go_state_hash(state_hash) state_hash.each do |name, value| variable = "@#{name}".to_sym case name when "from" from.set_ruby2go_state_hash(value) unless from.nil? || value.nil? when "built_id" if value.to_s.empty? @built_id = nil else @built_id = value end when "image_inspect" instance_variable_set(variable, (value || {})) when "options", "change_options", "service_change_options" instance_variable_set(variable, (value || {}).reject { |_, v| v.nil? || v.empty? }.symbolize_keys) when "bash_commands", "service_bash_commands" instance_variable_set(variable, value || []) else instance_variable_set(variable, value) end end end
size()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 95 def size Float(built_image_inspect!["Size"]) end
tag!(name)
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 161 def tag!(name) ruby2go_command(:tag, options: { name: name }) end
tagged?()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 71 def tagged? not image_inspect.empty? end
untag!()
click to toggle source
# File lib/dapp/dimg/image/stage.rb, line 173 def untag! ruby2go_command(:untag) end