rna 0.3.8 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  output
20
+ spec/project
data/Guardfile CHANGED
@@ -4,7 +4,6 @@ end
4
4
 
5
5
  guard 'rspec' do
6
6
  watch(%r{^spec/.+_spec\.rb$})
7
- watch(%r{^spec/project/config/.*$}) { |m| "spec/lib/rna_spec.rb" }
8
7
  watch(%r{^lib/rna/(.+)\.rb$}) { |m| "spec/lib/rna_spec.rb" }
9
8
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/rna_spec.rb" }
10
9
  # watch('spec/spec_helper.rb') { "spec" }
data/README.md CHANGED
@@ -16,8 +16,8 @@ $ gem install rna
16
16
  ## Usage
17
17
 
18
18
  <pre>
19
- $ mkdir rna_project
20
- $ cd rna_project
19
+ $ mkdir rna
20
+ $ cd rna
21
21
  $ rna init
22
22
  </pre>
23
23
 
@@ -32,7 +32,7 @@ This will create starter config/rna.rb and config/s3.yml files.
32
32
  # This is meant be be modified to your needs.
33
33
  default_includes 'base'
34
34
  # Pre processing rules that run at the beginning
35
- pre_rule do
35
+ before do
36
36
  if role != 'base'
37
37
  node[:application] = nil
38
38
  node[:deploy_code] = false
@@ -40,7 +40,7 @@ pre_rule do
40
40
  node[:repository] = nil
41
41
  end
42
42
 
43
- node[:pre_rule] = 1
43
+ node[:before] = 1
44
44
  node[:chef_branch] = 'prod' if role =~ /^prod/
45
45
  node[:chef_branch] = 'master' if role =~ /^stag/
46
46
  end
@@ -74,8 +74,8 @@ end
74
74
 
75
75
 
76
76
  # Post processing rules that run at the end
77
- post_rule do
78
- node[:post_rule] = 2
77
+ after do
78
+ node[:after] = 2
79
79
  node[:framework_env] = 'production' if role =~ /^prod/
80
80
  node[:framework_env] = 'staging' if role =~ /^stag/
81
81
 
@@ -120,7 +120,7 @@ If you have a lot of roles, the config/rna.rb file can get unwieldy long. You c
120
120
  An example is in the spec/project folder:
121
121
 
122
122
  * config/rna/api.rb
123
- * config/rna/masta.rb
123
+ * config/rna/blog.rb
124
124
 
125
125
  #### Generating the json files
126
126
 
@@ -134,12 +134,12 @@ base.json:
134
134
 
135
135
  ```json
136
136
  {
137
- "pre_rule": 1,
137
+ "before": 1,
138
138
  "role": "base",
139
139
  "run_list": [
140
140
  "role[base]"
141
141
  ],
142
- "post_rule": 2
142
+ "after": 2
143
143
  }
144
144
  ```
145
145
 
@@ -147,7 +147,7 @@ prod-api-app.json:
147
147
 
148
148
  ```json
149
149
  {
150
- "pre_rule": 1,
150
+ "before": 1,
151
151
  "role": "prod-api-app",
152
152
  "run_list": [
153
153
  "role[base]",
@@ -162,7 +162,7 @@ prod-api-app.json:
162
162
  "pass": "pass"
163
163
  },
164
164
  "repository": "git@github.com:owner/repo.git/api.git",
165
- "post_rule": 2,
165
+ "after": 2,
166
166
  "framework_env": "production"
167
167
  }
168
168
  ```
@@ -171,13 +171,13 @@ prod-api-redis.json:
171
171
 
172
172
  ```json
173
173
  {
174
- "pre_rule": 1,
174
+ "before": 1,
175
175
  "role": "prod-api-redis",
176
176
  "run_list": [
177
177
  "role[base]",
178
178
  "role[api_redis]"
179
179
  ],
180
- "post_rule": 2,
180
+ "after": 2,
181
181
  "framework_env": "production",
182
182
  "application": "api"
183
183
  }
@@ -187,7 +187,7 @@ prod-api-resque.json:
187
187
 
188
188
  ```json
189
189
  {
190
- "pre_rule": 1,
190
+ "before": 1,
191
191
  "role": "prod-api-resque",
192
192
  "run_list": [
193
193
  "role[base]",
@@ -203,7 +203,7 @@ prod-api-resque.json:
203
203
  },
204
204
  "repository": "git@github.com:owner/repo.git/api.git",
205
205
  "workers": 8,
206
- "post_rule": 2,
206
+ "after": 2,
207
207
  "framework_env": "production"
208
208
  }
209
209
  ```
@@ -212,7 +212,7 @@ stag-api-app.json:
212
212
 
213
213
  ```json
214
214
  {
215
- "pre_rule": 1,
215
+ "before": 1,
216
216
  "role": "stag-api-app",
217
217
  "run_list": [
218
218
  "role[base]",
@@ -227,7 +227,7 @@ stag-api-app.json:
227
227
  "pass": "pass"
228
228
  },
229
229
  "repository": "git@github.com:owner/repo.git/api.git",
230
- "post_rule": 2,
230
+ "after": 2,
231
231
  "framework_env": "staging"
232
232
  }
233
233
  ```
@@ -236,13 +236,13 @@ stag-api-redis.json:
236
236
 
237
237
  ```json
238
238
  {
239
- "pre_rule": 1,
239
+ "before": 1,
240
240
  "role": "stag-api-redis",
241
241
  "run_list": [
242
242
  "role[base]",
243
243
  "role[api_redis]"
244
244
  ],
245
- "post_rule": 2,
245
+ "after": 2,
246
246
  "framework_env": "staging",
247
247
  "application": "api"
248
248
  }
@@ -252,7 +252,7 @@ stag-api-resque.json:
252
252
 
253
253
  ```json
254
254
  {
255
- "pre_rule": 1,
255
+ "before": 1,
256
256
  "role": "stag-api-resque",
257
257
  "run_list": [
258
258
  "role[base]",
@@ -268,7 +268,7 @@ stag-api-resque.json:
268
268
  },
269
269
  "repository": "git@github.com:owner/repo.git/api.git",
270
270
  "workers": 8,
271
- "post_rule": 2,
271
+ "after": 2,
272
272
  "framework_env": "staging"
273
273
  }
274
274
  ```
@@ -2,7 +2,7 @@
2
2
  # This is meant be be modified to your needs.
3
3
  default_includes 'base'
4
4
  # Pre processing rules that run at the beginning
5
- pre_rule do
5
+ before do
6
6
  if role != 'base'
7
7
  node[:application] = nil
8
8
  node[:deploy_code] = false
@@ -10,7 +10,7 @@ pre_rule do
10
10
  node[:repository] = nil
11
11
  end
12
12
 
13
- node[:pre_rule] = 1
13
+ node[:before] = 1
14
14
  node[:chef_branch] = 'prod' if role =~ /^prod/
15
15
  node[:chef_branch] = 'master' if role =~ /^stag/
16
16
  end
@@ -23,8 +23,8 @@ role 'base' do
23
23
  end
24
24
 
25
25
  # Post processing rules that run at the end
26
- post_rule do
27
- node[:post_rule] = 2
26
+ after do
27
+ node[:after] = 2
28
28
  node[:framework_env] = 'production' if role =~ /^prod/
29
29
  node[:framework_env] = 'staging' if role =~ /^stag/
30
30
 
@@ -5,7 +5,6 @@ role 'prod-api-resque', 'stag-api-resque' do
5
5
  node[:workers] = 8
6
6
  end
7
7
  role 'prod-api-app', 'stag-api-app' do
8
- role_list ['base','api_app']
9
8
  node[:application] = 'api'
10
9
  node[:deploy_code] = true
11
10
  node[:repository] = 'git@github.com:owner/repo.git/api.git'
@@ -0,0 +1,13 @@
1
+ # blog
2
+ role 'blog-app' do
3
+ output false
4
+ node[:blog_app] = 123
5
+ end
6
+ role 'prod-blog-redis', 'stag-blog-redis'
7
+ role 'prod-blog-app', 'stag-blog-app' do
8
+ includes 'blog-app'
9
+ node[:application] = 'blog'
10
+ node[:deploy_code] = true
11
+ node[:repository] = 'git@github.com:arockwell/blog_blasta.git'
12
+ node[:relayhost] = settings[:sendgrid][:relayhost]
13
+ end
@@ -0,0 +1,4 @@
1
+ access_key_id: 0JABDCSHH7HR4CEMM6G2
2
+ secret_access_key: eQavuSsZRfmSiY1noIFDBy29jARbsqjHBWvPFtDK
3
+ bucket: br-testing
4
+ folder: chef/rna
data/lib/rna.rb CHANGED
@@ -3,6 +3,7 @@ require 'thor'
3
3
  require 'yaml'
4
4
  require 'aws-sdk'
5
5
  require 'pp'
6
+ require 'deep_merge'
6
7
 
7
8
  $:.unshift File.expand_path('../', __FILE__)
8
9
  require 'node'
@@ -3,8 +3,11 @@ module Rna
3
3
 
4
4
  desc "init", "Setup rna project"
5
5
  long_desc "Sets up config/rna.rb"
6
+ method_option :force, :type => :boolean, :aliases => "-f", :desc => "override existing starter files"
7
+ method_option :project_root, :default => ".", :aliases => "-r", :desc => "project root"
8
+ method_option :quiet, :type => :boolean, :aliases => "-q", :desc => "silence the output"
6
9
  def init
7
- Rna::Task.init
10
+ Rna::Task.init(options)
8
11
  end
9
12
 
10
13
  desc "generate", "Builds node.json files"
@@ -12,16 +15,18 @@ module Rna
12
15
  Examples:
13
16
 
14
17
  1. rna generate
18
+ 2. rna g -c # shortcut
15
19
 
16
20
  Builds the node.json files based on config/rna.rb and writes them to the ouput folder on the filesystem.
17
21
 
18
- 2. rna generate -o s3
22
+ 3. rna generate -o s3
19
23
 
20
24
  Builds the node.json files based on config/rna.rb and writes them to s3 based on the s3 settings in config/s3.yml.
21
25
  EOL
22
26
  method_option :output, :aliases => '-o', :desc => "specify where to output the generated files to", :default => 'filesystem'
23
27
  method_option :clean, :type => :boolean, :aliases => "-c", :desc => "remove all output files before generating"
24
28
  method_option :verbose, :type => :boolean, :aliases => "-v", :desc => "show files being generated"
29
+ method_option :project_root, :default => ".", :aliases => "-r", :desc => "project root"
25
30
  def generate
26
31
  Rna::Task.generate(options)
27
32
  puts "Rna files generated"
@@ -2,11 +2,13 @@ module Rna
2
2
  class DSL
3
3
  attr_reader :data, :jsons
4
4
  def initialize(options={})
5
- @options = options
5
+ @options = options.dup
6
+ @project_root = options[:project_root] || '.'
7
+ @path = "#{@project_root}/config/rna.rb"
8
+ @options[:output_path] = "#{@project_root}/output"
6
9
 
7
- @path = options[:config_path] || 'config/rna.rb'
8
- @pre_rule = nil
9
- @post_rule = nil
10
+ @before = nil
11
+ @after = nil
10
12
  @roles = []
11
13
  end
12
14
 
@@ -33,12 +35,12 @@ module Rna
33
35
  Role.default_includes = role
34
36
  end
35
37
 
36
- def pre_rule(&block)
37
- @pre_rule = {:block => block}
38
+ def before(&block)
39
+ @before = {:block => block}
38
40
  end
39
41
 
40
- def post_rule(&block)
41
- @post_rule = {:block => block}
42
+ def after(&block)
43
+ @after = {:block => block}
42
44
  end
43
45
 
44
46
  def role(*names, &block)
@@ -50,6 +52,7 @@ module Rna
50
52
  end
51
53
 
52
54
  def run
55
+ puts "Generating rna files" unless @options[:quiet]
53
56
  evaluate
54
57
  build
55
58
  process
@@ -85,18 +88,18 @@ module Rna
85
88
  json = process_role(includes, depth+1)
86
89
  else
87
90
  json = {}
88
- if @pre_rule
89
- pre_data = Rule.new(role, @pre_rule[:block]).build
90
- json.merge!(pre_data[:attributes])
91
+ if @before
92
+ pre_data = Rule.new(role, @before[:block]).build
93
+ json.deep_merge!(pre_data[:attributes])
91
94
  end
92
95
  end
93
96
 
94
97
  attributes = role_data[:attributes] || {}
95
- json.merge!(attributes)
98
+ json.deep_merge!(attributes)
96
99
  # only process post rule at the very last step
97
- if @post_rule and depth == 1
98
- post_data = Rule.new(role, @post_rule[:block]).build
99
- json.merge!(post_data[:attributes])
100
+ if @after and depth == 1
101
+ post_data = Rule.new(role, @after[:block]).build
102
+ json.deep_merge!(post_data[:attributes])
100
103
  end
101
104
  json
102
105
  end
@@ -122,7 +125,7 @@ module Rna
122
125
  @dsl = eval "self", @block.binding
123
126
  instance_eval(&@block)
124
127
  end
125
- @data[:attributes].merge!(set.to_mash)
128
+ @data[:attributes].deep_merge!(set.to_mash)
126
129
  @data
127
130
  end
128
131
 
@@ -8,7 +8,6 @@ module Rna
8
8
 
9
9
  class Filesystem < Outputer
10
10
  def run(jsons)
11
- # options[:output_path] only used for specs
12
11
  output_path = options[:output_path] || "output"
13
12
  FileUtils.rm_rf(output_path) if options[:clean]
14
13
  FileUtils.mkdir(output_path) unless File.exist?(output_path)
@@ -1,19 +1,25 @@
1
1
  module Rna
2
2
  class Task
3
- def self.init(project_root=".",options={})
4
- puts "Settin up rna project" unless options[:quiet]
5
- FileUtils.mkdir("#{project_root}/config") unless File.exist?("#{project_root}/config")
6
- %w/rna.rb s3.yml Guardfile/.each do |name|
7
- source = File.expand_path("../../files/#{name}", __FILE__)
8
- dest = "#{project_root}/config/#{File.basename(source)}"
9
- dest = "#{project_root}/#{File.basename(source)}" if name == 'Guardfile'
10
- if File.exist?(dest)
3
+ def self.init(options={})
4
+ project_root = options[:project_root] || '.'
5
+ puts "Setting up lono project" unless options[:quiet]
6
+ source_root = File.expand_path("../../starter_project", __FILE__)
7
+ paths = Dir.glob("#{source_root}/**/*").
8
+ select {|p| File.file?(p) }
9
+ paths.each do |src|
10
+ dest = src.gsub(%r{.*starter_project/},'')
11
+ dest = "#{project_root}/#{dest}"
12
+
13
+ if File.exist?(dest) and !options[:force]
11
14
  puts "already exists: #{dest}" unless options[:quiet]
12
15
  else
13
16
  puts "creating: #{dest}" unless options[:quiet]
14
- FileUtils.cp(source, dest)
17
+ dirname = File.dirname(dest)
18
+ FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
19
+ FileUtils.cp(src, dest)
15
20
  end
16
21
  end
22
+ puts "Starter lono project created"
17
23
  end
18
24
  def self.generate(options)
19
25
  new(options).generate
@@ -1,3 +1,3 @@
1
1
  module Rna
2
- VERSION = '0.3.8'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -2,7 +2,7 @@
2
2
  # This is meant be be modified to your needs.
3
3
  default_includes 'base'
4
4
  # Pre processing rules that run at the beginning
5
- pre_rule do
5
+ before do
6
6
  if role != 'base'
7
7
  node[:application] = nil
8
8
  node[:deploy_code] = false
@@ -10,7 +10,7 @@ pre_rule do
10
10
  node[:repository] = nil
11
11
  end
12
12
 
13
- node[:pre_rule] = 1
13
+ node[:before] = 1
14
14
  node[:chef_branch] = 'prod' if role =~ /^prod/
15
15
  node[:chef_branch] = 'master' if role =~ /^stag/
16
16
  end
@@ -22,30 +22,9 @@ role 'base' do
22
22
  role_list ['base']
23
23
  end
24
24
 
25
- # api
26
- role 'prod-api-redis', 'stag-api-redis' do
27
- run_list ['base','api_redis']
28
- end
29
- role 'prod-api-app', 'stag-api-app' do
30
- run_list ['base','api_app']
31
- node[:application] = 'api'
32
- node[:deploy_code] = true
33
- node[:database][:adapter] = "mysql"
34
- node[:database][:host] = "127.0.0.1"
35
- node[:database][:user] = "user"
36
- node[:database][:pass] = "pass"
37
- node[:repository] = 'git@github.com:owner/repo.git/api.git'
38
- end
39
- role 'prod-api-resque', 'stag-api-resque' do
40
- includes 'prod-api-app'
41
- run_list ['base','api_resque']
42
- node[:workers] = 8
43
- end
44
-
45
-
46
25
  # Post processing rules that run at the end
47
- post_rule do
48
- node[:post_rule] = 2
26
+ after do
27
+ node[:after] = 2
49
28
  node[:framework_env] = 'production' if role =~ /^prod/
50
29
  node[:framework_env] = 'staging' if role =~ /^stag/
51
30
 
@@ -0,0 +1,18 @@
1
+ # api
2
+ role 'prod-api-redis', 'stag-api-redis'
3
+ role 'prod-api-resque', 'stag-api-resque' do
4
+ includes 'prod-api-app'
5
+ node[:workers] = 8
6
+ end
7
+ role 'prod-api-app', 'stag-api-app' do
8
+ node[:application] = 'api'
9
+ node[:deploy_code] = true
10
+ node[:repository] = 'git@github.com:owner/repo.git/api.git'
11
+ node[:database][:adapter] = "mysql"
12
+ node[:database][:host] = "127.0.0.1"
13
+ node[:database][:user] = "user"
14
+ node[:database][:pass] = "pass"
15
+ node[:scout][:key] = 'abc'
16
+ node[:scout][:gems] = {'redis' => nil}
17
+ node[:relayhost] = settings[:sendgrid][:relayhost]
18
+ end
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.add_dependency "thor"
21
21
  gem.add_dependency "aws-sdk"
22
22
  gem.add_dependency "guard-rna"
23
+ gem.add_dependency "deep_merge"
23
24
 
24
25
  gem.add_development_dependency 'rspec'
25
26
  gem.add_development_dependency 'guard'
@@ -1,165 +1,184 @@
1
- require 'rna'
2
- require 'rspec'
3
- require 'pp'
1
+ require File.expand_path("../../spec_helper", __FILE__)
4
2
 
5
3
  describe Rna do
6
4
  before(:each) do
7
- @project_root = File.expand_path("../../project", __FILE__)
8
- @project2_root = File.expand_path("../../project2", __FILE__)
9
- @dsl = Rna::DSL.new(
10
- :config_path => "#{@project_root}/config/rna.rb",
11
- :output_path => "#{@project_root}/output"
12
- )
5
+ @project = File.expand_path("../../project", __FILE__)
6
+ FileUtils.mkdir(@project) unless File.exist?(@project)
7
+ execute("./bin/rna init -f -q --project-root #{@project}")
13
8
  end
14
9
 
15
10
  after(:each) do
16
- FileUtils.rm_rf("#{@project_root}/output")
11
+ FileUtils.rm_rf("#{@project}/output")
17
12
  end
18
13
 
19
- # uncomment to look a data deeper
20
- # it "should build attributes" do
21
- # @dsl.evaluate
22
- # @dsl.build
23
- # pp @dsl.data
24
- # @dsl.process
25
- # pp @dsl.jsons
26
- # end
27
-
28
- it "should write json files to outputs folder" do
29
- @dsl.run
30
- Dir.glob("#{@project_root}/output/*").size.should > 0
14
+ describe "cli specs" do
15
+ it "should generate templates" do
16
+ out = execute("./bin/rna generate -c --project-root #{@project}")
17
+ out.should match /Generating rna files/
18
+ end
31
19
  end
32
20
 
33
- # complete end to end tests
34
- it "base.json should contain correct attributes" do
35
- @dsl.run
36
- base = JSON.load(IO.read("#{@project_root}/output/base.json"))
37
- base['role'].should == 'base'
38
- base['run_list'].should == ["role[base]"]
39
- end
21
+ describe "ruby specs" do
22
+ before(:each) do
23
+ @dsl = Rna::DSL.new(
24
+ :quiet => true,
25
+ :project_root => @project
26
+ )
27
+ end
40
28
 
41
- it "base.json should not contain settings attributes" do
42
- @dsl.run
43
- base = JSON.load(IO.read("#{@project_root}/output/base.json"))
44
- base['framework_env'].should be_nil
45
- base['deploy_code'].should be_nil
46
- end
29
+ it "should build attributes" do
30
+ @dsl.evaluate
31
+ @dsl.build
32
+ pp @dsl.data
33
+ @dsl.process
34
+ pp @dsl.jsons
35
+ end if ENV['DEBUG']
47
36
 
48
- it "prod-api-redis.json should contain base and settings attributes" do
49
- @dsl.run
50
- json = JSON.load(IO.read("#{@project_root}/output/prod-api-redis.json"))
51
- json['role'].should == 'prod-api-redis'
52
- json['run_list'].should == ["role[base]", "role[api_redis]"]
53
- json['framework_env'].should == 'production'
54
- json['deploy_code'].should == nil
55
- end
37
+ it "should write json files to outputs folder" do
38
+ @dsl.run
39
+ Dir.glob("#{@project}/output/*").size.should > 0
40
+ end
56
41
 
57
- it "stag-api-redis.json should contain base and settings attributes and apply rules" do
58
- @dsl.run
59
- json = JSON.load(IO.read("#{@project_root}/output/stag-api-redis.json"))
60
- json['role'].should == 'stag-api-redis'
61
- json['run_list'].should == ["role[base]", "role[api_redis]"]
62
- json['deploy_code'].should == nil
63
- json['framework_env'].should == 'staging' # this is tests the rule
64
- end
42
+ # complete end to end tests
43
+ it "base.json should contain correct attributes" do
44
+ @dsl.run
45
+ base = JSON.load(IO.read("#{@project}/output/base.json"))
46
+ base['role'].should == 'base'
47
+ base['run_list'].should == ["role[base]"]
48
+ end
65
49
 
66
- it "prod-api-app.json should contain base and settings attributes" do
67
- @dsl.run
68
- json = JSON.load(IO.read("#{@project_root}/output/prod-api-app.json"))
69
- json['role'].should == 'prod-api-app'
70
- json['run_list'].should == ["role[base]","role[api_app]"]
71
- json['deploy_code'].should == true
72
- json['framework_env'].should == 'production'
73
- json['scout'].should be_a(Hash)
74
- end
50
+ it "base.json should not contain settings attributes" do
51
+ @dsl.run
52
+ base = JSON.load(IO.read("#{@project}/output/base.json"))
53
+ base['framework_env'].should be_nil
54
+ base['deploy_code'].should be_nil
55
+ end
75
56
 
76
- it "prod-api-app.json should contain attributes from node" do
77
- @dsl.run
78
- json = JSON.load(IO.read("#{@project_root}/output/prod-api-app.json"))
79
- json['database']['user'].should == 'user'
80
- json['database']['pass'].should == 'pass'
81
- json['database']['host'].should == '127.0.0.1'
82
- end
57
+ it "prod-api-redis.json should contain base and settings attributes" do
58
+ @dsl.run
59
+ json = JSON.load(IO.read("#{@project}/output/prod-api-redis.json"))
60
+ json['role'].should == 'prod-api-redis'
61
+ json['run_list'].should == ["role[base]", "role[api_redis]"]
62
+ json['framework_env'].should == 'production'
63
+ json['deploy_code'].should == nil
64
+ end
83
65
 
84
- it "prod-api-app.json should contain pre and post rules" do
85
- @dsl.run
86
- json = JSON.load(IO.read("#{@project_root}/output/prod-api-app.json"))
87
- json['role'].should == 'prod-api-app'
88
- json['run_list'].should == ["role[base]","role[api_app]"]
89
- json['deploy_code'].should == true
90
- json['framework_env'].should == 'production'
91
- json['scout'].should be_a(Hash)
92
- json['pre_rule'].should == 1
93
- json['post_rule'].should == 2
94
- end
66
+ it "prod-api-resque should contain inherited attributes" do
67
+ @dsl.run
68
+ json = JSON.load(IO.read("#{@project}/output/prod-api-resque.json"))
69
+ json['role'].should == 'prod-api-resque'
70
+ json['run_list'].should == ["role[base]","role[api_resque]"]
71
+ json['deploy_code'].should == true
72
+ json['framework_env'].should == 'production'
73
+ json['scout'].should be_a(Hash)
74
+ json['database']['adapter'].should == "mysql"
75
+ json['scout'].should be_a(Hash)
76
+ end
95
77
 
96
- it "masta-app should not generate output file" do
97
- @dsl.run
98
- File.exist?("#{@project_root}/output/masta-app.json").should be_false
99
- File.exist?("#{@project_root}/output/prod-masta-android.json").should be_true
100
- json = JSON.load(IO.read("#{@project_root}/output/prod-masta-android.json"))
101
- json['masta_app'].should == 123
102
- end
78
+ it "stag-api-redis.json should contain base and settings attributes and apply rules" do
79
+ @dsl.run
80
+ json = JSON.load(IO.read("#{@project}/output/stag-api-redis.json"))
81
+ json['role'].should == 'stag-api-redis'
82
+ json['run_list'].should == ["role[base]", "role[api_redis]"]
83
+ json['deploy_code'].should == nil
84
+ json['framework_env'].should == 'staging' # this is tests the rule
85
+ end
103
86
 
104
- it "should be able to read shared settings" do
105
- @dsl.run
106
- File.exist?("#{@project_root}/output/masta-app.json").should be_false
107
- File.exist?("#{@project_root}/output/prod-masta-android.json").should be_true
108
- json = JSON.load(IO.read("#{@project_root}/output/prod-masta-android.json"))
109
- json['relayhost'].should == "smtp.sendgrid.net"
110
- json = JSON.load(IO.read("#{@project_root}/output/prod-api-app.json"))
111
- json['relayhost'].should == "smtp.sendgrid.net"
112
- end
113
- ###################
114
-
115
- # only run when S3=1, will need to setup spec/project/config/s3.yml
116
- it "should upload to s3" do
117
- @dsl = Rna::DSL.new(
118
- :output => 's3',
119
- :s3_config_path => "#{@project_root}/config/s3.yml",
120
- :config_path => "#{@project_root}/config/rna.rb"
121
- )
122
- outputer = @dsl.run
123
-
124
- config = outputer.config
125
- s3 = outputer.s3
126
- bucket = s3.buckets[config['bucket']]
127
- raw = bucket.objects["#{config['folder']}/prod-api-app.json"].read
128
-
129
- json = JSON.load(raw)
130
- json['role'].should == 'prod-api-app'
131
- json['run_list'].should == ["role[base]","role[api_app]"]
132
- json['deploy_code'].should == true
133
- json['framework_env'].should == 'production'
134
- json['scout'].should be_a(Hash)
135
- # clean up
136
- tree = bucket.as_tree(:prefix => config['folder'])
137
- tree.children.select(&:leaf?).each do |leaf|
138
- leaf.object.delete
139
- end
140
- end if ENV['S3'] == '1'
141
-
142
- it "task init should set up project" do
143
- File.exist?("#{@project2_root}/config/s3.yml").should be_false
144
- File.exist?("#{@project2_root}/config/rna.rb").should be_false
145
- Rna::Task.init(@project2_root, :quiet => true)
146
- File.exist?("#{@project2_root}/config/s3.yml").should be_true
147
- File.exist?("#{@project2_root}/config/rna.rb").should be_true
148
- FileUtils.rm_rf("#{@project2_root}/config")
149
- end
87
+ it "prod-api-app.json should contain base and settings attributes" do
88
+ @dsl.run
89
+ json = JSON.load(IO.read("#{@project}/output/prod-api-app.json"))
90
+ json['role'].should == 'prod-api-app'
91
+ json['run_list'].should == ["role[base]","role[api_app]"]
92
+ json['deploy_code'].should == true
93
+ json['framework_env'].should == 'production'
94
+ json['scout'].should be_a(Hash)
95
+ end
150
96
 
151
- it "task build should generate node.json files" do
152
- Rna::Task.generate(
153
- :config_path => "#{@project_root}/config/rna.rb",
154
- :output_path => "#{@project_root}/output"
155
- )
156
- json = JSON.load(IO.read("#{@project_root}/output/prod-api-app.json"))
157
- json['role'].should == 'prod-api-app'
158
- json['run_list'].should == ["role[base]","role[api_app]"]
159
- json['deploy_code'].should == true
160
- json['framework_env'].should == 'production'
161
- json['scout'].should be_a(Hash)
97
+ it "prod-api-app.json should contain attributes from node" do
98
+ @dsl.run
99
+ json = JSON.load(IO.read("#{@project}/output/prod-api-app.json"))
100
+ json['database']['user'].should == 'user'
101
+ json['database']['pass'].should == 'pass'
102
+ json['database']['host'].should == '127.0.0.1'
103
+ end
104
+
105
+ it "prod-api-app.json should contain pre and post rules" do
106
+ @dsl.run
107
+ json = JSON.load(IO.read("#{@project}/output/prod-api-app.json"))
108
+ json['role'].should == 'prod-api-app'
109
+ json['run_list'].should == ["role[base]","role[api_app]"]
110
+ json['deploy_code'].should == true
111
+ json['framework_env'].should == 'production'
112
+ json['scout'].should be_a(Hash)
113
+ json['before'].should == 1
114
+ json['after'].should == 2
115
+ end
116
+
117
+ it "masta-app should not generate output file" do
118
+ @dsl.run
119
+ File.exist?("#{@project}/output/masta-app.json").should be_false
120
+ File.exist?("#{@project}/output/prod-masta-android.json").should be_true
121
+ json = JSON.load(IO.read("#{@project}/output/prod-masta-android.json"))
122
+ json['masta_app'].should == 123
123
+ end
124
+
125
+ it "should be able to read shared settings" do
126
+ @dsl.run
127
+ File.exist?("#{@project}/output/masta-app.json").should be_false
128
+ File.exist?("#{@project}/output/prod-masta-android.json").should be_true
129
+ json = JSON.load(IO.read("#{@project}/output/prod-masta-android.json"))
130
+ json['relayhost'].should == "smtp.sendgrid.net"
131
+ json = JSON.load(IO.read("#{@project}/output/prod-api-app.json"))
132
+ json['relayhost'].should == "smtp.sendgrid.net"
133
+ end
134
+ ###################
135
+
136
+ # only run when S3=1, will need to setup spec/project/config/s3.yml
137
+ it "should upload to s3" do
138
+ @dsl = Rna::DSL.new(
139
+ :output => 's3',
140
+ :s3_config_path => "#{@project}/config/s3.yml",
141
+ :project_root => @project
142
+ )
143
+ outputer = @dsl.run
144
+
145
+ config = outputer.config
146
+ s3 = outputer.s3
147
+ bucket = s3.buckets[config['bucket']]
148
+ raw = bucket.objects["#{config['folder']}/prod-api-app.json"].read
149
+
150
+ json = JSON.load(raw)
151
+ json['role'].should == 'prod-api-app'
152
+ json['run_list'].should == ["role[base]","role[api_app]"]
153
+ json['deploy_code'].should == true
154
+ json['framework_env'].should == 'production'
155
+ json['scout'].should be_a(Hash)
156
+ # clean up
157
+ tree = bucket.as_tree(:prefix => config['folder'])
158
+ tree.children.select(&:leaf?).each do |leaf|
159
+ leaf.object.delete
160
+ end
161
+ end if ENV['S3'] == '1'
162
+
163
+ it "task init should set up project" do
164
+ File.exist?("#{@project}/config/s3.example.yml").should be_true
165
+ File.exist?("#{@project}/config/rna.rb").should be_true
166
+ end
167
+
168
+ it "task build should generate node.json files" do
169
+ Rna::Task.generate(
170
+ :quiet => true,
171
+ :project_root => @project
172
+ )
173
+ json = JSON.load(IO.read("#{@project}/output/prod-api-app.json"))
174
+ json['role'].should == 'prod-api-app'
175
+ json['run_list'].should == ["role[base]","role[api_app]"]
176
+ json['deploy_code'].should == true
177
+ json['framework_env'].should == 'production'
178
+ json['scout'].should be_a(Hash)
179
+ end
162
180
  end
181
+
163
182
  end
164
183
 
165
184
  describe Node do
@@ -0,0 +1,21 @@
1
+ require "pp"
2
+ require "bundler"
3
+
4
+ Bundler.require(:development)
5
+
6
+ $root = File.expand_path('../../', __FILE__)
7
+
8
+ require "#{$root}/lib/rna"
9
+
10
+ module Helpers
11
+ def execute(cmd)
12
+ puts "Running: #{cmd}" if ENV['DEBUG']
13
+ out = `#{cmd}`
14
+ puts out if ENV['DEBUG']
15
+ out
16
+ end
17
+ end
18
+
19
+ RSpec.configure do |c|
20
+ c.include Helpers
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-21 00:00:00.000000000 Z
12
+ date: 2013-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: deep_merge
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
94
110
  - !ruby/object:Gem::Dependency
95
111
  name: rspec
96
112
  requirement: !ruby/object:Gem::Requirement
@@ -190,10 +206,12 @@ files:
190
206
  - README.md
191
207
  - Rakefile
192
208
  - bin/rna
209
+ - config/rna.rb
210
+ - config/rna/api.rb
211
+ - config/rna/blog.rb
212
+ - config/s3.example.yml
213
+ - config/s3.yml
193
214
  - lib/ext/hash.rb
194
- - lib/files/Guardfile
195
- - lib/files/rna.rb
196
- - lib/files/s3.yml
197
215
  - lib/mash.rb
198
216
  - lib/node.rb
199
217
  - lib/rna.rb
@@ -202,14 +220,15 @@ files:
202
220
  - lib/rna/outputers.rb
203
221
  - lib/rna/task.rb
204
222
  - lib/rna/version.rb
223
+ - lib/starter_project/config/rna.rb
224
+ - lib/starter_project/config/rna/api.rb
225
+ - lib/starter_project/config/rna/masta.rb
226
+ - lib/starter_project/config/s3.example.yml
205
227
  - rna.gemspec
206
228
  - spec/lib/rna_spec.rb
207
- - spec/project/config/rna.rb
208
- - spec/project/config/rna/api.rb
209
- - spec/project/config/rna/masta.rb
210
- - spec/project/config/s3.example.yml
211
229
  - spec/project2/.gitkeep
212
230
  - spec/project2/Guardfile
231
+ - spec/spec_helper.rb
213
232
  homepage: http://github.com/tongueroo/rna
214
233
  licenses: []
215
234
  post_install_message:
@@ -236,9 +255,6 @@ specification_version: 3
236
255
  summary: Rna is a simple DSL for generating node.json files required by chef-solo.
237
256
  test_files:
238
257
  - spec/lib/rna_spec.rb
239
- - spec/project/config/rna.rb
240
- - spec/project/config/rna/api.rb
241
- - spec/project/config/rna/masta.rb
242
- - spec/project/config/s3.example.yml
243
258
  - spec/project2/.gitkeep
244
259
  - spec/project2/Guardfile
260
+ - spec/spec_helper.rb
@@ -1,3 +0,0 @@
1
- guard "rna" do
2
- watch(%r{^config/rna.rb$})
3
- end