lib/percheron/container/main.rb in percheron-0.3.1 vs lib/percheron/container/main.rb in percheron-0.3.2
- old
+ new
@@ -3,11 +3,11 @@
class Main
extend Forwardable
extend ConfigDelegator
- def_delegators :container_config, :name, :dockerfile_md5
+ def_delegators :container_config, :name
def_config_item_with_default :container_config, false, :auto_recreate
def_config_item_with_default :container_config, [], :env, :ports, :volumes, :dependant_container_names
alias_method :auto_recreate?, :auto_recreate
@@ -78,20 +78,22 @@
def create!
unless exists?
$logger.debug "Container '#{name}' does not exist, creating"
Container::Actions::Create.new(self).execute!
+ set_dockerfile_md5!
else
$logger.debug "Not creating '#{name}' container as it already exists"
end
end
def recreate!(bypass_auto_recreate: false)
if exists?
if recreate?(bypass_auto_recreate: bypass_auto_recreate)
$logger.warn "Container '#{name}' exists and will be recreated"
Container::Actions::Recreate.new(self).execute!
+ set_dockerfile_md5!
else
if recreatable?
$logger.warn "Container '#{name}' MD5's do not match, consider recreating"
else
$logger.debug "Container '#{name}' does not need to be recreated"
@@ -120,11 +122,11 @@
def valid?
Validators::Container.new(self).valid?
end
- protected
+ private
attr_reader :config, :stack, :container_name
def dockerfile_md5s_match?
stored_dockerfile_md5 == current_dockerfile_md5
@@ -138,9 +140,22 @@
info.Config.Image.split(':')[1]
end
def stored_dockerfile_md5
dockerfile_md5 || current_dockerfile_md5
+ end
+
+ def metastore_key
+ @metastore_key ||= 'stacks.%s.containers.%s' % [ stack.name, name ]
+ end
+
+ def dockerfile_md5
+ $metastore.get("#{metastore_key}.dockerfile_md5")
+ end
+
+ def set_dockerfile_md5!
+ $logger.debug "Setting MD5 for '#{name}' container to #{current_dockerfile_md5}"
+ $metastore.set("#{metastore_key}.dockerfile_md5", current_dockerfile_md5)
end
def current_dockerfile_md5
Digest::MD5.file(dockerfile).hexdigest
end