knife-spork 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.2.2 (10th Sept, 2013)
2
+
3
+ Bugfixes:
4
+
5
+ - Fix bug with promoting when environment groups are present (thanks to Jimmy Chao & Nik Keating - https://github.com/CaseCommonsDevOps)
6
+
1
7
  ## 1.2.1 (28th June, 2013)
2
8
 
3
9
  Bugfixes:
data/knife-spork.gemspec CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'knife-spork'
5
- gem.version = '1.2.1'
5
+ gem.version = '1.2.2'
6
6
  gem.authors = ["Jon Cowie"]
7
7
  gem.email = 'jonlives@gmail.com'
8
8
  gem.homepage = 'https://github.com/jonlives/knife-spork'
@@ -26,7 +26,7 @@ module KnifeSpork
26
26
  if defined?(::Berkshelf)
27
27
  option :berksfile,
28
28
  :short => '-b',
29
- :long => 'berksfile',
29
+ :long => '--berksfile BERKSFILE',
30
30
  :description => 'Path to a Berksfile to operate off of',
31
31
  :default => File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME)
32
32
  end
@@ -11,8 +11,8 @@ module KnifeSpork
11
11
  git_pull(environment_path) unless cookbook_path.include?(environment_path.gsub"/environments","")
12
12
  git_pull_submodules(environment_path) unless cookbook_path.include?(environment_path.gsub"/environments","")
13
13
  cookbooks.each do |cookbook|
14
- git_pull(cookbook.root_dir)
15
- git_pull_submodules(cookbook.root_dir)
14
+ git_pull(cookbook_path_for(cookbook))
15
+ git_pull_submodules(cookbook_path_for(cookbook))
16
16
  end
17
17
  end
18
18
 
@@ -20,23 +20,23 @@ module KnifeSpork
20
20
  git_pull(environment_path) unless cookbook_path.include?(environment_path.gsub"/environments","")
21
21
  git_pull_submodules(environment_path) unless cookbook_path.include?(environment_path.gsub"/environments","")
22
22
  cookbooks.each do |cookbook|
23
- git_pull(cookbook.root_dir)
24
- git_pull_submodules(cookbook.root_dir)
23
+ git_pull(cookbook_path_for(cookbook))
24
+ git_pull_submodules(cookbook_path_for(cookbook))
25
25
  end
26
26
  end
27
27
 
28
28
  def before_promote
29
29
  cookbooks.each do |cookbook|
30
- git_pull(environment_path) unless cookbook.root_dir.include?(environment_path.gsub"/environments","")
31
- git_pull_submodules(environment_path) unless cookbook.root_dir.include?(environment_path.gsub"/environments","")
32
- git_pull(cookbook.root_dir)
33
- git_pull_submodules(cookbook.root_dir)
30
+ git_pull(environment_path) unless cookbook_path_for(cookbook).include?(environment_path.gsub"/environments","")
31
+ git_pull_submodules(environment_path) unless cookbook_path_for(cookbook).include?(environment_path.gsub"/environments","")
32
+ git_pull(cookbook_path_for(cookbook))
33
+ git_pull_submodules(cookbook_path_for(cookbook))
34
34
  end
35
35
  end
36
36
 
37
37
  def after_bump
38
38
  cookbooks.each do |cookbook|
39
- git_add(cookbook.root_dir,"metadata.rb")
39
+ git_add(cookbook_path_for(cookbook),"metadata.rb")
40
40
  end
41
41
  end
42
42
 
@@ -92,7 +92,7 @@ module KnifeSpork
92
92
  end
93
93
  end
94
94
  end
95
-
95
+
96
96
  def git_add(filepath,filename)
97
97
  if is_repo?(filepath)
98
98
  ui.msg "Git add'ing #{filepath}/#{filename}"
@@ -105,7 +105,7 @@ module KnifeSpork
105
105
  end
106
106
  end
107
107
  end
108
-
108
+
109
109
  # Commit changes, if any
110
110
  def git_commit
111
111
  begin
@@ -184,6 +184,14 @@ module KnifeSpork
184
184
  def tag_name
185
185
  cookbooks.collect{|c| "#{c.name}@#{c.version}"}.join('-')
186
186
  end
187
+
188
+ def cookbook_path_for cookbook
189
+ if defined?(Berkshelf) and cookbook.is_a? Berkshelf::CachedCookbook
190
+ cookbook.path.to_s
191
+ else
192
+ cookbook.root_dir
193
+ end
194
+ end
187
195
  end
188
196
  end
189
197
  end
@@ -53,10 +53,10 @@ module KnifeSpork
53
53
  end
54
54
 
55
55
  def load_specified_environment_group(name)
56
- if spork_config.environment_groups.nil?
57
- [name]
58
- else
56
+ if !spork_config.environment_groups.nil? && spork_config.environment_groups.keys.include?(name)
59
57
  spork_config.environment_groups[name]
58
+ else
59
+ [name]
60
60
  end
61
61
  end
62
62
 
@@ -107,26 +107,40 @@ module KnifeSpork
107
107
  ::Chef::CookbookLoader.new(::Chef::Config.cookbook_path)
108
108
  end
109
109
 
110
- def load_cookbook(cookbook_name)
111
- return cookbook_name if cookbook_name.is_a?(::Chef::CookbookVersion)
110
+ def load_cookbook(name)
111
+ return name if name.is_a?(Chef::CookbookVersion)
112
112
 
113
- # Search the local chef repo first
114
- loader = ::Chef::CookbookLoader.new(Chef::Config.cookbook_path)
115
- if loader.has_key?(cookbook_name)
116
- return loader[cookbook_name]
117
- end
113
+ cookbook = load_from_chef(name) || load_from_berkshelf(name) || load_from_librarian(name)
118
114
 
119
- # We didn't find the cookbook in our local repo, so check Berkshelf
120
- if defined?(::Berkshelf)
121
- berksfile = ::Berkshelf::Berksfile.from_file(self.config[:berksfile])
122
- if cookbook = berksfile.sources.find{ |source| source.name == cookbook_name }
123
- return cookbook
124
- end
125
- end
115
+ cookbook || raise(Chef::Exceptions::CookbookNotFound,
116
+ "Could not find cookbook '#{name}' in any of the sources!")
117
+ end
118
+
119
+ def load_from_chef(name)
120
+ all_cookbooks[name]
121
+ rescue Chef::Exceptions::CookbookNotFound,
122
+ Chef::Exceptions::CookbookNotFoundInRepo
123
+ nil
124
+ end
125
+
126
+ def load_from_berkshelf(name)
127
+ return unless defined?(::Berkshelf)
128
+ berksfile = ::Berkshelf::Berksfile.from_file(self.config[:berksfile])
129
+ lockfile = ::Berkshelf::Lockfile.new(berksfile)
130
+
131
+ raise Berkshelf::BerkshelfError, "LockFileNotFound" unless File.exists?(lockfile.filepath)
126
132
 
127
- # TODO: add librarian support here
133
+ cookbook = Berkshelf.ui.mute {
134
+ berksfile.resolve(lockfile.find(name))[:solution].first
135
+ }
128
136
 
129
- raise ::Chef::Exceptions::CookbookNotFound, "Could not find cookbook '#{cookbook_name}' in any of the sources!"
137
+ cookbook
138
+ end
139
+
140
+ # @todo #opensource
141
+ def load_from_librarian(name)
142
+ # Your code here :)
143
+ nil
130
144
  end
131
145
 
132
146
  def load_cookbooks(cookbook_names)
@@ -150,7 +164,16 @@ module KnifeSpork
150
164
  def environment_diff(local_environment, remote_environment)
151
165
  local_environment_versions = local_environment.to_hash['cookbook_versions']
152
166
  remote_environment_versions = remote_environment.to_hash['cookbook_versions']
153
- remote_environment_versions.diff(local_environment_versions)
167
+ hash_diff remote_environment_versions, local_environment_versions
168
+ end
169
+
170
+ def hash_diff(hash, other)
171
+ hash.keys.inject({}) do |memo, key|
172
+ unless hash[key] == other[key]
173
+ memo[key] = "#{hash[key]} changed to #{other[key]}"
174
+ end
175
+ memo
176
+ end
154
177
  end
155
178
 
156
179
  def constraints_diff (environment_diff)
@@ -189,15 +212,3 @@ module KnifeSpork
189
212
  end
190
213
  end
191
214
  end
192
-
193
-
194
- class Hash
195
- def diff(other)
196
- self.keys.inject({}) do |memo, key|
197
- unless self[key] == other[key]
198
- memo[key] = "#{self[key]} changed to #{other[key]}"
199
- end
200
- memo
201
- end
202
- end
203
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-spork
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
12
+ date: 2013-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef