berkshelf_ext 1.0.6 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v1.0.8
2
+ * Add environment variable to allow loading all available extensions
3
+ * Add new addon extension fast_resolution to locate and use cached cookbooks faster
4
+
1
5
  ## v1.0.6
2
6
  * Add custom resolve to berksfile for dependency_chains to account for reverted changeset
3
7
 
data/README.md CHANGED
@@ -46,9 +46,20 @@ Addons are extensions that must be explicitly enabled via environment variable:
46
46
 
47
47
  * `BERKSHELF_EXT_ADDONS="knife_uploader"`
48
48
 
49
+ It is important to note that these addons will generally make use of Chef internals
50
+ to do things.
51
+
49
52
  ### Available addons
50
53
 
51
54
  * Knife based cookbook uploading (disables Ridley)[4]
55
+ * Faster dependency resolution via faster cached cookbook handling (fast_resolution)
56
+
57
+ ## Load all the things!
58
+
59
+ If you want to just load everything that is available without explicitly defining
60
+ all the addons, just set the everything env variable:
61
+
62
+ * `BERKSHELF_EXT_EVERYTHING="true"`
52
63
 
53
64
  # References
54
65
 
@@ -0,0 +1,48 @@
1
+ require 'chef'
2
+
3
+ module BerkshelfExt
4
+ module FastResolution
5
+ module CookbookStore
6
+
7
+ class << self
8
+ def included(klass)
9
+ klass.class_eval do
10
+ alias_method :non_fast_resolution_satisfy, :satisfy
11
+ alias_method :satisfy, :fast_resolution_satisfy
12
+ alias_method :non_fast_resolution_cookbooks, :cookbooks
13
+ alias_method :cookbooks, :fast_resolution_cookbooks
14
+ end
15
+ end
16
+ end
17
+
18
+ def fast_resolution_satisfy(name, constraint)
19
+ if(constraint.to_s.start_with?('='))
20
+ get_version = constraint.version
21
+ else
22
+ graph = Solve::Graph.new
23
+ cookbooks(name).each { |cookbook| graph.artifacts(name, cookbook.version) }
24
+ get_version = Solve.it!(graph, [[name, constraint]]).first.last
25
+ end
26
+ c = cookbooks(name).detect{|ckbk| ckbk.version.to_s == get_version.to_s }
27
+ ::Berkshelf::CachedCookbook.from_store_path(c.root_dir) if c
28
+ rescue Solve::Errors::NoSolutionError
29
+ nil
30
+ end
31
+
32
+ def fast_resolution_cookbooks(filter = nil)
33
+ [].tap do |cookbooks|
34
+ storage_path.each_child do |path|
35
+ loader = ::Chef::Cookbook::CookbookVersionLoader.new(path)
36
+ loader.load_cookbooks
37
+ cv = loader.cookbook_version
38
+ cb_name = cv.metadata.name.to_s.sub("-#{cv.version}", '')
39
+ next if filter && cb_name != filter
40
+ cookbooks << cv
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ Berkshelf::CookbookStore.send(:include, BerkshelfExt::FastResolution::CookbookStore)
@@ -1,17 +1,23 @@
1
1
  require 'berkshelf'
2
2
 
3
- Dir.glob(File.join(File.dirname(__FILE__), '*.rb')).each do |ext_file|
4
- if(ENV['BERKSHELF_EXT_EXCEPT'])
5
- next if ENV['BERKSHELF_EXT_EXCEPT'].split(',').include?(File.basename(ext_file).sub('.rb', ''))
3
+ if(ENV['BERKSHELF_EXT_EVERYTHING'].to_s.downcase == 'true')
4
+ Dir.glob(File.join(File.dirname(__FILE__), '**', '*.rb')).each do |ext_file|
5
+ require ext_file
6
6
  end
7
- if(ENV['BERKSHELF_EXT_ONLY'])
8
- next unless ENV['BERKSHELF_EXT_ONLY'].split(',').include?(File.basename(ext_file).sub('.rb', ''))
7
+ else
8
+ Dir.glob(File.join(File.dirname(__FILE__), '*.rb')).each do |ext_file|
9
+ if(ENV['BERKSHELF_EXT_EXCEPT'])
10
+ next if ENV['BERKSHELF_EXT_EXCEPT'].split(',').include?(File.basename(ext_file).sub('.rb', ''))
11
+ end
12
+ if(ENV['BERKSHELF_EXT_ONLY'])
13
+ next unless ENV['BERKSHELF_EXT_ONLY'].split(',').include?(File.basename(ext_file).sub('.rb', ''))
14
+ end
15
+ require ext_file
9
16
  end
10
- require ext_file
11
- end
12
17
 
13
- if(ENV['BERKSHELF_EXT_ADDONS'])
14
- ENV['BERKSHELF_EXT_ADDONS'].split(',').each do |addon|
15
- require "berkshelf_ext/addons/#{addon.strip}"
18
+ if(ENV['BERKSHELF_EXT_ADDONS'])
19
+ ENV['BERKSHELF_EXT_ADDONS'].split(',').each do |addon|
20
+ require "berkshelf_ext/addons/#{addon.strip}"
21
+ end
16
22
  end
17
23
  end
@@ -2,6 +2,6 @@ module BerkshelfExt
2
2
  class Version < Gem::Version
3
3
  end
4
4
 
5
- VERSION = Version.new('1.0.6')
5
+ VERSION = Version.new('1.0.8')
6
6
  BERKSHELF_CONSTRAINT = '~> 1.3.1'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -56,6 +56,7 @@ files:
56
56
  - lib/berkshelf_ext/version.rb
57
57
  - lib/berkshelf_ext/dependency_chains.rb
58
58
  - lib/berkshelf_ext/addons/knife_uploader.rb
59
+ - lib/berkshelf_ext/addons/fast_resolution.rb
59
60
  - lib/berkshelf_ext/non_recommends_depends.rb
60
61
  - lib/berkshelf_ext/berksfile_loader_context.rb
61
62
  - lib/berkshelf_ext.rb