Class: Batali::Command::Install

Inherits:
Batali::Command show all
Defined in:
lib/batali/command/install.rb

Overview

Install cookbooks based on manifest

Constant Summary

Constants inherited from Batali::Command

DEFAULT_CONFIGURATION_FILES

Instance Method Summary collapse

Methods inherited from Batali::Command

#batali_file, #cache_directory, #dry_run, #infrastructure?, #initialize, #manifest

Constructor Details

This class inherits a constructor from Batali::Command

Instance Method Details

#execute!Object

Install cookbooks



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/batali/command/install.rb', line 11

def execute!
  dry_run('Cookbook installation') do
    install_path = config.fetch(:path, 'cookbooks')
    run_action('Readying installation destination') do
      FileUtils.rm_rf(install_path)
      FileUtils.mkdir_p(install_path)
      nil
    end
    if(manifest.cookbook.nil? || manifest.cookbook.empty?)
      ui.error "No cookbooks defined within manifest! Try resolving first. (`batali resolve`)"
    else
      run_action('Installing cookbooks') do
        manifest.cookbook.each do |unit|
          if(unit.source.respond_to?(:cache))
            unit.source.cache = cache_directory(
              Bogo::Utility.snake(unit.source.class.name.split('::').last)
            )
          end
          asset_path = unit.source.asset
          final_path = File.join(install_path, unit.name)
          if(infrastructure?)
            final_path << "-#{unit.version}"
          end
          begin
            FileUtils.cp_r(
              File.join(asset_path, '.'),
              final_path
            )
          ensure
            unit.source.clean_asset(asset_path)
          end
        end
        nil
      end
    end
  end
end