caterer 0.6.6 → 0.7.0

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/Berksfile CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- site :opscode
3
+ site :opscode
@@ -0,0 +1,26 @@
1
+ module Caterer
2
+ module Action
3
+ module Berkshelf
4
+ class Clean < Base
5
+
6
+ attr_reader :shelf
7
+
8
+ def initialize(app, env)
9
+ super
10
+ @shelf = Caterer::Berkshelf.shelf_for(env)
11
+ end
12
+
13
+ def call(env)
14
+
15
+ if env[:provisioner].is_a? Caterer::Provisioner::ChefSolo
16
+ ::Berkshelf.formatter.msg "cleaning Caterer's shelf"
17
+ FileUtils.remove_dir(shelf, fore: true)
18
+ end
19
+
20
+ @app.call(env)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ module Caterer
2
+ module Action
3
+ module Berkshelf
4
+ class Install < Base
5
+
6
+ attr_reader :shelf
7
+ attr_reader :berksfile
8
+
9
+ def initialize(app, env)
10
+ super
11
+
12
+ @shelf = Caterer::Berkshelf.shelf_for(env)
13
+ @berksfile = ::Berkshelf::Berksfile.from_file(env[:config].berkshelf.berksfile_path)
14
+ end
15
+
16
+
17
+ def call(env)
18
+
19
+ if env[:provisioner].is_a? Caterer::Provisioner::ChefSolo
20
+ configure_cookbooks_path(env[:provisioner])
21
+ install(env)
22
+ end
23
+
24
+ @app.call(env)
25
+ end
26
+
27
+ protected
28
+
29
+ def install(env)
30
+ ::Berkshelf.formatter.msg "installing cookbooks..."
31
+ opts = {
32
+ path: shelf
33
+ }.merge(env[:config].berkshelf.to_hash).symbolize_keys!
34
+ berksfile.install(opts)
35
+ end
36
+
37
+ def configure_cookbooks_path(provisioner)
38
+
39
+ # if for some reason the cookbooks path is a string, convert it into an array
40
+ if not provisioner.cookbooks_path.is_a? Array
41
+ provisioner.cookbooks_path = Array(provisioner.cookbooks_path)
42
+ end
43
+
44
+ provisioner.cookbooks_path.unshift(shelf)
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,20 @@
1
+ module Caterer
2
+ module Action
3
+ module Berkshelf
4
+ class UI < Base
5
+
6
+ def call(env)
7
+
8
+ ::Berkshelf.ui = begin
9
+ ui = env[:ui].dup
10
+ ui.resource = "Berkshelf"
11
+ ui
12
+ end
13
+
14
+ @app.call(env)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ module Caterer
2
+ module Action
3
+ module Berkshelf
4
+ autoload :Clean, 'caterer/action/berkshelf/clean'
5
+ autoload :Install, 'caterer/action/berkshelf/install'
6
+ autoload :UI, 'caterer/action/berkshelf/ui'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Caterer
2
+ module Action
3
+ module Provisioner
4
+ class Uninstall < Base
5
+
6
+ def call(env)
7
+ env[:provisioner].uninstall(env[:server])
8
+ @app.call(env)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -8,6 +8,7 @@ module Caterer
8
8
  autoload :Lock, 'caterer/action/provisioner/lock'
9
9
  autoload :Prepare, 'caterer/action/provisioner/prepare'
10
10
  autoload :Provision, 'caterer/action/provisioner/provision'
11
+ autoload :Uninstall, 'caterer/action/provisioner/uninstall'
11
12
  autoload :Unlock, 'caterer/action/provisioner/unlock'
12
13
  autoload :Validate, 'caterer/action/provisioner/validate'
13
14
  end
@@ -1,6 +1,7 @@
1
1
  module Caterer
2
2
  module Action
3
3
  autoload :Base, 'caterer/action/base'
4
+ autoload :Berkshelf, 'caterer/action/berkshelf'
4
5
  autoload :Config, 'caterer/action/config'
5
6
  autoload :Runner, 'caterer/action/runner'
6
7
  autoload :Provisioner, 'caterer/action/provisioner'
@@ -68,4 +68,12 @@ Caterer.actions.register(:reboot) do
68
68
  use Caterer::Action::Server::Validate::SSH
69
69
  use Caterer::Action::Server::Reboot
70
70
  end
71
+ end
72
+
73
+ Caterer.actions.register(:clean) do
74
+ Vli::Action::Builder.new do
75
+ use Caterer.actions.get(:validate)
76
+ use Caterer::Action::Provisioner::Load
77
+ use Caterer::Action::Provisioner::Uninstall
78
+ end
71
79
  end
@@ -0,0 +1,43 @@
1
+ require 'berkshelf' # this can take a bit of time :(
2
+
3
+ module Caterer
4
+ module Berkshelf
5
+
6
+ extend self
7
+
8
+ def shelf_for(env)
9
+ return nil if env[:uuid].nil?
10
+
11
+ File.join(::Berkshelf.berkshelf_path, "caterer", env[:uuid])
12
+ end
13
+
14
+ def install
15
+ Vli::Action::Builder.new do
16
+ use Action::Berkshelf::UI
17
+ use Action::Berkshelf::Install
18
+ end
19
+ end
20
+
21
+ def clean
22
+ Vli::Action::Builder.new do
23
+ use Action::Berkshelf::UI
24
+ use Action::Berkshelf::Clean
25
+ end
26
+ end
27
+
28
+ def init!
29
+
30
+ Caterer.config_keys.register(:berkshelf) { Config::Berkshelf }
31
+
32
+ [ :provision, :up ].each do |action|
33
+ Caterer.actions[action].insert_after(Caterer::Action::Provisioner::Load, install)
34
+ end
35
+
36
+ Caterer.actions[:clean].use clean
37
+
38
+ end
39
+
40
+ end
41
+ end
42
+
43
+ Caterer::Berkshelf.init!
@@ -0,0 +1,24 @@
1
+ module Caterer
2
+ module Command
3
+ class Clean < Base
4
+
5
+ def execute
6
+ options = {}
7
+ opts = OptionParser.new do |opts|
8
+ opts.banner = "Usage: cater provision HOST [options]"
9
+ end
10
+
11
+ # Parse the options
12
+ argv = parse_options(opts, options, true)
13
+ return if not argv
14
+
15
+ with_target_servers(argv, options) do |server|
16
+ server.clean
17
+ end
18
+
19
+ 0
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -1,6 +1,7 @@
1
1
  module Caterer
2
2
  module Command
3
3
  autoload :Base, 'caterer/command/base'
4
+ autoload :Clean, 'caterer/command/clean'
4
5
  autoload :Bootstrap, 'caterer/command/bootstrap'
5
6
  autoload :Lock, 'caterer/command/lock'
6
7
  autoload :Provision, 'caterer/command/provision'
@@ -1,5 +1,6 @@
1
1
  # commands
2
2
  Caterer.commands.register(:bootstrap) { Caterer::Command::Bootstrap }
3
+ Caterer.commands.register(:clean) { Caterer::Command::Clean }
3
4
  Caterer.commands.register(:lock) { Caterer::Command::Lock }
4
5
  Caterer.commands.register(:provision) { Caterer::Command::Provision }
5
6
  Caterer.commands.register(:reboot) { Caterer::Command::Reboot }
@@ -6,19 +6,22 @@ module Caterer
6
6
  attr_accessor :default_provisioner
7
7
 
8
8
  def initialize
9
- @images = {}
10
- @groups = {}
9
+ @images = {}
10
+ @groups = {}
11
+ @keys = {}
11
12
  @default_provisioner = :chef_solo
12
13
  end
13
14
 
14
15
  def image(name)
15
16
  @images[name] ||= Image.new(name)
16
17
  yield @images[name] if block_given?
18
+ @images[name]
17
19
  end
18
20
 
19
21
  def group(name)
20
22
  @groups[name] ||= Group.new(name)
21
23
  yield @groups[name] if block_given?
24
+ @groups[name]
22
25
  end
23
26
 
24
27
  def member(name, &block)
@@ -27,6 +30,19 @@ module Caterer
27
30
  end
28
31
  end
29
32
 
33
+ # here we allow custom config keys
34
+ def method_missing(method, *args, &block)
35
+ @keys[method] ||= begin
36
+ if klass = Caterer.config_keys.get(method)
37
+ klass.new
38
+ else
39
+ super
40
+ end
41
+ end
42
+ yield @keys[method] if block_given?
43
+ @keys[method]
44
+ end
45
+
30
46
  end
31
47
  end
32
48
  end
@@ -0,0 +1,40 @@
1
+ module Caterer
2
+ module Config
3
+ class Berkshelf
4
+
5
+ # @return [String]
6
+ # path to the Berksfile to use with Vagrant
7
+ attr_reader :berksfile_path
8
+
9
+ # @return [Array<Symbol>]
10
+ # only cookbooks in these groups will be installed and copied to
11
+ # Vagrant's shelf
12
+ attr_accessor :only
13
+
14
+ # @return [Array<Symbol>]
15
+ # cookbooks in all other groups except for these will be installed
16
+ # and copied to Vagrant's shelf
17
+ attr_accessor :except
18
+
19
+ def initialize
20
+ @berksfile_path = File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME)
21
+ @except = []
22
+ @only = []
23
+ end
24
+
25
+ # @param [String] value
26
+ def berksfile_path=(value)
27
+ @berksfile_path = File.expand_path(value)
28
+ end
29
+
30
+ def to_hash
31
+ {
32
+ :berksfile_path => @berksfile_path,
33
+ :only => @only,
34
+ :except => @except
35
+ }
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -18,6 +18,7 @@ module Caterer
18
18
  def member(name)
19
19
  @members[name] ||= Member.new(name)
20
20
  yield @members[name] if block_given?
21
+ @members[name]
21
22
  end
22
23
  end
23
24
  end
@@ -13,6 +13,7 @@ module Caterer
13
13
  raise ":#{type} is not a valida provisioner" if not provisioner_klass
14
14
  @provisioner = provisioner_klass.new
15
15
  yield @provisioner if block_given?
16
+ @provisioner
16
17
  end
17
18
 
18
19
  end
@@ -1,6 +1,7 @@
1
1
  module Caterer
2
2
  module Config
3
3
  autoload :Base, 'caterer/config/base'
4
+ autoload :Berkshelf, 'caterer/config/berkshelf'
4
5
  autoload :Cluster, 'caterer/config/cluster'
5
6
  autoload :Group, 'caterer/config/group'
6
7
  autoload :Member, 'caterer/config/member'
@@ -33,11 +33,16 @@ module Caterer
33
33
  @action_runner ||= Vli::Action::Runner.new(action_registry) do
34
34
  {
35
35
  :action_runner => action_runner,
36
- :ui => @ui
36
+ :ui => @ui,
37
+ :uuid => uuid
37
38
  }
38
39
  end
39
40
  end
40
41
 
42
+ def uuid
43
+ @uuid ||= Digest::MD5.hexdigest(@cwd.to_s)
44
+ end
45
+
41
46
  def action_registry
42
47
  Caterer.actions
43
48
  end
@@ -12,7 +12,8 @@ module Caterer
12
12
  def install(server); end
13
13
  def prepare(server); end
14
14
  def provision(server); end
15
-
15
+ def uninstall(server); end
16
+
16
17
  end
17
18
  end
18
19
  end
@@ -202,6 +202,12 @@ module Caterer
202
202
  # for now, leave cookbooks, roles, and data bags for faster provisioning
203
203
  end
204
204
 
205
+ def uninstall(server)
206
+ server.ui.info "Uninstalling..."
207
+
208
+ server.ssh.sudo "rm -rf #{target_base_path}", :stream => true
209
+ end
210
+
205
211
  protected
206
212
 
207
213
  def with_bootstrap_scripts
@@ -258,6 +264,16 @@ module Caterer
258
264
  {:run_list => run_list}.merge(json)
259
265
  end
260
266
 
267
+ def final_cookbook_paths
268
+ cookbooks_path.inject([]) do |res, path|
269
+ # make sure they actually contain recipes, otherwise chef-solo will freak
270
+ if Dir.entries(path).length > 2
271
+ res << "#{target_cookbooks_path}/#{Digest::MD5.hexdigest(path)}"
272
+ end
273
+ res
274
+ end
275
+ end
276
+
261
277
  def command_string
262
278
  "chef-solo -c #{target_solo_path} -j #{target_json_config_path}"
263
279
  end
@@ -72,6 +72,11 @@ module Caterer
72
72
  run_action(:unlock, opts)
73
73
  end
74
74
 
75
+ def clean(opts={})
76
+ ui.info "*** Cleaning ***"
77
+ run_action(:clean, opts)
78
+ end
79
+
75
80
  def reboot!
76
81
  ui.info "Rebooting..."
77
82
  ssh.sudo "shutdown -r now", :stream => true
@@ -1,3 +1,3 @@
1
1
  module Caterer
2
- VERSION = "0.6.6"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/caterer.rb CHANGED
@@ -4,6 +4,7 @@ require 'caterer/logger'
4
4
 
5
5
  module Caterer
6
6
  autoload :Action, 'caterer/action'
7
+ autoload :Berkshelf, 'caterer/berkshelf'
7
8
  autoload :Cli, 'caterer/cli'
8
9
  autoload :Command, 'caterer/command'
9
10
  autoload :Communication, 'caterer/communication'
@@ -27,6 +28,10 @@ module Caterer
27
28
  @provisioners ||= Vli::Registry.new
28
29
  end
29
30
 
31
+ def config_keys
32
+ @config_keys ||= Vli::Registry.new
33
+ end
34
+
30
35
  def config
31
36
  @config ||= Config::Base.new
32
37
  end
@@ -1,5 +1,5 @@
1
1
  file_cache_path "<%= target_base_path %>"
2
2
  node_name "<%= server.host %>"
3
- cookbook_path <%= cookbooks_path.map { |path| "#{target_cookbooks_path}/#{Digest::MD5.hexdigest(path)}" }.inspect %>
3
+ cookbook_path <%= final_cookbook_paths.inspect %>
4
4
  data_bag_path "<%= target_data_bags_path %>"
5
5
  role_path "<%= target_roles_path %>"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caterer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.7.0
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: 2012-12-28 00:00:00.000000000 Z
12
+ date: 2013-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: log4r
@@ -182,6 +182,10 @@ files:
182
182
  - lib/caterer.rb
183
183
  - lib/caterer/action.rb
184
184
  - lib/caterer/action/base.rb
185
+ - lib/caterer/action/berkshelf.rb
186
+ - lib/caterer/action/berkshelf/clean.rb
187
+ - lib/caterer/action/berkshelf/install.rb
188
+ - lib/caterer/action/berkshelf/ui.rb
185
189
  - lib/caterer/action/config.rb
186
190
  - lib/caterer/action/config/validate.rb
187
191
  - lib/caterer/action/config/validate/image.rb
@@ -193,6 +197,7 @@ files:
193
197
  - lib/caterer/action/provisioner/load.rb
194
198
  - lib/caterer/action/provisioner/prepare.rb
195
199
  - lib/caterer/action/provisioner/provision.rb
200
+ - lib/caterer/action/provisioner/uninstall.rb
196
201
  - lib/caterer/action/provisioner/validate.rb
197
202
  - lib/caterer/action/provisioner/validate/bootstrapped.rb
198
203
  - lib/caterer/action/provisioner/validate/engine.rb
@@ -204,10 +209,12 @@ files:
204
209
  - lib/caterer/action/server/validate/ssh.rb
205
210
  - lib/caterer/action/server/validate/unlocked.rb
206
211
  - lib/caterer/actions.rb
212
+ - lib/caterer/berkshelf.rb
207
213
  - lib/caterer/cli.rb
208
214
  - lib/caterer/command.rb
209
215
  - lib/caterer/command/base.rb
210
216
  - lib/caterer/command/bootstrap.rb
217
+ - lib/caterer/command/clean.rb
211
218
  - lib/caterer/command/lock.rb
212
219
  - lib/caterer/command/provision.rb
213
220
  - lib/caterer/command/reboot.rb
@@ -220,6 +227,7 @@ files:
220
227
  - lib/caterer/communication/ssh.rb
221
228
  - lib/caterer/config.rb
222
229
  - lib/caterer/config/base.rb
230
+ - lib/caterer/config/berkshelf.rb
223
231
  - lib/caterer/config/group.rb
224
232
  - lib/caterer/config/image.rb
225
233
  - lib/caterer/config/member.rb