caterer 0.6.6 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Berksfile +1 -1
- data/lib/caterer/action/berkshelf/clean.rb +26 -0
- data/lib/caterer/action/berkshelf/install.rb +50 -0
- data/lib/caterer/action/berkshelf/ui.rb +20 -0
- data/lib/caterer/action/berkshelf.rb +9 -0
- data/lib/caterer/action/provisioner/uninstall.rb +14 -0
- data/lib/caterer/action/provisioner.rb +1 -0
- data/lib/caterer/action.rb +1 -0
- data/lib/caterer/actions.rb +8 -0
- data/lib/caterer/berkshelf.rb +43 -0
- data/lib/caterer/command/clean.rb +24 -0
- data/lib/caterer/command.rb +1 -0
- data/lib/caterer/commands.rb +1 -0
- data/lib/caterer/config/base.rb +18 -2
- data/lib/caterer/config/berkshelf.rb +40 -0
- data/lib/caterer/config/group.rb +1 -0
- data/lib/caterer/config/image.rb +1 -0
- data/lib/caterer/config.rb +1 -0
- data/lib/caterer/environment.rb +6 -1
- data/lib/caterer/provisioner/base.rb +2 -1
- data/lib/caterer/provisioner/chef_solo.rb +16 -0
- data/lib/caterer/server.rb +5 -0
- data/lib/caterer/version.rb +1 -1
- data/lib/caterer.rb +5 -0
- data/lib/templates/provisioner/chef_solo/solo.erb +1 -1
- metadata +10 -2
data/Berksfile
CHANGED
@@ -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
|
@@ -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
|
data/lib/caterer/action.rb
CHANGED
data/lib/caterer/actions.rb
CHANGED
@@ -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
|
data/lib/caterer/command.rb
CHANGED
data/lib/caterer/commands.rb
CHANGED
@@ -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 }
|
data/lib/caterer/config/base.rb
CHANGED
@@ -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
|
data/lib/caterer/config/group.rb
CHANGED
data/lib/caterer/config/image.rb
CHANGED
data/lib/caterer/config.rb
CHANGED
data/lib/caterer/environment.rb
CHANGED
@@ -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
|
@@ -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
|
data/lib/caterer/server.rb
CHANGED
data/lib/caterer/version.rb
CHANGED
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 <%=
|
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.
|
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:
|
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
|