lib/capistrano-chef-solo.rb in yyuu-capistrano-chef-solo-0.0.1 vs lib/capistrano-chef-solo.rb in yyuu-capistrano-chef-solo-0.0.2

- old
+ new

@@ -55,30 +55,45 @@ } task(:update) { update_cookbook update_config + update_attributes invoke } _cset(:chef_solo_cookbook_repository) { abort("chef_solo_cookbook_repository not set") } _cset(:chef_solo_cookbook_revision, 'HEAD') - task(:update_cookbook) { + _cset(:chef_solo_cookbooks_exclude, []) + task(:update_cookbook) { # TODO: refactor git = fetch(:chef_solo_git, 'git') tar = fetch(:chef_solo_tar, 'tar') copy_dir = Dir.mktmpdir() destination = File.join(copy_dir, 'cookbooks') filename = "#{destination}.tar.gz" remote_destination = File.join(chef_solo_path, 'cookbooks') remote_filename = File.join('/tmp', File.basename(filename)) + repository_cache = File.join(copy_dir, 'cached-copy') + if fetch(:chef_solo_cookbook_subdir, nil) + repository_cache_subdir = File.join(repository_cache, chef_solo_cookbook_subdir) + else + repository_cache_subdir = repository_cache + end + begin checkout = [] - checkout << "#{git} clone -q #{chef_solo_cookbook_repository} #{destination}" - checkout << "cd #{destination} && #{git} checkout -q -b deploy #{chef_solo_cookbook_revision}" + checkout << "#{git} clone -q #{chef_solo_cookbook_repository} #{repository_cache}" + checkout << "cd #{repository_cache} && #{git} checkout -q -b deploy #{chef_solo_cookbook_revision}" + if chef_solo_cookbooks_exclude.empty? + checkout << "cp -RPp #{repository_cache_subdir} #{destination}" + else + exclusions = chef_solo_cookbooks_exclude.map { |e| "--exclude=\"#{e}\"" }.join(' ') + checkout << "rsync -lrpt #{exclusions} #{repository_cache_subdir} #{destination}" + end run_locally(checkout.join(' && ')) copy = [] copy << "cd #{File.dirname(destination)} && #{tar} chzf #{filename} #{File.basename(destination)}" run_locally(copy.join(' && ')) @@ -94,13 +109,15 @@ (<<-EOS).gsub(/^\s*/, '') file_cache_path #{File.join(chef_solo_path, 'cache').dump} cookbook_path #{File.join(chef_solo_path, 'cookbooks').dump} EOS } - _cset(:chef_solo_attributes, {}) task(:update_config) { put(chef_solo_config, File.join(chef_solo_path, 'config', 'solo.rb')) + } + _cset(:chef_solo_attributes, {}) + task(:update_attributes) { attributes = chef_solo_attributes.merge('run_list' => fetch(:chef_solo_run_list, [])) put(attributes.to_json, File.join(chef_solo_path, 'config', 'solo.json')) } task(:invoke) {