soloist 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in soloist.gemspec
4
4
  gemspec
5
+
6
+ gem "rspec", "2.4.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soloist (0.0.2)
4
+ soloist (0.0.3)
5
5
  chef (= 0.9.12)
6
6
  json (= 1.4.6)
7
7
 
@@ -24,6 +24,7 @@ GEM
24
24
  ohai (>= 0.5.7)
25
25
  rest-client (>= 1.0.4, < 1.7.0)
26
26
  uuidtools
27
+ diff-lcs (1.1.2)
27
28
  erubis (2.6.6)
28
29
  abstract (>= 1.0.0)
29
30
  extlib (0.9.15)
@@ -45,13 +46,20 @@ GEM
45
46
  systemu
46
47
  rest-client (1.6.1)
47
48
  mime-types (>= 1.16)
49
+ rspec (2.4.0)
50
+ rspec-core (~> 2.4.0)
51
+ rspec-expectations (~> 2.4.0)
52
+ rspec-mocks (~> 2.4.0)
53
+ rspec-core (2.4.0)
54
+ rspec-expectations (2.4.0)
55
+ diff-lcs (~> 1.1.2)
56
+ rspec-mocks (2.4.0)
48
57
  systemu (1.2.0)
49
- uuidtools (2.1.1)
58
+ uuidtools (2.1.2)
50
59
 
51
60
  PLATFORMS
52
61
  ruby
53
62
 
54
63
  DEPENDENCIES
55
- chef (= 0.9.12)
56
- json (= 1.4.6)
64
+ rspec (= 2.4.0)
57
65
  soloist!
data/README.markdown CHANGED
@@ -39,9 +39,9 @@ directory layout:
39
39
 
40
40
  soloistrc
41
41
  ---------
42
- Cookbook_Paths:
42
+ cookbook_paths:
43
43
  - ./chef/cookbooks/
44
- Recipes:
44
+ recipes:
45
45
  - pivotal_workstation::ack
46
46
  - pivotal_workstation::bash_path_order
47
47
  - pivotal_workstation::bash_profile
@@ -65,3 +65,19 @@ soloistrc
65
65
  - pivotal_workstation::turn_on_ssh
66
66
  - pivotal_workstation::user_owns_usr_local
67
67
  - pivotal_workstation::workspace_directory
68
+
69
+ Environment Variable Switching (Alpha)
70
+ ======================================
71
+ I'm undecided on how recipes should be selected once you get to the point of running chef on various platforms and on boxes with different roles. I'm trying out adding support in the soloistrc file for selecting recipes based on environment variables. Cap should allow setting environment variables fairly easily, and they can be set permanently on the machine if desired. To use these, add a env_variable_switches key to your soloistrc. They keys of the hash should be the environment variable you wish to change the configuration based on, and the value should be a hash keyed by the value of the environment variable. It's easier than it sounds - see the example below. (NB: Note that the CamelSnake is gone in the soloistrc, and while the basic config accepts the old keys, environment variable switching requires snake case keys)
72
+
73
+ cookbook_paths:
74
+ - ./chef/cookbooks/
75
+ recipes:
76
+ - pivotal_workstation::ack
77
+ env_variable_switches:
78
+ RACK_ENV:
79
+ development:
80
+ cookbook_paths:
81
+ - ./chef/dev_cookbooks/
82
+ recipes:
83
+ - pivotal_dev::foo
data/bin/soloist CHANGED
@@ -1,9 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
- require "json"
4
- require 'fileutils'
5
- require 'yaml'
6
- require 'tempfile'
3
+ require 'soloist'
7
4
 
8
5
  def fileify(contents)
9
6
  file = Tempfile.new("soloist")
@@ -29,18 +26,7 @@ end
29
26
  log_level = ENV['LOG_LEVEL'] || "info"
30
27
 
31
28
  soloistrc_contents, soloistrc_path = walk_up_and_find_file(["soloistrc"])
32
- soloistrc = YAML.load(soloistrc_contents)
33
-
34
- json_contents = {
35
- :recipes => soloistrc["Recipes"]
36
- }
37
-
38
- cookbook_paths = soloistrc["Cookbook_Paths"].map do |v|
39
- (v =~ /\//) == 0 ? v : "#{FileUtils.pwd}/#{soloistrc_path}/#{v}"
40
- end
41
- puts FileUtils.pwd
42
- puts cookbook_paths.inspect
43
- solo_rb_contents = "cookbook_path #{cookbook_paths.inspect}"
29
+ config_generator = ChefConfigGenerator.new(soloistrc_contents, soloistrc_path)
44
30
 
45
31
  # if ARGV.length >= 1
46
32
  # json_config = JSON.parse(File.read(json_file))
@@ -50,8 +36,8 @@ solo_rb_contents = "cookbook_path #{cookbook_paths.inspect}"
50
36
  # File.open(json_file, "w+"){|f| f<<JSON.pretty_generate(json_config) }
51
37
  # end
52
38
 
53
- solo_rb = fileify(solo_rb_contents)
54
- metadata_json = fileify(json_contents.to_json)
39
+ solo_rb = fileify(config_generator.solo_rb)
40
+ metadata_json = fileify(config_generator.json_file)
55
41
 
56
42
  env_vars = ["PATH=#{ENV['PATH']}"]
57
43
  %w{BUNDLE_PATH GEM_HOME GEM_PATH RAILS_ENV}.each do |v|
@@ -0,0 +1,43 @@
1
+ require 'yaml'
2
+
3
+ class ChefConfigGenerator
4
+ def initialize(yaml_string, relative_path_to_soloistrc)
5
+ @hash = YAML.load(yaml_string)
6
+ @relative_path_to_soloistrc = relative_path_to_soloistrc
7
+ merge_env_variable_switches
8
+ end
9
+
10
+ def merge_env_variable_switches
11
+ return unless @hash["env_variable_switches"]
12
+ @hash["env_variable_switches"].keys.each do |variable|
13
+ sub_hash = @hash["env_variable_switches"][variable][ENV[variable]]
14
+ if sub_hash && sub_hash["recipes"]
15
+ @hash["recipes"] = (@hash["recipes"] + sub_hash["recipes"]).uniq
16
+ end
17
+ if sub_hash && sub_hash["cookbook_paths"]
18
+ @hash["cookbook_paths"] = (@hash["cookbook_paths"] + sub_hash["cookbook_paths"]).uniq
19
+ end
20
+ end
21
+ end
22
+
23
+ def cookbook_paths
24
+ (@hash["cookbook_paths"] || @hash["Cookbook_Paths"]).map do |v|
25
+ (v =~ /\//) == 0 ? v : "#{FileUtils.pwd}/#{@relative_path_to_soloistrc}/#{v}"
26
+ end
27
+ end
28
+
29
+ def solo_rb
30
+ "cookbook_path #{cookbook_paths.inspect}"
31
+ end
32
+
33
+ def json_hash
34
+ recipes = @hash["Recipes"] || @hash["recipes"]
35
+ {
36
+ "recipes" => recipes
37
+ }
38
+ end
39
+
40
+ def json_file
41
+ json_hash.to_json
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Soloist
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/soloist.rb CHANGED
@@ -1,3 +1,10 @@
1
+ require 'soloist/chef_config_generator'
2
+ require "json"
3
+ require 'fileutils'
4
+ require 'yaml'
5
+ require 'tempfile'
6
+
7
+
1
8
  module Soloist
2
9
  # Your code goes here...
3
10
  end
@@ -0,0 +1,100 @@
1
+ require 'rspec'
2
+ require 'lib/soloist'
3
+
4
+ describe "ChefConfigGenerator" do
5
+ describe "generation" do
6
+ before do
7
+ @config = <<-CONFIG
8
+ Cookbook_Paths:
9
+ - ./chef/cookbooks/
10
+ Recipes:
11
+ - pivotal_workstation::ack
12
+ CONFIG
13
+ @generator = ChefConfigGenerator.new(@config, "../..")
14
+ FileUtils.stub(:pwd).and_return("/current/working/directory")
15
+ end
16
+
17
+ it "appends the current path and relative path to the cookbooks directory" do
18
+ @generator.cookbook_paths.should == ["/current/working/directory/../.././chef/cookbooks/"]
19
+ end
20
+
21
+ it "can generate a solo.rb contents" do
22
+ @generator.solo_rb.should == 'cookbook_path ["/current/working/directory/../.././chef/cookbooks/"]'
23
+ end
24
+
25
+ it "can generate the json contents" do
26
+ @generator.json_hash.should == {
27
+ "recipes" => ['pivotal_workstation::ack']
28
+ }
29
+ end
30
+
31
+ it "can generate json files" do
32
+ JSON.parse(@generator.json_file).should == {
33
+ "recipes" => ['pivotal_workstation::ack']
34
+ }
35
+ end
36
+ end
37
+
38
+ describe "yaml config values" do
39
+ before do
40
+ FileUtils.stub(:pwd).and_return("/")
41
+ end
42
+
43
+ it "accepts Cookbook_Paths, because the CamelSnake is a typo that must be supported" do
44
+ @config = "Cookbook_Paths:\n- ./chef/cookbooks/\n"
45
+ @generator = ChefConfigGenerator.new(@config, "")
46
+ @generator.cookbook_paths.should == ["///./chef/cookbooks/"]
47
+ end
48
+
49
+ it "accepts cookbook_paths, because it is sane" do
50
+ @config = "cookbook_paths:\n- ./chef/cookbooks/\n"
51
+ @generator = ChefConfigGenerator.new(@config, "")
52
+ @generator.cookbook_paths.should == ["///./chef/cookbooks/"]
53
+ end
54
+
55
+ it "accepts Recipes, because that's the way it was" do
56
+ @config = "Recipes:\n- pivotal_workstation::ack"
57
+ @generator = ChefConfigGenerator.new(@config, "")
58
+ @generator.json_hash.should == { "recipes" => ["pivotal_workstation::ack"]}
59
+ end
60
+
61
+ it "accepts recipes, because it's snake now" do
62
+ @config = "recipes:\n- pivotal_workstation::ack"
63
+ @generator = ChefConfigGenerator.new(@config, "")
64
+ @generator.json_hash.should == { "recipes" => ["pivotal_workstation::ack"]}
65
+ end
66
+ end
67
+
68
+
69
+ describe "environment variable merging" do
70
+ before do
71
+ @config = <<-CONFIG
72
+ cookbook_paths:
73
+ - ./chef/cookbooks/
74
+ recipes:
75
+ - pivotal_workstation::ack
76
+ env_variable_switches:
77
+ RACK_ENV:
78
+ development:
79
+ cookbook_paths:
80
+ - ./chef/dev_cookbooks/
81
+ recipes:
82
+ - pivotal_dev::foo
83
+ CONFIG
84
+ FileUtils.stub(:pwd).and_return("/")
85
+ end
86
+
87
+ it "merges in if the variable is set to the the value" do
88
+ ENV["RACK_ENV"]="development"
89
+ @generator = ChefConfigGenerator.new(@config, "../..")
90
+ @generator.cookbook_paths.should == [
91
+ "//../.././chef/cookbooks/",
92
+ "//../.././chef/dev_cookbooks/"
93
+ ]
94
+ @generator.json_hash["recipes"].should == [
95
+ "pivotal_workstation::ack",
96
+ "pivotal_dev::foo"
97
+ ]
98
+ end
99
+ end
100
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soloist
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew Kocher
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-27 00:00:00 -08:00
18
+ date: 2011-02-04 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -67,8 +67,10 @@ files:
67
67
  - Rakefile
68
68
  - bin/soloist
69
69
  - lib/soloist.rb
70
+ - lib/soloist/chef_config_generator.rb
70
71
  - lib/soloist/version.rb
71
72
  - soloist.gemspec
73
+ - spec/chef_config_generator_spec.rb
72
74
  has_rdoc: true
73
75
  homepage: http://rubygems.org/gems/soloist
74
76
  licenses: []
@@ -103,5 +105,5 @@ rubygems_version: 1.3.7
103
105
  signing_key:
104
106
  specification_version: 3
105
107
  summary: Soloist is a simple way of running chef-solo
106
- test_files: []
107
-
108
+ test_files:
109
+ - spec/chef_config_generator_spec.rb