rna 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +2 -1
- data/README.md +84 -53
- data/lib/files/rna.rb +33 -20
- data/lib/node.rb +55 -0
- data/lib/rna.rb +1 -0
- data/lib/rna/dsl.rb +47 -74
- data/lib/rna/version.rb +1 -1
- data/rna.gemspec +1 -0
- data/spec/lib/rna_spec.rb +78 -6
- data/spec/project/config/rna.rb +19 -26
- data/spec/project/config/rna/api.rb +13 -13
- data/spec/project/config/rna/masta.rb +7 -7
- metadata +19 -8
data/Guardfile
CHANGED
@@ -4,7 +4,8 @@ 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" }
|
7
8
|
watch(%r{^lib/rna/(.+)\.rb$}) { |m| "spec/lib/rna_spec.rb" }
|
8
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib
|
9
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/rna_spec.rb" }
|
9
10
|
# watch('spec/spec_helper.rb') { "spec" }
|
10
11
|
end
|
data/README.md
CHANGED
@@ -30,46 +30,61 @@ This will sets starter config/rna.rb and config/s3.yml files.
|
|
30
30
|
```ruby
|
31
31
|
# This is starter example rna template.
|
32
32
|
# This is meant be be modified to your needs.
|
33
|
-
|
34
|
-
#
|
35
|
-
default_inherits 'base'
|
36
|
-
global(:except => 'base') do
|
37
|
-
set 'framework_env', 'production'
|
38
|
-
end
|
39
|
-
|
40
|
-
###################################
|
33
|
+
default_includes 'base'
|
34
|
+
# Pre processing rules that run at the beginning
|
41
35
|
pre_rule do
|
42
|
-
|
43
|
-
|
36
|
+
if role != 'base'
|
37
|
+
node[:application] = nil
|
38
|
+
node[:deploy_code] = false
|
39
|
+
node[:framework_env] = 'production'
|
40
|
+
node[:repository] = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
node[:pre_rule] = 1
|
44
|
+
node[:chef_branch] = 'prod' if role =~ /^prod/
|
45
|
+
node[:chef_branch] = 'master' if role =~ /^stag/
|
44
46
|
end
|
45
47
|
|
46
|
-
|
48
|
+
settings(
|
49
|
+
:sendgrid => {
|
50
|
+
:relayhost => "smtp.sendgrid.net"
|
51
|
+
}
|
52
|
+
)
|
53
|
+
|
47
54
|
# Roles
|
48
|
-
# base
|
49
55
|
role 'base' do
|
50
|
-
|
56
|
+
role_list ['base']
|
51
57
|
end
|
58
|
+
|
52
59
|
# api
|
53
60
|
role 'prod-api-redis', 'stag-api-redis' do
|
54
61
|
run_list ['base','api_redis']
|
55
62
|
end
|
56
63
|
role 'prod-api-app', 'stag-api-app' do
|
57
64
|
run_list ['base','api_app']
|
58
|
-
|
59
|
-
|
60
|
-
|
65
|
+
node[:application] = 'api'
|
66
|
+
node[:deploy_code] = true
|
67
|
+
node[:repository] = 'git@github.com:br/api.git'
|
61
68
|
end
|
62
69
|
role 'prod-api-resque', 'stag-api-resque' do
|
63
|
-
|
70
|
+
includes 'prod-api-app'
|
64
71
|
run_list ['base','api_resque']
|
65
|
-
|
72
|
+
node[:workers], 8
|
66
73
|
end
|
67
74
|
|
68
|
-
|
75
|
+
|
69
76
|
# Post processing rules that run at the end
|
70
77
|
post_rule do
|
71
|
-
|
72
|
-
|
78
|
+
node[:post_rule] = 2
|
79
|
+
node[:framework_env] = 'production' if role =~ /^prod/
|
80
|
+
node[:framework_env] = 'staging' if role =~ /^stag/
|
81
|
+
|
82
|
+
list = role.split('-')
|
83
|
+
if list.size == 3
|
84
|
+
env, repo, role = list
|
85
|
+
role_list ['base', "#{repo}_#{role}"]
|
86
|
+
node[:application] = repo
|
87
|
+
end
|
73
88
|
end
|
74
89
|
```
|
75
90
|
|
@@ -77,16 +92,18 @@ end
|
|
77
92
|
$ rna generate
|
78
93
|
</pre>
|
79
94
|
|
80
|
-
Here
|
95
|
+
Here is the example of the output looks like:
|
81
96
|
|
82
97
|
output/base.json:
|
83
98
|
|
84
99
|
```json
|
85
100
|
{
|
101
|
+
"pre_rule": 1,
|
86
102
|
"role": "base",
|
87
103
|
"run_list": [
|
88
|
-
"base"
|
89
|
-
]
|
104
|
+
"role[base]"
|
105
|
+
],
|
106
|
+
"post_rule": 2
|
90
107
|
}
|
91
108
|
```
|
92
109
|
|
@@ -94,15 +111,17 @@ output/prod-api-app.json:
|
|
94
111
|
|
95
112
|
```json
|
96
113
|
{
|
97
|
-
"
|
114
|
+
"pre_rule": 1,
|
98
115
|
"role": "prod-api-app",
|
99
116
|
"run_list": [
|
100
|
-
"base",
|
101
|
-
"api_app"
|
117
|
+
"role[base]",
|
118
|
+
"role[api_app]"
|
102
119
|
],
|
103
120
|
"application": "api",
|
104
121
|
"deploy_code": true,
|
105
|
-
"repository": "git@github.com:br/api.git"
|
122
|
+
"repository": "git@github.com:br/api.git",
|
123
|
+
"post_rule": 2,
|
124
|
+
"framework_env": "production"
|
106
125
|
}
|
107
126
|
```
|
108
127
|
|
@@ -110,12 +129,15 @@ output/prod-api-redis.json:
|
|
110
129
|
|
111
130
|
```json
|
112
131
|
{
|
113
|
-
"
|
132
|
+
"pre_rule": 1,
|
114
133
|
"role": "prod-api-redis",
|
115
134
|
"run_list": [
|
116
|
-
"base",
|
117
|
-
"api_redis"
|
118
|
-
]
|
135
|
+
"role[base]",
|
136
|
+
"role[api_redis]"
|
137
|
+
],
|
138
|
+
"post_rule": 2,
|
139
|
+
"framework_env": "production",
|
140
|
+
"application": "api"
|
119
141
|
}
|
120
142
|
```
|
121
143
|
|
@@ -123,16 +145,18 @@ output/prod-api-resque.json:
|
|
123
145
|
|
124
146
|
```json
|
125
147
|
{
|
126
|
-
"
|
148
|
+
"pre_rule": 1,
|
127
149
|
"role": "prod-api-resque",
|
128
150
|
"run_list": [
|
129
|
-
"base",
|
130
|
-
"api_resque"
|
151
|
+
"role[base]",
|
152
|
+
"role[api_resque]"
|
131
153
|
],
|
132
154
|
"application": "api",
|
133
155
|
"deploy_code": true,
|
134
156
|
"repository": "git@github.com:br/api.git",
|
135
|
-
"workers": 8
|
157
|
+
"workers": 8,
|
158
|
+
"post_rule": 2,
|
159
|
+
"framework_env": "production"
|
136
160
|
}
|
137
161
|
```
|
138
162
|
|
@@ -140,15 +164,17 @@ output/stag-api-app.json:
|
|
140
164
|
|
141
165
|
```json
|
142
166
|
{
|
143
|
-
"
|
167
|
+
"pre_rule": 1,
|
144
168
|
"role": "stag-api-app",
|
145
169
|
"run_list": [
|
146
|
-
"base",
|
147
|
-
"api_app"
|
170
|
+
"role[base]",
|
171
|
+
"role[api_app]"
|
148
172
|
],
|
149
173
|
"application": "api",
|
150
174
|
"deploy_code": true,
|
151
|
-
"repository": "git@github.com:br/api.git"
|
175
|
+
"repository": "git@github.com:br/api.git",
|
176
|
+
"post_rule": 2,
|
177
|
+
"framework_env": "staging"
|
152
178
|
}
|
153
179
|
```
|
154
180
|
|
@@ -156,12 +182,15 @@ output/stag-api-redis.json:
|
|
156
182
|
|
157
183
|
```json
|
158
184
|
{
|
159
|
-
"
|
185
|
+
"pre_rule": 1,
|
160
186
|
"role": "stag-api-redis",
|
161
187
|
"run_list": [
|
162
|
-
"base",
|
163
|
-
"api_redis"
|
164
|
-
]
|
188
|
+
"role[base]",
|
189
|
+
"role[api_redis]"
|
190
|
+
],
|
191
|
+
"post_rule": 2,
|
192
|
+
"framework_env": "staging",
|
193
|
+
"application": "api"
|
165
194
|
}
|
166
195
|
```
|
167
196
|
|
@@ -169,16 +198,18 @@ output/stag-api-resque.json:
|
|
169
198
|
|
170
199
|
```json
|
171
200
|
{
|
172
|
-
"
|
201
|
+
"pre_rule": 1,
|
173
202
|
"role": "stag-api-resque",
|
174
203
|
"run_list": [
|
175
|
-
"base",
|
176
|
-
"api_resque"
|
204
|
+
"role[base]",
|
205
|
+
"role[api_resque]"
|
177
206
|
],
|
178
207
|
"application": "api",
|
179
208
|
"deploy_code": true,
|
180
209
|
"repository": "git@github.com:br/api.git",
|
181
|
-
"workers": 8
|
210
|
+
"workers": 8,
|
211
|
+
"post_rule": 2,
|
212
|
+
"framework_env": "staging"
|
182
213
|
}
|
183
214
|
```
|
184
215
|
|
@@ -211,20 +242,20 @@ An example is in the spec/project folder:
|
|
211
242
|
You might want a shared settings hash that you can use in only some of your roles.
|
212
243
|
|
213
244
|
```ruby
|
214
|
-
settings
|
215
|
-
|
216
|
-
|
245
|
+
settings do
|
246
|
+
node[:foo] = 1
|
247
|
+
end
|
217
248
|
```
|
218
249
|
|
219
250
|
You can use this any where in your roles.
|
220
251
|
|
221
252
|
```ruby
|
222
253
|
role 'role1' do
|
223
|
-
|
254
|
+
node[:foo] = settings[:foo]
|
224
255
|
end
|
225
256
|
|
226
257
|
role 'role2' do
|
227
|
-
|
258
|
+
node[:foo] = settings[:foo]
|
228
259
|
end
|
229
260
|
|
230
261
|
role 'role3' do
|
data/lib/files/rna.rb
CHANGED
@@ -1,43 +1,56 @@
|
|
1
1
|
# This is starter example rna template.
|
2
2
|
# This is meant be be modified to your needs.
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
default_includes 'base'
|
4
|
+
# Pre processing rules that run at the beginning
|
5
|
+
pre_rule do
|
6
|
+
if role != 'base'
|
7
|
+
node[:application] = nil
|
8
|
+
node[:deploy_code] = false
|
9
|
+
node[:framework_env] = 'production'
|
10
|
+
node[:repository] = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
node[:pre_rule] = 1
|
14
|
+
node[:chef_branch] = 'prod' if role =~ /^prod/
|
15
|
+
node[:chef_branch] = 'master' if role =~ /^stag/
|
8
16
|
end
|
9
17
|
|
10
|
-
|
11
|
-
|
12
|
-
set 'chef_branch', 'prod' if role =~ /^prod/
|
13
|
-
set 'chef_branch', 'master' if role =~ /^stag/
|
18
|
+
settings do
|
19
|
+
node[:sendgrid][:relayhost] = "smtp.sendgrid.net"
|
14
20
|
end
|
15
21
|
|
16
|
-
###################################
|
17
22
|
# Roles
|
18
|
-
# base
|
19
23
|
role 'base' do
|
20
|
-
|
24
|
+
role_list ['base']
|
21
25
|
end
|
26
|
+
|
22
27
|
# api
|
23
28
|
role 'prod-api-redis', 'stag-api-redis' do
|
24
29
|
run_list ['base','api_redis']
|
25
30
|
end
|
26
31
|
role 'prod-api-app', 'stag-api-app' do
|
27
32
|
run_list ['base','api_app']
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
node[:application] = 'api'
|
34
|
+
node[:deploy_code] = true
|
35
|
+
node[:repository] = 'git@github.com:br/api.git'
|
31
36
|
end
|
32
37
|
role 'prod-api-resque', 'stag-api-resque' do
|
33
|
-
|
38
|
+
includes 'prod-api-app'
|
34
39
|
run_list ['base','api_resque']
|
35
|
-
|
40
|
+
node[:workers] = 8
|
36
41
|
end
|
37
42
|
|
38
|
-
|
43
|
+
|
39
44
|
# Post processing rules that run at the end
|
40
45
|
post_rule do
|
41
|
-
|
42
|
-
|
46
|
+
node[:post_rule] = 2
|
47
|
+
node[:framework_env] = 'production' if role =~ /^prod/
|
48
|
+
node[:framework_env] = 'staging' if role =~ /^stag/
|
49
|
+
|
50
|
+
list = role.split('-')
|
51
|
+
if list.size == 3
|
52
|
+
env, repo, role = list
|
53
|
+
role_list ['base', "#{repo}_#{role}"]
|
54
|
+
node[:application] = repo
|
55
|
+
end
|
43
56
|
end
|
data/lib/node.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
class Node < Hash
|
2
|
+
class Attribute
|
3
|
+
attr_reader :value
|
4
|
+
def initialize(value)
|
5
|
+
@value = value
|
6
|
+
end
|
7
|
+
def [](key)
|
8
|
+
puts "Node::Attribute key #{key}"
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@data = {}
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def []=(key,value)
|
19
|
+
key = convert_key(key)
|
20
|
+
result = super
|
21
|
+
attribute = Attribute.new(result)
|
22
|
+
@data[key] = attribute
|
23
|
+
end
|
24
|
+
|
25
|
+
def [](key)
|
26
|
+
key = convert_key(key)
|
27
|
+
if @data[key].nil?
|
28
|
+
result = @data[key] = Node.new
|
29
|
+
elsif @data[key].is_a?(Node::Attribute)
|
30
|
+
result = @data[key].value
|
31
|
+
elsif @data[key].is_a?(Node)
|
32
|
+
result = @data[key]
|
33
|
+
else
|
34
|
+
raise "should never happen"
|
35
|
+
end
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_hash
|
40
|
+
hash = {}
|
41
|
+
@data.each do |key,item|
|
42
|
+
if item.is_a?(Node)
|
43
|
+
hash[key] = item.to_hash
|
44
|
+
else
|
45
|
+
hash[key] = item.value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
hash
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def convert_key(key)
|
53
|
+
key.to_sym
|
54
|
+
end
|
55
|
+
end
|
data/lib/rna.rb
CHANGED
data/lib/rna/dsl.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module Rna
|
2
2
|
class DSL
|
3
|
-
attr_reader :data, :jsons
|
3
|
+
attr_reader :data, :jsons, :settings_node
|
4
4
|
def initialize(options={})
|
5
5
|
@options = options
|
6
6
|
|
7
7
|
@path = options[:config_path] || 'config/rna.rb'
|
8
|
-
@global_attributes = nil
|
9
8
|
@pre_rule = nil
|
10
9
|
@post_rule = nil
|
11
10
|
@roles = []
|
@@ -23,22 +22,18 @@ module Rna
|
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
def
|
27
|
-
|
28
|
-
if data.empty?
|
29
|
-
@settings
|
30
|
-
# writer method
|
31
|
-
else
|
32
|
-
@settings = data[0]
|
33
|
-
end
|
25
|
+
def settings_node
|
26
|
+
@settings_node ||= Node.new
|
34
27
|
end
|
28
|
+
alias_method :set, :settings_node
|
29
|
+
alias_method :node, :settings_node
|
35
30
|
|
36
|
-
def
|
37
|
-
|
31
|
+
def settings(&block)
|
32
|
+
instance_eval(&block)
|
38
33
|
end
|
39
34
|
|
40
|
-
def
|
41
|
-
Role.
|
35
|
+
def default_includes(role)
|
36
|
+
Role.default_includes = role
|
42
37
|
end
|
43
38
|
|
44
39
|
def pre_rule(&block)
|
@@ -65,24 +60,17 @@ module Rna
|
|
65
60
|
end
|
66
61
|
|
67
62
|
def build
|
68
|
-
@data = {
|
69
|
-
'global' => nil,
|
70
|
-
'roles' => []
|
71
|
-
}
|
72
|
-
# build global attributes
|
73
|
-
@data['global'] = Global.new(@global[:options], @global[:block]).build
|
74
|
-
|
63
|
+
@data = {:roles => []}
|
75
64
|
# build roles
|
76
65
|
@roles.each do |r|
|
77
|
-
@data[
|
66
|
+
@data[:roles] << Role.new(r[:name], r[:block], @options).build
|
78
67
|
end
|
79
|
-
|
80
68
|
@data
|
81
69
|
end
|
82
70
|
|
83
71
|
def process
|
84
72
|
@jsons = {}
|
85
|
-
roles = @data[
|
73
|
+
roles = @data[:roles].collect{|h| h[:name]}
|
86
74
|
roles.each do |role|
|
87
75
|
@jsons[role] = process_role(role)
|
88
76
|
end
|
@@ -90,34 +78,28 @@ module Rna
|
|
90
78
|
end
|
91
79
|
|
92
80
|
# builds node.json hash
|
93
|
-
# 1.
|
94
|
-
# 2.
|
95
|
-
# 3.
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
if
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
role_data = @data['roles'].find {|h| h['name'] == role}
|
104
|
-
inherits = role_data['inherits']
|
105
|
-
if inherits
|
106
|
-
json = process_role(inherits, exclude_global, depth+1)
|
81
|
+
# 1. pre rule
|
82
|
+
# 2. role, going up the includes chain
|
83
|
+
# 3. post rule
|
84
|
+
def process_role(role, depth=1)
|
85
|
+
role_data = @data[:roles].find {|h| h[:name] == role}
|
86
|
+
includes = role_data[:includes]
|
87
|
+
if includes
|
88
|
+
json = process_role(includes, depth+1)
|
107
89
|
else
|
108
|
-
json =
|
90
|
+
json = {}
|
109
91
|
if @pre_rule
|
110
92
|
pre_data = Rule.new(role, @pre_rule[:block]).build
|
111
|
-
json.merge!(pre_data[
|
93
|
+
json.merge!(pre_data[:attributes])
|
112
94
|
end
|
113
95
|
end
|
114
96
|
|
115
|
-
attributes = role_data[
|
97
|
+
attributes = role_data[:attributes] || {}
|
116
98
|
json.merge!(attributes)
|
117
99
|
# only process post rule at the very last step
|
118
100
|
if @post_rule and depth == 1
|
119
101
|
post_data = Rule.new(role, @post_rule[:block]).build
|
120
|
-
json.merge!(post_data[
|
102
|
+
json.merge!(post_data[:attributes])
|
121
103
|
end
|
122
104
|
json
|
123
105
|
end
|
@@ -125,8 +107,8 @@ module Rna
|
|
125
107
|
def output(options={})
|
126
108
|
jsons = {}
|
127
109
|
@jsons.each do |role,data|
|
128
|
-
role_data = @data[
|
129
|
-
if role_data[
|
110
|
+
role_data = @data[:roles].find {|h| h[:name] == role}
|
111
|
+
if role_data[:output]
|
130
112
|
jsons[role] = JSON.pretty_generate(data)
|
131
113
|
end
|
132
114
|
end
|
@@ -142,26 +124,28 @@ module Rna
|
|
142
124
|
if @block
|
143
125
|
@dsl = eval "self", @block.binding
|
144
126
|
instance_eval(&@block)
|
145
|
-
end
|
127
|
+
end
|
128
|
+
@data[:attributes].merge!(set.to_hash)
|
146
129
|
@data
|
147
130
|
end
|
148
131
|
|
149
132
|
# http://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation
|
150
|
-
def settings
|
151
|
-
@dsl.
|
133
|
+
def settings
|
134
|
+
@dsl.settings_node
|
152
135
|
end
|
153
136
|
|
154
|
-
def
|
155
|
-
@
|
137
|
+
def node
|
138
|
+
@node ||= Node.new
|
156
139
|
end
|
140
|
+
alias_method :set, :node
|
157
141
|
|
158
142
|
def role_list(list)
|
159
143
|
list = list.collect {|i| "role[#{i}]"}
|
160
|
-
|
144
|
+
run_list(list)
|
161
145
|
end
|
162
146
|
|
163
147
|
def run_list(list)
|
164
|
-
|
148
|
+
node[:run_list] = list
|
165
149
|
end
|
166
150
|
end
|
167
151
|
|
@@ -172,7 +156,7 @@ module Rna
|
|
172
156
|
@role = role
|
173
157
|
@block = block
|
174
158
|
@data = {
|
175
|
-
|
159
|
+
:attributes => {}
|
176
160
|
}
|
177
161
|
end
|
178
162
|
|
@@ -181,17 +165,6 @@ module Rna
|
|
181
165
|
end
|
182
166
|
end
|
183
167
|
|
184
|
-
class Global < Builder
|
185
|
-
def initialize(options, block)
|
186
|
-
@options = options
|
187
|
-
@block = block
|
188
|
-
@data = {
|
189
|
-
'except' => [options[:except]].compact,
|
190
|
-
'attributes' => {}
|
191
|
-
}
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
168
|
class Role < Builder
|
196
169
|
attr_reader :name
|
197
170
|
def initialize(name, block, options)
|
@@ -200,17 +173,17 @@ module Rna
|
|
200
173
|
@options = options
|
201
174
|
|
202
175
|
@data = {
|
203
|
-
|
204
|
-
|
205
|
-
|
176
|
+
:name => name,
|
177
|
+
:attributes => {
|
178
|
+
:role => name
|
206
179
|
},
|
207
|
-
|
208
|
-
|
180
|
+
:includes => @@default_includes != name ? @@default_includes : nil,
|
181
|
+
:output => true
|
209
182
|
}
|
210
183
|
end
|
211
184
|
|
212
|
-
def self.
|
213
|
-
@@
|
185
|
+
def self.default_includes=(includes)
|
186
|
+
@@default_includes = includes
|
214
187
|
end
|
215
188
|
|
216
189
|
def role
|
@@ -218,12 +191,12 @@ module Rna
|
|
218
191
|
end
|
219
192
|
|
220
193
|
def output(val)
|
221
|
-
@data[
|
194
|
+
@data[:output] = val
|
222
195
|
end
|
223
196
|
|
224
|
-
def
|
225
|
-
role = nil if role == @name # can't
|
226
|
-
@data[
|
197
|
+
def includes(role)
|
198
|
+
role = nil if role == @name # can't include itself
|
199
|
+
@data[:includes] = role
|
227
200
|
end
|
228
201
|
end
|
229
202
|
|
data/lib/rna/version.rb
CHANGED
data/rna.gemspec
CHANGED
data/spec/lib/rna_spec.rb
CHANGED
@@ -16,6 +16,7 @@ describe Rna do
|
|
16
16
|
FileUtils.rm_rf("#{@project_root}/output")
|
17
17
|
end
|
18
18
|
|
19
|
+
# uncomment to look a data deeper
|
19
20
|
# it "should build attributes" do
|
20
21
|
# @dsl.evaluate
|
21
22
|
# @dsl.build
|
@@ -37,32 +38,32 @@ describe Rna do
|
|
37
38
|
base['run_list'].should == ["role[base]"]
|
38
39
|
end
|
39
40
|
|
40
|
-
it "base.json should not contain
|
41
|
+
it "base.json should not contain settings attributes" do
|
41
42
|
@dsl.run
|
42
43
|
base = JSON.load(IO.read("#{@project_root}/output/base.json"))
|
43
44
|
base['framework_env'].should be_nil
|
44
45
|
base['deploy_code'].should be_nil
|
45
46
|
end
|
46
47
|
|
47
|
-
it "prod-api-redis.json should contain base and
|
48
|
+
it "prod-api-redis.json should contain base and settings attributes" do
|
48
49
|
@dsl.run
|
49
50
|
json = JSON.load(IO.read("#{@project_root}/output/prod-api-redis.json"))
|
50
51
|
json['role'].should == 'prod-api-redis'
|
51
52
|
json['run_list'].should == ["role[base]", "role[api_redis]"]
|
52
53
|
json['framework_env'].should == 'production'
|
53
|
-
json['deploy_code'].should ==
|
54
|
+
json['deploy_code'].should == nil
|
54
55
|
end
|
55
56
|
|
56
|
-
it "stag-api-redis.json should contain base and
|
57
|
+
it "stag-api-redis.json should contain base and settings attributes and apply rules" do
|
57
58
|
@dsl.run
|
58
59
|
json = JSON.load(IO.read("#{@project_root}/output/stag-api-redis.json"))
|
59
60
|
json['role'].should == 'stag-api-redis'
|
60
61
|
json['run_list'].should == ["role[base]", "role[api_redis]"]
|
61
|
-
json['deploy_code'].should ==
|
62
|
+
json['deploy_code'].should == nil
|
62
63
|
json['framework_env'].should == 'staging' # this is tests the rule
|
63
64
|
end
|
64
65
|
|
65
|
-
it "prod-api-app.json should contain base and
|
66
|
+
it "prod-api-app.json should contain base and settings attributes" do
|
66
67
|
@dsl.run
|
67
68
|
json = JSON.load(IO.read("#{@project_root}/output/prod-api-app.json"))
|
68
69
|
json['role'].should == 'prod-api-app'
|
@@ -72,6 +73,14 @@ describe Rna do
|
|
72
73
|
json['scout'].should be_a(Hash)
|
73
74
|
end
|
74
75
|
|
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 == 'host'
|
82
|
+
end
|
83
|
+
|
75
84
|
it "prod-api-app.json should contain pre and post rules" do
|
76
85
|
@dsl.run
|
77
86
|
json = JSON.load(IO.read("#{@project_root}/output/prod-api-app.json"))
|
@@ -151,4 +160,67 @@ describe Rna do
|
|
151
160
|
json['framework_env'].should == 'production'
|
152
161
|
json['scout'].should be_a(Hash)
|
153
162
|
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe Node do
|
166
|
+
before(:each) do
|
167
|
+
@node = Node.new
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should be able to set multiple levels deep even" do
|
171
|
+
@node[:a][:b][:c] = 2
|
172
|
+
@node[:a][:b][:c].should == 2
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should convert to a hash with symbols as keys" do
|
176
|
+
@node[:a][:b][:c] = 2
|
177
|
+
@node[:a][:b][:c].should == 2
|
178
|
+
hash = @node.to_hash
|
179
|
+
# uncomment to see hash structure
|
180
|
+
# pp hash
|
181
|
+
# pp hash[:a][:b]
|
182
|
+
hash[:a][:b][:c].should == 2
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should raise error if namespace is a non-node value and you try to access a value below that" do
|
186
|
+
@node[:a][:b] = 4
|
187
|
+
# this errors because it will run: 4[:c]
|
188
|
+
expect { @node[:a][:b][:c].class.should be_a(Node) }.to raise_error(TypeError)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should not adjust values set in other namespaces" do
|
192
|
+
@node[:a][:b][:c] = 2
|
193
|
+
@node[:a][:b][:c].should == 2
|
194
|
+
@node[:a][:b2] = 3
|
195
|
+
@node[:a][:b2].should == 3
|
196
|
+
@node[:a][:b][:c].should == 2
|
197
|
+
@node[:a][:b2].should == 3
|
198
|
+
@node[:a][:b3][:c] = 5
|
199
|
+
@node[:a][:b3][:c].should == 5
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should behave like a mash" do
|
203
|
+
@node[:a][:b] = 4
|
204
|
+
@node[:a][:b].should == 4
|
205
|
+
@node[:a]['b'].should == 4
|
206
|
+
|
207
|
+
@node[:a]['c'] = 5
|
208
|
+
@node[:a][:c].should == 5
|
209
|
+
@node[:a]['c'].should == 5
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should default to an empty Node object if never been set" do
|
213
|
+
@node[:one].should be_a(Node)
|
214
|
+
@node[:all][:roads][:lead][:to][:nothing].should be_a(Node)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should be able to set nil" do
|
218
|
+
@node[:a][:b4][:c] = nil
|
219
|
+
@node[:a][:b4][:c].should == nil
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should be able to set false" do
|
223
|
+
@node[:a][:b4][:c] = false
|
224
|
+
@node[:a][:b4][:c].should == false
|
225
|
+
end
|
154
226
|
end
|
data/spec/project/config/rna.rb
CHANGED
@@ -1,44 +1,37 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
default_includes 'base'
|
2
|
+
# Pre processing rules that run at the beginning
|
3
|
+
pre_rule do
|
4
|
+
if role != 'base'
|
5
|
+
node[:application] = nil
|
6
|
+
node[:deploy_code] = false
|
7
|
+
node[:framework_env] = 'production'
|
8
|
+
node[:repository] = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
node[:pre_rule] = 1
|
12
|
+
node[:chef_branch] = 'prod' if role =~ /^prod/
|
13
|
+
node[:chef_branch] = 'master' if role =~ /^stag/
|
9
14
|
end
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
set 'pre_rule', 1
|
14
|
-
set 'chef_branch', 'prod' if role =~ /^prod/
|
15
|
-
set 'chef_branch', 'master' if role =~ /^stag/
|
16
|
+
settings do
|
17
|
+
node[:sendgrid][:relayhost] = "smtp.sendgrid.net"
|
16
18
|
end
|
17
19
|
|
18
|
-
###################################
|
19
20
|
# Roles
|
20
|
-
# base
|
21
21
|
role 'base' do
|
22
22
|
role_list ['base']
|
23
23
|
end
|
24
24
|
|
25
|
-
settings(
|
26
|
-
'sendgrid' => {
|
27
|
-
"relayhost"=>"smtp.sendgrid.net"
|
28
|
-
}
|
29
|
-
)
|
30
|
-
|
31
|
-
###################################
|
32
25
|
# Post processing rules that run at the end
|
33
26
|
post_rule do
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
node[:post_rule] = 2
|
28
|
+
node[:framework_env] = 'production' if role =~ /^prod/
|
29
|
+
node[:framework_env] = 'staging' if role =~ /^stag/
|
37
30
|
|
38
31
|
list = role.split('-')
|
39
32
|
if list.size == 3
|
40
33
|
env, repo, role = list
|
41
34
|
role_list ['base', "#{repo}_#{role}"]
|
42
|
-
|
35
|
+
node[:application] = repo
|
43
36
|
end
|
44
37
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
# api
|
2
2
|
role 'prod-api-redis', 'stag-api-redis'
|
3
3
|
role 'prod-api-resque', 'stag-api-resque' do
|
4
|
-
|
5
|
-
|
4
|
+
includes 'prod-api-app'
|
5
|
+
node[:workers] = 8
|
6
6
|
end
|
7
7
|
role 'prod-api-app', 'stag-api-app' do
|
8
8
|
role_list ['base','api_app']
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
9
|
+
node[:application] = 'api'
|
10
|
+
node[:deploy_code] = true
|
11
|
+
node[:repository] = 'git@github.com:br/api.git'
|
12
|
+
node[:scout][:key] = 'abc'
|
13
|
+
node[:scout][:gems] = {'redis' => nil}
|
14
|
+
node[:relayhost] = settings[:sendgrid][:relayhost]
|
15
|
+
|
16
|
+
node[:database][:user] = 'user'
|
17
|
+
node[:database][:pass] = 'pass'
|
18
|
+
node[:database][:host] = 'host'
|
19
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# masta
|
2
2
|
role 'masta-app' do
|
3
3
|
output false
|
4
|
-
|
4
|
+
node[:masta_app] = 123
|
5
5
|
end
|
6
6
|
role 'prod-masta-redis', 'stag-masta-redis'
|
7
7
|
role 'prod-masta-android', 'stag-masta-android' do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
8
|
+
includes 'masta-app'
|
9
|
+
node[:application] = 'masta'
|
10
|
+
node[:deploy_code] = true
|
11
|
+
node[:repository] = 'git@github.com:arockwell/masta_blasta.git'
|
12
|
+
node[:relayhost] = settings[:sendgrid][:relayhost]
|
13
|
+
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.
|
4
|
+
version: 0.3.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: 2012-12-
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: guard-rna
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: rspec
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,6 +195,7 @@ files:
|
|
179
195
|
- lib/files/Guardfile
|
180
196
|
- lib/files/rna.rb
|
181
197
|
- lib/files/s3.yml
|
198
|
+
- lib/node.rb
|
182
199
|
- lib/rna.rb
|
183
200
|
- lib/rna/cli.rb
|
184
201
|
- lib/rna/dsl.rb
|
@@ -205,18 +222,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
222
|
- - ! '>='
|
206
223
|
- !ruby/object:Gem::Version
|
207
224
|
version: '0'
|
208
|
-
segments:
|
209
|
-
- 0
|
210
|
-
hash: 3576656030338073956
|
211
225
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
212
226
|
none: false
|
213
227
|
requirements:
|
214
228
|
- - ! '>='
|
215
229
|
- !ruby/object:Gem::Version
|
216
230
|
version: '0'
|
217
|
-
segments:
|
218
|
-
- 0
|
219
|
-
hash: 3576656030338073956
|
220
231
|
requirements: []
|
221
232
|
rubyforge_project:
|
222
233
|
rubygems_version: 1.8.24
|