require "rake" require "fileutils" require "dtc_rake/config" require "dtc_rake/product" require "dtc_rake/ui" require "dtc_rake/util" include DtcRake::UI product = DtcRake::Product.instance def build_dockerfiles(product) begin require "zip" rescue LoadError error "Gem rubyzip is not available. In order to use this task, you must: gem install rubyzip" end announce "Building Dockerfiles pack" output_dir = DtcRake::Config.instance.output_dir base_name = File.basename(product.dockerfiles_file_name, ".zip") tmp_dir = File.join(output_dir, base_name) FileUtils.rm_rf tmp_dir if File.directory? tmp_dir FileUtils.mkdir_p tmp_dir %w[ ../docker ].each do |dir| FileUtils.cp_r dir, tmp_dir end archive = File.join(output_dir, product.dockerfiles_file_name) info "Creating #{archive}" FileUtils.rm_f archive Zip::File.open(archive, "w") do |zip| Dir["#{tmp_dir}/**/**"].reject { |f| f == archive }.each do |file| zip.add(file.sub("#{tmp_dir}/", ""), file) end end FileUtils.rm_rf tmp_dir end if product.has_dockerfiles namespace :build do desc "Builds pack with Dockerfiles" task :dockerfiles do build_dockerfiles(product) end end end