lib/percheron/container/actions/create.rb in percheron-0.4.0 vs lib/percheron/container/actions/create.rb in percheron-0.5.0
- old
+ new
@@ -1,40 +1,54 @@
module Percheron
module Container
module Actions
class Create
+ include Base
+
def initialize(container)
@container = container
end
def execute!
- unless image_exists?
- $logger.debug "Creating '#{container.image}' image"
- Container::Actions::Build.new(container).execute!
- end
-
- $logger.debug "Creating '#{container.name}' container"
- Docker::Container.create(create_opts)
+ build!
+ insert_post_start_scripts!
+ create!
end
private
attr_reader :container
def create_opts
{
'name' => container.name,
- 'Image' => container.image,
+ 'Image' => container.image_name,
'Hostname' => container.name,
'Env' => container.env,
'ExposedPorts' => container.exposed_ports,
'VolumesFrom' => container.volumes
}
end
- def image_exists?
- Docker::Image.exist?(container.image)
+ def build!
+ unless container.image
+ $logger.debug "Creating '#{container.image_name}' image"
+ Container::Actions::Build.new(container).execute!
+ end
+ end
+
+ def create!
+ $logger.debug "Creating '#{container.name}' container"
+ Docker::Container.create(create_opts)
+ end
+
+ def insert_post_start_scripts!
+ container.post_start_scripts.each do |script|
+ file = Pathname.new(File.expand_path(script, base_dir))
+ new_image = container.image.insert_local('localPath' => file.to_s, 'outputPath' => "/tmp/#{file.basename}")
+ new_image.tag(repo: container.name, tag: container.version.to_s, force: true)
+ end
end
end
end
end