knife-spork 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/knife-spork.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'knife-spork'
16
- s.version = '0.1.4'
17
- s.date = '2012-02-03'
16
+ s.version = '0.1.6'
17
+ s.date = '2012-02-21'
18
18
  s.rubyforge_project = 'knife-spork'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -70,12 +70,14 @@ module KnifeSpork
70
70
  bump_type = name_args[1]
71
71
  elsif name_args.size == 2
72
72
  bump_type = name_args.last
73
+ elsif name_args.size == 1
74
+ bump_type = "patch"
73
75
  else
74
76
  ui.fatal "Please specify the cookbook whose version you which to bump, and the type of bump you wish to apply."
75
77
  show_usage
76
78
  exit 1
77
79
  end
78
-
80
+
79
81
  unless TYPE_INDEX.has_key?(bump_type)
80
82
  ui.fatal "Sorry, '#{name_args.last}' isn't a valid bump type. Specify one of 'major', 'minor', 'patch' or 'manual'"
81
83
  show_usage
@@ -86,13 +88,11 @@ module KnifeSpork
86
88
  manual_version = name_args.last
87
89
  cookbook = name_args.first
88
90
  cookbook_path = Array(config[:cookbook_path]).first
89
- patch_type = "manual"
90
91
  patch_manual(cookbook_path, cookbook, manual_version)
91
92
  else
92
93
  cookbook = name_args.first
93
- patch_type = name_args.last
94
94
  cookbook_path = Array(config[:cookbook_path]).first
95
- patch(cookbook_path, cookbook, patch_type)
95
+ patch(cookbook_path, cookbook, bump_type)
96
96
  end
97
97
 
98
98
  if !AppConf.git.nil? && AppConf.git.enabled
@@ -170,7 +170,7 @@ module KnifeSpork
170
170
  rescue ArgumentError => e
171
171
  ui.warn "Git: The root of your chef repo doesn't look like it's a git repo. Skipping git add...\n\n"
172
172
  rescue
173
- ui.warn "Git: Cookbook uploaded, but something went wrong with git add metadata.rb, Dumping log info..."
173
+ ui.warn "Git: Cookbook bump succeeded, but something went wrong with git add metadata.rb, so you'll want to manually git add it. Dumping log info..."
174
174
  ui.warn "#{strio.string}"
175
175
  end
176
176
  end
@@ -120,7 +120,15 @@ module KnifeSpork
120
120
  environments.each do |e|
121
121
  ui.msg ""
122
122
  ui.msg "Environment: #{e}"
123
- @environment = loader.load_from("environments", "#{e}.json")
123
+
124
+
125
+ cookbook_path = config[:cookbook_path]
126
+ if cookbook_path.size > 1
127
+ @environment = loader.load_from("environments", "#{e}.json")
128
+ else
129
+ path = cookbook_path[0].gsub("cookbooks","environments") + "/#{e}.json"
130
+ @environment = loader.object_from_file("#{path}")
131
+ end
124
132
 
125
133
  if @cookbook == "all"
126
134
  ui.msg "Promoting ALL cookbooks to environment #{@environment}"
@@ -195,7 +203,12 @@ module KnifeSpork
195
203
  env_server = Chef::Environment.load(environment.gsub(".json","")).to_hash["cookbook_versions"]
196
204
  env_local = updated.to_hash["cookbook_versions"]
197
205
  env_diff = env_server.diff(env_local)
198
-
206
+
207
+ if env_diff.size > 1
208
+ ui.warn "You're about to promote changes to several cookbooks:"
209
+ ui.warn "\n#{env_diff.collect { |k, v| "#{k}: #{v}\n" }.join}"
210
+ ui.confirm("Are you sure you want to continue?")
211
+ end
199
212
  updated.save
200
213
 
201
214
  if !AppConf.gist.nil? && AppConf.gist.enabled
@@ -209,21 +222,39 @@ module KnifeSpork
209
222
  @gist = %x[ echo "#{msg}" | #{gist_path}]
210
223
  end
211
224
 
212
- if !AppConf.irccat.nil? && AppConf.irccat.enabled
213
- message = "#{AppConf.irccat.channel} CHEF: #{ENV['USER']} uploaded environment #{environment.gsub(".json","")} #{@gist}"
214
- s = TCPSocket.open(AppConf.irccat.server,AppConf.irccat.port)
215
- s.write(message)
216
- s.close
225
+ if !AppConf.irccat.nil? && AppConf.irccat.enabled
226
+ begin
227
+
228
+ if !AppConf.irccat.channel?(String)
229
+ channels = AppConf.irccat.channel
230
+ else
231
+ channels = ["#{AppConf.irccat.channel}"]
232
+ end
233
+
234
+ channels.each do |c|
235
+ message = "#{c} #BOLD#PURPLECHEF:#NORMAL #{ENV['USER']} uploaded environment #TEAL#{environment.gsub(".json","")}#NORMAL #{@gist}"
236
+ s = TCPSocket.open(AppConf.irccat.server,AppConf.irccat.port)
237
+ s.write(message)
238
+ s.close
239
+ end
240
+ rescue Exception => msg
241
+ puts "Something went wrong with sending to irccat: (#{msg})"
242
+ end
217
243
  end
218
244
 
219
245
 
220
246
  if !AppConf.graphite.nil? && AppConf.graphite.enabled
221
- time = Time.now
222
- message = "deploys.chef.#{environment.gsub(".json","")} 1 #{time.to_i}\n"
223
- s = TCPSocket.open(AppConf.graphite.server,AppConf.graphite.port)
224
- s.write(message)
225
- s.close
247
+ begin
248
+ time = Time.now
249
+ message = "deploys.chef.#{environment.gsub(".json","")} 1 #{time.to_i}\n"
250
+ s = TCPSocket.open(AppConf.graphite.server,AppConf.graphite.port)
251
+ s.write(message)
252
+ s.close
253
+ rescue Exception => msg
254
+ puts "Something went wrong with sending to graphite: (#{msg})"
255
+ end
226
256
  end
257
+
227
258
  end
228
259
 
229
260
  def save_environment_changes(environment,envjson)
@@ -281,16 +312,32 @@ module KnifeSpork
281
312
  ui.warn "It looks like you have multiple cookbook paths defined so I can't tell if you're running inside a git repo.\n\n"
282
313
  else
283
314
  begin
284
- path = cookbook_path[0].gsub("cookbooks","")
315
+ path = cookbook_path[0].gsub("/cookbooks","")
285
316
  ui.msg "Opening git repo #{path}\n\n"
286
317
  g = Git.open(path, :log => Logger.new(strio))
287
318
  ui.msg "Pulling latest changes from git\n\n"
288
- g.pull
319
+ output = IO.popen ("cd #{path} && git pull 2>&1")
320
+ Process.wait
321
+ exit_code = $?
322
+ if exit_code.exitstatus == 0
323
+ ui.msg "#{output.read()}\n"
324
+ else
325
+ ui.error "#{output.read()}\n"
326
+ exit 1
327
+ end
328
+
329
+ ui.msg "Pulling latest changes from git submodules (if any)\n\n"
330
+ output = IO.popen ("cd #{path} && git submodule foreach git pull 2>&1")
331
+ Process.wait
332
+ exit_code = $?
333
+ if exit_code.exitstatus == 0
334
+ ui.msg "#{output.read()}\n"
335
+ else
336
+ ui.error "#{output.read()}\n"
337
+ exit 1
338
+ end
289
339
  rescue ArgumentError => e
290
340
  ui.warn "Git: The root of your chef repo doesn't look like it's a git repo. Skipping git pull...\n\n"
291
- rescue
292
- ui.warn "Git: Something went wrong with git pull, Dumping log info..."
293
- ui.warn "#{strio.string}"
294
341
  end
295
342
  end
296
343
  end
@@ -118,12 +118,25 @@ module KnifeSpork
118
118
  cookbook.freeze_version
119
119
  upload(cookbook, justify_width)
120
120
  version_constraints_to_update[cookbook_name] = cookbook.version
121
-
121
+
122
122
  if !AppConf.irccat.nil? && AppConf.irccat.enabled
123
- message = "#{AppConf.irccat.channel} CHEF: #{ENV['USER']} uploaded and froze cookbook #{cookbook_name} version #{cookbook.version}"
124
- s = TCPSocket.open(AppConf.irccat.server,AppConf.irccat.port)
125
- s.write(message)
126
- s.close
123
+ begin
124
+
125
+ if !AppConf.irccat.channel?(String)
126
+ channels = AppConf.irccat.channel
127
+ else
128
+ channels = ["#{AppConf.irccat.channel}"]
129
+ end
130
+
131
+ channels.each do |c|
132
+ message = "#{c} #BOLD#PURPLECHEF:#NORMAL #{ENV['USER']} uploaded and froze cookbook #TEAL#{cookbook_name}#NORMAL version #TEAL#{cookbook.version}#NORMAL"
133
+ s = TCPSocket.open(AppConf.irccat.server,AppConf.irccat.port)
134
+ s.write(message)
135
+ s.close
136
+ end
137
+ rescue Exception => msg
138
+ puts "Something went wrong with sending to irccat: (#{msg})"
139
+ end
127
140
  end
128
141
 
129
142
  rescue Chef::Exceptions::CookbookNotFoundInRepo => e
data/lib/knife-spork.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module KnifeSpork
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jon Cowie
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-02-03 00:00:00 +00:00
17
+ date: 2012-02-21 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency