Skip to content
This repository was archived by the owner on Jul 14, 2021. It is now read-only.

Commit ec9c964

Browse files
onlyhavecansdanielsdeleo
authored andcommitted
Use Chef::Cookbook::ChefIgnore in policyfile export
This could maybe be a bit more in depth. The way I did it automatically excludes all dotfiles and only really checks the base level directories. I'm not sure if we need to get any more in depth in the chefignore here. Fixes #519
1 parent a96e5a1 commit ec9c964

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/chef-dk/policyfile_services/export_repo.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
require 'archive/tar/minitar'
2323

24+
require 'chef/cookbook/chefignore'
25+
2426
require 'chef-dk/service_exceptions'
2527
require 'chef-dk/policyfile_lock'
2628
require 'chef-dk/policyfile/storage_config'
@@ -152,7 +154,8 @@ def copy_cookbook(lock)
152154
dirname = "#{lock.name}-#{lock.dotted_decimal_identifier}"
153155
export_path = File.join(staging_dir, "cookbooks", dirname)
154156
metadata_rb_path = File.join(export_path, "metadata.rb")
155-
FileUtils.cp_r(lock.cookbook_path, export_path)
157+
FileUtils.mkdir(export_path) if not File.directory?(export_path)
158+
FileUtils.cp_r(cookbook_files_to_copy(lock.cookbook_path), export_path)
156159
FileUtils.rm_f(metadata_rb_path)
157160
metadata = lock.cookbook_version.metadata
158161
metadata.version(lock.dotted_decimal_identifier)
@@ -164,6 +167,13 @@ def copy_cookbook(lock)
164167
end
165168
end
166169

170+
def cookbook_files_to_copy(cookbook_path)
171+
chefignore_file = File.join(cookbook_path, 'chefignore')
172+
chefignore = Chef::Cookbook::Chefignore.new(chefignore_file)
173+
Dir.glob(File.join(cookbook_path, '*')).
174+
reject{ |f| chefignore.ignored?(File.basename(f)) }
175+
end
176+
167177
def create_policyfile_data_item
168178
lock_data = policyfile_lock.to_lock.dup
169179

0 commit comments

Comments
 (0)