sprinkle 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +18 -14
- data/Gemfile.lock +11 -11
- data/lib/sprinkle.rb +19 -9
- data/lib/sprinkle/actors/capistrano.rb +2 -1
- data/lib/sprinkle/actors/dummy.rb +3 -3
- data/lib/sprinkle/actors/local.rb +7 -9
- data/lib/sprinkle/actors/ssh.rb +5 -5
- data/lib/sprinkle/deployment.rb +2 -1
- data/lib/sprinkle/extensions/sudo.rb +8 -4
- data/lib/sprinkle/installers/installer.rb +48 -37
- data/lib/sprinkle/installers/npm.rb +31 -30
- data/lib/sprinkle/installers/source.rb +6 -6
- data/lib/sprinkle/installers/user.rb +7 -6
- data/lib/sprinkle/package.rb +55 -51
- data/lib/sprinkle/package/chooser.rb +5 -4
- data/lib/sprinkle/package/rendering.rb +2 -2
- data/lib/sprinkle/policy.rb +13 -13
- data/lib/sprinkle/script.rb +5 -1
- data/lib/sprinkle/verify.rb +1 -0
- data/lib/sprinkle/version.rb +1 -1
- data/spec/spec_helper.rb +13 -7
- data/spec/sprinkle/actors/capistrano_spec.rb +18 -18
- data/spec/sprinkle/actors/local_spec.rb +3 -3
- data/spec/sprinkle/deployment_spec.rb +3 -3
- data/spec/sprinkle/installers/apt_spec.rb +1 -1
- data/spec/sprinkle/installers/binary_spec.rb +1 -1
- data/spec/sprinkle/installers/brew_spec.rb +1 -1
- data/spec/sprinkle/installers/bsd_port_spec.rb +1 -1
- data/spec/sprinkle/installers/file_spec.rb +9 -9
- data/spec/sprinkle/installers/freebsd_pkg_spec.rb +1 -1
- data/spec/sprinkle/installers/freebsd_portinstall_spec.rb +1 -1
- data/spec/sprinkle/installers/gem_spec.rb +1 -1
- data/spec/sprinkle/installers/installer_spec.rb +62 -25
- data/spec/sprinkle/installers/mac_port_spec.rb +1 -1
- data/spec/sprinkle/installers/npm_spec.rb +1 -1
- data/spec/sprinkle/installers/openbsd_pkg_spec.rb +1 -1
- data/spec/sprinkle/installers/opensolaris_pkg_spec.rb +1 -1
- data/spec/sprinkle/installers/pear_spec.rb +1 -1
- data/spec/sprinkle/installers/push_text_spec.rb +12 -12
- data/spec/sprinkle/installers/rake_spec.rb +1 -1
- data/spec/sprinkle/installers/replace_text_spec.rb +10 -10
- data/spec/sprinkle/installers/rpm_spec.rb +1 -1
- data/spec/sprinkle/installers/runner_spec.rb +9 -9
- data/spec/sprinkle/installers/smart_spec.rb +1 -1
- data/spec/sprinkle/installers/source_spec.rb +22 -27
- data/spec/sprinkle/installers/thor_spec.rb +1 -1
- data/spec/sprinkle/installers/transfer_spec.rb +35 -35
- data/spec/sprinkle/installers/user_spec.rb +13 -7
- data/spec/sprinkle/installers/yum_spec.rb +1 -1
- data/spec/sprinkle/installers/zypper_spec.rb +1 -1
- data/spec/sprinkle/package/package_repository_spec.rb +7 -7
- data/spec/sprinkle/package_spec.rb +58 -58
- data/spec/sprinkle/policy_spec.rb +20 -20
- data/spec/sprinkle/script_spec.rb +1 -1
- data/spec/sprinkle/verify_spec.rb +2 -2
- metadata +2 -2
@@ -1,41 +1,42 @@
|
|
1
1
|
module Sprinkle
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
2
|
+
module Installers
|
3
|
+
# = Npm package Installed
|
4
|
+
#
|
5
|
+
# Installs an npm module
|
6
|
+
#
|
7
|
+
# == Example Usage
|
8
|
+
#
|
9
|
+
# package :magic_beans do
|
10
|
+
# npm 'grunt'
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# verify { has_npm 'grunt' }
|
14
|
+
class Npm < Installer
|
15
15
|
|
16
|
-
|
16
|
+
attr_accessor :package_name
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
api do
|
19
|
+
def npm(package, &block)
|
20
|
+
install Npm.new(self, package, &block)
|
22
21
|
end
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
24
|
+
verify_api do
|
25
|
+
def has_npm(package)
|
26
|
+
@commands << "npm --global list | grep \"#{package}@\""
|
28
27
|
end
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def initialize(parent, package_name, &block) #:nodoc:
|
31
|
+
super parent, &block
|
32
|
+
@package_name = package_name
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
37
|
+
def install_commands #:nodoc:
|
38
|
+
"npm install --global #{@package_name}"
|
39
|
+
end
|
39
40
|
|
40
41
|
end
|
41
42
|
end
|
@@ -88,7 +88,7 @@ module Sprinkle
|
|
88
88
|
|
89
89
|
class Source < Installer
|
90
90
|
attr_accessor :source #:nodoc:
|
91
|
-
|
91
|
+
|
92
92
|
api do
|
93
93
|
def source(source, options = {}, &block)
|
94
94
|
recommends :build_essential # Ubuntu/Debian
|
@@ -171,15 +171,15 @@ module Sprinkle
|
|
171
171
|
end
|
172
172
|
|
173
173
|
protected
|
174
|
-
|
174
|
+
|
175
175
|
def with_log(cmd, stage)
|
176
176
|
"#{cmd} > #{@package.name}-#{stage}.log 2>&1"
|
177
177
|
end
|
178
|
-
|
178
|
+
|
179
179
|
def in_build_dir(cmd)
|
180
180
|
"bash -c 'cd #{build_dir} && #{cmd}'"
|
181
181
|
end
|
182
|
-
|
182
|
+
|
183
183
|
def pre_commands(stage) #:nodoc:
|
184
184
|
dress @pre[stage] || [], :pre, stage
|
185
185
|
end
|
@@ -187,7 +187,7 @@ module Sprinkle
|
|
187
187
|
def post_commands(stage) #:nodoc:
|
188
188
|
dress @post[stage] || [], :post, stage
|
189
189
|
end
|
190
|
-
|
190
|
+
|
191
191
|
|
192
192
|
# dress is overriden from the base Sprinkle::Installers::Installer class so that the command changes
|
193
193
|
# directory to the build directory first. Also, the result of the command is logged.
|
@@ -195,7 +195,7 @@ module Sprinkle
|
|
195
195
|
chdir = "cd #{build_dir} && "
|
196
196
|
chdir = "" if [:prepare, :download].include?(stage)
|
197
197
|
chdir = "" if stage == :extract and pre_or_post == :pre
|
198
|
-
commands.collect { |command| "bash -c '#{chdir}#{command} >> #{@package.name}-#{stage}.log 2>&1'" }
|
198
|
+
flatten(commands).collect { |command| "bash -c '#{chdir}#{command} >> #{@package.name}-#{stage}.log 2>&1'" }
|
199
199
|
end
|
200
200
|
|
201
201
|
private
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Sprinkle
|
2
2
|
module Installers
|
3
3
|
# The user installer add users. You may pass :flags as an option.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# == Example Usage
|
6
6
|
#
|
7
7
|
# package :users do
|
@@ -12,13 +12,13 @@ module Sprinkle
|
|
12
12
|
# end
|
13
13
|
# end
|
14
14
|
class User < Installer
|
15
|
-
|
15
|
+
|
16
16
|
api do
|
17
17
|
def add_user(username, options={}, &block)
|
18
18
|
install User.new(self, username, options, &block)
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
verify_api do
|
23
23
|
def has_user(user, opts = {})
|
24
24
|
if opts[:in_group]
|
@@ -34,14 +34,15 @@ module Sprinkle
|
|
34
34
|
@username = username
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
protected
|
38
|
+
|
39
39
|
def install_commands #:nodoc:
|
40
40
|
noninteractive = " --gecos ,,,"
|
41
41
|
flags = @options[:flags] || ""
|
42
42
|
flags << noninteractive unless flags =~ /--gecos/
|
43
|
-
"adduser #{flags} #{@username}"
|
43
|
+
"#{sudo_cmd}adduser #{flags.strip} #{@username}"
|
44
44
|
end
|
45
|
+
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
data/lib/sprinkle/package.rb
CHANGED
@@ -20,7 +20,7 @@ module Sprinkle
|
|
20
20
|
# 'ruby' being availble. Pretty simple, right?
|
21
21
|
#
|
22
22
|
# <b>Note:</b> Defining a package does not INSTALL it. To install a
|
23
|
-
# package, you must require it in a Sprinkle::Policy block.
|
23
|
+
# package, you must require it in a Sprinkle::Policy block.
|
24
24
|
#
|
25
25
|
# == Pre-Requirements
|
26
26
|
#
|
@@ -53,11 +53,11 @@ module Sprinkle
|
|
53
53
|
#
|
54
54
|
# == Verifications
|
55
55
|
#
|
56
|
-
# Most of the time its important to know whether the software you're
|
56
|
+
# Most of the time its important to know whether the software you're
|
57
57
|
# attempting to install was installed successfully or not. For this,
|
58
58
|
# Sprinkle provides verifications. Verifications are one or more blocks
|
59
59
|
# which define rules with which Sprinkle can check if it installed
|
60
|
-
# the package successfully. If these verification blocks fail, then
|
60
|
+
# the package successfully. If these verification blocks fail, then
|
61
61
|
# Sprinkle will gracefully stop the entire process. An example below:
|
62
62
|
#
|
63
63
|
# package :rubygems do
|
@@ -89,9 +89,9 @@ module Sprinkle
|
|
89
89
|
#
|
90
90
|
# The :provides option allows you to reference this package either by :sqlite3
|
91
91
|
# or by :database. But whereas the package name is unique, multiple packages may
|
92
|
-
# share the same provision. If this is the case, when running Sprinkle, the
|
92
|
+
# share the same provision. If this is the case, when running Sprinkle, the
|
93
93
|
# script will ask you which provision you want to install. At this time, you
|
94
|
-
# can only install one.
|
94
|
+
# can only install one.
|
95
95
|
#
|
96
96
|
# == Meta-Packages
|
97
97
|
#
|
@@ -107,7 +107,7 @@ module Sprinkle
|
|
107
107
|
# FIXME: Should probably document recommendations.
|
108
108
|
#++
|
109
109
|
module Package
|
110
|
-
|
110
|
+
|
111
111
|
PACKAGES = PackageRepository.new
|
112
112
|
|
113
113
|
def package(name, metadata = {}, &block)
|
@@ -117,16 +117,16 @@ module Sprinkle
|
|
117
117
|
end
|
118
118
|
|
119
119
|
class Package #:nodoc:
|
120
|
-
attr_accessor :name, :provides, :
|
120
|
+
attr_accessor :name, :provides, :verifications
|
121
121
|
attr_internal :args, :opts
|
122
122
|
cattr_reader :installer_methods
|
123
123
|
@@installer_methods = []
|
124
|
-
|
124
|
+
|
125
125
|
include Rendering
|
126
|
-
|
126
|
+
|
127
127
|
def self.add_api(&block)
|
128
128
|
before = self.instance_methods
|
129
|
-
self.class_eval
|
129
|
+
self.class_eval(&block)
|
130
130
|
added = self.instance_methods - before
|
131
131
|
@@installer_methods += added.map(&:to_sym)
|
132
132
|
end
|
@@ -141,33 +141,35 @@ module Sprinkle
|
|
141
141
|
@recommends = []
|
142
142
|
@optional = []
|
143
143
|
@verifications = []
|
144
|
-
@
|
144
|
+
@install_queues ||= [[]]
|
145
145
|
@block = block
|
146
|
+
@use_sudo = false
|
147
|
+
@version = nil
|
146
148
|
# this should probably not be done twice
|
147
|
-
self.instance_eval
|
149
|
+
self.instance_eval(&block)
|
148
150
|
end
|
149
|
-
|
151
|
+
|
150
152
|
def description(s=nil)
|
151
153
|
s ? @description = s : @description
|
152
154
|
end
|
153
|
-
|
155
|
+
|
154
156
|
def version(s=nil)
|
155
157
|
s ? @version = s : @version
|
156
158
|
end
|
157
|
-
|
159
|
+
|
158
160
|
def instance(*args)
|
159
161
|
p=Package.new(name, @metadata) {}
|
160
162
|
p.opts = defaults.merge(args.extract_options!)
|
161
163
|
p.args = args
|
162
164
|
p.instance_variable_set("@block", @block)
|
163
|
-
p.instance_eval
|
165
|
+
p.instance_eval(&@block)
|
164
166
|
p
|
165
167
|
end
|
166
|
-
|
168
|
+
|
167
169
|
def sudo?
|
168
170
|
@use_sudo
|
169
171
|
end
|
170
|
-
|
172
|
+
|
171
173
|
def use_sudo(flag=true)
|
172
174
|
@use_sudo = flag
|
173
175
|
end
|
@@ -179,69 +181,69 @@ module Sprinkle
|
|
179
181
|
def args
|
180
182
|
@_args ||= []
|
181
183
|
end
|
182
|
-
|
184
|
+
|
183
185
|
def opts
|
184
186
|
@_opts ||= defaults.clone
|
185
187
|
end
|
186
|
-
|
188
|
+
|
187
189
|
class ContextError < StandardError #:nodoc:
|
188
190
|
end
|
189
|
-
|
191
|
+
|
190
192
|
def get(x)
|
191
193
|
raise ContextError, "Cannot call get inside a package, must be inside an Installer block"
|
192
194
|
end
|
193
|
-
|
195
|
+
|
194
196
|
# TODO - remove
|
195
197
|
def push_file(file, options ={}, &block)
|
196
198
|
ActiveSupport::Deprecation.warn("push_file is depreciated and will be removed in v0.9. Use the new `file` installer instead.")
|
197
199
|
raise "need content" unless options[:content]
|
198
200
|
runner "#{"sudo " if sudo?}rm -f #{file}"
|
199
|
-
push_text
|
201
|
+
push_text(options[:content], file, options, &block)
|
200
202
|
end
|
201
|
-
|
203
|
+
|
202
204
|
def verify(description = '', &block)
|
203
205
|
@verifications << Sprinkle::Verify.new(self, description, &block)
|
204
206
|
end
|
205
|
-
|
207
|
+
|
206
208
|
def process(deployment, roles)
|
207
209
|
logger.info " * #{name}"
|
208
210
|
return if meta_package?
|
209
|
-
opts.each_with_index do |(k, v), index|
|
211
|
+
opts.each_with_index do |(k, v), index|
|
210
212
|
branch = (index == opts.size - 1) ? "└" : "├"
|
211
|
-
logger.debug " #{branch}─ #{k}: #{v}"
|
213
|
+
logger.debug " #{branch}─ #{k}: #{v}"
|
212
214
|
end
|
213
|
-
|
215
|
+
|
214
216
|
# Run a pre-test to see if the software is already installed. If so,
|
215
217
|
# we can skip it, unless we have the force option turned on!
|
216
218
|
unless @verifications.empty? || Sprinkle::OPTIONS[:force]
|
217
219
|
begin
|
218
220
|
process_verifications(deployment, roles, true)
|
219
|
-
|
221
|
+
|
220
222
|
logger.info " --> already installed for roles: #{roles}"
|
221
223
|
return
|
222
|
-
rescue Sprinkle::VerificationFailed
|
224
|
+
rescue Sprinkle::VerificationFailed
|
223
225
|
# Continue
|
224
226
|
end
|
225
227
|
end
|
226
228
|
|
227
|
-
|
229
|
+
installers.each do |installer|
|
228
230
|
installer.defaults(deployment)
|
229
231
|
installer.process(roles)
|
230
232
|
end
|
231
|
-
|
233
|
+
|
232
234
|
process_verifications(deployment, roles)
|
233
235
|
logger.info " --> INSTALLED for roles: #{roles}"
|
234
236
|
end
|
235
|
-
|
237
|
+
|
236
238
|
def process_verifications(deployment, roles, pre = false)
|
237
239
|
return if @verifications.blank?
|
238
|
-
|
240
|
+
|
239
241
|
if pre
|
240
242
|
logger.debug "--> Checking if #{self.name} is already installed for roles: #{roles}"
|
241
243
|
else
|
242
244
|
logger.debug "--> Verifying #{self.name} was properly installed for roles: #{roles}"
|
243
245
|
end
|
244
|
-
|
246
|
+
|
245
247
|
@verifications.each do |v|
|
246
248
|
v.defaults(deployment)
|
247
249
|
v.process(roles)
|
@@ -259,11 +261,11 @@ module Sprinkle
|
|
259
261
|
def optional(*packages)
|
260
262
|
add_dependencies packages, :optional
|
261
263
|
end
|
262
|
-
|
264
|
+
|
263
265
|
def dependencies
|
264
266
|
@dependencies.map {|a,b| a }
|
265
267
|
end
|
266
|
-
|
268
|
+
|
267
269
|
def tree(depth = 1, &block)
|
268
270
|
packages = []
|
269
271
|
packages << tree_for_packages(@recommends, :depth => depth, &block)
|
@@ -276,29 +278,31 @@ module Sprinkle
|
|
276
278
|
def to_s
|
277
279
|
"#{@name} #{@version}".strip
|
278
280
|
end
|
279
|
-
|
281
|
+
|
280
282
|
# allow an installer to request a private install queue from the package
|
281
283
|
# for example to allow pre and post hooks to have their own installers that
|
282
284
|
# do not mess with the packages installer list
|
283
|
-
#
|
285
|
+
#
|
284
286
|
# returns: the private queue
|
285
287
|
def with_private_install_queue()
|
286
|
-
|
287
|
-
@installers = private_queue =[]
|
288
|
+
@install_queues.push []
|
288
289
|
yield
|
289
|
-
@
|
290
|
-
private_queue
|
290
|
+
@install_queues.pop
|
291
291
|
end
|
292
|
-
|
292
|
+
|
293
|
+
def installers
|
294
|
+
@install_queues.last
|
295
|
+
end
|
296
|
+
|
293
297
|
protected
|
294
|
-
|
298
|
+
|
295
299
|
def install(i)
|
296
|
-
|
300
|
+
installers << i
|
297
301
|
i
|
298
302
|
end
|
299
|
-
|
303
|
+
|
300
304
|
private
|
301
|
-
|
305
|
+
|
302
306
|
def add_dependencies(packages, kind)
|
303
307
|
opts = packages.extract_options!
|
304
308
|
depends = instance_variable_get("@#{kind}")
|
@@ -307,7 +311,7 @@ module Sprinkle
|
|
307
311
|
end
|
308
312
|
depends.map {|a,b| a }
|
309
313
|
end
|
310
|
-
|
314
|
+
|
311
315
|
def tree_for_packages(packages, opts={}, &block)
|
312
316
|
depth = opts[:depth]
|
313
317
|
tree = []
|
@@ -322,13 +326,13 @@ module Sprinkle
|
|
322
326
|
end
|
323
327
|
tree
|
324
328
|
end
|
325
|
-
|
329
|
+
|
326
330
|
def cloud_info(message)
|
327
331
|
logger.info(message) if Sprinkle::OPTIONS[:cloud] or logger.debug?
|
328
332
|
end
|
329
333
|
|
330
334
|
def meta_package?
|
331
|
-
|
335
|
+
installers.blank?
|
332
336
|
end
|
333
337
|
end
|
334
338
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module Sprinkle::Package
|
2
2
|
class Chooser #:nodoc:
|
3
|
+
|
3
4
|
def self.select_package(name, packages)
|
4
5
|
if packages.size <= 1
|
5
6
|
package = packages.first
|
6
7
|
else
|
7
8
|
package = choose do |menu|
|
8
9
|
menu.prompt = "Multiple choices exist for virtual package #{name}"
|
9
|
-
menu.choices *packages.collect(&:to_s)
|
10
|
+
menu.choices( *packages.collect(&:to_s) )
|
10
11
|
end
|
11
12
|
package = Sprinkle::Package::PACKAGES.first(package)
|
12
13
|
end
|
@@ -15,10 +16,10 @@ module Sprinkle::Package
|
|
15
16
|
|
16
17
|
package
|
17
18
|
end
|
18
|
-
|
19
|
+
|
19
20
|
def self.cloud_info(message)
|
20
21
|
logger.info(message) if Sprinkle::OPTIONS[:cloud] or logger.debug?
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
end
|
24
|
-
end
|
25
|
+
end
|