class Percheron::Unit
Attributes
config[R]
stack[R]
unit_config[R]
unit_name[R]
Public Class Methods
new(config, stack, unit_name)
click to toggle source
# File lib/percheron/unit.rb, line 15 def initialize(config, stack, unit_name) @config = config @stack = stack @unit_name = unit_name @unit_config = stack.unit_configs[unit_name] || Hashie::Mash.new({}) # FIXME self end
Public Instance Methods
buildable?()
click to toggle source
# File lib/percheron/unit.rb, line 136 def buildable? !dockerfile.nil? && unit_config.docker_image.nil? end
built_version()
click to toggle source
# File lib/percheron/unit.rb, line 83 def built_version @built_version ||= Semantic::Version.new(built_image_version) end
container()
click to toggle source
# File lib/percheron/unit.rb, line 95 def container Connection.perform(Docker::Container, :get, full_name) rescue Docker::Error::NotFoundError, Excon::Errors::SocketError NullUnit.new end
display_name()
click to toggle source
# File lib/percheron/unit.rb, line 65 def display_name '%s:%s' % [ stack.name, name ] end
dockerfile()
click to toggle source
# File lib/percheron/unit.rb, line 109 def dockerfile return nil unless unit_config.dockerfile Pathname.new(File.expand_path(unit_config.dockerfile, config.file_base_path)) end
dockerfile_md5s_match?()
click to toggle source
# File lib/percheron/unit.rb, line 120 def dockerfile_md5s_match? dockerfile_md5 == current_dockerfile_md5 end
exists?()
click to toggle source
# File lib/percheron/unit.rb, line 132 def exists? !info.empty? end
exposed_ports()
click to toggle source
# File lib/percheron/unit.rb, line 87 def exposed_ports ports.each_with_object({}) { |p, all| all[p.split(':')[1]] = {} } end
full_name()
click to toggle source
# File lib/percheron/unit.rb, line 61 def full_name '%s_%s' % [ stack.name, name ] end
hostname()
click to toggle source
# File lib/percheron/unit.rb, line 45 def hostname unit_config.fetch('hostname', full_name) end
id()
click to toggle source
# File lib/percheron/unit.rb, line 41 def id exists? ? info.id[0...12] : nil end
image()
click to toggle source
# File lib/percheron/unit.rb, line 73 def image Connection.perform(Docker::Image, :get, image_name) rescue Docker::Error::NotFoundError nil end
ip()
click to toggle source
# File lib/percheron/unit.rb, line 105 def ip exists? ? info.NetworkSettings.IPAddress : 'n/a' end
labels()
click to toggle source
# File lib/percheron/unit.rb, line 101 def labels { version: version.to_s, created_by: "Percheron #{Percheron::VERSION}" } end
links()
click to toggle source
# File lib/percheron/unit.rb, line 91 def links startable_needed_units.map { |_, unit| '%s:%s' % [ unit.full_name, unit.full_name ] } end
metastore_key()
click to toggle source
# File lib/percheron/unit.rb, line 37 def metastore_key @metastore_key ||= '%s.units.%s' % [ stack.metastore_key, name ] end
needed_unit_names()
click to toggle source
# File lib/percheron/unit.rb, line 23 def needed_unit_names unit_config.fetch('needed_unit_names', unit_config.fetch('dependant_unit_names', [])) end
needed_units()
click to toggle source
# File lib/percheron/unit.rb, line 27 def needed_units needed_unit_names.each_with_object({}) do |unit_name, all| all[unit_name] = stack.units[unit_name] end end
privileged()
click to toggle source
# File lib/percheron/unit.rb, line 57 def privileged unit_config.fetch('privileged', false) end
pseudo?()
click to toggle source
# File lib/percheron/unit.rb, line 144 def pseudo? !pseudo_name.nil? end
pseudo_full_name()
click to toggle source
# File lib/percheron/unit.rb, line 69 def pseudo_full_name '%s_%s' % [ stack.name, pseudo_name ] end
restart_policy()
click to toggle source
# File lib/percheron/unit.rb, line 49 def restart_policy @restart_policy ||= begin name = unit_config.fetch('restart_policy', 'always') max_retry_count = unit_config.fetch('restart_policy_retry_count', 0) { 'Name' => name, 'MaximumRetryCount' => max_retry_count } end end
running?()
click to toggle source
# File lib/percheron/unit.rb, line 128 def running? exists? && info.State.Running end
startable_needed_units()
click to toggle source
# File lib/percheron/unit.rb, line 33 def startable_needed_units needed_units.select { |_, unit| unit.startable? } end
update_dockerfile_md5!()
click to toggle source
# File lib/percheron/unit.rb, line 114 def update_dockerfile_md5! md5 = current_dockerfile_md5 $logger.debug "Setting MD5 for '#{name}' unit to #{md5}" $metastore.set("#{metastore_key}.dockerfile_md5", md5) end
valid?()
click to toggle source
# File lib/percheron/unit.rb, line 140 def valid? Validators::Unit.new(self).valid? end
version()
click to toggle source
# File lib/percheron/unit.rb, line 79 def version @version ||= Semantic::Version.new(unit_config.version) end
versions_match?()
click to toggle source
# File lib/percheron/unit.rb, line 124 def versions_match? version == built_version end
Private Instance Methods
built_image_version()
click to toggle source
# File lib/percheron/unit.rb, line 162 def built_image_version (exists? && info.Config.Labels) ? info.Config.Labels.version : '0.0.0' end
current_dockerfile_md5()
click to toggle source
# File lib/percheron/unit.rb, line 154 def current_dockerfile_md5 dockerfile ? Digest::MD5.file(dockerfile).hexdigest : Digest::MD5.hexdigest(image_name) end
dockerfile_md5()
click to toggle source
# File lib/percheron/unit.rb, line 158 def dockerfile_md5 $metastore.get("#{metastore_key}.dockerfile_md5") || current_dockerfile_md5 end
info()
click to toggle source
# File lib/percheron/unit.rb, line 166 def info Hashie::Mash.new(container.info) end