devstructure 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/devstructure/blueprint.rb +124 -118
  2. metadata +5 -5
@@ -160,29 +160,6 @@ EOF
160
160
  def sh(io=StringIO.new)
161
161
  io.puts disclaimer
162
162
 
163
- # First come packages. The algorithm used to walk the package tree
164
- # is pluggable and in this case we only need to take action as each
165
- # package name is encountered. Each manager is annotated with a
166
- # shell command suitable for installing packages in `printf`(3)-style.
167
- #
168
- # RubyGems is, once again, a special case. Ubuntu ships with a very
169
- # old version so we take the liberty of upgrading it anytime it is
170
- # encountered.
171
- walk(
172
- :before => lambda { |manager, command|
173
- io.puts "apt-get update" if "apt" == manager
174
- },
175
- :package => lambda { |manager, command, package, version|
176
- return if manager == package
177
- io.printf "#{command}\n", package, version
178
- if "apt" == manager && package =~ /^rubygems(\d+\.\d+(?:\.\d+)?)$/
179
- io.puts "/usr/bin/gem#{$1} install --no-rdoc --no-ri rubygems-update"
180
- io.puts "/usr/bin/ruby#{$1} $(PATH=\"$PATH:/var/lib/gems/#{
181
- $1}/bin\" which update_rubygems)"
182
- end
183
- }
184
- )
185
-
186
163
  # Plaintext files are written to their final destination using `cat`(1)
187
164
  # and heredoc syntax. Binary files are written using `base64`(1) and
188
165
  # symbolic links are placed using `ln`(1). Shocking stuff.
@@ -218,6 +195,31 @@ EOF
218
195
  io.puts "chmod #{mode} #{pathname}" if mode
219
196
  end if files
220
197
 
198
+ # Packages used to come first. Now they follow files so things like
199
+ # `/etc/apt/sources.list.d/*` or `/root/.gemrc` can be in place before
200
+ # package managers are called. The algorithm used to walk the package
201
+ # tree is pluggable and in this case we only need to take action as
202
+ # each package name is encountered. Each manager is annotated with a
203
+ # shell command suitable for installing packages in `printf`(3)-style.
204
+ #
205
+ # RubyGems is, once again, a special case. Ubuntu ships with a very
206
+ # old version so we take the liberty of upgrading it anytime it is
207
+ # encountered.
208
+ walk(
209
+ :before => lambda { |manager, command|
210
+ io.puts "apt-get update" if "apt" == manager
211
+ },
212
+ :package => lambda { |manager, command, package, version|
213
+ return if manager == package
214
+ io.printf "#{command}\n", package, version
215
+ if "apt" == manager && package =~ /^rubygems(\d+\.\d+(?:\.\d+)?)$/
216
+ io.puts "/usr/bin/gem#{$1} install --no-rdoc --no-ri rubygems-update"
217
+ io.puts "/usr/bin/ruby#{$1} $(PATH=\"$PATH:/var/lib/gems/#{
218
+ $1}/bin\" which update_rubygems)"
219
+ end
220
+ }
221
+ )
222
+
221
223
  # Source tarballs are downloaded, extracted, and removed. Generally,
222
224
  # the directory in question is `/usr/local` but the future could hold
223
225
  # anything.
@@ -246,6 +248,66 @@ EOF
246
248
  managers[package] = manager if packages[package] && manager != package
247
249
  })
248
250
 
251
+ # System files must be placed before packages are installed so we set
252
+ # Puppet's dependencies to put all packages ahead of all files. This
253
+ # is a change from the past when files were placed later. The new
254
+ # way allows `/etc/apt/sources.list.d/*` and `/root/.gemrc` (for
255
+ # example) to be placed prior to running package manager commands.
256
+ #
257
+ # File content is handled much like the shell version except base 64
258
+ # decoding takes place here in Ruby rather than in the `base64`(1)
259
+ # tool.
260
+ if files && 0 < files.length
261
+ classes = managers.keys.
262
+ reject { |manager| 0 == packages[manager]["_packages"].length }.
263
+ map { |manager| Puppet::Class[manager] }
264
+ if 0 < classes.length
265
+ manifest << Puppet::File.defaults(:before => classes)
266
+ end
267
+ files.sort.each do |pathname, content|
268
+
269
+ # Resources for all parent directories are created ahead of
270
+ # any file. Puppet's autorequire mechanism will ensure that a
271
+ # file's parent directories are realized before the file itself.
272
+ dirnames = File.dirname(pathname).split("/")
273
+ dirnames.shift
274
+ (0..(dirnames.length - 1)).each do |i|
275
+ manifest << Puppet::File.new("/#{dirnames[0..i].join("/")}",
276
+ :ensure => :directory)
277
+ end
278
+
279
+ # Convert the blueprint file attributes to those that Puppet
280
+ # understands. Everything's optional.
281
+ options = {}
282
+ if Hash === content
283
+ options[:owner] = content["_owner"] if content["_owner"]
284
+ options[:group] = content["_group"] if content["_group"]
285
+ if content["_target"]
286
+ options[:ensure] = content["_target"]
287
+ else
288
+ options[:mode] = content["_mode"] if content["_mode"]
289
+ options[:ensure] = :file
290
+ options[:content] = if content["_base64"]
291
+ Base64.decode64(content["_base64"])
292
+ else
293
+ content["_content"]
294
+ end
295
+ end
296
+
297
+ # The easiest way to specify a file is to include just the
298
+ # content. The owner and group will be `root` and the mode will
299
+ # be set according to the `umask`.
300
+ else
301
+ options = {
302
+ :content => content,
303
+ :ensure => :file,
304
+ }
305
+ end
306
+
307
+ manifest << Puppet::File.new(pathname, options)
308
+ end
309
+ end
310
+
249
311
  # Each manager's packages are grouped to create a series of subclasses
250
312
  # that allow dependency management to be handled coursely using Puppet
251
313
  # classes. Because of Puppet's rules about resource name uniqueness,
@@ -359,63 +421,6 @@ EOF
359
421
  }
360
422
  )
361
423
 
362
- # System files must be placed after packages are installed so we set
363
- # Puppet's dependencies to put all packages ahead of all files.
364
- #
365
- # File content is handled much like the shell version except base 64
366
- # decoding takes place here in Ruby rather than in the `base64`(1)
367
- # tool.
368
- if files && 0 < files.length
369
- classes = managers.keys.
370
- reject { |manager| 0 == packages[manager]["_packages"].length }.
371
- map { |manager| Puppet::Class[manager] }
372
- if 0 < classes.length
373
- manifest << Puppet::File.defaults(:require => classes)
374
- end
375
- files.sort.each do |pathname, content|
376
-
377
- # Resources for all parent directories are created ahead of
378
- # any file. Puppet's autorequire mechanism will ensure that a
379
- # file's parent directories are realized before the file itself.
380
- dirnames = File.dirname(pathname).split("/")
381
- dirnames.shift
382
- (0..(dirnames.length - 1)).each do |i|
383
- manifest << Puppet::File.new("/#{dirnames[0..i].join("/")}",
384
- :ensure => :directory)
385
- end
386
-
387
- # Convert the blueprint file attributes to those that Puppet
388
- # understands. Everything's optional.
389
- options = {}
390
- if Hash === content
391
- options[:owner] = content["_owner"] if content["_owner"]
392
- options[:group] = content["_group"] if content["_group"]
393
- if content["_target"]
394
- options[:ensure] = content["_target"]
395
- else
396
- options[:mode] = content["_mode"] if content["_mode"]
397
- options[:ensure] = :file
398
- options[:content] = if content["_base64"]
399
- Base64.decode64(content["_base64"])
400
- else
401
- content["_content"]
402
- end
403
- end
404
-
405
- # The easiest way to specify a file is to include just the
406
- # content. The owner and group will be `root` and the mode will
407
- # be set according to the `umask`.
408
- else
409
- options = {
410
- :content => content,
411
- :ensure => :file,
412
- }
413
- end
414
-
415
- manifest << Puppet::File.new(pathname, options)
416
- end
417
- end
418
-
419
424
  # Source tarballs are downloaded, extracted, and removed in one fell
420
425
  # swoop. Puppet 2.6 introduced the requirement to wrap compound commands
421
426
  # such as this in a shell invocation. This is a pretty direct Puppet
@@ -441,7 +446,45 @@ EOF
441
446
  def chef(io=StringIO.new)
442
447
  cookbook = Chef::Cookbook.new(@name, disclaimer)
443
448
 
444
- # First come packages, traversed in the same order as with the shell
449
+ # Files are handled by the `cookbook_file` resource type and are
450
+ # preceded by the `directory` which contains them. Just like the
451
+ # shell and Puppet generators, this code handles binary files and
452
+ # symbolic links (handled by the `link` resource type), too.
453
+ files.sort.each do |pathname, content|
454
+ cookbook.directory File.dirname(pathname),
455
+ :group => "root",
456
+ :mode => "755",
457
+ :owner => "root",
458
+ :recursive => true
459
+ owner = group = mode = nil
460
+ if Hash === content
461
+ owner = content["_owner"]
462
+ group = content["_group"]
463
+ if content["_target"]
464
+ cookbook.link pathname,
465
+ :group => group || "root",
466
+ :owner => owner || "root",
467
+ :to => content["_target"]
468
+ next
469
+ else
470
+ mode = content["_mode"]
471
+ if content["_base64"]
472
+ content = content["_base64"]
473
+ else
474
+ content = content["_content"]
475
+ end
476
+ end
477
+ end
478
+ cookbook.cookbook_file pathname, content,
479
+ :backup => false,
480
+ :group => group || "root",
481
+ :mode => mode || "644",
482
+ :owner => owner || "root",
483
+ :source => pathname[1..-1]
484
+ end if files
485
+
486
+ # Packages come after files so managers can be configured before they
487
+ # run. Packages are traversed in the same order as with the shell
445
488
  # code generator but passed off to the cookbook.
446
489
  walk(
447
490
  :before => lambda { |manager, command|
@@ -488,43 +531,6 @@ EOF
488
531
  }
489
532
  )
490
533
 
491
- # Files are handled by the `cookbook_file` resource type and are
492
- # preceded by the `directory` which contains them. Just like the
493
- # shell and Puppet generators, this code handles binary files and
494
- # symbolic links (handled by the `link` resource type), too.
495
- files.sort.each do |pathname, content|
496
- cookbook.directory File.dirname(pathname),
497
- :group => "root",
498
- :mode => "755",
499
- :owner => "root",
500
- :recursive => true
501
- owner = group = mode = nil
502
- if Hash === content
503
- owner = content["_owner"]
504
- group = content["_group"]
505
- if content["_target"]
506
- cookbook.link pathname,
507
- :group => group || "root",
508
- :owner => owner || "root",
509
- :to => content["_target"]
510
- next
511
- else
512
- mode = content["_mode"]
513
- if content["_base64"]
514
- content = content["_base64"]
515
- else
516
- content = content["_content"]
517
- end
518
- end
519
- end
520
- cookbook.cookbook_file pathname, content,
521
- :backup => false,
522
- :group => group || "root",
523
- :mode => mode || "644",
524
- :owner => owner || "root",
525
- :source => pathname[1..-1]
526
- end if files
527
-
528
534
  # Source tarballs are lifted directly from the shell code generator
529
535
  # and wrapped in `execute` resources.
530
536
  sources.sort.each do |dirname, filename|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devstructure
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Crowley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-02 00:00:00 +00:00
18
+ date: 2010-09-19 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency