lib/percheron/container/main.rb in percheron-0.3.2 vs lib/percheron/container/main.rb in percheron-0.4.0
- old
+ new
@@ -6,11 +6,11 @@
extend ConfigDelegator
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
+ def_config_item_with_default :container_config, [], :env, :ports, :volumes, :dependant_container_names, :pre_build_scripts
alias_method :auto_recreate?, :auto_recreate
def initialize(config, stack, container_name)
@config = config
@@ -64,10 +64,11 @@
rescue Errors::ContainerNotRunning
$logger.debug "Container '#{name}' is not running"
end
def start!
+ start_dependant_containers!
create!
recreate!
Container::Actions::Start.new(self).execute!
end
@@ -84,13 +85,13 @@
else
$logger.debug "Not creating '#{name}' container as it already exists"
end
end
- def recreate!(bypass_auto_recreate: false)
+ def recreate!(force_recreate: false, force_auto_recreate: false)
if exists?
- if recreate?(bypass_auto_recreate: bypass_auto_recreate)
+ if recreate?(force_recreate: force_recreate, force_auto_recreate: force_auto_recreate)
$logger.warn "Container '#{name}' exists and will be recreated"
Container::Actions::Recreate.new(self).execute!
set_dockerfile_md5!
else
if recreatable?
@@ -106,12 +107,12 @@
def recreatable?
!dockerfile_md5s_match?
end
- def recreate?(bypass_auto_recreate: false)
- recreatable? && versions_mismatch? && (bypass_auto_recreate || auto_recreate?)
+ def recreate?(force_recreate: false, force_auto_recreate: false)
+ (force_recreate || (recreatable? && versions_mismatch?)) && (force_auto_recreate || auto_recreate?)
end
def running?
exists? && info.State.Running
end
@@ -165,9 +166,21 @@
Hashie::Mash.new(docker_container.info)
end
def container_config
@container_config ||= stack.container_configs[container_name] || Hashie::Mash.new({})
+ end
+
+ def dependant_containers
+ dependant_container_names.map { |container_name| stack.containers[container_name] }
+ end
+
+ def start_dependant_containers!
+ dependant_containers.each do |container|
+ next if container.running?
+ $logger.debug "Container '#{container.name}' being started as it's a dependancy"
+ container.start!
+ end
end
end
end
end