sprinkle 0.7.1.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.tm_properties +7 -0
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +46 -4
  5. data/Rakefile +38 -1
  6. data/examples/rails/packages/database.rb +7 -0
  7. data/examples/rails/templates/mysql.cnf.erb +3 -0
  8. data/lib/sprinkle.rb +8 -13
  9. data/lib/sprinkle/actors/actor.rb +17 -17
  10. data/lib/sprinkle/actors/capistrano.rb +3 -3
  11. data/lib/sprinkle/actors/local.rb +10 -6
  12. data/lib/sprinkle/actors/ssh.rb +8 -8
  13. data/lib/sprinkle/actors/vlad.rb +7 -7
  14. data/lib/sprinkle/core.rb +16 -0
  15. data/lib/sprinkle/deployment.rb +8 -6
  16. data/lib/sprinkle/errors/pretty_failure.rb +1 -1
  17. data/lib/sprinkle/errors/template_error.rb +1 -1
  18. data/lib/sprinkle/installers/brew.rb +0 -2
  19. data/lib/sprinkle/installers/deb.rb +6 -2
  20. data/lib/sprinkle/installers/file.rb +38 -39
  21. data/lib/sprinkle/installers/freebsd_pkg.rb +4 -0
  22. data/lib/sprinkle/installers/group.rb +11 -12
  23. data/lib/sprinkle/installers/install_package.rb +5 -5
  24. data/lib/sprinkle/installers/openbsd_pkg.rb +5 -1
  25. data/lib/sprinkle/installers/opensolaris_pkg.rb +5 -1
  26. data/lib/sprinkle/installers/package_installer.rb +7 -3
  27. data/lib/sprinkle/installers/pacman.rb +4 -0
  28. data/lib/sprinkle/installers/push_text.rb +1 -1
  29. data/lib/sprinkle/installers/rake.rb +14 -6
  30. data/lib/sprinkle/installers/rpm.rb +5 -0
  31. data/lib/sprinkle/installers/runner.rb +3 -2
  32. data/lib/sprinkle/installers/thor.rb +14 -15
  33. data/lib/sprinkle/installers/transfer.rb +0 -1
  34. data/lib/sprinkle/installers/user.rb +2 -2
  35. data/lib/sprinkle/installers/yum.rb +9 -8
  36. data/lib/sprinkle/installers/zypper.rb +5 -1
  37. data/lib/sprinkle/package.rb +31 -8
  38. data/lib/sprinkle/package/chooser.rb +1 -1
  39. data/lib/sprinkle/package/package_repository.rb +1 -1
  40. data/lib/sprinkle/package/rendering.rb +13 -10
  41. data/lib/sprinkle/policy.rb +71 -74
  42. data/lib/sprinkle/script.rb +2 -2
  43. data/lib/sprinkle/utility/log_recorder.rb +1 -1
  44. data/lib/sprinkle/verifiers/file.rb +17 -1
  45. data/lib/sprinkle/verifiers/package.rb +2 -2
  46. data/lib/sprinkle/verify.rb +2 -2
  47. data/lib/sprinkle/version.rb +1 -1
  48. data/spec/sprinkle/deployment_spec.rb +5 -3
  49. data/spec/sprinkle/extensions/rendering_spec.rb +29 -14
  50. data/spec/sprinkle/installers/file_spec.rb +1 -1
  51. data/spec/sprinkle/installers/installer_spec.rb +1 -1
  52. data/spec/sprinkle/installers/opensolaris_pkg_spec.rb +0 -4
  53. data/spec/sprinkle/installers/transfer_spec.rb +1 -1
  54. data/spec/sprinkle/package_spec.rb +31 -0
  55. data/spec/sprinkle/policy_spec.rb +5 -5
  56. data/spec/sprinkle/verify_spec.rb +0 -7
  57. data/spec/templates/locals.erb +1 -0
  58. data/spec/templates/test.erb +1 -0
  59. data/templates/test.erb +1 -0
  60. metadata +10 -4
  61. data/lib/sprinkle/verifiers/directory.rb +0 -16
  62. data/lib/sprinkle/verifiers/symlink.rb +0 -30
@@ -0,0 +1,16 @@
1
+ module Sprinkle
2
+ # stores the global list of policies as they are defined
3
+ POLICIES = []
4
+
5
+ module Core
6
+ # Defines a single policy. Currently the only option, which is also
7
+ # required, is :roles, which defines which servers a policy is
8
+ # used on.
9
+ def policy(name, options = {}, &block)
10
+ p = Sprinkle::Policy.new(name, options, &block)
11
+ POLICIES << p
12
+ p
13
+ end
14
+
15
+ end
16
+ end
@@ -1,4 +1,6 @@
1
1
  module Sprinkle
2
+ # = Deployments
3
+ #
2
4
  # Deployment blocks specify deployment specific information about a
3
5
  # sprinkle script. An example:
4
6
  #
@@ -62,14 +64,14 @@ module Sprinkle
62
64
  end
63
65
 
64
66
  def method_missing(sym, *args, &block) #:nodoc:
65
- @defaults[sym] = block
67
+ if Sprinkle::Package::Package.installer_methods.include?(sym)
68
+ @defaults[sym] = block
69
+ else
70
+ super sym, *args, &block
71
+ end
66
72
  end
67
73
 
68
- def respond_to?(sym) #:nodoc:
69
- !!@defaults[sym]
70
- end
71
-
72
- def active_policies
74
+ def active_policies #:nodoc:
73
75
  if role=Sprinkle::OPTIONS[:only_role]
74
76
  role=role.to_sym
75
77
  POLICIES.select {|x| [x.roles].flatten.include?(role) }
@@ -1,5 +1,5 @@
1
1
  module Sprinkle
2
- module Errors
2
+ module Errors #:nodoc:
3
3
 
4
4
  class PrettyFailure < StandardError #:nodoc:
5
5
 
@@ -1,6 +1,6 @@
1
1
  module Sprinkle::Errors
2
2
  # Blatantly stole this from Chef
3
- class TemplateError < RuntimeError
3
+ class TemplateError < RuntimeError #:nodoc:
4
4
  attr_reader :original_exception, :context
5
5
  SOURCE_CONTEXT_WINDOW = 2 unless defined? SOURCE_CONTEXT_WINDOW
6
6
 
@@ -1,7 +1,5 @@
1
1
  module Sprinkle
2
2
  module Installers
3
- # = Homebrew Package Installer
4
- #
5
3
  # The Homebrew package installer uses the +brew+ command to install
6
4
  # packages on OSX.
7
5
  #
@@ -11,8 +11,12 @@ module Sprinkle
11
11
  # end
12
12
  #
13
13
  class Deb < PackageInstaller
14
-
15
- auto_api
14
+
15
+ ##
16
+ # install deb packages from an external URL
17
+ # :call-seq:
18
+ # deb(*package_urls)
19
+ auto_api :deb
16
20
 
17
21
  protected
18
22
 
@@ -2,47 +2,44 @@ require 'tempfile'
2
2
 
3
3
  module Sprinkle
4
4
  module Installers
5
+ # = File installer
6
+ #
7
+ # This installer creates a file on the remote server.
8
+ #
9
+ # == Example Usage
10
+ #
11
+ # Installing a nginx.conf onto remote servers
12
+ #
13
+ # package :nginx_conf do
14
+ # file '/etc/nginx.conf', :content => File.read('files/nginx.conf'),
15
+ # :sudo => true
16
+ # end
17
+ #
18
+ # Sudo is only necessary when the user your sprinkle is running as does
19
+ # not have necessarily permissions to create the file on its own.
20
+ # Such as when the file is in /etc.
21
+ #
22
+ # Should you need to run commands before or after the file transfer (making
23
+ # directories or changing permissions), you can use the pre/post :install directives.
24
+ #
25
+ # == Rendering templates
26
+ #
27
+ # Use the template render helper to render an ERB template to a remote file (you
28
+ # can use variables in your templates by setting them as instance variables inside
29
+ # your package. Templates have access to package methods such as opts, args, etc.
30
+ #
31
+ # package :nginx_conf do
32
+ # @nginx_port = 8080
33
+ # file '/etc/nginx.conf',
34
+ # :contents => render("nginx.conf")
35
+ # # ./templates/nginx.conf.erb or
36
+ # # ./templates/nginx.conf should contain the erb template
37
+ # end
5
38
  class FileInstaller < Installer
6
- # = File installer
7
- #
8
- # This installer creates a file on the remote server.
9
- #
10
- # == Example Usage
11
- #
12
- # Installing a nginx.conf onto remote servers
13
- #
14
- # package :nginx_conf do
15
- # file '/etc/nginx.conf', :content => File.read('files/nginx.conf')
16
- # end
17
- #
18
- # If you user has access to 'sudo' and theres a file that requires
19
- # priveledges to install, you can pass :sudo => true
20
- #
21
- # package :nginx_conf do
22
- # file '/etc/nginx.conf', :sudo => true,
23
- # :content => File.read('files/nginx.conf')
24
- # end
25
- #
26
- # Should you need to run commands before or after the file transfer (making
27
- # directories or changing permissions), you can use the pre/post :install directives.
28
- #
29
- # == Rendering templates
30
- #
31
- # Use the template render helper to render an ERB template to a remote file (you
32
- # can use variables in your templates by setting them as instance variables inside
33
- # your package. Templates have access to package methods such as opts, args, etc.
34
- #
35
- # package :nginx_conf do
36
- # @nginx_port = 8080
37
- # file '/etc/nginx.conf',
38
- # :contents => render("nginx.conf")
39
- # # ./templates/nginx.conf.erb or
40
- # # ./templates/nginx.conf should contain the erb template
41
- # end
42
- attr_reader :sourcepath, :destination, :contents
39
+ attr_reader :sourcepath, :destination, :contents #:nodoc:
43
40
 
44
41
  api do
45
- def file(destination, options = {}, &block)
42
+ def file(destination, options = {}, &block) #:nodoc:
46
43
  # options.merge!(:binding => binding())
47
44
  install FileInstaller.new(self, destination, options, &block)
48
45
  end
@@ -61,15 +58,17 @@ module Sprinkle
61
58
  mode options[:mode] if options[:mode]
62
59
  end
63
60
 
64
- def install_commands
61
+ def install_commands #:nodoc:
65
62
  :TRANSFER
66
63
  end
67
64
 
65
+ # calls chown own to set the file ownership
68
66
  def owner(owner)
69
67
  @owner = owner
70
68
  post :install, "#{sudo_cmd}chown #{owner} #{@destination}"
71
69
  end
72
70
 
71
+ # calls chmod to set the files permissions
73
72
  def mode(mode)
74
73
  @mode = mode
75
74
  post :install, "#{sudo_cmd}chmod #{mode} #{@destination}"
@@ -18,6 +18,10 @@ module Sprinkle
18
18
  #
19
19
  class FreebsdPkg < PackageInstaller
20
20
 
21
+ ##
22
+ # installs the FreeBSD packages passed
23
+ # :method: freebsd_pkg
24
+ # :call-seq: freebsd_pkg(*packages)
21
25
  auto_api
22
26
 
23
27
  protected
@@ -1,18 +1,17 @@
1
1
  module Sprinkle
2
2
  module Installers
3
+ # The user installer helps add groups. You may pass flags as an option.
4
+ #
5
+ # == Example Usage
6
+ #
7
+ # package :users do
8
+ # add_group 'webguys', :flags => "--shell /usr/bin/zsh"
9
+ #
10
+ # verify do
11
+ # has_group 'webguys'
12
+ # end
13
+ # end
3
14
  class Group < Installer
4
- # The user installer helps add groups. You may pass flags as an option.
5
- #
6
- # == Example Usage
7
- #
8
- # package :users do
9
- # add_group 'webguys', :flags => "--shell /usr/bin/zsh"
10
- #
11
- # verify do
12
- # has_group 'webguys'
13
- # end
14
- # end
15
-
16
15
  api do
17
16
  def add_group(group, options={}, &block)
18
17
  install Group.new(self, group, options, &block)
@@ -1,6 +1,6 @@
1
1
  module Sprinkle
2
2
  module Installers
3
- class InstallPackage < Installer
3
+ class InstallPackage < Installer #:nodoc:
4
4
  cattr_accessor :installer
5
5
  attr_accessor :packages #:nodoc:
6
6
 
@@ -62,18 +62,18 @@ end
62
62
  module Sprinkle
63
63
  module Package
64
64
  class Package
65
- def install_package(*names, &block)
65
+ def install_package(*names, &block) #:nodoc:
66
66
  ActiveSupport::Deprecation.warn("install_package will be removed from sprinkle 0.8, please use yum or smart installers instead.")
67
67
  @installers << Sprinkle::Installers::InstallPackage.new(self, names, &block)
68
68
  end
69
69
 
70
- def uninstall_package(*names, &block)
70
+ def uninstall_package(*names, &block) #:nodoc:
71
71
  ActiveSupport::Deprecation.warn("uninstall_package will be removed from sprinkle 0.8, please use yum or smart installers instead.")
72
72
  @installers << Sprinkle::Installers::UninstallPackage.new(self, names, &block)
73
73
  end
74
74
 
75
- alias_method :install_packages, :install_package
76
- alias_method :uninstall_packages, :uninstall_package
75
+ alias_method :install_packages, :install_package #:nodoc:
76
+ alias_method :uninstall_packages, :uninstall_package #:nodoc:
77
77
  end
78
78
  end
79
79
  end
@@ -26,7 +26,11 @@ module Sprinkle
26
26
  # For help on PKG_PATH see section 15.2.2 of the OpenBSD FAQ
27
27
  # (http://www.openbsd.org/faq/faq15.html)
28
28
  class OpenbsdPkg < PackageInstaller
29
-
29
+
30
+ ##
31
+ # installs the OpenBSD packages passed
32
+ # :method: openbsd_pkg
33
+ # :call-seq: openbsd_pkg(*packages)
30
34
  auto_api
31
35
 
32
36
  protected
@@ -13,7 +13,7 @@ module Sprinkle
13
13
  # You may also specify multiple packages as an array:
14
14
  #
15
15
  # package :magic_beans do
16
- # opensolaris_pkg %w(magic_beans magic_sauce)
16
+ # opensolaris_pkg 'magic_beans', 'magic_sauce'
17
17
  # end
18
18
  #
19
19
  # == Note
@@ -24,6 +24,10 @@ module Sprinkle
24
24
  # set :sudo_prompt, ''
25
25
  class OpensolarisPkg < PackageInstaller
26
26
 
27
+ ##
28
+ # installs the OpenSolaris packages passed
29
+ # :method: opensolaris_pkg
30
+ # :call-seq: opensolaris_pkg(*packages)
27
31
  auto_api
28
32
 
29
33
  protected
@@ -4,7 +4,8 @@ module Sprinkle
4
4
  # inherit from (deb, *BSD pkg, rpm, etc)
5
5
  class PackageInstaller < Installer
6
6
 
7
- attr_accessor :packages #:nodoc:
7
+ # holds the list of packages to be installed
8
+ attr_accessor :packages
8
9
 
9
10
  def initialize(parent, *packages, &block) #:nodoc:
10
11
  options = packages.extract_options!
@@ -12,8 +13,11 @@ module Sprinkle
12
13
  @packages = [*packages].flatten
13
14
  end
14
15
 
15
- def self.auto_api
16
- method_name = self.to_s.underscore.split("/").last
16
+ # automatically sets up the api for package installation based on the class name
17
+ #
18
+ # Apt becomes the method `apt`, etc
19
+ def self.auto_api(*args)
20
+ method_name = args.first || self.to_s.underscore.split("/").last
17
21
  class_name = self.to_s
18
22
  api do
19
23
  method="def #{method_name}(*names, &block)
@@ -3,6 +3,10 @@ module Sprinkle
3
3
  # The pacman installer installs Pacman packages
4
4
  class Pacman < PackageInstaller
5
5
 
6
+ ##
7
+ # installs the Pacman packages passed
8
+ # :method: pacman
9
+ # :call-seq: pacman(*packages)
6
10
  auto_api
7
11
 
8
12
  protected
@@ -47,7 +47,7 @@ module Sprinkle
47
47
  @path = path
48
48
  end
49
49
 
50
- def announce
50
+ def announce #:nodoc:
51
51
  log "--> Append '#{@text}' to file #{@path}"
52
52
  end
53
53
 
@@ -1,6 +1,6 @@
1
1
  module Sprinkle
2
2
  module Installers
3
- # This installer runs a rake command.
3
+ # This installer runs a rake task.
4
4
  #
5
5
  # == Example Usage
6
6
  #
@@ -9,13 +9,13 @@ module Sprinkle
9
9
  # the :rakefile option.
10
10
  #
11
11
  # package :spec do
12
- # rake 'spec', :rakefile => "/var/setup/Rakefile"
12
+ # rake 'spec', :file => "/var/setup/Rakefile"
13
13
  # end
14
14
  class Rake < Installer
15
15
 
16
16
  api do
17
- def rake(name, options = {}, &block)
18
- install Rake.new(self, name, options, &block)
17
+ def rake(task, options = {}, &block)
18
+ install Rake.new(self, task, options, &block)
19
19
  end
20
20
  end
21
21
 
@@ -27,8 +27,16 @@ module Sprinkle
27
27
  protected
28
28
 
29
29
  def install_commands #:nodoc:
30
- file = @options[:rakefile] ? "-f #{@options[:rakefile]} " : ""
31
- "rake #{file}#{@commands}"
30
+ "#{executable} #{taskfile}#{@commands}"
31
+ end
32
+
33
+ def executable #:nodoc:
34
+ "rake"
35
+ end
36
+
37
+ def taskfile #:nodoc:
38
+ file = @options[:rakefile] || @options[:file]
39
+ file ? "-f #{file} " : ""
32
40
  end
33
41
 
34
42
  end
@@ -20,6 +20,11 @@ module Sprinkle
20
20
  # end
21
21
  class Rpm < PackageInstaller
22
22
 
23
+ ##
24
+ # install RPM packages
25
+ # :method: rpm
26
+ # :call-seq:
27
+ # rpm(*packages)
23
28
  auto_api
24
29
 
25
30
  verify_api do
@@ -23,8 +23,9 @@ module Sprinkle
23
23
  install Runner.new(self, cmds, options, &block)
24
24
  end
25
25
 
26
- def noop(&block)
27
- install Runner.new(self, "echo noop", &block)
26
+ # runs 'echo noop' on the remote host
27
+ def noop
28
+ install Runner.new(self, "echo noop")
28
29
  end
29
30
  end
30
31
 
@@ -2,7 +2,7 @@ module Sprinkle
2
2
  module Installers
3
3
  # = Thor Installer
4
4
  #
5
- # This installer runs a thor command.
5
+ # This installer runs a thor task.
6
6
  #
7
7
  # == Example Usage
8
8
  #
@@ -15,29 +15,28 @@ module Sprinkle
15
15
  #
16
16
  # Specify a Thorfile with the :thorfile option.
17
17
  #
18
- # package :spec, :thorfile => "/var/setup/Thorfile" do
19
- # thor 'spec'
18
+ # package :spec do
19
+ # thor 'spec', :file => "/var/setup/Thorfile"
20
20
  # end
21
21
 
22
- class Thor < Installer
22
+ class Thor < Rake
23
23
 
24
24
  api do
25
- def thor(name, options = {}, &block)
26
- install Thor.new(self, name, options, &block)
25
+ def thor(task, options = {}, &block)
26
+ install Thor.new(self, task, options, &block)
27
27
  end
28
28
  end
29
29
 
30
- def initialize(parent, commands, options = {}, &block) #:nodoc:
31
- super parent, options, &block
32
- @commands = commands
33
- end
34
-
35
30
  protected
36
31
 
37
- def install_commands #:nodoc:
38
- file = @options[:thorfile] ? "-f #{@options[:thorfile]} " : ""
39
- "thor #{file}#{@commands}"
40
- end
32
+ def executable #:nodoc:
33
+ "thor"
34
+ end
35
+
36
+ def taskfile #:nodoc:
37
+ file = @options[:thorfile] || @options[:file]
38
+ file ? "-f #{file} " : ""
39
+ end
41
40
 
42
41
  end
43
42
  end