powcloud-sprinkle 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.gitignore +5 -0
  2. data/CREDITS +33 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.markdown +241 -0
  5. data/Rakefile +50 -0
  6. data/VERSION +1 -0
  7. data/bin/sprinkle +90 -0
  8. data/examples/packages/build_essential.rb +9 -0
  9. data/examples/packages/databases/mysql.rb +13 -0
  10. data/examples/packages/databases/sqlite3.rb +16 -0
  11. data/examples/packages/phusion.rb +55 -0
  12. data/examples/packages/ruby/rails.rb +9 -0
  13. data/examples/packages/ruby/ruby.rb +17 -0
  14. data/examples/packages/ruby/rubygems.rb +17 -0
  15. data/examples/packages/scm/git.rb +11 -0
  16. data/examples/packages/scm/subversion.rb +4 -0
  17. data/examples/packages/servers/apache.rb +15 -0
  18. data/examples/rails/README +15 -0
  19. data/examples/rails/deploy.rb +2 -0
  20. data/examples/rails/packages/database.rb +9 -0
  21. data/examples/rails/packages/essential.rb +9 -0
  22. data/examples/rails/packages/rails.rb +29 -0
  23. data/examples/rails/packages/scm.rb +11 -0
  24. data/examples/rails/packages/search.rb +11 -0
  25. data/examples/rails/packages/server.rb +28 -0
  26. data/examples/rails/rails.rb +73 -0
  27. data/examples/sprinkle/sprinkle.rb +38 -0
  28. data/lib/sprinkle/actors/actors.rb +17 -0
  29. data/lib/sprinkle/actors/capistrano.rb +140 -0
  30. data/lib/sprinkle/actors/local.rb +37 -0
  31. data/lib/sprinkle/actors/ssh.rb +123 -0
  32. data/lib/sprinkle/actors/vlad.rb +78 -0
  33. data/lib/sprinkle/configurable.rb +31 -0
  34. data/lib/sprinkle/deployment.rb +73 -0
  35. data/lib/sprinkle/extensions/arbitrary_options.rb +10 -0
  36. data/lib/sprinkle/extensions/array.rb +5 -0
  37. data/lib/sprinkle/extensions/blank_slate.rb +5 -0
  38. data/lib/sprinkle/extensions/dsl_accessor.rb +15 -0
  39. data/lib/sprinkle/extensions/string.rb +10 -0
  40. data/lib/sprinkle/extensions/symbol.rb +7 -0
  41. data/lib/sprinkle/installers/apt.rb +52 -0
  42. data/lib/sprinkle/installers/binary.rb +46 -0
  43. data/lib/sprinkle/installers/bsd_port.rb +33 -0
  44. data/lib/sprinkle/installers/deb.rb +38 -0
  45. data/lib/sprinkle/installers/freebsd_pkg.rb +37 -0
  46. data/lib/sprinkle/installers/freebsd_portinstall.rb +36 -0
  47. data/lib/sprinkle/installers/gem.rb +64 -0
  48. data/lib/sprinkle/installers/install_package.rb +79 -0
  49. data/lib/sprinkle/installers/installer.rb +120 -0
  50. data/lib/sprinkle/installers/mac_port.rb +38 -0
  51. data/lib/sprinkle/installers/noop.rb +20 -0
  52. data/lib/sprinkle/installers/openbsd_pkg.rb +47 -0
  53. data/lib/sprinkle/installers/opensolaris_pkg.rb +43 -0
  54. data/lib/sprinkle/installers/push_text.rb +45 -0
  55. data/lib/sprinkle/installers/rake.rb +37 -0
  56. data/lib/sprinkle/installers/rpm.rb +37 -0
  57. data/lib/sprinkle/installers/smart.rb +29 -0
  58. data/lib/sprinkle/installers/source.rb +190 -0
  59. data/lib/sprinkle/installers/transfer.rb +164 -0
  60. data/lib/sprinkle/installers/yum.rb +37 -0
  61. data/lib/sprinkle/package.rb +309 -0
  62. data/lib/sprinkle/policy.rb +125 -0
  63. data/lib/sprinkle/script.rb +23 -0
  64. data/lib/sprinkle/verifiers/directory.rb +16 -0
  65. data/lib/sprinkle/verifiers/executable.rb +53 -0
  66. data/lib/sprinkle/verifiers/file.rb +26 -0
  67. data/lib/sprinkle/verifiers/package.rb +26 -0
  68. data/lib/sprinkle/verifiers/process.rb +21 -0
  69. data/lib/sprinkle/verifiers/rpm.rb +21 -0
  70. data/lib/sprinkle/verifiers/ruby.rb +25 -0
  71. data/lib/sprinkle/verifiers/symlink.rb +30 -0
  72. data/lib/sprinkle/verify.rb +114 -0
  73. data/lib/sprinkle.rb +32 -0
  74. data/script/console +8 -0
  75. data/script/destroy +14 -0
  76. data/script/generate +14 -0
  77. data/spec/spec.opts +1 -0
  78. data/spec/spec_helper.rb +17 -0
  79. data/spec/sprinkle/actors/capistrano_spec.rb +265 -0
  80. data/spec/sprinkle/actors/local_spec.rb +29 -0
  81. data/spec/sprinkle/configurable_spec.rb +46 -0
  82. data/spec/sprinkle/deployment_spec.rb +80 -0
  83. data/spec/sprinkle/extensions/array_spec.rb +19 -0
  84. data/spec/sprinkle/extensions/string_spec.rb +21 -0
  85. data/spec/sprinkle/installers/apt_spec.rb +70 -0
  86. data/spec/sprinkle/installers/bsd_port_spec.rb +42 -0
  87. data/spec/sprinkle/installers/freebsd_pkg_spec.rb +49 -0
  88. data/spec/sprinkle/installers/freebsd_portinstall_spec.rb +42 -0
  89. data/spec/sprinkle/installers/gem_spec.rb +107 -0
  90. data/spec/sprinkle/installers/installer_spec.rb +151 -0
  91. data/spec/sprinkle/installers/mac_port_spec.rb +42 -0
  92. data/spec/sprinkle/installers/noop_spec.rb +23 -0
  93. data/spec/sprinkle/installers/openbsd_pkg_spec.rb +49 -0
  94. data/spec/sprinkle/installers/opensolaris_pkg_spec.rb +49 -0
  95. data/spec/sprinkle/installers/push_text_spec.rb +66 -0
  96. data/spec/sprinkle/installers/rake_spec.rb +29 -0
  97. data/spec/sprinkle/installers/rpm_spec.rb +50 -0
  98. data/spec/sprinkle/installers/source_spec.rb +371 -0
  99. data/spec/sprinkle/installers/transfer_spec.rb +98 -0
  100. data/spec/sprinkle/installers/yum_spec.rb +49 -0
  101. data/spec/sprinkle/package_spec.rb +466 -0
  102. data/spec/sprinkle/policy_spec.rb +126 -0
  103. data/spec/sprinkle/script_spec.rb +51 -0
  104. data/spec/sprinkle/sprinkle_spec.rb +25 -0
  105. data/spec/sprinkle/verify_spec.rb +174 -0
  106. metadata +244 -0
@@ -0,0 +1,10 @@
1
+ module ArbitraryOptions #:nodoc:
2
+ def self.included(base)
3
+ base.alias_method_chain :method_missing, :arbitrary_options
4
+ end
5
+
6
+ def method_missing_with_arbitrary_options(sym, *args, &block)
7
+ self.class.dsl_accessor sym
8
+ send(sym, *args, &block)
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class Array #:nodoc:
2
+ def to_task_name
3
+ collect(&:to_task_name).join('_')
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class BlankSlate #:nodoc:
2
+ instance_methods.each do |m|
3
+ undef_method(m) unless %w( __send__ __id__ send class inspect instance_eval instance_variables ).include?(m)
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ class Module #:nodoc:
2
+ def dsl_accessor(*symbols)
3
+ symbols.each do |sym|
4
+ class_eval %{
5
+ def #{sym}(*val)
6
+ if val.empty?
7
+ @#{sym}
8
+ else
9
+ @#{sym} = val.size == 1 ? val[0] : val
10
+ end
11
+ end
12
+ }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ class String #:nodoc:
2
+
3
+ # REVISIT: what chars shall we allow in task names?
4
+ def to_task_name
5
+ s = downcase
6
+ s.gsub!(/-/, '_') # all - to _ chars
7
+ s
8
+ end
9
+
10
+ end
@@ -0,0 +1,7 @@
1
+ class Symbol #:nodoc:
2
+
3
+ def to_task_name
4
+ to_s.to_task_name
5
+ end
6
+
7
+ end
@@ -0,0 +1,52 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = Apt Package Installer
4
+ #
5
+ # The Apt package installer uses the +apt-get+ command to install
6
+ # packages. The apt installer has only one option which can be
7
+ # modified which is the +dependencies_only+ option. When this is
8
+ # set to true, the installer uses +build-dep+ instead of +install+
9
+ # to only build the dependencies.
10
+ #
11
+ # == Example Usage
12
+ #
13
+ # First, a simple installation of the magic_beans package:
14
+ #
15
+ # package :magic_beans do
16
+ # description "Beans beans they're good for your heart..."
17
+ # apt 'magic_beans_package'
18
+ # end
19
+ #
20
+ # Second, only build the magic_beans dependencies:
21
+ #
22
+ # package :magic_beans_depends do
23
+ # apt 'magic_beans_package' { dependencies_only true }
24
+ # end
25
+ #
26
+ # As you can see, setting options is as simple as creating a
27
+ # block and calling the option as a method with the value as
28
+ # its parameter.
29
+ class Apt < Installer
30
+ attr_accessor :packages #:nodoc:
31
+
32
+ def initialize(parent, *packages, &block) #:nodoc:
33
+ packages.flatten!
34
+
35
+ options = { :dependencies_only => false }
36
+ options.update(packages.pop) if packages.last.is_a?(Hash)
37
+
38
+ super parent, options, &block
39
+
40
+ @packages = packages
41
+ end
42
+
43
+ protected
44
+
45
+ def install_commands #:nodoc:
46
+ command = @options[:dependencies_only] ? 'build-dep' : 'install'
47
+ "env DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive apt-get --force-yes -qyu #{command} #{@packages.join(' ')}"
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,46 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = Binary Installer
4
+ #
5
+ # binary "http://some.url.com/archive.tar.gz" do
6
+ # prefix "/home/user/local"
7
+ # archives "/home/user/sources"
8
+ # end
9
+ #
10
+ class Binary < Installer
11
+ def initialize(parent, binary_archive, options = {}, &block) #:nodoc:
12
+ @binary_archive = binary_archive
13
+ @options = options
14
+ super parent, options, &block
15
+ end
16
+
17
+ def prepare_commands #:nodoc:
18
+ raise 'No installation area defined' unless @options[:prefix]
19
+ raise 'No archive download area defined' unless @options[:archives]
20
+
21
+ [ "mkdir -p #{@options[:prefix]}",
22
+ "mkdir -p #{@options[:archives]}" ]
23
+ end
24
+
25
+ def install_commands #:nodoc:
26
+ commands = [ "bash -c 'wget -cq --directory-prefix=#{@options[:archives]} #{@binary_archive}'" ]
27
+ commands << "bash -c 'cd #{@options[:prefix]} && #{extract_command} #{@options[:archives]}/#{@binary_archive.split("/").last}'"
28
+ end
29
+
30
+ def extract_command(archive_name = @binary_archive.split("/").last)
31
+ case archive_name
32
+ when /(tar.gz)|(tgz)$/
33
+ 'tar xzf'
34
+ when /(tar.bz2)|(tb2)$/
35
+ 'tar xjf'
36
+ when /tar$/
37
+ 'tar xf'
38
+ when /zip$/
39
+ 'unzip'
40
+ else
41
+ raise "Unknown binary archive format: #{archive_name}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,33 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = OpenBSD and FreeBSD Port Installer
4
+ #
5
+ # The Port installer installs OpenBSD and FreeBSD ports.
6
+ # Before usage, the ports sytem must be installed and
7
+ # read on the target operating system.
8
+ #
9
+ # == Example Usage
10
+ #
11
+ # Installing the magic_beans port.
12
+ #
13
+ # package :magic_beans do
14
+ # bsd_port 'magic/magic_beans'
15
+ # end
16
+ #
17
+ class BsdPort < Installer
18
+ attr_accessor :port #:nodoc:
19
+
20
+ def initialize(parent, port, &block) #:nodoc:
21
+ super parent, &block
22
+ @port = port
23
+ end
24
+
25
+ protected
26
+
27
+ def install_commands #:nodoc:
28
+ "sh -c 'cd /usr/ports/#{@port} && make BATCH=yes install clean'"
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = Deb Package Installer
4
+ #
5
+ # The Deb installer installs deb packages sourced from a remote URL
6
+ #
7
+ # == Example Usage
8
+ #
9
+ # Installing the magic_beans deb.
10
+ #
11
+ # package :magic_beans do
12
+ # deb 'http://debs.example.com/magic_beans.deb'
13
+ # end
14
+ #
15
+ class Deb < Installer
16
+ attr_accessor :packages #:nodoc:
17
+
18
+ def initialize(parent, packages, &block) #:nodoc:
19
+ super parent, &block
20
+ packages = [packages] unless packages.is_a? Array
21
+ @packages = packages
22
+ end
23
+
24
+ protected
25
+
26
+ def install_commands #:nodoc:
27
+ "wget -cq --directory-prefix=/tmp #{@packages.join(' ')}; dpkg -i #{@packages.collect{|p| "/tmp/#{package_name(p)}"}.join(" ")}"
28
+ end
29
+
30
+ private
31
+
32
+ def package_name(url)
33
+ url.split('/').last
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,37 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = FreeBSD Package Installer
4
+ #
5
+ # The Pkg package installer installs FreeBSD packages.
6
+ #
7
+ # == Example Usage
8
+ #
9
+ # Installing the magic_beans package.
10
+ #
11
+ # package :magic_beans do
12
+ # freebsd_pkg 'magic_beans'
13
+ # end
14
+ #
15
+ # You may also specify multiple packages as an array:
16
+ #
17
+ # package :magic_beans do
18
+ # freebsd_pkg %w(magic_beans magic_sauce)
19
+ # end
20
+ class FreebsdPkg < Installer
21
+ attr_accessor :packages #:nodoc:
22
+
23
+ def initialize(parent, packages, &block) #:nodoc:
24
+ super parent, &block
25
+ packages = [packages] unless packages.is_a? Array
26
+ @packages = packages
27
+ end
28
+
29
+ protected
30
+
31
+ def install_commands #:nodoc:
32
+ "pkg_add -r #{@packages.join(' ')}"
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = FreeBSD Portinstall Installer
4
+ #
5
+ # The Portinstall installer installs FreeBSD ports.
6
+ # It uses the ports-mgmt/portupgrade port to install.
7
+ # Before usage, the ports system must be installed and
8
+ # read on the target operating system.
9
+ # It is recommended to use `portsnap fetch extract` to
10
+ # install the ports system.
11
+ #
12
+ # == Example Usage
13
+ #
14
+ # Installing the magic_beans port.
15
+ #
16
+ # package :magic_beans do
17
+ # freebsd_portinstall 'magic/magic_beans'
18
+ # end
19
+ #
20
+ class FreebsdPortinstall < Installer
21
+ attr_accessor :port #:nodoc:
22
+
23
+ def initialize(parent, port, &block) #:nodoc:
24
+ super parent, &block
25
+ @port = port
26
+ end
27
+
28
+ protected
29
+
30
+ def install_commands #:nodoc:
31
+ "portinstall --batch #{@port}"
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,64 @@
1
+ module Sprinkle
2
+ module Installers
3
+ # = Ruby Gem Package Installer
4
+ #
5
+ # The gem package installer installs ruby gems.
6
+ #
7
+ # The installer has a single optional configuration: source.
8
+ # By changing source you can specify a given ruby gems
9
+ # repository from which to install.
10
+ #
11
+ # == Example Usage
12
+ #
13
+ # First, a simple installation of the magic_beans gem:
14
+ #
15
+ # package :magic_beans do
16
+ # description "Beans beans they're good for your heart..."
17
+ # gem 'magic_beans'
18
+ # end
19
+ #
20
+ # Second, install magic_beans gem from github:
21
+ #
22
+ # package :magic_beans do
23
+ # gem 'magic_beans_package' do
24
+ # source 'http://gems.github.com'
25
+ # end
26
+ # end
27
+ #
28
+ # As you can see, setting options is as simple as creating a
29
+ # block and calling the option as a method with the value as
30
+ # its parameter.
31
+ class Gem < Installer
32
+ attr_accessor :gem #:nodoc:
33
+
34
+ def initialize(parent, gem, options = {}, &block) #:nodoc:
35
+ super parent, options, &block
36
+ @gem = gem
37
+ end
38
+
39
+ def source(location = nil) #:nodoc:
40
+ # package defines an installer called source so here we specify a method directly
41
+ # rather than rely on the automatic options processing since packages' method missing
42
+ # won't be run
43
+ return @options[:source] unless location
44
+ @options[:source] = location
45
+ end
46
+
47
+ protected
48
+
49
+ # rubygems 0.9.5+ installs dependencies by default, and does platform selection
50
+
51
+ def install_commands #:nodoc:
52
+ cmd = "gem install #{gem}"
53
+ cmd << " --version '#{version}'" if version
54
+ cmd << " --source #{source}" if source
55
+ cmd << " --install-dir #{repository}" if option?(:repository)
56
+ cmd << " --no-rdoc --no-ri" unless option?(:build_docs)
57
+ cmd << " --http-proxy #{http_proxy}" if option?(:http_proxy)
58
+ cmd << " -- #{build_flags}" if option?(:build_flags)
59
+ cmd
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,79 @@
1
+ module Sprinkle
2
+ module Installers
3
+ class InstallPackage < Installer
4
+ cattr_accessor :installer
5
+ attr_accessor :packages #:nodoc:
6
+
7
+ def initialize(parent, packages, &block) #:nodoc:
8
+ super parent, &block
9
+ if packages.is_a?(Array) && packages.first.is_a?(Array)
10
+ packages = packages.first
11
+ else
12
+ packages = [packages] unless packages.is_a? Array
13
+ end
14
+
15
+ @packages = packages
16
+ end
17
+
18
+ protected
19
+
20
+ def install_commands #:nodoc:
21
+ case installer
22
+ when :smart
23
+ "smart install #{@packages.join(' ')} -y 2>&1 | tee -a /var/log/smart-sprinkle"
24
+ when :yum
25
+ "yum install #{@packages.join(' ')} -y 2>&1 | tee -a /var/log/yum-sprinkle"
26
+ else
27
+ raise "Unknown InstallPackage.installer"
28
+ end
29
+ end
30
+ end
31
+
32
+ class UninstallPackage < Installer
33
+ attr_accessor :packages #:nodoc:
34
+
35
+ def initialize(parent, packages, &block) #:nodoc:
36
+ super parent, &block
37
+ if packages.is_a?(Array) && packages.first.is_a?(Array)
38
+ packages = packages.first
39
+ else
40
+ packages = [packages] unless packages.is_a? Array
41
+ end
42
+
43
+ @packages = packages
44
+ end
45
+
46
+ protected
47
+
48
+ def install_commands #:nodoc:
49
+ case Sprinkle::Installers::InstallPackage.installer
50
+ when :smart
51
+ "smart remove #{@packages.join(' ')} -y 2>&1 | tee -a /var/log/smart-sprinkle"
52
+ when :yum
53
+ "yum erase #{@packages.join(' ')} -y 2>&1 | tee -a /var/log/yum-sprinkle"
54
+ else
55
+ raise "Unknown InstallPackage.installer"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ module Sprinkle
63
+ module Package
64
+ class Package
65
+ def install_package(*names, &block)
66
+ @installers << Sprinkle::Installers::InstallPackage.new(self, names, &block)
67
+ end
68
+
69
+ def uninstall_package(*names, &block)
70
+ @installers << Sprinkle::Installers::UninstallPackage.new(self, names, &block)
71
+ end
72
+
73
+
74
+ alias_method :install_packages, :install_package
75
+ alias_method :uninstall_packages, :uninstall_package
76
+ end
77
+ end
78
+ end
79
+