chef_cap 0.3.9 → 0.3.10

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.
@@ -1,3 +1,3 @@
1
1
  module ChefCap
2
- VERSION = "0.3.9"
2
+ VERSION = "0.3.10"
3
3
  end
data/recipes/chef_cap.rb CHANGED
@@ -9,6 +9,7 @@ ChefCapConfiguration.configuration = self
9
9
  ChefDnaParser.load_dna
10
10
 
11
11
  before "deploy", "chef:setup"
12
+ before "chef:setup", "bootstrap:ruby"
12
13
 
13
14
  set :application, ChefDnaParser.parsed["application"]["name"] rescue nil
14
15
  set :repository, ChefDnaParser.parsed["application"]["repository"] rescue nil
@@ -154,15 +155,22 @@ else
154
155
  set :chef_version, default_chef_version
155
156
  end
156
157
 
157
- set :rvm_bin_path, "/tmp/.chef_cap_rvm_path"
158
+ set :debug_flag, ENV['DEBUG'] ? '-l debug' : ''
158
159
 
159
160
  namespace :chef do
160
- desc "Setup chef solo on the server(s)"
161
161
  task :setup do
162
- gem_check_for_chef_cmd = "gem specification --version '>=#{chef_version}' chef 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }'"
163
- install_chef_cmd = "sudo `cat #{rvm_bin_path}` default exec gem install chef --no-ri --no-rdoc"
164
- sudo "`cat #{rvm_bin_path}` default exec #{gem_check_for_chef_cmd} || #{install_chef_cmd} && echo 'Chef Solo already on this server.'"
165
- sudo "`cat #{rvm_bin_path}` default exec which chef-solo"
162
+ case ruby_version_switcher
163
+ when 'rbenv'
164
+ gem_check_for_chef_cmd = "gem specification --version '>=#{chef_version}' chef 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }'"
165
+ install_chef_cmd = "gem install chef --no-ri --no-rdoc"
166
+ run "#{gem_check_for_chef_cmd} || #{install_chef_cmd} && echo 'Chef Solo already on this server.'"
167
+ run "rbenv rehash"
168
+ else
169
+ gem_check_for_chef_cmd = "gem specification --version '>=#{chef_version}' chef 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }'"
170
+ install_chef_cmd = "sudo `cat #{rvm_bin_path}` default exec gem install chef --no-ri --no-rdoc"
171
+ sudo "`cat #{rvm_bin_path}` default exec #{gem_check_for_chef_cmd} || #{install_chef_cmd} && echo 'Chef Solo already on this server.'"
172
+ sudo "`cat #{rvm_bin_path}` default exec which chef-solo"
173
+ end
166
174
  end
167
175
 
168
176
  desc "Run chef-solo on the server(s)"
@@ -218,8 +226,6 @@ namespace :chef do
218
226
  end
219
227
 
220
228
  task :setup_to_run_chef_solo do
221
- set :debug_flag, ENV['DEBUG'] ? '-l debug' : ''
222
- exec_chef_solo = "env PATH=$PATH:/usr/sbin `cat #{rvm_bin_path}` default exec chef-solo -c /tmp/chef-cap-solo-#{rails_env}.rb #{debug_flag}"
223
229
  set :run_chef_solo_deploy_command, "#{exec_chef_solo} -j /tmp/chef-cap-#{rails_env}-`hostname`.json"
224
230
  set :run_chef_solo_rollback_command, "#{exec_chef_solo} -j /tmp/chef-cap-#{rails_env}-`hostname`-rollback.json"
225
231
  set :run_chef_solo_block, { :block => lambda { |command_to_run|
data/recipes/rbenv.rb ADDED
@@ -0,0 +1,49 @@
1
+ namespace :bootstrap do
2
+ desc "Create a standalone rbenv installation with a default ruby to use with chef-solo"
3
+ task :rbenv do
4
+ set :rvm_ruby_version, (ChefDnaParser.parsed["environment"]["rvm_ruby_version"] rescue "ruby-1.9.3-p0" || "ruby-1.9.3-p0")
5
+ set :rbenv_ruby_version, rvm_ruby_version.gsub(/^ruby\-/,'')
6
+ standup_script = <<-SH
7
+ #!/bin/bash
8
+ #
9
+ # And now install rbenv
10
+ export PATH=$HOME/bin:$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH
11
+
12
+ HAVE_RBENV_ALREADY=`which rbenv 2>/dev/null`
13
+ if [ $? != 0 ]; then
14
+ ## Install rbenv dependencies
15
+ sudo yum install -y automake gcc make libtool curl zlib zlib-devel patch readline readline-devel libffi-devel openssl openssl-devel git
16
+
17
+ echo "Building rbenv..."
18
+ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
19
+ # Add rbenv to your path
20
+ echo 'export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"' >> .bashrc
21
+ echo 'eval "$(rbenv init -)"' >> .bashrc
22
+ source ~/.bash_profile
23
+ fi;
24
+
25
+ # Install ruby-build
26
+ HAVE_RUBY_BUILD=`which ruby-build 2>/dev/null`
27
+ if [ $? != 0 ]; then
28
+ echo "Building ruby-build..."
29
+ cd /tmp
30
+ git clone git://github.com/sstephenson/ruby-build.git
31
+ cd ruby-build
32
+ PREFIX=$HOME ./install.sh
33
+ cd $HOME
34
+ fi;
35
+
36
+ # Install Ruby #{rbenv_ruby_version}
37
+ HAVE_CORRECT_VERSION=`rbenv versions | grep '#{rbenv_ruby_version}' | wc -l`
38
+ if [ $HAVE_CORRECT_VERSION -eq 0 ]; then
39
+ echo "Installing #{rbenv_ruby_version}..."
40
+ rbenv install #{rbenv_ruby_version}
41
+ rbenv global #{rbenv_ruby_version}
42
+ # Rehash!
43
+ rbenv rehash
44
+ fi;
45
+ SH
46
+ put standup_script, "/tmp/chef-cap-#{rails_env}-rbenv-standup.sh", :mode => "0700"
47
+ run "/tmp/chef-cap-#{rails_env}-rbenv-standup.sh"
48
+ end
49
+ end
data/recipes/ruby.rb ADDED
@@ -0,0 +1,30 @@
1
+ namespace :bootstrap do
2
+ desc "Create a standalone rbenv installation with a default ruby to use with chef-solo"
3
+ task :ruby do
4
+ local_rvs = ruby_version_switcher rescue 'rvm'
5
+ local_env = rails_env rescue 'unkown'
6
+
7
+ case local_rvs
8
+ when 'rbenv'
9
+
10
+ set :default_environment, {
11
+ 'PATH' => "$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH:/usr/sbin"
12
+ }
13
+ set :ruby_version_switcher, "rbenv"
14
+ set :exec_chef_solo, "chef-solo -c /tmp/chef-cap-solo-#{local_env}.rb #{debug_flag}"
15
+ else
16
+ ## rvm is the default
17
+ set :default_environment, {
18
+ 'PATH' => "$PATH:/usr/sbin"
19
+ }
20
+ set :ruby_version_switcher, "rvm"
21
+ set :rvm_bin_path, "/tmp/.chef_cap_rvm_path"
22
+ set :exec_chef_solo, "`cat #{rvm_bin_path}` default exec chef-solo -c /tmp/chef-cap-solo-#{local_env}.rb #{debug_flag}"
23
+ end
24
+
25
+ depend :remote, :command, ruby_version_switcher
26
+ depend :remote, :command, "chef-solo"
27
+
28
+ after "bootstrap:ruby", "bootstrap:#{ruby_version_switcher}"
29
+ end
30
+ end
@@ -1,11 +1,6 @@
1
- depend :remote, :command, "rvm"
2
- depend :remote, :command, "chef-solo"
3
-
4
- before "chef:setup", "rvm:bootstrap"
5
-
6
- namespace :rvm do
1
+ namespace :bootstrap do
7
2
  desc "Create a standalone rvm installation with a default ruby to use with chef-solo"
8
- task :bootstrap do
3
+ task :rvm do
9
4
  set :rvm_ruby_version, (ChefDnaParser.parsed["environment"]["rvm_ruby_version"] rescue "ruby-1.9.3-p0" || "ruby-1.9.3-p0")
10
5
  rvm_standup_script = <<-SH
11
6
  #!/bin/bash
@@ -302,7 +302,7 @@ describe "chef_cap" do
302
302
 
303
303
  end
304
304
 
305
- describe "rvm bootstrap" do
305
+ describe "rbenv bootstrap" do
306
306
  it "uploads a shell script to the server and runs it as root" do
307
307
  @test_dna = <<-ERB
308
308
  {
@@ -311,6 +311,7 @@ describe "chef_cap" do
311
311
  },
312
312
  "environments": {
313
313
  "some_env": {
314
+ "ruby_version_switcher": "rbenv",
314
315
  "rails_env": "my_env"
315
316
  }
316
317
  }
@@ -318,17 +319,37 @@ describe "chef_cap" do
318
319
  ERB
319
320
 
320
321
  chef_cap.cap_task[:some_env].call
321
- chef_cap.cap_namespace[:rvm].should_not be_nil
322
- chef_cap.cap_task["rvm:bootstrap"].should_not be_nil
322
+ chef_cap.cap_namespace[:bootstrap].should_not be_nil
323
+ chef_cap.cap_task["bootstrap:rbenv"].should_not be_nil
323
324
 
324
325
  chef_cap.should_receive(:put)
325
- chef_cap.should_receive(:sudo).with("/tmp/chef-cap-my_env-rvm-standup.sh")
326
- chef_cap.cap_task["rvm:bootstrap"].call
326
+ chef_cap.should_receive(:run).with("/tmp/chef-cap-my_env-rbenv-standup.sh")
327
+ chef_cap.cap_task["bootstrap:rbenv"].call
327
328
  end
329
+ end
328
330
 
329
- it "adds a dependency check on the rvm command" do
330
- chef_cap.cap_depends["rvm"].should_not be_nil
331
- chef_cap.cap_depends["rvm"].should == { :remote => :command }
331
+ describe "rvm bootstrap" do
332
+ it "uploads a shell script to the server and runs it as root" do
333
+ @test_dna = <<-ERB
334
+ {
335
+ "chef": {
336
+ "root": "path_to_cookbooks"
337
+ },
338
+ "environments": {
339
+ "some_env": {
340
+ "rails_env": "my_env"
341
+ }
342
+ }
343
+ }
344
+ ERB
345
+
346
+ chef_cap.cap_task[:some_env].call
347
+ chef_cap.cap_namespace[:bootstrap].should_not be_nil
348
+ chef_cap.cap_task["bootstrap:rvm"].should_not be_nil
349
+
350
+ chef_cap.should_receive(:put)
351
+ chef_cap.should_receive(:sudo).with("/tmp/chef-cap-my_env-rvm-standup.sh")
352
+ chef_cap.cap_task["bootstrap:rvm"].call
332
353
  end
333
354
  end
334
355
 
@@ -344,25 +365,19 @@ describe "chef_cap" do
344
365
 
345
366
  describe "namespace :chef" do
346
367
 
347
- it "adds a remote dependency on chef-solo" do
348
- chef_cap.cap_depends["chef-solo"].should_not be_nil
349
- chef_cap.cap_depends["chef-solo"].should == { :remote => :command }
350
- end
351
-
352
368
  it "runs chef:setup before chef:deploy" do
353
369
  chef_cap.cap_before["chef:deploy"].should_not be_nil
354
370
  chef_cap.cap_before["chef:deploy"].should include("chef:setup")
355
371
  end
356
372
 
357
- it "runs rvm:bootstrap before chef:setup" do
373
+ it "runs bootstrap:ruby before chef:setup" do
358
374
  chef_cap.cap_before["chef:setup"].should_not be_nil
359
- chef_cap.cap_before["chef:setup"].should include("rvm:bootstrap")
375
+ chef_cap.cap_before["chef:setup"].should include("bootstrap:ruby")
360
376
  end
361
377
 
362
378
  describe "task :deploy" do
363
-
364
- before do
365
- @test_dna = <<-JS
379
+ let(:test_dna) do
380
+ <<-JS
366
381
  {
367
382
  "chef": {
368
383
  "root": "path_to_cookbooks",
@@ -389,7 +404,10 @@ describe "chef_cap" do
389
404
  }
390
405
  }
391
406
  JS
407
+ end
392
408
 
409
+ before do
410
+ @test_dna = test_dna
393
411
  chef_cap.cap_task[:some_env].should_not be_nil
394
412
  chef_cap.cap_task[:some_env].call
395
413
  chef_cap.stub(:system).and_return(true)
@@ -459,23 +477,78 @@ describe "chef_cap" do
459
477
  chef_cap.cap_task["chef:deploy"].call
460
478
  end
461
479
 
462
- it "sets up chef gem" do
463
- chef_cap.cap_servers.should_not be_empty
464
- chef_cap.should_receive(:sudo).ordered.with("`cat /tmp/.chef_cap_rvm_path` default exec gem specification --version '>=0.1982.1234' chef 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }' || sudo `cat /tmp/.chef_cap_rvm_path` default exec gem install chef --no-ri --no-rdoc && echo 'Chef Solo already on this server.'").and_return("mocked")
465
- chef_cap.should_receive(:sudo).ordered.with("`cat /tmp/.chef_cap_rvm_path` default exec which chef-solo").and_return("mocked")
466
- chef_cap.cap_task["chef:setup"].call
467
- end
480
+ context "using rvm" do
481
+ it "sets up chef gem" do
482
+ chef_cap.cap_servers.should_not be_empty
483
+ chef_cap.should_receive(:sudo).ordered.with("`cat /tmp/.chef_cap_rvm_path` default exec gem specification --version '>=0.1982.1234' chef 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }' || sudo `cat /tmp/.chef_cap_rvm_path` default exec gem install chef --no-ri --no-rdoc && echo 'Chef Solo already on this server.'").and_return("mocked")
484
+ chef_cap.should_receive(:sudo).ordered.with("`cat /tmp/.chef_cap_rvm_path` default exec which chef-solo").and_return("mocked")
468
485
 
469
- it "installs rvm + ruby and run it if it does not exist" do
470
- chef_cap.cap_servers.should_not be_empty
471
- chef_cap.stub!(:put => "stubbed")
472
- chef_cap.should_receive(:sudo).ordered.with("/tmp/chef-cap-myenv-rvm-standup.sh").and_return("mocked")
473
- chef_cap.cap_task["rvm:bootstrap"].call
486
+ chef_cap.cap_task["bootstrap:ruby"].call
487
+ chef_cap.cap_task["chef:setup"].call
488
+ end
489
+
490
+ it "installs rvm + ruby and run it if it does not exist" do
491
+ chef_cap.cap_servers.should_not be_empty
492
+ chef_cap.stub!(:put => "stubbed")
493
+ chef_cap.should_receive(:sudo).ordered.with("/tmp/chef-cap-myenv-rvm-standup.sh").and_return("mocked")
494
+ chef_cap.cap_task["bootstrap:rvm"].call
495
+ end
474
496
  end
475
497
 
498
+ context "using rbenv" do
499
+
500
+ let(:test_dna) do
501
+ <<-JS
502
+ {
503
+ "chef": {
504
+ "root": "path_to_cookbooks",
505
+ "version": "0.1982.1234"
506
+ },
507
+ "environments": {
508
+ "some_env": {
509
+ "rails_env": "myenv",
510
+ "ruby_version_switcher": "rbenv",
511
+ "servers": [
512
+ {
513
+ "hostname": "localhost",
514
+ "roles": ["role1", "role2"]
515
+ },
516
+ {
517
+ "hostname": "otherhost.com",
518
+ "roles": ["role1"]
519
+ }
520
+ ]
521
+ }
522
+ },
523
+ "roles": {
524
+ "role1": { "run_list": ["foo"] },
525
+ "role2": { "run_list": ["foo", "bar"] }
526
+ }
527
+ }
528
+ JS
529
+ end
530
+
531
+ it "sets up chef gem" do
532
+ chef_cap.cap_servers.should_not be_empty
533
+ chef_cap.stub!(:put => "stubbed")
534
+ chef_cap.should_receive(:run).ordered.with("gem specification --version '>=0.1982.1234' chef 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }' || gem install chef --no-ri --no-rdoc && echo 'Chef Solo already on this server.'").and_return("mocked")
535
+ chef_cap.should_receive(:run).ordered.with("rbenv rehash").and_return("mocked")
536
+
537
+ chef_cap.cap_task["bootstrap:ruby"].call
538
+ chef_cap.cap_task["chef:setup"].call
539
+ end
540
+
541
+ it "installs rbenv + ruby and run it if it does not exist" do
542
+ chef_cap.cap_servers.should_not be_empty
543
+ chef_cap.stub!(:put => "stubbed")
544
+ chef_cap.should_receive(:run).ordered.with("/tmp/chef-cap-myenv-rbenv-standup.sh").and_return("mocked")
545
+ chef_cap.cap_task["bootstrap:rbenv"].call
546
+ end
547
+ end
476
548
  end
477
549
 
478
550
  describe "task :run_chef_solo" do
551
+
479
552
  context "with a db role" do
480
553
  before do
481
554
  @test_dna = <<-JS
@@ -508,6 +581,7 @@ describe "chef_cap" do
508
581
 
509
582
  chef_cap.cap_task[:some_env].should_not be_nil
510
583
  chef_cap.cap_task[:some_env].call
584
+ chef_cap.cap_task["bootstrap:ruby"].call
511
585
  chef_cap.cap_task["chef:setup_to_run_chef_solo"].call
512
586
  end
513
587
 
@@ -516,6 +590,7 @@ describe "chef_cap" do
516
590
 
517
591
  chef_cap.should_receive(:sudo).ordered.with(/.*chef-solo.*/, :hosts => ["dbhost"]).and_return("mocked")
518
592
  chef_cap.should_receive(:sudo).ordered.with(/.*chef-solo.*/, :hosts => ["apphost"]).and_return("mocked")
593
+ chef_cap.cap_task["bootstrap:ruby"].call
519
594
  chef_cap.cap_task["chef:run_chef_solo"].call
520
595
  end
521
596
  end
@@ -546,6 +621,7 @@ describe "chef_cap" do
546
621
 
547
622
  chef_cap.cap_task[:some_env].should_not be_nil
548
623
  chef_cap.cap_task[:some_env].call
624
+ chef_cap.cap_task["bootstrap:ruby"].call
549
625
  chef_cap.cap_task["chef:setup_to_run_chef_solo"].call
550
626
  end
551
627
 
@@ -598,6 +674,7 @@ describe "chef_cap" do
598
674
 
599
675
  chef_cap.cap_task[:some_env].should_not be_nil
600
676
  chef_cap.cap_task[:some_env].call
677
+ chef_cap.cap_task["bootstrap:ruby"].call
601
678
  chef_cap.cap_task["chef:setup_to_run_chef_solo"].call
602
679
  end
603
680
 
@@ -649,6 +726,7 @@ describe "chef_cap" do
649
726
 
650
727
  chef_cap.cap_task[:some_env].should_not be_nil
651
728
  chef_cap.cap_task[:some_env].call
729
+ chef_cap.cap_task["bootstrap:ruby"].call
652
730
  chef_cap.cap_task["chef:setup_to_run_chef_solo"].call
653
731
  end
654
732
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef_cap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-07 00:00:00.000000000 Z
12
+ date: 2012-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &70278612405080 !ruby/object:Gem::Requirement
16
+ requirement: &70167065111120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.5.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70278612405080
24
+ version_requirements: *70167065111120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-rails
27
- requirement: &70278612404580 !ruby/object:Gem::Requirement
27
+ requirement: &70167065110620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.1'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70278612404580
35
+ version_requirements: *70167065110620
36
36
  description: chef_cap uses chef"s JSON config format to drive both capistrano and
37
37
  chef-solo"
38
38
  email:
@@ -68,7 +68,9 @@ files:
68
68
  - recipes/lib/chef_cap_helper.rb
69
69
  - recipes/lib/chef_cap_initializer.rb
70
70
  - recipes/lib/chef_dna_parser.rb
71
- - recipes/rvm_bootstrap.rb
71
+ - recipes/rbenv.rb
72
+ - recipes/ruby.rb
73
+ - recipes/rvm.rb
72
74
  - recipes/unset_default_deploy.rb
73
75
  - spec/chef_cap_configuration_spec.rb
74
76
  - spec/chef_cap_helper_spec.rb
@@ -91,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
93
  version: '0'
92
94
  segments:
93
95
  - 0
94
- hash: -4600452591196724743
96
+ hash: -2439517596644042865
95
97
  required_rubygems_version: !ruby/object:Gem::Requirement
96
98
  none: false
97
99
  requirements:
@@ -100,10 +102,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
102
  version: '0'
101
103
  segments:
102
104
  - 0
103
- hash: -4600452591196724743
105
+ hash: -2439517596644042865
104
106
  requirements: []
105
107
  rubyforge_project:
106
- rubygems_version: 1.8.15
108
+ rubygems_version: 1.8.17
107
109
  signing_key:
108
110
  specification_version: 3
109
111
  summary: capistrano + chef-solo == chef_cap"