Sha256: 055a90a3f15f4c9771dea5634539a5235245b5fd7726b7f833a52b1cba598dfe

Contents?: true

Size: 1.25 KB

Versions: 19

Compression:

Stored size: 1.25 KB

Contents

require 'rake_factory'

module RakeDocker
  module Tasks
    class Prepare < RakeFactory::Task
      default_name :prepare
      default_description RakeFactory::DynamicValue.new { |t|
        "Prepare for build of #{t.image_name} image"
      }

      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 = entry.is_a?(Hash) ? entry[:from] : entry
          to = entry.is_a?(Hash) ?
              File.join(image_directory, entry[:to]) :
              image_directory

          if File.directory?(from)
            FileUtils.mkdir_p to
            FileUtils.cp_r from, to
          else
            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
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
rake_docker-2.5.0 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.13 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.12 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.11 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.10 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.9 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.8 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.7 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.6 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.5 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.4 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.3 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.2 lib/rake_docker/tasks/prepare.rb
rake_docker-2.4.0.pre.1 lib/rake_docker/tasks/prepare.rb
rake_docker-2.3.0 lib/rake_docker/tasks/prepare.rb
rake_docker-2.2.0.pre.1 lib/rake_docker/tasks/prepare.rb
rake_docker-2.1.0 lib/rake_docker/tasks/prepare.rb
rake_docker-2.0.0.pre.2 lib/rake_docker/tasks/prepare.rb
rake_docker-1.4.0.pre.1 lib/rake_docker/tasks/prepare.rb