jemmyw-sprinkle 0.2.3

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.
Files changed (105) hide show
  1. data/CREDITS +21 -0
  2. data/History.txt +4 -0
  3. data/MIT-LICENSE +20 -0
  4. data/Manifest.txt +104 -0
  5. data/README.txt +241 -0
  6. data/Rakefile +4 -0
  7. data/bin/sprinkle +86 -0
  8. data/config/hoe.rb +70 -0
  9. data/config/requirements.rb +17 -0
  10. data/examples/packages/build_essential.rb +9 -0
  11. data/examples/packages/databases/mysql.rb +13 -0
  12. data/examples/packages/databases/sqlite3.rb +16 -0
  13. data/examples/packages/phusion.rb +55 -0
  14. data/examples/packages/ruby/rails.rb +9 -0
  15. data/examples/packages/ruby/ruby.rb +17 -0
  16. data/examples/packages/ruby/rubygems.rb +17 -0
  17. data/examples/packages/scm/git.rb +11 -0
  18. data/examples/packages/scm/subversion.rb +4 -0
  19. data/examples/packages/servers/apache.rb +15 -0
  20. data/examples/rails/README +15 -0
  21. data/examples/rails/deploy.rb +2 -0
  22. data/examples/rails/packages/database.rb +9 -0
  23. data/examples/rails/packages/essential.rb +9 -0
  24. data/examples/rails/packages/rails.rb +28 -0
  25. data/examples/rails/packages/scm.rb +11 -0
  26. data/examples/rails/packages/search.rb +11 -0
  27. data/examples/rails/packages/server.rb +28 -0
  28. data/examples/rails/rails.rb +73 -0
  29. data/examples/sprinkle/sprinkle.rb +38 -0
  30. data/lib/sprinkle/actors/actors.rb +17 -0
  31. data/lib/sprinkle/actors/capistrano.rb +147 -0
  32. data/lib/sprinkle/actors/local.rb +50 -0
  33. data/lib/sprinkle/actors/ssh.rb +81 -0
  34. data/lib/sprinkle/actors/vlad.rb +65 -0
  35. data/lib/sprinkle/configurable.rb +31 -0
  36. data/lib/sprinkle/deployment.rb +77 -0
  37. data/lib/sprinkle/extensions/arbitrary_options.rb +10 -0
  38. data/lib/sprinkle/extensions/array.rb +5 -0
  39. data/lib/sprinkle/extensions/blank_slate.rb +5 -0
  40. data/lib/sprinkle/extensions/dsl_accessor.rb +15 -0
  41. data/lib/sprinkle/extensions/string.rb +10 -0
  42. data/lib/sprinkle/extensions/symbol.rb +7 -0
  43. data/lib/sprinkle/installers/apt.rb +52 -0
  44. data/lib/sprinkle/installers/bsd_port.rb +33 -0
  45. data/lib/sprinkle/installers/custom.rb +28 -0
  46. data/lib/sprinkle/installers/deb.rb +38 -0
  47. data/lib/sprinkle/installers/freebsd_pkg.rb +37 -0
  48. data/lib/sprinkle/installers/gem.rb +63 -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/openbsd_pkg.rb +47 -0
  52. data/lib/sprinkle/installers/opensolaris_pkg.rb +43 -0
  53. data/lib/sprinkle/installers/push_text.rb +45 -0
  54. data/lib/sprinkle/installers/rake.rb +37 -0
  55. data/lib/sprinkle/installers/rpm.rb +37 -0
  56. data/lib/sprinkle/installers/source.rb +179 -0
  57. data/lib/sprinkle/installers/yum.rb +37 -0
  58. data/lib/sprinkle/package.rb +293 -0
  59. data/lib/sprinkle/policy.rb +126 -0
  60. data/lib/sprinkle/script.rb +23 -0
  61. data/lib/sprinkle/verifiers/directory.rb +16 -0
  62. data/lib/sprinkle/verifiers/dpkg.rb +14 -0
  63. data/lib/sprinkle/verifiers/executable.rb +36 -0
  64. data/lib/sprinkle/verifiers/file.rb +26 -0
  65. data/lib/sprinkle/verifiers/process.rb +21 -0
  66. data/lib/sprinkle/verifiers/ruby.rb +25 -0
  67. data/lib/sprinkle/verifiers/symlink.rb +30 -0
  68. data/lib/sprinkle/verifiers/user.rb +11 -0
  69. data/lib/sprinkle/verify.rb +114 -0
  70. data/lib/sprinkle/version.rb +9 -0
  71. data/lib/sprinkle.rb +32 -0
  72. data/script/destroy +14 -0
  73. data/script/generate +14 -0
  74. data/spec/spec.opts +1 -0
  75. data/spec/spec_helper.rb +17 -0
  76. data/spec/sprinkle/actors/capistrano_spec.rb +194 -0
  77. data/spec/sprinkle/actors/local_spec.rb +29 -0
  78. data/spec/sprinkle/configurable_spec.rb +46 -0
  79. data/spec/sprinkle/deployment_spec.rb +80 -0
  80. data/spec/sprinkle/extensions/array_spec.rb +19 -0
  81. data/spec/sprinkle/extensions/string_spec.rb +21 -0
  82. data/spec/sprinkle/installers/apt_spec.rb +70 -0
  83. data/spec/sprinkle/installers/bsd_port_spec.rb +42 -0
  84. data/spec/sprinkle/installers/custom_spec.rb +29 -0
  85. data/spec/sprinkle/installers/freebsd_pkg_spec.rb +49 -0
  86. data/spec/sprinkle/installers/gem_spec.rb +91 -0
  87. data/spec/sprinkle/installers/installer_spec.rb +151 -0
  88. data/spec/sprinkle/installers/mac_port_spec.rb +42 -0
  89. data/spec/sprinkle/installers/openbsd_pkg_spec.rb +49 -0
  90. data/spec/sprinkle/installers/opensolaris_pkg_spec.rb +49 -0
  91. data/spec/sprinkle/installers/push_text_spec.rb +55 -0
  92. data/spec/sprinkle/installers/rake_spec.rb +29 -0
  93. data/spec/sprinkle/installers/rpm_spec.rb +50 -0
  94. data/spec/sprinkle/installers/source_spec.rb +331 -0
  95. data/spec/sprinkle/installers/yum_spec.rb +49 -0
  96. data/spec/sprinkle/package_spec.rb +452 -0
  97. data/spec/sprinkle/policy_spec.rb +133 -0
  98. data/spec/sprinkle/script_spec.rb +51 -0
  99. data/spec/sprinkle/sprinkle_spec.rb +25 -0
  100. data/spec/sprinkle/verify_spec.rb +185 -0
  101. data/sprinkle.gemspec +45 -0
  102. data/tasks/deployment.rake +34 -0
  103. data/tasks/environment.rake +7 -0
  104. data/tasks/rspec.rake +21 -0
  105. metadata +199 -0
@@ -0,0 +1,9 @@
1
+ package :rails do
2
+ description 'Ruby on Rails'
3
+ gem 'rails'
4
+ version '2.1.0'
5
+
6
+ verify do
7
+ has_executable 'rails'
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ package :ruby do
2
+ description 'Ruby Virtual Machine'
3
+ version '1.8.6'
4
+ apt %q(ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby) do
5
+ post :install, [%q(ln -s /usr/bin/ruby1.8 /usr/bin/ruby),
6
+ %q(ln -s /usr/bin/ri1.8 /usr/bin/ri),
7
+ %q(ln -s /usr/bin/rdoc1.8 /usr/bin/rdoc),
8
+ %q(ln -s /usr/bin/irb1.8 /usr/bin/irb)]
9
+ end
10
+
11
+ verify 'binaries' do
12
+ has_file '/usr/bin/ruby1.8'
13
+ has_file '/usr/bin/ri1.8'
14
+ has_file '/usr/bin/rdoc1.8'
15
+ has_file '/usr/bin/irb1.8'
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ package :rubygems do
2
+ description 'Ruby Gems Package Management System'
3
+ version '1.2.0'
4
+ source "http://rubyforge.org/frs/download.php/38646/rubygems-#{version}.tgz" do
5
+ custom_install 'ruby setup.rb'
6
+ post :install, 'ln -s /usr/bin/gem1.8 /usr/bin/gem'
7
+ post :install, 'gem update'
8
+ post :install, 'gem update --system'
9
+ end
10
+
11
+ verify 'binary' do
12
+ has_file '/usr/bin/gem1.8'
13
+ has_symlink '/usr/bin/gem', '/usr/bin/gem1.8'
14
+ end
15
+
16
+ requires :ruby
17
+ end
@@ -0,0 +1,11 @@
1
+ package :git, :provides => :scm do
2
+ description 'Git Distributed Version Control'
3
+ version '1.5.6.3'
4
+ source "http://kernel.org/pub/software/scm/git/git-#{version}.tar.gz"
5
+ requires :git_dependencies
6
+ end
7
+
8
+ package :git_dependencies do
9
+ description 'Git Build Dependencies'
10
+ apt 'git', :dependencies_only => true
11
+ end
@@ -0,0 +1,4 @@
1
+ package :subversion, :provides => :scm do
2
+ description 'Subversion Version Control'
3
+ apt 'subversion'
4
+ end
@@ -0,0 +1,15 @@
1
+ package :apache, :provides => :webserver do
2
+ description 'Apache2 web server.'
3
+ apt 'apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert' do
4
+ post :install, 'a2enmod rewrite'
5
+ end
6
+
7
+ verify do
8
+ has_process 'apache2'
9
+ end
10
+ end
11
+
12
+ package :apache2_prefork_dev do
13
+ description 'A dependency required by some packages.'
14
+ apt 'apache2-prefork-dev'
15
+ end
@@ -0,0 +1,15 @@
1
+ = Example Rails Spinkle Deployment Script
2
+
3
+ The following example shows how you can provision Rails and associated packages onto a remote server (or set of servers).
4
+
5
+ == Usage:
6
+
7
+ $> sprinkle -s rails.rb
8
+
9
+ or in test mode:
10
+
11
+ $> sprinkle -t -s rails.rb
12
+
13
+ == Information
14
+
15
+ For more information, please see: http://github.com/crafterm/sprinkle/tree/master/README.txt
@@ -0,0 +1,2 @@
1
+ set :user, 'root'
2
+ role :app, 'yourhost.com', :primary => true
@@ -0,0 +1,9 @@
1
+ package :mysql, :provides => :database do
2
+ description 'MySQL Database'
3
+ apt %w( mysql-server mysql-client )
4
+ end
5
+
6
+ package :mysql_driver do
7
+ description 'Ruby MySQL database driver'
8
+ gem 'mysql'
9
+ end
@@ -0,0 +1,9 @@
1
+ ## Special package, anything that defines a 'source' package means build-essential should be installed for Ubuntu
2
+
3
+ package :build_essential do
4
+ description 'Build tools'
5
+ apt 'build-essential' do
6
+ # Update the sources and upgrade the lists before we build essentials
7
+ pre :install, 'apt-get update'
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ ## Defines available packages
2
+
3
+ package :ruby do
4
+ description 'Ruby Virtual Machine'
5
+ version '1.8.6'
6
+ source "ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-#{version}-p111.tar.gz" # implicit :style => :gnu
7
+ requires :ruby_dependencies
8
+ end
9
+
10
+ package :ruby_dependencies do
11
+ description 'Ruby Virtual Machine Build Dependencies'
12
+ apt %w( bison zlib1g-dev libssl-dev libreadline5-dev libncurses5-dev file )
13
+ end
14
+
15
+ package :rubygems do
16
+ description 'Ruby Gems Package Management System'
17
+ version '1.2.0'
18
+ source "http://rubyforge.org/frs/download.php/38646/rubygems-#{version}.tgz" do
19
+ custom_install 'ruby setup.rb'
20
+ end
21
+ requires :ruby
22
+ end
23
+
24
+ package :rails do
25
+ description 'Ruby on Rails'
26
+ gem 'rails'
27
+ version '2.1.0'
28
+ end
@@ -0,0 +1,11 @@
1
+ package :git, :provides => :scm do
2
+ description 'Git Distributed Version Control'
3
+ version '1.5.6.3'
4
+ source "http://kernel.org/pub/software/scm/git/git-#{version}.tar.gz"
5
+ requires :git_dependencies
6
+ end
7
+
8
+ package :git_dependencies do
9
+ description 'Git Build Dependencies'
10
+ apt 'git', :dependencies_only => true
11
+ end
@@ -0,0 +1,11 @@
1
+ package :sphinx, :provides => :search do
2
+ description 'MySQL full text search engine'
3
+ version '0.9.8-rc2'
4
+ source "http://www.sphinxsearch.com/downloads/sphinx-#{version}.tar.gz"
5
+ requires :mysql_dev
6
+ end
7
+
8
+ package :mysql_dev do
9
+ description 'MySQL Database development package'
10
+ apt %w( libmysqlclient15-dev )
11
+ end
@@ -0,0 +1,28 @@
1
+ package :mongrel do
2
+ description 'Mongrel Application Server'
3
+ gem 'mongrel'
4
+ version '1.1.4'
5
+ end
6
+
7
+ package :mongrel_cluster, :provides => :appserver do
8
+ description 'Cluster Management for Mongrel'
9
+ gem 'mongrel_cluster'
10
+ version '1.0.5'
11
+ requires :mongrel
12
+ end
13
+
14
+ package :apache, :provides => :webserver do
15
+ description 'Apache 2 HTTP Server'
16
+ version '2.2.9'
17
+ source "http://www.apache.org/dist/httpd/httpd-#{version}.tar.bz2" do
18
+ enable %w( mods-shared=all proxy proxy-balancer proxy-http rewrite cache headers ssl deflate so )
19
+ prefix "/opt/local/apache2-#{version}"
20
+ post :install, 'install -m 755 support/apachectl /etc/init.d/apache2', 'update-rc.d -f apache2 defaults'
21
+ end
22
+ requires :apache_dependencies
23
+ end
24
+
25
+ package :apache_dependencies do
26
+ description 'Apache 2 HTTP Server Build Dependencies'
27
+ apt %w( openssl libtool mawk zlib1g-dev libssl-dev )
28
+ end
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env sprinkle -s
2
+
3
+ # Annotated Example Sprinkle Rails deployment script
4
+ #
5
+ # This is an example Sprinkle script configured to install Rails from gems, Apache, Ruby,
6
+ # Sphinx and Git from source, and mysql and Git dependencies from apt on an Ubuntu system.
7
+ #
8
+ # Installation is configured to run via capistrano (and an accompanying deploy.rb recipe script).
9
+ # Source based packages are downloaded and built into /usr/local on the remote system.
10
+ #
11
+ # A sprinkle script is separated into 3 different sections. Packages, policies and deployment:
12
+
13
+
14
+ # Packages (separate files for brevity)
15
+ #
16
+ # Defines the world of packages as we know it. Each package has a name and
17
+ # set of metadata including its installer type (eg. apt, source, gem, etc). Packages can have
18
+ # relationships to each other via dependencies.
19
+
20
+ require 'packages/essential'
21
+ require 'packages/rails'
22
+ require 'packages/database'
23
+ require 'packages/server'
24
+ require 'packages/search'
25
+ require 'packages/scm'
26
+
27
+
28
+ # Policies
29
+ #
30
+ # Names a group of packages (optionally with versions) that apply to a particular set of roles:
31
+ #
32
+ # Associates the rails policy to the application servers. Contains rails, and surrounding
33
+ # packages. Note, appserver, database, webserver and search are all virtual packages defined above.
34
+ # If there's only one implementation of a virtual package, it's selected automatically, otherwise
35
+ # the user is requested to select which one to use.
36
+
37
+ policy :rails, :roles => :app do
38
+ requires :rails, :version => '2.1.0'
39
+ requires :appserver
40
+ requires :database
41
+ requires :webserver
42
+ requires :search
43
+ requires :scm
44
+ end
45
+
46
+
47
+ # Deployment
48
+ #
49
+ # Defines script wide settings such as a delivery mechanism for executing commands on the target
50
+ # system (eg. capistrano), and installer defaults (eg. build locations, etc):
51
+ #
52
+ # Configures spinkle to use capistrano for delivery of commands to the remote machines (via
53
+ # the named 'deploy' recipe). Also configures 'source' installer defaults to put package gear
54
+ # in /usr/local
55
+
56
+ deployment do
57
+
58
+ # mechanism for deployment
59
+ delivery :capistrano do
60
+ recipes 'deploy'
61
+ end
62
+
63
+ # source based package installer defaults
64
+ source do
65
+ prefix '/usr/local'
66
+ archives '/usr/local/sources'
67
+ builds '/usr/local/build'
68
+ end
69
+
70
+ end
71
+
72
+ # End of script, given the above information, Spinkle will apply the defined policy on all roles using the
73
+ # deployment settings specified.
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env sprinkle -c -s
2
+
3
+ # Example of the simplest Sprinkle script to install a single gem on a remote host. This
4
+ # particular script assumes that rubygems (and ruby, etc) are already installed on the remote
5
+ # host. To see a larger example of installing an entire ruby, rubygems, gem stack from source,
6
+ # please see the rails example.
7
+
8
+ # Packages, only sprinkle is defined in this world
9
+
10
+ package :sprinkle do
11
+ description 'Sprinkle Provisioning Tool'
12
+ gem 'crafterm-sprinkle' do
13
+ source 'http://gems.github.com' # use alternate gem server
14
+ #repository '/opt/local/gems' # specify an alternate local gem repository
15
+ end
16
+ end
17
+
18
+
19
+ # Policies, sprinkle policy requires only the sprinkle gem
20
+
21
+ policy :sprinkle, :roles => :app do
22
+ requires :sprinkle
23
+ end
24
+
25
+
26
+ # Deployment settings
27
+
28
+ deployment do
29
+
30
+ # use vlad for deployment
31
+ delivery :vlad do
32
+ role :app, 'yourhost.com'
33
+ end
34
+
35
+ end
36
+
37
+ # End of script, given the above information, Spinkle will apply the defined policy on all roles using the
38
+ # deployment settings specified.
@@ -0,0 +1,17 @@
1
+ #--
2
+ # The only point of this file is to give RDoc a definition for
3
+ # Sprinkle::Actors. This file in production is never actually included
4
+ # since ActiveSupport only on-demand loads classes which are needed
5
+ # and this module is never explicitly needed.
6
+ #++
7
+
8
+ module Sprinkle
9
+ # An actor is a method of command delivery to a remote machine. It is the
10
+ # layer between sprinkle and the SSH connection to run commands. This gives
11
+ # you the flexibility to define custom actors, for whatever purpose you need.
12
+ #
13
+ # 99% of the time, however, the two built-in actors Sprinkle::Actors::Capistrano
14
+ # and Sprinkle::Actors::Vlad will be enough.
15
+ module Actors
16
+ end
17
+ end
@@ -0,0 +1,147 @@
1
+ require 'capistrano/cli'
2
+
3
+ module Sprinkle
4
+ module Actors
5
+ # = Capistrano Delivery Method
6
+ #
7
+ # Capistrano is one of the delivery method options available out of the
8
+ # box with Sprinkle. If you have the capistrano gem install, you may use
9
+ # this delivery. The only configuration option available, and which is
10
+ # mandatory to include is +recipes+. An example:
11
+ #
12
+ # deployment do
13
+ # delivery :capistrano do
14
+ # recipes 'deploy'
15
+ # end
16
+ # end
17
+ #
18
+ # Recipes is given a list of files which capistrano will include and load.
19
+ # These recipes are mainly to set variables such as :user, :password, and to
20
+ # set the app domain which will be sprinkled.
21
+ class Capistrano
22
+ attr_accessor :config, :loaded_recipes #:nodoc:
23
+
24
+ def initialize(&block) #:nodoc:
25
+ @config = ::Capistrano::Configuration.new
26
+ @config.logger.level = Sprinkle::OPTIONS[:verbose] ? ::Capistrano::Logger::INFO : ::Capistrano::Logger::IMPORTANT
27
+ @config.set(:password) { ::Capistrano::CLI.password_prompt }
28
+ @name_counters = Hash.new { |h, v| h[v] = 0 }
29
+
30
+ if block
31
+ self.instance_eval(&block)
32
+ else
33
+ @config.load 'deploy' # normally in the config directory for rails
34
+ end
35
+ end
36
+
37
+ # Defines a recipe file which will be included by capistrano. Use these
38
+ # recipe files to set capistrano specific configurations. Default recipe
39
+ # included is "deploy." But if any other recipe is specified, it will
40
+ # include that instead. Multiple recipes may be specified through multiple
41
+ # recipes calls, an example:
42
+ #
43
+ # deployment do
44
+ # delivery :capistrano do
45
+ # recipes 'deploy'
46
+ # recipes 'magic_beans'
47
+ # end
48
+ # end
49
+ def recipes(script)
50
+ @loaded_recipes ||= []
51
+ @config.load script
52
+ @loaded_recipes << script
53
+ end
54
+
55
+ def find_servers(roles)
56
+ @config.find_servers(:roles => roles).collect(&:host)
57
+ end
58
+
59
+ def process(name, commands, server, suppress_and_return_failures = false) #:nodoc:
60
+ task = task_sym(name)
61
+
62
+ define_task(task, server) do
63
+ via = fetch(:run_method, :sudo)
64
+ commands.each do |command|
65
+ invoke_command command, :via => via
66
+ end
67
+ end
68
+
69
+ begin
70
+ run(task)
71
+
72
+ return true
73
+ rescue ::Capistrano::CommandError => e
74
+ return false if suppress_and_return_failures
75
+
76
+ # Reraise error if we're not suppressing it
77
+ raise
78
+ end
79
+ end
80
+
81
+ def put(name, uploads, roles, suppress_and_return_failures = false) #:nodoc:
82
+ task = task_sym(name)
83
+
84
+ define_task(task, roles) do
85
+ uploads.each do |file, upload|
86
+ put upload[:content], file, upload[:options]
87
+ end
88
+ end
89
+
90
+ begin
91
+ run(task)
92
+
93
+ return true
94
+ rescue ::Capistrano::CommandError => e
95
+ return false if suppress_and_return_failures
96
+
97
+ # Reraise error if we're not suppressing it
98
+ raise
99
+ end
100
+ end
101
+
102
+ private
103
+
104
+ # REVISIT: can we set the description somehow?
105
+ def define_task(name, server, &block)
106
+ @config.task name, :hosts => server, &block
107
+ end
108
+
109
+ def run(name)
110
+ @config.find_and_execute_task(name)
111
+ end
112
+
113
+ def task_sym(name)
114
+ "install_#{name.to_task_name}_#{@name_counters[name] += 1}".to_sym
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+
121
+ =begin
122
+
123
+ # channel: the SSH channel object used for this response
124
+ # stream: either :err or :out, for stderr or stdout responses
125
+ # output: the text that the server is sending, might be in chunks
126
+ run "apt-get update" do |channel, stream, output|
127
+ if output =~ /Are you sure?/
128
+ answer = Capistrano::CLI.ui.ask("Are you sure: ")
129
+ channel.send_data(answer + "\n")
130
+ else
131
+ # allow the default callback to be processed
132
+ Capistrano::Configuration.default_io_proc.call[channel, stream, output]
133
+ end
134
+ end
135
+
136
+
137
+
138
+ You can tell subversion to use a different username+password by
139
+ setting a couple variables:
140
+ set :svn_username, "my svn username"
141
+ set :svn_password, "my svn password"
142
+ If you don't want to set the password explicitly in your recipe like
143
+ that, you can make capistrano prompt you for it like this:
144
+ set(:svn_password) { Capistrano::CLI.password_prompt("Subversion
145
+ password: ") }
146
+ - Jamis
147
+ =end
@@ -0,0 +1,50 @@
1
+ module Sprinkle
2
+ module Actors
3
+ # = Local Delivery Method
4
+ #
5
+ # This actor implementation performs any given commands on your local system, as
6
+ # opposed to other implementations that generally run commands on a remote system
7
+ # via the network.
8
+ #
9
+ # This is useful if you'd like to use Sprinkle to provision your local machine.
10
+ # To enable this actor, in your Sprinkle script specify the :local delivery mechanism.
11
+ #
12
+ # deployment do
13
+ # delivery :local
14
+ # end
15
+ #
16
+ # Note, your local machine will be assumed to be a member of all roles when applying policies
17
+ #
18
+ class Local
19
+
20
+ def process(name, commands, roles, suppress_and_return_failures = false) #:nodoc:
21
+ commands.each do |command|
22
+ system command
23
+ return false if $?.to_i != 0
24
+ end
25
+ return true
26
+ end
27
+
28
+ def put(name, uploads, roles, suppress_and_return_failures = false)
29
+ uploads.each do |file, content|
30
+ retried = false
31
+ begin
32
+ File.open(file, "w+") { |fp| fp << content }
33
+ rescue Errno::ENOENT
34
+ FileUtils.mkdir_p(File.dirname(file))
35
+ if retried == false
36
+ retried = true
37
+ retry
38
+ end
39
+ end
40
+ end
41
+
42
+ return true
43
+ end
44
+
45
+ def find_servers(role)
46
+ ['localhost']
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,81 @@
1
+ require 'net/ssh/gateway'
2
+
3
+ module Sprinkle
4
+ module Actors
5
+ class Ssh
6
+ attr_accessor :options
7
+
8
+ def initialize(options = {}, &block) #:nodoc:
9
+ @options = options.update(:user => 'root')
10
+ self.instance_eval &block if block
11
+ end
12
+
13
+ def roles(roles)
14
+ @options[:roles] = roles
15
+ end
16
+
17
+ def gateway(gateway)
18
+ @options[:gateway] = gateway
19
+ end
20
+
21
+ def user(user)
22
+ @options[:user] = user
23
+ end
24
+
25
+ def process(name, commands, roles, suppress_and_return_failures = false)
26
+ return process_with_gateway(name, commands, roles) if gateway_defined?
27
+ process_direct(name, commands, roles)
28
+ end
29
+
30
+ protected
31
+
32
+ def process_with_gateway(name, commands, roles)
33
+ on_gateway do |gateway|
34
+ Array(roles).each { |role| execute_on_role(commands, role, gateway) }
35
+ end
36
+ end
37
+
38
+ def process_direct(name, commands, roles)
39
+ Array(roles).each { |role| execute_on_role(commands, role) }
40
+ end
41
+
42
+ def execute_on_role(commands, role, gateway = nil)
43
+ hosts = @options[:roles][role]
44
+ Array(hosts).each { |host| execute_on_host(commands, host, gateway) }
45
+ end
46
+
47
+ def execute_on_host(commands, host, gateway = nil)
48
+ if gateway # SSH connection via gateway
49
+ gateway.ssh(host, @options[:user]) do |ssh|
50
+ execute_on_connection(commands, ssh)
51
+ end
52
+ else # direct SSH connection
53
+ Net::SSH.start(host, @options[:user]) do |ssh|
54
+ execute_on_connection(commands, ssh)
55
+ end
56
+ end
57
+ end
58
+
59
+ def execute_on_connection(commands, connection)
60
+ Array(commands).each do |command|
61
+ connection.exec! command do |ch, stream, data|
62
+ logger.send((stream == :stderr ? 'error' : 'debug'), data)
63
+ end
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def gateway_defined?
70
+ !! @options[:gateway]
71
+ end
72
+
73
+ def on_gateway(&block)
74
+ gateway = Net::SSH::Gateway.new(@options[:gateway], @options[:user])
75
+ block.call gateway
76
+ ensure
77
+ gateway.shutdown!
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,65 @@
1
+ module Sprinkle
2
+ module Actors
3
+ # = Vlad Delivery Method
4
+ #
5
+ # Vlad is one of the delivery method options available out of the
6
+ # box with Sprinkle. If you have the vlad the deployer gem install, you
7
+ # may use this delivery. The only configuration option available, and
8
+ # which is mandatory to include is +script+. An example:
9
+ #
10
+ # deployment do
11
+ # delivery :vlad do
12
+ # script 'deploy'
13
+ # end
14
+ # end
15
+ #
16
+ # script is given a list of files which capistrano will include and load.
17
+ # These recipes are mainly to set variables such as :user, :password, and to
18
+ # set the app domain which will be sprinkled.
19
+ class Vlad
20
+ require 'vlad'
21
+ attr_accessor :loaded_recipes #:nodoc:
22
+
23
+ def initialize(&block) #:nodoc:
24
+ self.instance_eval &block if block
25
+ end
26
+
27
+ # Defines a script file which will be included by vlad. Use these
28
+ # script files to set vlad specific configurations. Multiple scripts
29
+ # may be specified through multiple script calls, an example:
30
+ #
31
+ # deployment do
32
+ # delivery :vlad do
33
+ # script 'deploy'
34
+ # script 'magic_beans'
35
+ # end
36
+ # end
37
+ def script(name)
38
+ @loaded_recipes ||= []
39
+ self.load name
40
+ @loaded_recipes << script
41
+ end
42
+
43
+ def process(name, commands, roles, suppress_and_return_failures = false) #:nodoc:
44
+ commands = commands.join ' && ' if commands.is_a? Array
45
+ t = remote_task(task_sym(name), :roles => roles) { run commands }
46
+
47
+ begin
48
+ t.invoke
49
+ return true
50
+ rescue ::Vlad::CommandFailedError => e
51
+ return false if suppress_and_return_failures
52
+
53
+ # Reraise error if we're not suppressing it
54
+ raise
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def task_sym(name)
61
+ "install_#{name.to_task_name}".to_sym
62
+ end
63
+ end
64
+ end
65
+ end