lib/percheron/actions/create.rb in percheron-0.6.3 vs lib/percheron/actions/create.rb in percheron-0.6.4
- old
+ new
@@ -8,16 +8,17 @@
@container = container
@recreate = recreate
end
def execute!(opts={})
+ results = []
if recreate? || !container.exists?
- create!(opts)
- container
+ results << create!(opts)
else
$logger.debug "Container '#{container.name}' already exists"
end
+ results.compact.empty? ? nil : container
end
private
attr_reader :container, :recreate
@@ -58,51 +59,38 @@
def recreate?
recreate
end
def create!(opts)
- $logger.debug "Container '#{container.name}' does not exist, creating"
- build_image!
+ build_image! unless container.image_exists?
insert_scripts!
create_container!(opts.fetch(:create, {}))
execute_post_create_scripts! unless container.post_create_scripts.empty?
set_dockerfile_md5!
end
def build_image!
- unless container.image_exists?
- $logger.info "Creating '#{container.image_name}' image"
- Build.new(container).execute!
- end
+ Build.new(container).execute!
end
- def set_dockerfile_md5!
- $logger.info "Setting MD5 for '#{container.name}' container to #{container.current_dockerfile_md5}"
- $metastore.set("#{container.metastore_key}.dockerfile_md5", container.current_dockerfile_md5)
+ def insert_scripts!
+ insert_files!(container.post_create_scripts)
+ insert_files!(container.post_start_scripts)
end
def create_container!(opts)
options = base_options.merge(host_config_options).merge(opts)
-
$logger.info "Creating '%s' container" % options['name']
Docker::Container.create(options)
end
- def insert_scripts!
- insert_post_create_scripts!
- insert_post_start_scripts!
- end
-
- def insert_post_create_scripts!
- insert_files!(container.post_create_scripts)
- end
-
- def insert_post_start_scripts!
- insert_files!(container.post_start_scripts)
- end
-
def execute_post_create_scripts!
Exec.new(container, container.dependant_containers.values, container.post_create_scripts, 'POST create').execute!
+ end
+
+ def set_dockerfile_md5!
+ $logger.info "Setting MD5 for '#{container.name}' container to #{container.current_dockerfile_md5}"
+ $metastore.set("#{container.metastore_key}.dockerfile_md5", container.current_dockerfile_md5)
end
end
end
end