Sha256: 8db55fda64d2c2cfdc65ce1da5dfa052c82e5e663e535027c6ca829ab1e5a503
Contents?: true
Size: 1.5 KB
Versions: 16
Compression:
Stored size: 1.5 KB
Contents
# frozen_string_literal: true require 'rake_factory' module RakeDocker module Tasks class Prepare < RakeFactory::Task default_name :prepare default_description(RakeFactory::DynamicValue.new do |t| "Prepare for build of #{t.image_name} image" end) parameter :image_name, required: true parameter :work_directory, required: true parameter :copy_spec, default: [] parameter :create_spec, default: [] action do |t| image_directory = File.join(t.work_directory, t.image_name) FileUtils.mkdir_p image_directory t.copy_spec.each do |entry| from = resolve_from(entry) to = resolve_to(entry, image_directory) if File.directory?(from) FileUtils.mkdir_p(to) FileUtils.cp_r(from, to) else FileUtils.mkdir_p(File.dirname(to)) FileUtils.cp(from, to) end end t.create_spec.each do |entry| content = entry[:content] to = entry[:to] file = File.join(image_directory, to) FileUtils.mkdir_p(File.dirname(file)) File.open(file, 'w') do |f| f.write(content) end end end def resolve_from(entry) entry.is_a?(Hash) ? entry[:from] : entry end def resolve_to(entry, image_directory) if entry.is_a?(Hash) File.join(image_directory, entry[:to]) else image_directory end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems