chef_cap 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .DS_Store
2
2
  *.gem
3
+ Gemfile.lock
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.2-p0@chef_cap
1
+ rvm 1.9.2-p136@chef_cap
data/Capfile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ gemfile = File.expand_path('Gemfile', __FILE__)
5
+ begin
6
+ ENV['BUNDLE_GEMFILE'] = gemfile
7
+ require 'bundler'
8
+ Bundler.setup
9
+ rescue Bundler::GemNotFound => e
10
+ STDERR.puts e.message
11
+ STDERR.puts "Try running `bundle install`."
12
+ exit!
13
+ end if File.exist?(gemfile)
14
+ require File.join(File.dirname(__FILE__), "lib/chef_cap")
15
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
16
+ ::ChefCap::Capistrano.load_recipes(self)
data/Gemfile CHANGED
@@ -1,9 +1,10 @@
1
1
  source :rubygems
2
2
 
3
+ gemspec
4
+
3
5
  group :development do
4
6
  gem "rspec-rails", "2.1"
5
7
  gem 'wirble'
6
- gem 'capistrano'
7
8
  end
8
9
 
9
10
  group :test do
data/README.rdoc CHANGED
@@ -12,9 +12,7 @@ Using chef's JSON configuration format to drive capistrano and chef-solo so you
12
12
 
13
13
  Add chef_cap to your Gemfile
14
14
 
15
- group :development do
16
- gem 'chef_cap'
17
- end
15
+ gem 'chef_cap'
18
16
 
19
17
  Then run:
20
18
 
data/Rakefile CHANGED
@@ -4,6 +4,9 @@ require 'rake'
4
4
  require 'rspec/core'
5
5
  require 'rspec/core/rake_task'
6
6
 
7
+ require 'bundler'
8
+ Bundler::GemHelper.install_tasks
9
+
7
10
  task :default => :spec
8
11
 
9
12
  desc "Run all specs in spec directory (excluding plugin specs)"
data/chef/node.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "application": {
3
+ "name": "your-app-name",
4
+ "repository": "your-repo"
5
+ },
6
+ "upload": [
7
+ ],
8
+ "environments": {
9
+ "defaults": {
10
+ "user": "deploy",
11
+ "branch": "master"
12
+ },
13
+ "production": {
14
+ "rails_env": "production",
15
+ "database": {
16
+ "user": "production-db-user",
17
+ "host": "production-db-host"
18
+ },
19
+ "servers": [
20
+ {
21
+ "hostname": "some.fq.dn",
22
+ "roles": ["web", "app", "db"],
23
+ "primary": ["web", "app", "db"]
24
+ }
25
+ ]
26
+ }
27
+ },
28
+ "shared": {
29
+ "gems": [
30
+ { "name": "bundler" },
31
+ { "name": "chef", "version": ">=0.9.12" }
32
+ ],
33
+ "run_list": ["gems"]
34
+ },
35
+ "roles": {
36
+ "web": {},
37
+ "app": {},
38
+ "db": {}
39
+ }
40
+ // "deploy_recipe": "yourcustomdeployrecipe",
41
+ }
@@ -1,3 +1,3 @@
1
1
  module ChefCap
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/chef_cap.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "chef_cap/version"
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "chef_cap/version"))
2
2
 
3
3
  module ChefCap
4
4
 
data/recipes/chef_cap.rb CHANGED
@@ -134,7 +134,9 @@ end
134
134
  namespace :chef do
135
135
  desc "Setup chef solo on the server(s)"
136
136
  task :setup do
137
- sudo "rvm default exec gem specification --version '>=0.9.12' chef 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }' || sudo rvm default exec gem install chef --no-ri --no-rdoc && echo 'Chef Solo already on this server.'"
137
+ gem_check_for_chef_cmd = "gem specification --version '>=0.9.12' chef 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }'"
138
+ install_chef_cmd = "sudo rvm default exec gem install chef --no-ri --no-rdoc"
139
+ sudo "rvm default exec #{gem_check_for_chef_cmd} || #{install_chef_cmd} && echo 'Chef Solo already on this server.'"
138
140
  sudo "rvm default exec which chef-solo"
139
141
  end
140
142
 
@@ -165,6 +167,7 @@ namespace :chef do
165
167
  env_settings.each { |k, v| ChefCapHelper.recursive_merge(json_to_modify["environment"] || {}, k, v) }
166
168
 
167
169
  json_to_modify["environment"]["revision"] = ChefCapHelper.set_revision if ChefCapHelper.has_revision?
170
+ json_to_modify["environment"]["branch"] = ChefCapHelper.set_branch if ChefCapHelper.has_branch?
168
171
  json_to_modify["environment"]["servers"] = ChefCapHelper.intialize_primary_values(json_to_modify["environment"]["servers"])
169
172
 
170
173
  should_not_deploy = no_deploy rescue false
@@ -49,7 +49,23 @@ class ChefCapHelper
49
49
  end
50
50
 
51
51
  def set_revision
52
- ENV["rev"] || ENV["tag"] || ENV["REV"] || ENV["TAG"] || ENV["revision"] || ENV["REVISION"]
52
+ ["rev", "tag", "revision"].each do |word|
53
+ [word, word.upcase, "-S#{word}"].each do |variable|
54
+ return ENV[variable] if ENV[variable]
55
+ end
56
+ end
57
+ nil
58
+ end
59
+
60
+ def set_branch
61
+ ["branch", "BRANCH", "-Sbranch"].each do |variable|
62
+ return ENV[variable] if ENV[variable]
63
+ end
64
+ nil
65
+ end
66
+
67
+ def has_branch?
68
+ !set_branch.nil?
53
69
  end
54
70
 
55
71
  def has_revision?
@@ -123,4 +123,35 @@ describe ChefDnaParser do
123
123
  ChefCapHelper.intialize_primary_values(array_of_servers_hash).should == array_of_servers_hash
124
124
  end
125
125
  end
126
+
127
+ describe ".set_revision" do
128
+ ["rev", "tag", "revision"].each do |word|
129
+ [word, word.upcase, "-S#{word}"].each do |variable|
130
+ it "returns the value of ENV['#{variable}']" do
131
+ value = Time.now.to_f.to_s
132
+ ENV["#{variable}"] = value
133
+ ChefCapHelper.set_revision.should == value
134
+ end
135
+
136
+ after :each do
137
+ ENV["#{variable}"] = nil
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ describe ".set_branch" do
144
+ ["branch", "BRANCH", "-Sbranch"].each do |variable|
145
+ it "returns the value of ENV['#{variable}']" do
146
+ value = Time.now.to_f.to_s
147
+ ENV["#{variable}"] = value
148
+ ChefCapHelper.set_branch.should == value
149
+ end
150
+
151
+ after :each do
152
+ ENV["#{variable}"] = nil
153
+ end
154
+ end
155
+ end
156
+
126
157
  end
@@ -785,6 +785,7 @@ describe "chef_cap" do
785
785
 
786
786
  it "shoves the value into the node json alongside branch" do
787
787
  ENV['rev'] = "123"
788
+ ENV['branch'] = "somebranch"
788
789
  chef_cap.stub!(:put => "stubbed")
789
790
  chef_cap.stub!(:upload => "stubbed")
790
791
  chef_cap.stub!(:sudo => "stubbed")
@@ -798,7 +799,7 @@ describe "chef_cap" do
798
799
  "something"=>"other", "foo"=>"bar",
799
800
  "chef"=>{"root"=>"path_to_cookbooks"},
800
801
  "run_list"=>nil, "shared"=>{"foo"=>"bar"},
801
- "environment"=> {"revision"=>"123", "servers"=>[{"primary" => [], "hostname"=>"localhost", "roles"=>["role1", "role2"]}]}, "roles"=>{"role1"=>{"something"=>"other"}}}
802
+ "environment"=> {"revision"=>"123", "branch" => "somebranch", "servers"=>[{"primary" => [], "hostname"=>"localhost", "roles"=>["role1", "role2"]}]}, "roles"=>{"role1"=>{"something"=>"other"}}}
802
803
  )
803
804
  }
804
805
  chef_cap.cap_task["chef:deploy"].call
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 7
9
+ version: 0.0.7
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-19 00:00:00 -05:00
17
+ date: 2011-01-21 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -45,11 +45,12 @@ files:
45
45
  - .gitignore
46
46
  - .rspec
47
47
  - .rvmrc
48
+ - Capfile
48
49
  - Gemfile
49
- - Gemfile.lock
50
50
  - LICENSE
51
51
  - README.rdoc
52
52
  - Rakefile
53
+ - chef/node.json
53
54
  - chef_cap.gemspec
54
55
  - fixtures/parser.json
55
56
  - fixtures/ssh_deploy_key
data/Gemfile.lock DELETED
@@ -1,37 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- capistrano (2.5.19)
5
- highline
6
- net-scp (>= 1.0.0)
7
- net-sftp (>= 2.0.0)
8
- net-ssh (>= 2.0.14)
9
- net-ssh-gateway (>= 1.0.0)
10
- diff-lcs (1.1.2)
11
- highline (1.6.1)
12
- net-scp (1.0.4)
13
- net-ssh (>= 1.99.1)
14
- net-sftp (2.0.5)
15
- net-ssh (>= 2.0.9)
16
- net-ssh (2.0.23)
17
- net-ssh-gateway (1.0.1)
18
- net-ssh (>= 1.99.1)
19
- rspec (2.1.0)
20
- rspec-core (~> 2.1.0)
21
- rspec-expectations (~> 2.1.0)
22
- rspec-mocks (~> 2.1.0)
23
- rspec-core (2.1.0)
24
- rspec-expectations (2.1.0)
25
- diff-lcs (~> 1.1.2)
26
- rspec-mocks (2.1.0)
27
- rspec-rails (2.1.0)
28
- rspec (~> 2.1.0)
29
- wirble (0.1.3)
30
-
31
- PLATFORMS
32
- ruby
33
-
34
- DEPENDENCIES
35
- capistrano
36
- rspec-rails (= 2.1)
37
- wirble