chef_cap 0.0.7 → 0.1.1

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.
data/README.rdoc CHANGED
@@ -34,6 +34,40 @@ Then run:
34
34
 
35
35
  Which will overwrite your Capfile and create a chef directory with sample files unless one already exists.
36
36
 
37
+ === Tasks
38
+
39
+ Remove all chef-cap files from /tmp
40
+
41
+ $ cap <environment> chef:cleanup
42
+
43
+ Run chef-solo on the server(s)
44
+
45
+ $ cap <environment> chef:deploy
46
+
47
+ Setup chef solo on the server(s)
48
+
49
+ $ cap <environment> chef:setup
50
+
51
+ Run chef without deploy
52
+
53
+ $ cap <environment> cook
54
+
55
+ === chef/node.json
56
+
57
+ The following JSON keys are required in your node.json file:
58
+
59
+ { "application": { "name": NAME } }
60
+ { "application": { "repository": REPOSITORY } }
61
+ { "environments": { ENVIRONMENT: { "rails_env": RAILS_ENV } } }
62
+ { "roles": { ROLE: { "run_list": [] } } }
63
+ { "run_list": [] }
64
+
65
+ Optional JSON keys:
66
+
67
+ { "environments": { ENVIRONMENT: { "role_order": { FIRST_ROLE: [OTHER_ROLES] } } } }
68
+ { "environments": { ENVIRONMENT: { "environment_settings": ENV_HASH } } }
69
+
70
+
37
71
  == REQUIREMENTS
38
72
 
39
73
  * Capistrano 2.x
@@ -1,3 +1,3 @@
1
1
  module ChefCap
2
- VERSION = "0.0.7"
3
- end
2
+ VERSION = "0.1.1"
3
+ end
data/recipes/chef_cap.rb CHANGED
@@ -28,6 +28,7 @@ if ChefDnaParser.parsed["environments"]
28
28
  task environment.to_sym do
29
29
  set :environment_settings, environment_hash
30
30
  set :rails_env, environment_hash["rails_env"] || environment
31
+ set :role_order, environment_hash["role_order"] || {}
31
32
  default_environment["RAILS_ENV"] = rails_env
32
33
 
33
34
  ChefCapHelper.parse_hash(environment_hash)
@@ -182,12 +183,20 @@ namespace :chef do
182
183
  end
183
184
 
184
185
  task :run_chef_solo do
185
- db = find_servers(:roles => [:db]).map(&:host)
186
- app_and_web_only = find_servers(:roles => [:app, :web]).map(&:host) - db
187
-
188
186
  run_chef_solo = "env PATH=$PATH:/usr/sbin rvm default exec chef-solo -c /tmp/chef-cap-solo-#{rails_env}.rb -j /tmp/chef-cap-#{rails_env}-`hostname`.json #{ENV['DEBUG'] ? '-l debug' : ''}"
189
- sudo(run_chef_solo, :hosts => db) if db.any?
190
- sudo(run_chef_solo, :hosts => app_and_web_only) if app_and_web_only.any?
187
+
188
+ unless role_order.empty?
189
+ role_order.each do |role, dependent_roles|
190
+ role_hosts = find_servers(:roles => [role.to_sym]).map(&:host)
191
+ dependent_hosts = find_servers(:roles => dependent_roles.map(&:to_sym)).map(&:host) - role_hosts
192
+
193
+ sudo(run_chef_solo, :hosts => role_hosts) if role_hosts.any?
194
+ sudo(run_chef_solo, :hosts => dependent_hosts) if dependent_hosts.any?
195
+ end
196
+ else
197
+ sudo(run_chef_solo)
198
+ end
199
+
191
200
  end
192
201
 
193
202
  desc "Remove all chef-cap files from /tmp"
@@ -13,10 +13,12 @@ end
13
13
  def find_servers(options = {})
14
14
  servers = []
15
15
  options[:roles].each do |role|
16
- if @servers.has_key? role
16
+ if @servers && @servers.has_key?(role)
17
17
  @servers[role][:servers].each do |server|
18
18
  servers << TestCapServer.new(server)
19
19
  end
20
+ else
21
+ raise ArgumentError, "unknown role `#{role}'" unless roles.include?(role)
20
22
  end
21
23
  end
22
24
  servers
@@ -351,20 +351,20 @@ describe "chef_cap" do
351
351
  server_session.things_that_were_set["node_hash_for_localhost"].should == {
352
352
  "environments" => {"some_env"=>{ "rails_env" => "myenv",
353
353
  "servers"=>[ {"hostname"=>"localhost", "roles"=>["role1", "role2"] }, {"hostname"=>"otherhost.com", "roles"=>["role1"]}]}},
354
- "chef" => {"root"=>"path_to_cookbooks"},
355
- "run_list" => ["foo", "bar"],
356
- "environment" => {"rails_env" => "myenv", "servers"=>[ {"primary" => [], "hostname"=>"localhost", "roles"=>["role1", "role2"] },
357
- {"primary" => [], "hostname"=>"otherhost.com", "roles"=>["role1"]}]},
358
- "roles" => {"role1" => {"run_list"=>["foo"]}, "role2"=>{"run_list"=>["foo", "bar"]}}}
354
+ "chef" => {"root"=>"path_to_cookbooks"},
355
+ "run_list" => ["foo", "bar"],
356
+ "environment" => {"rails_env" => "myenv", "servers"=>[ {"primary" => [], "hostname"=>"localhost", "roles"=>["role1", "role2"] },
357
+ {"primary" => [], "hostname"=>"otherhost.com", "roles"=>["role1"]}]},
358
+ "roles" => {"role1" => {"run_list"=>["foo"]}, "role2"=>{"run_list"=>["foo", "bar"]}}}
359
359
  elsif server_session.things_that_were_set.keys.include? "node_hash_for_otherhost"
360
360
  server_session.things_that_were_set["node_hash_for_otherhost"].should == {
361
- "environments" => {"some_env"=>{ "rails_env" => "myenv",
362
- "servers"=>[{"hostname"=>"localhost", "roles"=>["role1", "role2"]}, {"hostname"=>"otherhost.com", "roles"=>["role1"]}]}},
363
- "chef"=>{"root"=>"path_to_cookbooks"},
364
- "run_list"=>["foo"],
365
- "environment"=>{"rails_env" => "myenv", "servers"=>[{"primary" => [], "hostname"=>"localhost", "roles"=>["role1", "role2"]},
366
- {"primary" => [], "hostname"=>"otherhost.com", "roles"=>["role1"]}]},
367
- "roles"=>{"role1"=>{"run_list"=>["foo"]}, "role2"=>{"run_list"=>["foo", "bar"]}}}
361
+ "environments" => {"some_env"=>{ "rails_env" => "myenv",
362
+ "servers"=>[{"hostname"=>"localhost", "roles"=>["role1", "role2"]}, {"hostname"=>"otherhost.com", "roles"=>["role1"]}]}},
363
+ "chef"=>{"root"=>"path_to_cookbooks"},
364
+ "run_list"=>["foo"],
365
+ "environment"=>{"rails_env" => "myenv", "servers"=>[{"primary" => [], "hostname"=>"localhost", "roles"=>["role1", "role2"]},
366
+ {"primary" => [], "hostname"=>"otherhost.com", "roles"=>["role1"]}]},
367
+ "roles"=>{"role1"=>{"run_list"=>["foo"]}, "role2"=>{"run_list"=>["foo", "bar"]}}}
368
368
  end
369
369
  end
370
370
  end
@@ -419,9 +419,9 @@ describe "chef_cap" do
419
419
  end
420
420
 
421
421
  describe "task :run_chef_solo" do
422
-
423
- before do
424
- @test_dna = <<-JS
422
+ context "with a db role" do
423
+ before do
424
+ @test_dna = <<-JS
425
425
  {
426
426
  "chef": {
427
427
  "root": "path_to_cookbooks"
@@ -429,6 +429,7 @@ describe "chef_cap" do
429
429
  "environments": {
430
430
  "some_env": {
431
431
  "rails_env": "myenv",
432
+ "role_order": { "db": ["app"] },
432
433
  "servers": [
433
434
  {
434
435
  "hostname": "dbhost",
@@ -446,18 +447,54 @@ describe "chef_cap" do
446
447
  "app": { "run_list": [] }
447
448
  }
448
449
  }
449
- JS
450
+ JS
450
451
 
451
- chef_cap.cap_task[:some_env].should_not be_nil
452
- chef_cap.cap_task[:some_env].call
452
+ chef_cap.cap_task[:some_env].should_not be_nil
453
+ chef_cap.cap_task[:some_env].call
454
+ end
455
+
456
+ it "invokes chef-solo on db hosts then app and web only hosts" do
457
+ chef_cap.cap_servers.should_not be_empty
458
+
459
+ chef_cap.should_receive(:sudo).ordered.with(/.*chef-solo.*/, :hosts => ["dbhost"]).and_return("mocked")
460
+ chef_cap.should_receive(:sudo).ordered.with(/.*chef-solo.*/, :hosts => ["apphost"]).and_return("mocked")
461
+ chef_cap.cap_task["chef:run_chef_solo"].call
462
+ end
453
463
  end
454
464
 
455
- it "invokes chef-solo on db hosts then app and web only hosts" do
456
- chef_cap.cap_servers.should_not be_empty
465
+ context "without a db role" do
466
+ before do
467
+ @test_dna = <<-JS
468
+ {
469
+ "chef": {
470
+ "root": "path_to_cookbooks"
471
+ },
472
+ "environments": {
473
+ "some_env": {
474
+ "rails_env": "some_env",
475
+ "servers": [
476
+ {
477
+ "hostname": "somehost",
478
+ "roles": ["somerole"]
479
+ }
480
+ ]
481
+ }
482
+ },
483
+ "roles": {
484
+ "somerole": { "run_list": [] }
485
+ }
486
+ }
487
+ JS
488
+
489
+ chef_cap.cap_task[:some_env].should_not be_nil
490
+ chef_cap.cap_task[:some_env].call
491
+ end
457
492
 
458
- chef_cap.should_receive(:sudo).ordered.with(/.*chef-solo.*/, :hosts => ["dbhost"]).and_return("mocked")
459
- chef_cap.should_receive(:sudo).ordered.with(/.*chef-solo.*/, :hosts => ["apphost"]).and_return("mocked")
460
- chef_cap.cap_task["chef:run_chef_solo"].call
493
+
494
+ it "works" do
495
+ chef_cap.stub!(:sudo)
496
+ chef_cap.cap_task["chef:run_chef_solo"].call
497
+ end
461
498
  end
462
499
  end
463
500
 
@@ -646,8 +683,8 @@ describe "chef_cap" do
646
683
  chef_cap.parallel_sessions.each do |server_session|
647
684
  if server_session.things_that_were_set.keys.include? "node_hash_for_localhost"
648
685
  server_session.things_that_were_set["node_hash_for_localhost"]["environment"].should == {"some_default"=>"yes",
649
- "something_else"=>"okay",
650
- "servers"=>[{"primary" => [], "hostname"=>"localhost", "roles"=>["role1", "role2"]}]}
686
+ "something_else"=>"okay",
687
+ "servers"=>[{"primary" => [], "hostname"=>"localhost", "roles"=>["role1", "role2"]}]}
651
688
  end
652
689
  end
653
690
  end
@@ -795,12 +832,12 @@ describe "chef_cap" do
795
832
  server_session.stub!(:put => "stubbed")
796
833
  server_session.stub!(:sudo => "stubbed")
797
834
  server_session.should_receive(:set).with("node_hash_for_localhost",
798
- {"environments" => { "some_env"=>{"servers"=>[{"hostname"=>"localhost", "roles"=>["role1", "role2"]}]}},
799
- "something"=>"other", "foo"=>"bar",
800
- "chef"=>{"root"=>"path_to_cookbooks"},
801
- "run_list"=>nil, "shared"=>{"foo"=>"bar"},
802
- "environment"=> {"revision"=>"123", "branch" => "somebranch", "servers"=>[{"primary" => [], "hostname"=>"localhost", "roles"=>["role1", "role2"]}]}, "roles"=>{"role1"=>{"something"=>"other"}}}
803
- )
835
+ {"environments" => { "some_env"=>{"servers"=>[{"hostname"=>"localhost", "roles"=>["role1", "role2"]}]}},
836
+ "something"=>"other", "foo"=>"bar",
837
+ "chef"=>{"root"=>"path_to_cookbooks"},
838
+ "run_list"=>nil, "shared"=>{"foo"=>"bar"},
839
+ "environment"=> {"revision"=>"123", "branch" => "somebranch", "servers"=>[{"primary" => [], "hostname"=>"localhost", "roles"=>["role1", "role2"]}]}, "roles"=>{"role1"=>{"something"=>"other"}}}
840
+ )
804
841
  }
805
842
  chef_cap.cap_task["chef:deploy"].call
806
843
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
- - 7
9
- version: 0.0.7
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Case Commons, LLC
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-21 00:00:00 -05:00
17
+ date: 2011-02-25 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency