Sha256: d78a9b64b2b61d241c899c06f1a1b871b3fb647ae3e0eb4d63fe4dcf147354ab

Contents?: true

Size: 1.3 KB

Versions: 19

Compression:

Stored size: 1.3 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.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
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
rake_docker-2.18.0.pre.3 lib/rake_docker/tasks/prepare.rb
rake_docker-2.18.0.pre.2 lib/rake_docker/tasks/prepare.rb
rake_docker-2.18.0.pre.1 lib/rake_docker/tasks/prepare.rb
rake_docker-2.17.0 lib/rake_docker/tasks/prepare.rb
rake_docker-2.16.0.pre.1 lib/rake_docker/tasks/prepare.rb
rake_docker-2.15.0 lib/rake_docker/tasks/prepare.rb
rake_docker-2.14.0.pre.4 lib/rake_docker/tasks/prepare.rb
rake_docker-2.14.0.pre.3 lib/rake_docker/tasks/prepare.rb
rake_docker-2.14.0.pre.2 lib/rake_docker/tasks/prepare.rb
rake_docker-2.14.0.pre.1 lib/rake_docker/tasks/prepare.rb
rake_docker-2.13.0 lib/rake_docker/tasks/prepare.rb
rake_docker-2.12.0.pre.2 lib/rake_docker/tasks/prepare.rb
rake_docker-2.12.0.pre.1 lib/rake_docker/tasks/prepare.rb
rake_docker-2.11.0 lib/rake_docker/tasks/prepare.rb
rake_docker-2.10.0.pre.1 lib/rake_docker/tasks/prepare.rb
rake_docker-2.9.0 lib/rake_docker/tasks/prepare.rb
rake_docker-2.8.0.pre.1 lib/rake_docker/tasks/prepare.rb
rake_docker-2.7.0 lib/rake_docker/tasks/prepare.rb
rake_docker-2.6.0.pre.1 lib/rake_docker/tasks/prepare.rb