rna 0.1.7 → 0.2.0
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.
- data/Guardfile +1 -0
- data/README.md +116 -15
- data/lib/files/rna.rb +11 -5
- data/lib/rna.rb +1 -1
- data/lib/rna/cli.rb +6 -6
- data/lib/rna/dsl.rb +159 -84
- data/lib/rna/{tasks.rb → task.rb} +6 -12
- data/lib/rna/version.rb +1 -1
- data/spec/lib/rna_spec.rb +47 -94
- data/spec/project/config/rna.rb +20 -7
- data/spec/project/config/s3.example.yml +1 -1
- metadata +5 -27
- data/spec/project/nodejson/base.json +0 -6
- data/spec/project/nodejson/prod-api-app.json +0 -17
- data/spec/project/nodejson/prod-api-redis.json +0 -10
- data/spec/project/nodejson/prod-api-resque.json +0 -18
- data/spec/project/nodejson/prod-masta-android.json +0 -10
- data/spec/project/nodejson/prod-masta-redis.json +0 -10
- data/spec/project/nodejson/stag-api-app.json +0 -17
- data/spec/project/nodejson/stag-api-redis.json +0 -10
- data/spec/project/nodejson/stag-api-resque.json +0 -18
- data/spec/project/nodejson/stag-masta-android.json +0 -10
- data/spec/project/nodejson/stag-masta-redis.json +0 -10
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -35,15 +35,14 @@ Example rna.rb file
|
|
35
35
|
###################################
|
36
36
|
# Settings
|
37
37
|
default_inherits 'base'
|
38
|
-
|
38
|
+
global(:except => 'base') do
|
39
39
|
set 'framework_env', 'production'
|
40
40
|
end
|
41
41
|
|
42
42
|
###################################
|
43
|
-
|
44
|
-
|
45
|
-
set '
|
46
|
-
set 'framework_env', 'staging' if name =~ /^stag/
|
43
|
+
pre_rule do
|
44
|
+
set 'chef_branch', 'prod' if role =~ /^prod/
|
45
|
+
set 'chef_branch', 'master' if role =~ /^stag/
|
47
46
|
end
|
48
47
|
|
49
48
|
###################################
|
@@ -67,21 +66,123 @@ role 'prod-api-resque', 'stag-api-resque' do
|
|
67
66
|
run_list ['base','api_resque']
|
68
67
|
set 'workers', 8
|
69
68
|
end
|
69
|
+
|
70
|
+
###################################
|
71
|
+
# Post processing rules that run at the end
|
72
|
+
post_rule do
|
73
|
+
set 'framework_env', 'production' if role =~ /^prod/
|
74
|
+
set 'framework_env', 'staging' if role =~ /^stag/
|
75
|
+
end
|
70
76
|
```
|
71
77
|
|
72
78
|
<pre>
|
73
|
-
$ rna
|
79
|
+
$ rna generate
|
74
80
|
</pre>
|
75
81
|
|
76
|
-
|
82
|
+
Here's the example of the output looks like:
|
83
|
+
|
84
|
+
output/base.json:
|
85
|
+
|
86
|
+
```json
|
87
|
+
{
|
88
|
+
"role": "base",
|
89
|
+
"run_list": [
|
90
|
+
"base"
|
91
|
+
]
|
92
|
+
}
|
93
|
+
```
|
94
|
+
|
95
|
+
output/prod-api-app.json:
|
96
|
+
|
97
|
+
```json
|
98
|
+
{
|
99
|
+
"framework_env": "production",
|
100
|
+
"role": "prod-api-app",
|
101
|
+
"run_list": [
|
102
|
+
"base",
|
103
|
+
"api_app"
|
104
|
+
],
|
105
|
+
"application": "api",
|
106
|
+
"deploy_code": true,
|
107
|
+
"repository": "git@github.com:br/api.git"
|
108
|
+
}
|
109
|
+
```
|
77
110
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
111
|
+
output/prod-api-redis.json:
|
112
|
+
|
113
|
+
```json
|
114
|
+
{
|
115
|
+
"framework_env": "production",
|
116
|
+
"role": "prod-api-redis",
|
117
|
+
"run_list": [
|
118
|
+
"base",
|
119
|
+
"api_redis"
|
120
|
+
]
|
121
|
+
}
|
122
|
+
```
|
123
|
+
|
124
|
+
output/prod-api-resque.json:
|
125
|
+
|
126
|
+
```json
|
127
|
+
{
|
128
|
+
"framework_env": "production",
|
129
|
+
"role": "prod-api-resque",
|
130
|
+
"run_list": [
|
131
|
+
"base",
|
132
|
+
"api_resque"
|
133
|
+
],
|
134
|
+
"application": "api",
|
135
|
+
"deploy_code": true,
|
136
|
+
"repository": "git@github.com:br/api.git",
|
137
|
+
"workers": 8
|
138
|
+
}
|
139
|
+
```
|
140
|
+
|
141
|
+
output/stag-api-app.json:
|
142
|
+
|
143
|
+
```json
|
144
|
+
{
|
145
|
+
"framework_env": "staging",
|
146
|
+
"role": "stag-api-app",
|
147
|
+
"run_list": [
|
148
|
+
"base",
|
149
|
+
"api_app"
|
150
|
+
],
|
151
|
+
"application": "api",
|
152
|
+
"deploy_code": true,
|
153
|
+
"repository": "git@github.com:br/api.git"
|
154
|
+
}
|
155
|
+
```
|
156
|
+
|
157
|
+
output/stag-api-redis.json:
|
158
|
+
|
159
|
+
```json
|
160
|
+
{
|
161
|
+
"framework_env": "staging",
|
162
|
+
"role": "stag-api-redis",
|
163
|
+
"run_list": [
|
164
|
+
"base",
|
165
|
+
"api_redis"
|
166
|
+
]
|
167
|
+
}
|
168
|
+
```
|
169
|
+
|
170
|
+
output/stag-api-resque.json:
|
171
|
+
|
172
|
+
```json
|
173
|
+
{
|
174
|
+
"framework_env": "staging",
|
175
|
+
"role": "stag-api-resque",
|
176
|
+
"run_list": [
|
177
|
+
"base",
|
178
|
+
"api_resque"
|
179
|
+
],
|
180
|
+
"application": "api",
|
181
|
+
"deploy_code": true,
|
182
|
+
"repository": "git@github.com:br/api.git",
|
183
|
+
"workers": 8
|
184
|
+
}
|
185
|
+
```
|
85
186
|
|
86
187
|
<pre>
|
87
188
|
$ rna build -o s3 # saves s3 based on config/s3.yml settings
|
@@ -93,5 +194,5 @@ The config/s3.yml should look like this:
|
|
93
194
|
access_key_id: hocuspocus
|
94
195
|
secret_access_key: opensesame
|
95
196
|
bucket: my-bucket
|
96
|
-
folder: chef/
|
197
|
+
folder: chef/rna
|
97
198
|
```
|
data/lib/files/rna.rb
CHANGED
@@ -3,15 +3,14 @@
|
|
3
3
|
###################################
|
4
4
|
# Settings
|
5
5
|
default_inherits 'base'
|
6
|
-
|
6
|
+
global(:except => 'base') do
|
7
7
|
set 'framework_env', 'production'
|
8
8
|
end
|
9
9
|
|
10
10
|
###################################
|
11
|
-
|
12
|
-
|
13
|
-
set '
|
14
|
-
set 'framework_env', 'staging' if name =~ /^stag/
|
11
|
+
pre_rule do
|
12
|
+
set 'chef_branch', 'prod' if role =~ /^prod/
|
13
|
+
set 'chef_branch', 'master' if role =~ /^stag/
|
15
14
|
end
|
16
15
|
|
17
16
|
###################################
|
@@ -34,4 +33,11 @@ role 'prod-api-resque', 'stag-api-resque' do
|
|
34
33
|
inherits 'prod-api-app'
|
35
34
|
run_list ['base','api_resque']
|
36
35
|
set 'workers', 8
|
36
|
+
end
|
37
|
+
|
38
|
+
###################################
|
39
|
+
# Post processing rules that run at the end
|
40
|
+
post_rule do
|
41
|
+
set 'framework_env', 'production' if role =~ /^prod/
|
42
|
+
set 'framework_env', 'staging' if role =~ /^stag/
|
37
43
|
end
|
data/lib/rna.rb
CHANGED
data/lib/rna/cli.rb
CHANGED
@@ -4,24 +4,24 @@ module Rna
|
|
4
4
|
desc "init", "Setup rna project"
|
5
5
|
long_desc "Sets up config/rna.rb"
|
6
6
|
def init
|
7
|
-
Rna::
|
7
|
+
Rna::Task.init
|
8
8
|
end
|
9
9
|
|
10
|
-
desc "
|
10
|
+
desc "generate", "Builds node.json files"
|
11
11
|
long_desc <<EOL
|
12
12
|
Examples:
|
13
13
|
|
14
|
-
1. rna
|
14
|
+
1. rna generate
|
15
15
|
|
16
16
|
Builds the node.json files based on config/rna.rb and writes them to the ouput folder on the filesystem.
|
17
17
|
|
18
|
-
2. rna
|
18
|
+
2. rna generate -o s3
|
19
19
|
|
20
20
|
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
21
|
EOL
|
22
22
|
method_option :output, :aliases => '-o', :desc => "specify where to output the generated files to", :default => 'filesystem'
|
23
|
-
def
|
24
|
-
Rna::
|
23
|
+
def generate
|
24
|
+
Rna::Task.generate(options.dup.merge(:verbose => true))
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/lib/rna/dsl.rb
CHANGED
@@ -1,66 +1,116 @@
|
|
1
1
|
module Rna
|
2
2
|
class DSL
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
@
|
3
|
+
attr_reader :data, :jsons
|
4
|
+
def initialize(options={})
|
5
|
+
@options = options
|
6
|
+
|
7
|
+
@path = options[:config_path] || 'config/rna.rb'
|
8
|
+
@global_attributes = nil
|
9
|
+
@pre_rule = nil
|
10
|
+
@post_rule = nil
|
9
11
|
@roles = []
|
10
|
-
@attributes = {}
|
11
|
-
@nodejsons = {}
|
12
12
|
end
|
13
13
|
|
14
14
|
def evaluate
|
15
15
|
instance_eval(File.read(@path), @path)
|
16
16
|
end
|
17
17
|
|
18
|
+
def global(options={},&block)
|
19
|
+
@global = {:options => options, :block => block}
|
20
|
+
end
|
21
|
+
|
22
|
+
def default_inherits(role)
|
23
|
+
Role.default_inherits = role
|
24
|
+
end
|
25
|
+
|
26
|
+
def pre_rule(&block)
|
27
|
+
@pre_rule = {:block => block}
|
28
|
+
end
|
29
|
+
|
30
|
+
def post_rule(&block)
|
31
|
+
@post_rule = {:block => block}
|
32
|
+
end
|
33
|
+
|
34
|
+
def role(*names, &block)
|
35
|
+
names.each {|name| each_role(name, &block) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def each_role(name, &block)
|
39
|
+
@roles << {:name => name, :block => block}
|
40
|
+
end
|
41
|
+
|
42
|
+
def run
|
43
|
+
evaluate
|
44
|
+
build
|
45
|
+
process
|
46
|
+
@options.empty? ? output : output(@options)
|
47
|
+
end
|
48
|
+
|
18
49
|
def build
|
19
|
-
|
20
|
-
|
21
|
-
|
50
|
+
@data = {
|
51
|
+
'global' => nil,
|
52
|
+
'roles' => []
|
53
|
+
}
|
54
|
+
# build global attributes
|
55
|
+
@data['global'] = Global.new(@global[:options], @global[:block]).build
|
56
|
+
|
57
|
+
# build roles
|
58
|
+
@roles.each do |r|
|
59
|
+
@data['roles'] << Role.new(r[:name], r[:block], @options).build
|
22
60
|
end
|
23
|
-
|
61
|
+
|
62
|
+
@data
|
24
63
|
end
|
25
|
-
|
26
|
-
|
64
|
+
|
65
|
+
def process
|
66
|
+
@jsons = {}
|
67
|
+
roles = @data['roles'].collect{|h| h['name']}
|
68
|
+
roles.each do |role|
|
69
|
+
@jsons[role] = process_role(role)
|
70
|
+
end
|
71
|
+
@jsons
|
72
|
+
end
|
73
|
+
|
74
|
+
# builds node.json hash
|
27
75
|
# 1. global attributes
|
28
|
-
# 2.
|
29
|
-
#
|
30
|
-
#
|
31
|
-
def process_role(role, exclude_global=nil)
|
76
|
+
# 2. pre rule
|
77
|
+
# 3. role, going up the inherits chain
|
78
|
+
# 4. post rule
|
79
|
+
def process_role(role, exclude_global=nil, depth=1)
|
32
80
|
# only compute exclude_global on on top level call and continue passing down recursive stack call
|
33
81
|
if exclude_global.nil?
|
34
|
-
exclude_global = @
|
82
|
+
exclude_global = @data['global']['except'].include?(role)
|
35
83
|
end
|
36
84
|
|
37
|
-
|
85
|
+
role_data = @data['roles'].find {|h| h['name'] == role}
|
86
|
+
inherits = role_data['inherits']
|
38
87
|
if inherits
|
39
|
-
|
88
|
+
json = process_role(inherits, exclude_global, depth+1)
|
40
89
|
else
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
nodejson = attributes.clone
|
90
|
+
json = exclude_global ? {} : @data['global']['attributes'].clone
|
91
|
+
if @pre_rule
|
92
|
+
pre_data = Rule.new(role, @pre_rule[:block]).build
|
93
|
+
json.merge!(pre_data['attributes'])
|
46
94
|
end
|
47
95
|
end
|
48
96
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
97
|
+
attributes = role_data['attributes'] || {}
|
98
|
+
json.merge!(attributes)
|
99
|
+
# only process post rule at the very last step
|
100
|
+
if @post_rule and depth == 1
|
101
|
+
post_data = Rule.new(role, @post_rule[:block]).build
|
102
|
+
json.merge!(post_data['attributes'])
|
53
103
|
end
|
54
|
-
|
55
|
-
attributes = @attributes[role]['attributes'] || {}
|
56
|
-
nodejson.merge!(attributes)
|
57
|
-
nodejson
|
104
|
+
json
|
58
105
|
end
|
59
106
|
|
60
107
|
def output(options={})
|
61
108
|
jsons = {}
|
62
|
-
|
63
|
-
|
109
|
+
@jsons.each do |role,data|
|
110
|
+
role_data = @data['roles'].find {|h| h['name'] == role}
|
111
|
+
if role_data['output']
|
112
|
+
jsons[role] = JSON.pretty_generate(data)
|
113
|
+
end
|
64
114
|
end
|
65
115
|
|
66
116
|
outputer = options[:output] || 'filesystem'
|
@@ -69,62 +119,87 @@ module Rna
|
|
69
119
|
outputer_class.new(options).run(jsons)
|
70
120
|
end
|
71
121
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
122
|
+
class Builder
|
123
|
+
def build
|
124
|
+
instance_eval(&@block) if @block
|
125
|
+
@data
|
126
|
+
end
|
77
127
|
|
78
|
-
|
79
|
-
|
80
|
-
@attributes['global']['except'] = [options[:except]].flatten
|
81
|
-
self.instance_eval(&block)
|
82
|
-
end
|
83
|
-
def default_inherits(role)
|
84
|
-
@@default_inherits = role
|
85
|
-
end
|
86
|
-
# rules are stored in a different place than attributes
|
87
|
-
def rule(name=nil,&block)
|
88
|
-
@rules << block
|
89
|
-
end
|
90
|
-
def role(*names,&block)
|
91
|
-
names.each do |name|
|
92
|
-
evaluate_role(name,&block)
|
128
|
+
def set(key, value)
|
129
|
+
@data['attributes'][key] = value
|
93
130
|
end
|
94
131
|
end
|
95
|
-
def evaluate_role(name,&block)
|
96
|
-
@roles << name
|
97
|
-
set_scope(name)
|
98
|
-
instance_eval(&default_block)
|
99
|
-
instance_eval(&block) if block_given?
|
100
|
-
end
|
101
132
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
133
|
+
# rules get processed scoed to a specific role
|
134
|
+
class Rule < Builder
|
135
|
+
attr_reader :role
|
136
|
+
def initialize(role, block)
|
137
|
+
@role = role
|
138
|
+
@block = block
|
139
|
+
@data = {
|
140
|
+
'attributes' => {}
|
141
|
+
}
|
107
142
|
end
|
108
|
-
end
|
109
143
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
@attributes[@scope]['name']
|
114
|
-
end
|
115
|
-
def set(key, value)
|
116
|
-
# puts "%%% @scope #{@scope.inspect}"
|
117
|
-
# pp @attributes
|
118
|
-
@attributes[@scope]['attributes'] ||= {}
|
119
|
-
@attributes[@scope]['attributes'][key] = value
|
144
|
+
def name
|
145
|
+
@role
|
146
|
+
end
|
120
147
|
end
|
121
|
-
|
122
|
-
|
123
|
-
|
148
|
+
|
149
|
+
class Global < Builder
|
150
|
+
def initialize(options, block)
|
151
|
+
@options = options
|
152
|
+
@block = block
|
153
|
+
@data = {
|
154
|
+
'except' => [options[:except]].compact,
|
155
|
+
'attributes' => {}
|
156
|
+
}
|
157
|
+
end
|
124
158
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
159
|
+
|
160
|
+
class Role < Builder
|
161
|
+
attr_reader :name
|
162
|
+
def initialize(name, block, options)
|
163
|
+
@name = name
|
164
|
+
@block = block
|
165
|
+
@options = options
|
166
|
+
|
167
|
+
@data = {
|
168
|
+
'name' => name,
|
169
|
+
'attributes' => {
|
170
|
+
'role' => name
|
171
|
+
},
|
172
|
+
'inherits' => @@default_inherits != name ? @@default_inherits : nil,
|
173
|
+
'output' => true
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.default_inherits=(inherits)
|
178
|
+
@@default_inherits = inherits
|
179
|
+
end
|
180
|
+
|
181
|
+
def role
|
182
|
+
@name
|
183
|
+
end
|
184
|
+
|
185
|
+
def output(val)
|
186
|
+
@data['output'] = val
|
187
|
+
end
|
188
|
+
|
189
|
+
def inherits(role)
|
190
|
+
role = nil if role == @name # can't inherit itself
|
191
|
+
@data['inherits'] = role
|
192
|
+
end
|
193
|
+
|
194
|
+
def role_list(list)
|
195
|
+
list = list.collect {|i| "role[#{i}]"}
|
196
|
+
set('run_list', list)
|
197
|
+
end
|
198
|
+
|
199
|
+
def run_list(list)
|
200
|
+
set('run_list', list)
|
201
|
+
end
|
128
202
|
end
|
203
|
+
|
129
204
|
end
|
130
205
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Rna
|
2
|
-
class
|
2
|
+
class Task
|
3
3
|
def self.init(project_root=".",options={})
|
4
4
|
puts "Settin up rna project" unless options[:quiet]
|
5
5
|
FileUtils.mkdir("#{project_root}/config") unless File.exist?("#{project_root}/config")
|
@@ -15,22 +15,16 @@ module Rna
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
def self.
|
19
|
-
new(options).
|
18
|
+
def self.generate(options)
|
19
|
+
new(options).generate
|
20
20
|
end
|
21
21
|
|
22
22
|
def initialize(options={})
|
23
23
|
@options = options
|
24
|
-
|
25
|
-
@dsl = DSL.new(options[:config_path])
|
26
|
-
else
|
27
|
-
@dsl = DSL.new
|
28
|
-
end
|
24
|
+
@dsl = options[:config_path] ? DSL.new(options) : DSL.new
|
29
25
|
end
|
30
|
-
def
|
31
|
-
@dsl.
|
32
|
-
@dsl.build
|
33
|
-
@dsl.output(@options)
|
26
|
+
def generate
|
27
|
+
@dsl.run
|
34
28
|
end
|
35
29
|
end
|
36
30
|
end
|
data/lib/rna/version.rb
CHANGED
data/spec/lib/rna_spec.rb
CHANGED
@@ -6,117 +6,46 @@ describe Rna do
|
|
6
6
|
before(:each) do
|
7
7
|
@project_root = File.expand_path("../../project", __FILE__)
|
8
8
|
@project2_root = File.expand_path("../../project2", __FILE__)
|
9
|
-
@dsl = Rna::DSL.new(
|
10
|
-
|
9
|
+
@dsl = Rna::DSL.new(
|
10
|
+
:config_path => "#{@project_root}/config/rna.rb",
|
11
|
+
:output_path => "#{@project_root}/output"
|
12
|
+
)
|
11
13
|
end
|
12
14
|
|
13
15
|
after(:each) do
|
14
16
|
FileUtils.rm_rf("#{@project_root}/output")
|
15
17
|
end
|
16
18
|
|
17
|
-
it "
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
attributes['global']['attributes']['repository'].should be_nil
|
25
|
-
end
|
26
|
-
|
27
|
-
it "evaluate base attributes data that does not include the global attributes" do
|
28
|
-
attributes = @dsl.attributes
|
29
|
-
attributes.should be_a(Hash)
|
30
|
-
attributes['base']['attributes'].keys.should_not include('application')
|
31
|
-
attributes['base']['attributes']['run_list'].should == ["role[base]"]
|
32
|
-
end
|
33
|
-
|
34
|
-
it "evaluate base attributes data should not inherit itself" do
|
35
|
-
attributes = @dsl.attributes
|
36
|
-
attributes.should be_a(Hash)
|
37
|
-
attributes['base']['inherits'].should be_nil
|
38
|
-
end
|
39
|
-
|
40
|
-
it "roles without blocks should run the default block" do
|
41
|
-
attributes = @dsl.attributes
|
42
|
-
# running the default block will set inherits attribute
|
43
|
-
attributes['prod-api-redis']['inherits'].should == 'base'
|
44
|
-
end
|
45
|
-
|
46
|
-
it "roles with blocks should run the default block and then their own block" do
|
47
|
-
attributes = @dsl.attributes
|
48
|
-
# hard to read test, but after the default block runs, the passed in role block rusn and overrides the default_blocks inherits attribuute
|
49
|
-
attributes['prod-api-resque']['inherits'].should == 'prod-api-app'
|
50
|
-
end
|
51
|
-
|
52
|
-
it "roles with blocks should override the global attributes" do
|
53
|
-
attributes = @dsl.attributes
|
54
|
-
attributes['prod-masta-android']['attributes']['application'].should == 'masta'
|
55
|
-
attributes['prod-masta-android']['attributes']['deploy_code'].should be_true
|
56
|
-
attributes['prod-masta-android']['attributes']['repository'].should == 'git@github.com:arockwell/masta_blasta.git'
|
57
|
-
end
|
58
|
-
|
59
|
-
it "base node.json should not include global attributes" do
|
60
|
-
@dsl.build
|
61
|
-
@dsl.nodejsons['base']['run_list'].should == ["role[base]"]
|
62
|
-
@dsl.nodejsons['base']['role'].should == 'base'
|
63
|
-
@dsl.nodejsons['base'].keys.should_not include('application')
|
64
|
-
@dsl.nodejsons['base'].keys.should_not include('repository')
|
65
|
-
end
|
66
|
-
|
67
|
-
it "prod-api-redis node.json should include base plus global attributes" do
|
68
|
-
@dsl.build
|
69
|
-
@dsl.nodejsons['prod-api-redis']['run_list'].should == ["role[base]"]
|
70
|
-
@dsl.nodejsons['prod-api-redis']['deploy_code'].should be_false
|
71
|
-
end
|
72
|
-
|
73
|
-
it "prod-api-app node.json should include global attributes plus additional attributes" do
|
74
|
-
@dsl.build
|
75
|
-
@dsl.nodejsons['prod-api-app']['run_list'].should == ["role[base]", "role[api_app]"]
|
76
|
-
@dsl.nodejsons['prod-api-app']['deploy_code'].should be_true
|
77
|
-
@dsl.nodejsons['prod-api-app'].keys.should include('scout')
|
78
|
-
end
|
79
|
-
|
80
|
-
it "prod-api-resque node.json inherit attributes from prod-api-app" do
|
81
|
-
@dsl.build
|
82
|
-
@dsl.nodejsons['prod-api-resque']['run_list'].should == @dsl.nodejsons['prod-api-app']['run_list']
|
83
|
-
@dsl.nodejsons['prod-api-resque']['deploy_code'].should == @dsl.nodejsons['prod-api-app']['deploy_code']
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should respect rules and change framework_env" do
|
87
|
-
@dsl.build
|
88
|
-
@dsl.nodejsons['stag-masta-android']['application'].should == 'masta'
|
89
|
-
@dsl.nodejsons['stag-masta-android']['framework_env'].should == 'staging'
|
90
|
-
@dsl.nodejsons['prod-masta-android']['framework_env'].should == 'production'
|
91
|
-
@dsl.nodejsons
|
92
|
-
end
|
19
|
+
# it "should build attributes" do
|
20
|
+
# @dsl.evaluate
|
21
|
+
# @dsl.build
|
22
|
+
# pp @dsl.data
|
23
|
+
# @dsl.process
|
24
|
+
# pp @dsl.jsons
|
25
|
+
# end
|
93
26
|
|
94
27
|
it "should write json files to outputs folder" do
|
95
|
-
@dsl.
|
96
|
-
@dsl.output(:output => 'filesystem', :output_path => "#{@project_root}/output")
|
28
|
+
@dsl.run
|
97
29
|
Dir.glob("#{@project_root}/output/*").size.should > 0
|
98
30
|
end
|
99
31
|
|
100
32
|
# complete end to end tests
|
101
33
|
it "base.json should contain correct attributes" do
|
102
|
-
@dsl.
|
103
|
-
@dsl.output(:output => 'filesystem', :output_path => "#{@project_root}/output")
|
34
|
+
@dsl.run
|
104
35
|
base = JSON.load(IO.read("#{@project_root}/output/base.json"))
|
105
36
|
base['role'].should == 'base'
|
106
37
|
base['run_list'].should == ["role[base]"]
|
107
38
|
end
|
108
39
|
|
109
40
|
it "base.json should not contain global attributes" do
|
110
|
-
@dsl.
|
111
|
-
@dsl.output(:output => 'filesystem', :output_path => "#{@project_root}/output")
|
41
|
+
@dsl.run
|
112
42
|
base = JSON.load(IO.read("#{@project_root}/output/base.json"))
|
113
43
|
base['framework_env'].should be_nil
|
114
44
|
base['deploy_code'].should be_nil
|
115
45
|
end
|
116
46
|
|
117
47
|
it "prod-api-redis.json should contain base and global attributes" do
|
118
|
-
@dsl.
|
119
|
-
@dsl.output(:output => 'filesystem', :output_path => "#{@project_root}/output")
|
48
|
+
@dsl.run
|
120
49
|
json = JSON.load(IO.read("#{@project_root}/output/prod-api-redis.json"))
|
121
50
|
json['role'].should == 'prod-api-redis'
|
122
51
|
json['run_list'].should == ["role[base]"]
|
@@ -125,8 +54,7 @@ describe Rna do
|
|
125
54
|
end
|
126
55
|
|
127
56
|
it "stag-api-redis.json should contain base and global attributes and apply rules" do
|
128
|
-
@dsl.
|
129
|
-
@dsl.output(:output => 'filesystem', :output_path => "#{@project_root}/output")
|
57
|
+
@dsl.run
|
130
58
|
json = JSON.load(IO.read("#{@project_root}/output/stag-api-redis.json"))
|
131
59
|
json['role'].should == 'stag-api-redis'
|
132
60
|
json['run_list'].should == ["role[base]"]
|
@@ -135,8 +63,7 @@ describe Rna do
|
|
135
63
|
end
|
136
64
|
|
137
65
|
it "prod-api-app.json should contain base and global attributes" do
|
138
|
-
@dsl.
|
139
|
-
@dsl.output(:output => 'filesystem', :output_path => "#{@project_root}/output")
|
66
|
+
@dsl.run
|
140
67
|
json = JSON.load(IO.read("#{@project_root}/output/prod-api-app.json"))
|
141
68
|
json['role'].should == 'prod-api-app'
|
142
69
|
json['run_list'].should == ["role[base]","role[api_app]"]
|
@@ -145,10 +72,36 @@ describe Rna do
|
|
145
72
|
json['scout'].should be_a(Hash)
|
146
73
|
end
|
147
74
|
|
75
|
+
it "prod-api-app.json should contain pre and post rules" do
|
76
|
+
@dsl.run
|
77
|
+
json = JSON.load(IO.read("#{@project_root}/output/prod-api-app.json"))
|
78
|
+
json['role'].should == 'prod-api-app'
|
79
|
+
json['run_list'].should == ["role[base]","role[api_app]"]
|
80
|
+
json['deploy_code'].should == true
|
81
|
+
json['framework_env'].should == 'production'
|
82
|
+
json['scout'].should be_a(Hash)
|
83
|
+
json['pre_rule'].should == 1
|
84
|
+
json['post_rule'].should == 2
|
85
|
+
end
|
86
|
+
|
87
|
+
it "masta-app should not generate output file" do
|
88
|
+
@dsl.run
|
89
|
+
File.exist?("#{@project_root}/output/masta-app.json").should be_false
|
90
|
+
File.exist?("#{@project_root}/output/prod-masta-android.json").should be_true
|
91
|
+
json = JSON.load(IO.read("#{@project_root}/output/prod-masta-android.json"))
|
92
|
+
json['masta_app'].should == 123
|
93
|
+
end
|
94
|
+
|
95
|
+
###################
|
96
|
+
|
148
97
|
# only run when S3=1, will need to setup spec/project/config/s3.yml
|
149
98
|
it "should upload to s3" do
|
150
|
-
@dsl.
|
151
|
-
|
99
|
+
@dsl = Rna::DSL.new(
|
100
|
+
:output => 's3',
|
101
|
+
:s3_config_path => "#{@project_root}/config/s3.yml",
|
102
|
+
:config_path => "#{@project_root}/config/rna.rb"
|
103
|
+
)
|
104
|
+
outputer = @dsl.run
|
152
105
|
|
153
106
|
config = outputer.config
|
154
107
|
s3 = outputer.s3
|
@@ -171,14 +124,14 @@ describe Rna do
|
|
171
124
|
it "task init should set up project" do
|
172
125
|
File.exist?("#{@project2_root}/config/s3.yml").should be_false
|
173
126
|
File.exist?("#{@project2_root}/config/rna.rb").should be_false
|
174
|
-
Rna::
|
127
|
+
Rna::Task.init(@project2_root, :quiet => true)
|
175
128
|
File.exist?("#{@project2_root}/config/s3.yml").should be_true
|
176
129
|
File.exist?("#{@project2_root}/config/rna.rb").should be_true
|
177
130
|
FileUtils.rm_rf("#{@project2_root}/config")
|
178
131
|
end
|
179
132
|
|
180
133
|
it "task build should generate node.json files" do
|
181
|
-
Rna::
|
134
|
+
Rna::Task.generate(
|
182
135
|
:config_path => "#{@project_root}/config/rna.rb",
|
183
136
|
:output_path => "#{@project_root}/output"
|
184
137
|
)
|
data/spec/project/config/rna.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
###################################
|
2
2
|
# Settings
|
3
3
|
default_inherits 'base'
|
4
|
-
|
4
|
+
global(:except => 'base') do
|
5
5
|
set 'application', nil
|
6
6
|
set 'deploy_code', false
|
7
7
|
set 'framework_env', 'production'
|
@@ -9,17 +9,17 @@ global_attributes(:except => 'base') do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
###################################
|
12
|
-
|
13
|
-
|
14
|
-
set '
|
15
|
-
set '
|
12
|
+
pre_rule do
|
13
|
+
set 'pre_rule', 1
|
14
|
+
set 'chef_branch', 'prod' if role =~ /^prod/
|
15
|
+
set 'chef_branch', 'master' if role =~ /^stag/
|
16
16
|
end
|
17
17
|
|
18
18
|
###################################
|
19
19
|
# Roles
|
20
20
|
# base
|
21
21
|
role 'base' do
|
22
|
-
|
22
|
+
role_list ['base']
|
23
23
|
end
|
24
24
|
# api
|
25
25
|
role 'prod-api-redis', 'stag-api-redis'
|
@@ -28,7 +28,7 @@ role 'prod-api-resque', 'stag-api-resque' do
|
|
28
28
|
set 'workers', 8
|
29
29
|
end
|
30
30
|
role 'prod-api-app', 'stag-api-app' do
|
31
|
-
|
31
|
+
role_list ['base','api_app']
|
32
32
|
set 'application', 'api'
|
33
33
|
set 'deploy_code', true
|
34
34
|
set 'repository', 'git@github.com:br/api.git'
|
@@ -40,9 +40,22 @@ role 'prod-api-app', 'stag-api-app' do
|
|
40
40
|
}
|
41
41
|
end
|
42
42
|
# masta
|
43
|
+
role 'masta-app' do
|
44
|
+
output false
|
45
|
+
set 'masta_app', 123
|
46
|
+
end
|
43
47
|
role 'prod-masta-redis', 'stag-masta-redis'
|
44
48
|
role 'prod-masta-android', 'stag-masta-android' do
|
49
|
+
inherits 'masta-app'
|
45
50
|
set 'application', 'masta'
|
46
51
|
set 'deploy_code', true
|
47
52
|
set 'repository', 'git@github.com:arockwell/masta_blasta.git'
|
53
|
+
end
|
54
|
+
|
55
|
+
###################################
|
56
|
+
# Post processing rules that run at the end
|
57
|
+
post_rule do
|
58
|
+
set 'post_rule', 2
|
59
|
+
set 'framework_env', 'production' if role =~ /^prod/
|
60
|
+
set 'framework_env', 'staging' if role =~ /^stag/
|
48
61
|
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.2.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-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -183,23 +183,12 @@ files:
|
|
183
183
|
- lib/rna/cli.rb
|
184
184
|
- lib/rna/dsl.rb
|
185
185
|
- lib/rna/outputers.rb
|
186
|
-
- lib/rna/
|
186
|
+
- lib/rna/task.rb
|
187
187
|
- lib/rna/version.rb
|
188
188
|
- rna.gemspec
|
189
189
|
- spec/lib/rna_spec.rb
|
190
190
|
- spec/project/config/rna.rb
|
191
191
|
- spec/project/config/s3.example.yml
|
192
|
-
- spec/project/nodejson/base.json
|
193
|
-
- spec/project/nodejson/prod-api-app.json
|
194
|
-
- spec/project/nodejson/prod-api-redis.json
|
195
|
-
- spec/project/nodejson/prod-api-resque.json
|
196
|
-
- spec/project/nodejson/prod-masta-android.json
|
197
|
-
- spec/project/nodejson/prod-masta-redis.json
|
198
|
-
- spec/project/nodejson/stag-api-app.json
|
199
|
-
- spec/project/nodejson/stag-api-redis.json
|
200
|
-
- spec/project/nodejson/stag-api-resque.json
|
201
|
-
- spec/project/nodejson/stag-masta-android.json
|
202
|
-
- spec/project/nodejson/stag-masta-redis.json
|
203
192
|
- spec/project2/.gitkeep
|
204
193
|
- spec/project2/Guardfile
|
205
194
|
homepage: ''
|
@@ -216,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
216
205
|
version: '0'
|
217
206
|
segments:
|
218
207
|
- 0
|
219
|
-
hash:
|
208
|
+
hash: 4553005362745989703
|
220
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
221
210
|
none: false
|
222
211
|
requirements:
|
@@ -225,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
214
|
version: '0'
|
226
215
|
segments:
|
227
216
|
- 0
|
228
|
-
hash:
|
217
|
+
hash: 4553005362745989703
|
229
218
|
requirements: []
|
230
219
|
rubyforge_project:
|
231
220
|
rubygems_version: 1.8.24
|
@@ -237,16 +226,5 @@ test_files:
|
|
237
226
|
- spec/lib/rna_spec.rb
|
238
227
|
- spec/project/config/rna.rb
|
239
228
|
- spec/project/config/s3.example.yml
|
240
|
-
- spec/project/nodejson/base.json
|
241
|
-
- spec/project/nodejson/prod-api-app.json
|
242
|
-
- spec/project/nodejson/prod-api-redis.json
|
243
|
-
- spec/project/nodejson/prod-api-resque.json
|
244
|
-
- spec/project/nodejson/prod-masta-android.json
|
245
|
-
- spec/project/nodejson/prod-masta-redis.json
|
246
|
-
- spec/project/nodejson/stag-api-app.json
|
247
|
-
- spec/project/nodejson/stag-api-redis.json
|
248
|
-
- spec/project/nodejson/stag-api-resque.json
|
249
|
-
- spec/project/nodejson/stag-masta-android.json
|
250
|
-
- spec/project/nodejson/stag-masta-redis.json
|
251
229
|
- spec/project2/.gitkeep
|
252
230
|
- spec/project2/Guardfile
|
@@ -1,17 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"application": "api",
|
3
|
-
"deploy_code": true,
|
4
|
-
"framework_env": "production",
|
5
|
-
"repository": "git@github.com:br/api.git",
|
6
|
-
"role": "prod-api-app",
|
7
|
-
"run_list": [
|
8
|
-
"role[base]",
|
9
|
-
"role[api_app]"
|
10
|
-
],
|
11
|
-
"scout": {
|
12
|
-
"key": "abc",
|
13
|
-
"gems": {
|
14
|
-
"redis": null
|
15
|
-
}
|
16
|
-
}
|
17
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"application": "api",
|
3
|
-
"deploy_code": true,
|
4
|
-
"framework_env": "production",
|
5
|
-
"repository": "git@github.com:br/api.git",
|
6
|
-
"role": "prod-api-resque",
|
7
|
-
"run_list": [
|
8
|
-
"role[base]",
|
9
|
-
"role[api_app]"
|
10
|
-
],
|
11
|
-
"scout": {
|
12
|
-
"key": "abc",
|
13
|
-
"gems": {
|
14
|
-
"redis": null
|
15
|
-
}
|
16
|
-
},
|
17
|
-
"workers": 8
|
18
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"application": "api",
|
3
|
-
"deploy_code": true,
|
4
|
-
"framework_env": "staging",
|
5
|
-
"repository": "git@github.com:br/api.git",
|
6
|
-
"role": "stag-api-app",
|
7
|
-
"run_list": [
|
8
|
-
"role[base]",
|
9
|
-
"role[api_app]"
|
10
|
-
],
|
11
|
-
"scout": {
|
12
|
-
"key": "abc",
|
13
|
-
"gems": {
|
14
|
-
"redis": null
|
15
|
-
}
|
16
|
-
}
|
17
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"application": "api",
|
3
|
-
"deploy_code": true,
|
4
|
-
"framework_env": "staging",
|
5
|
-
"repository": "git@github.com:br/api.git",
|
6
|
-
"role": "stag-api-resque",
|
7
|
-
"run_list": [
|
8
|
-
"role[base]",
|
9
|
-
"role[api_app]"
|
10
|
-
],
|
11
|
-
"scout": {
|
12
|
-
"key": "abc",
|
13
|
-
"gems": {
|
14
|
-
"redis": null
|
15
|
-
}
|
16
|
-
},
|
17
|
-
"workers": 8
|
18
|
-
}
|