capistrano-soa 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +9 -0
- data/capistrano-soa.gemspec +2 -2
- data/lib/capistrano/ext/soa.rb +116 -92
- data/spec/recipes/fake_recipe.rb +4 -0
- data/spec/soa_spec.rb +68 -27
- metadata +4 -3
data/Guardfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec, :cli => "--color --format nested" do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
data/capistrano-soa.gemspec
CHANGED
@@ -5,11 +5,11 @@ require "capistrano/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
|
7
7
|
s.name = "capistrano-soa"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.8"
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.authors = ["Ben Wu"]
|
11
11
|
s.email = ["wucheokman@gmail.com"]
|
12
|
-
s.homepage = "http://github.com/
|
12
|
+
s.homepage = "http://github.com/cheokman/capistrano-soa"
|
13
13
|
s.summary = %q{An extension for Capistrano supporting SOA Services Deployment}
|
14
14
|
s.description = %q{Capistrano SOA let you management services group in SOA architecuture with multi-stage support.}
|
15
15
|
s.files = `git ls-files`.split("\n")
|
data/lib/capistrano/ext/soa.rb
CHANGED
@@ -2,6 +2,19 @@ require 'capistrano'
|
|
2
2
|
require 'fileutils'
|
3
3
|
require 'colored'
|
4
4
|
|
5
|
+
module Capistrano
|
6
|
+
class Configuration
|
7
|
+
module Namespaces
|
8
|
+
def rename_task(new_name, old_name)
|
9
|
+
metaclass = class << self; self; end
|
10
|
+
metaclass.send(:alias_method, new_name.to_s, old_name.to_s)
|
11
|
+
metaclass.send(:remove_method, old_name.to_s)
|
12
|
+
tasks[new_name.to_sym] = tasks.delete(old_name.to_sym)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
5
18
|
module Capistrano::Ext
|
6
19
|
module SOA
|
7
20
|
def get_config_files(config_root)
|
@@ -61,22 +74,22 @@ module Capistrano::Ext
|
|
61
74
|
stages.include?(possible_stage_name) ? possible_stage_name : nil
|
62
75
|
end
|
63
76
|
|
64
|
-
#
|
77
|
+
#
|
65
78
|
# One Environment with different applications deployment
|
66
79
|
# cap integration prj0:subprj0:app0 prj1:subprj0:app1 deploy
|
67
|
-
# cap prj0:subprj0:app0:integration prj0:subprj0:app0:integration deploy
|
80
|
+
# cap prj0:subprj0:app0:integration prj0:subprj0:app0:integration deploy
|
68
81
|
#
|
69
82
|
# One environment with one application
|
70
|
-
# cap prj0:subprj0:app0:integration deploy
|
71
|
-
#
|
72
|
-
# Different Environments with different applications deployment
|
83
|
+
# cap prj0:subprj0:app0:integration deploy
|
84
|
+
#
|
85
|
+
# Different Environments with different applications deployment
|
73
86
|
# cap prj0:subprj0:app0:integration prj0:subprj0:app0:staging deploy
|
74
87
|
#
|
75
88
|
|
76
89
|
def parse_args(args, stages, services)
|
77
90
|
args = args.dup
|
78
91
|
selected_services = []
|
79
|
-
|
92
|
+
tasks = nil
|
80
93
|
selected_stage = nil
|
81
94
|
|
82
95
|
selected_stage = if stages.include?(args.first)
|
@@ -88,7 +101,8 @@ module Capistrano::Ext
|
|
88
101
|
else
|
89
102
|
nil
|
90
103
|
end
|
91
|
-
|
104
|
+
|
105
|
+
args.each_with_index do |a, i|
|
92
106
|
if selected_stage.nil? && !get_stage_name(a, stages).nil?
|
93
107
|
selected_stage = get_stage_name(a, stages)
|
94
108
|
_service = get_service_name(a, services)
|
@@ -97,41 +111,51 @@ module Capistrano::Ext
|
|
97
111
|
_service = get_service_name(a, services)
|
98
112
|
selected_services << _service unless selected_services.include?(_service)
|
99
113
|
else
|
100
|
-
|
114
|
+
tasks = args[i..args.length].join(" ")
|
101
115
|
break
|
102
116
|
end
|
103
117
|
end
|
104
|
-
[selected_stage, selected_services.flatten.uniq,
|
118
|
+
[selected_stage, selected_services.flatten.uniq, tasks]
|
105
119
|
end
|
106
120
|
|
107
121
|
def build_task(stage, services, this_task)
|
108
|
-
|
109
122
|
if services.size > 1
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
123
|
+
these_tasks = this_task.split(" ")
|
124
|
+
these_tasks.each do |current_task|
|
125
|
+
next if find_task(current_task).nil?
|
126
|
+
|
127
|
+
segments = current_task.split(':')
|
128
|
+
if segments.size > 1
|
129
|
+
namespace_names = segments[0, segments.size-1]
|
130
|
+
task_name = segments.last
|
131
|
+
else
|
132
|
+
namespace_names = [segments[0]]
|
133
|
+
task_name = "default"
|
134
|
+
end
|
135
|
+
original_task = "original_#{task_name}"
|
121
136
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
137
|
+
block = lambda do |parent|
|
138
|
+
before current_task do
|
139
|
+
logger.debug "find_task:#{task_name}: #{find_task task_name}"
|
140
|
+
rename_task "original_#{task_name}", task_name
|
141
|
+
logger.debug "find_task:#{task_name}: #{find_task task_name}"
|
142
|
+
task(task_name.to_sym) do
|
143
|
+
logger.debug "call..."
|
144
|
+
services.each do |service|
|
145
|
+
system("cap #{stage} #{service} #{namespace_names.join(":")}:#{task_name}")
|
146
|
+
end
|
147
|
+
end
|
148
|
+
logger.debug "find_task:#{task_name}: #{find_task task_name}"
|
149
|
+
end
|
150
|
+
end
|
128
151
|
|
129
|
-
|
130
|
-
|
131
|
-
|
152
|
+
block = namespace_names.reverse.inject(block) do |child, name|
|
153
|
+
lambda do |parent|
|
154
|
+
parent.namespace(name, &child)
|
155
|
+
end
|
132
156
|
end
|
157
|
+
block.call(top)
|
133
158
|
end
|
134
|
-
block.call(top)
|
135
159
|
end
|
136
160
|
end
|
137
161
|
|
@@ -145,7 +169,7 @@ module Capistrano::Ext
|
|
145
169
|
config_files = get_config_files(config_root)
|
146
170
|
|
147
171
|
set :stages, collect_stages(config_files) unless exists?(:stages)
|
148
|
-
|
172
|
+
|
149
173
|
# build configuration names list
|
150
174
|
config_names = get_config_names(config_files,config_root)
|
151
175
|
|
@@ -160,7 +184,7 @@ module Capistrano::Ext
|
|
160
184
|
stages.each do |s|
|
161
185
|
desc "Set the target stage to `#{s}'."
|
162
186
|
|
163
|
-
task(s.to_sym) do
|
187
|
+
task(s.to_sym) do
|
164
188
|
top.set :stage, s.to_sym
|
165
189
|
end
|
166
190
|
end
|
@@ -234,70 +258,15 @@ module Capistrano::Ext
|
|
234
258
|
block.call(top)
|
235
259
|
end
|
236
260
|
|
237
|
-
|
238
|
-
before "deploy:update_code" do
|
239
|
-
print "Updating Code........ "
|
240
|
-
start_spinner()
|
241
|
-
end
|
242
|
-
|
243
|
-
after "deploy:update_code" do
|
244
|
-
stop_spinner()
|
245
|
-
puts "Done.".green
|
246
|
-
end
|
247
|
-
|
248
|
-
before "deploy:cleanup" do
|
249
|
-
print "Cleaning Up.......... "
|
250
|
-
start_spinner()
|
251
|
-
end
|
252
|
-
|
253
|
-
after "deploy:restart" do
|
254
|
-
stop_spinner()
|
255
|
-
puts "Done.".green
|
256
|
-
end
|
257
|
-
|
258
|
-
before "deploy:restart" do
|
259
|
-
print "Restarting .......... "
|
260
|
-
start_spinner()
|
261
|
-
end
|
262
|
-
|
263
|
-
after "deploy:cleanup" do
|
264
|
-
stop_spinner()
|
265
|
-
puts "Done.".green
|
266
|
-
end
|
267
|
-
# spinner stuff
|
268
|
-
@spinner_running = false
|
269
|
-
@chars = ['|', '/', '-', '\\']
|
270
|
-
@spinner = Thread.new do
|
271
|
-
loop do
|
272
|
-
unless @spinner_running
|
273
|
-
Thread.stop
|
274
|
-
end
|
275
|
-
print @chars[0]
|
276
|
-
sleep(0.1)
|
277
|
-
print "\b"
|
278
|
-
@chars.push @chars.shift
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
def start_spinner
|
283
|
-
@spinner_running = true
|
284
|
-
@spinner.wakeup
|
285
|
-
end
|
286
|
-
|
287
|
-
# stops the spinner and backspaces over last displayed character
|
288
|
-
def stop_spinner
|
289
|
-
@spinner_running = false
|
290
|
-
print "\b"
|
291
|
-
end
|
292
|
-
|
261
|
+
|
293
262
|
on :load do
|
294
263
|
services_name = get_services_name(config_names)
|
295
264
|
|
296
|
-
selected_stage, selected_services,
|
265
|
+
selected_stage, selected_services, selected_tasks = parse_args(ARGV, stages, services_name)
|
297
266
|
|
298
267
|
set :stage, selected_stage
|
299
268
|
set :services, selected_services
|
300
|
-
build_task(selected_stage, selected_services,
|
269
|
+
build_task(selected_stage, selected_services, selected_tasks)
|
301
270
|
|
302
271
|
if stages.include?(stage)
|
303
272
|
# Execute the specified stage so that recipes required in stage can contribute to task list
|
@@ -356,8 +325,63 @@ module Capistrano::Ext
|
|
356
325
|
# end
|
357
326
|
# end
|
358
327
|
# end
|
359
|
-
end
|
360
328
|
|
329
|
+
STDOUT.sync
|
330
|
+
before "deploy:update_code" do
|
331
|
+
print "Updating Code........ "
|
332
|
+
start_spinner()
|
333
|
+
end
|
334
|
+
|
335
|
+
after "deploy:update_code" do
|
336
|
+
stop_spinner()
|
337
|
+
puts "Done.".green
|
338
|
+
end
|
339
|
+
|
340
|
+
before "deploy:cleanup" do
|
341
|
+
print "Cleaning Up.......... "
|
342
|
+
start_spinner()
|
343
|
+
end
|
344
|
+
|
345
|
+
after "deploy:restart" do
|
346
|
+
stop_spinner()
|
347
|
+
puts "Done.".green
|
348
|
+
end
|
349
|
+
|
350
|
+
before "deploy:restart" do
|
351
|
+
print "Restarting .......... "
|
352
|
+
start_spinner()
|
353
|
+
end
|
354
|
+
|
355
|
+
after "deploy:cleanup" do
|
356
|
+
stop_spinner()
|
357
|
+
puts "Done.".green
|
358
|
+
end
|
359
|
+
# spinner stuff
|
360
|
+
@spinner_running = false
|
361
|
+
@chars = ['|', '/', '-', '\\']
|
362
|
+
@spinner = Thread.new do
|
363
|
+
loop do
|
364
|
+
unless @spinner_running
|
365
|
+
Thread.stop
|
366
|
+
end
|
367
|
+
print @chars[0]
|
368
|
+
sleep(0.1)
|
369
|
+
print "\b"
|
370
|
+
@chars.push @chars.shift
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
def start_spinner
|
375
|
+
@spinner_running = true
|
376
|
+
@spinner.wakeup
|
377
|
+
end
|
378
|
+
|
379
|
+
# stops the spinner and backspaces over last displayed character
|
380
|
+
def stop_spinner
|
381
|
+
@spinner_running = false
|
382
|
+
print "\b"
|
383
|
+
end
|
384
|
+
end
|
361
385
|
end
|
362
386
|
|
363
387
|
end
|
data/spec/recipes/fake_recipe.rb
CHANGED
data/spec/soa_spec.rb
CHANGED
@@ -7,10 +7,10 @@ describe Capistrano::Ext::SOA, "loaded into a configuration" do
|
|
7
7
|
@configuration.extend(Capistrano::Spec::ConfigurationExtension)
|
8
8
|
config_root = "/opt/deploy"
|
9
9
|
|
10
|
-
File.stub
|
10
|
+
File.stub(:expand_path) {config_root}
|
11
11
|
@project_dir = ["a/b/production.rb", "a/b/staging.rb", "a/b.rb", "a/c/staging.rb"]
|
12
12
|
|
13
|
-
Dir.stub
|
13
|
+
Dir.stub(:[]) {@project_dir.map {|dir| "#{config_root}/#{dir}"}}
|
14
14
|
@configuration.extend(Capistrano::Fakerecipe)
|
15
15
|
Capistrano::Fakerecipe.load_into(@configuration)
|
16
16
|
Capistrano::Ext::SOA.load_into(@configuration)
|
@@ -40,7 +40,7 @@ describe Capistrano::Ext::SOA, "loaded into a configuration" do
|
|
40
40
|
task.should == nil
|
41
41
|
end
|
42
42
|
|
43
|
-
it "should parse single stage with one
|
43
|
+
it "should parse single stage with one service and different environment" do
|
44
44
|
args = ["staging", "a:b", "a:b:production"]
|
45
45
|
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
46
46
|
selected_services.should == ["a:b"]
|
@@ -48,7 +48,7 @@ describe Capistrano::Ext::SOA, "loaded into a configuration" do
|
|
48
48
|
task.should == nil
|
49
49
|
end
|
50
50
|
|
51
|
-
it "should parse
|
51
|
+
it "should parse default stage with two services" do
|
52
52
|
args = ["a:b", "a:c"]
|
53
53
|
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
54
54
|
selected_services.should == ["a:b", "a:c"]
|
@@ -56,7 +56,7 @@ describe Capistrano::Ext::SOA, "loaded into a configuration" do
|
|
56
56
|
task.should == nil
|
57
57
|
end
|
58
58
|
|
59
|
-
it "should
|
59
|
+
it "should one or more services with undefined environment" do
|
60
60
|
args = ["a:b:integration", "a:c"]
|
61
61
|
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
62
62
|
selected_services.should == ["a:b", "a:c"]
|
@@ -64,7 +64,15 @@ describe Capistrano::Ext::SOA, "loaded into a configuration" do
|
|
64
64
|
task.should == nil
|
65
65
|
end
|
66
66
|
|
67
|
-
it "should
|
67
|
+
it "should one or more services with differnt environment" do
|
68
|
+
args = ["a:b:staging", "a:c"]
|
69
|
+
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
70
|
+
selected_services.should == ["a:b", "a:c"]
|
71
|
+
selected_stage.should == "staging"
|
72
|
+
task.should == nil
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should parse multiple service and different default and specific environment" do
|
68
76
|
args = ["staging", "a:b", "a:c:production"]
|
69
77
|
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
70
78
|
selected_services.should == ["a:b", "a:c"]
|
@@ -72,7 +80,7 @@ describe Capistrano::Ext::SOA, "loaded into a configuration" do
|
|
72
80
|
task.should == nil
|
73
81
|
end
|
74
82
|
|
75
|
-
it "should parse
|
83
|
+
it "should parse multiple services with different specific environments" do
|
76
84
|
args = ["a:b:staging", "a:c:production"]
|
77
85
|
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
78
86
|
selected_services.should == ["a:b", "a:c"]
|
@@ -80,7 +88,7 @@ describe Capistrano::Ext::SOA, "loaded into a configuration" do
|
|
80
88
|
task.should == nil
|
81
89
|
end
|
82
90
|
|
83
|
-
it "should parse
|
91
|
+
it "should parse multiple services with one specific environment" do
|
84
92
|
args = ["a:b", "a:c:production"]
|
85
93
|
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
86
94
|
selected_services.should == ["a:b", "a:c"]
|
@@ -88,7 +96,7 @@ describe Capistrano::Ext::SOA, "loaded into a configuration" do
|
|
88
96
|
task.should == nil
|
89
97
|
end
|
90
98
|
|
91
|
-
it "should parse
|
99
|
+
it "should parse default environment, service and task" do
|
92
100
|
args = ["staging","a:b", "deploy:start"]
|
93
101
|
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
94
102
|
selected_services.should == ["a:b"]
|
@@ -96,20 +104,28 @@ describe Capistrano::Ext::SOA, "loaded into a configuration" do
|
|
96
104
|
task.should == "deploy:start"
|
97
105
|
end
|
98
106
|
|
99
|
-
it "should parse
|
107
|
+
it "should parse default stage and one service" do
|
100
108
|
args = ["staging","a:b", "deploy:start", "a:d"]
|
101
109
|
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
102
110
|
selected_services.should == ["a:b"]
|
103
111
|
selected_stage.should == "staging"
|
104
|
-
task.should == "deploy:start"
|
112
|
+
task.should == "deploy:start a:d"
|
105
113
|
end
|
106
114
|
|
107
|
-
it "should parse
|
115
|
+
it "should parse one stage, multiple services and task" do
|
108
116
|
args = ["staging","a:b", "a:d", "deploy:start"]
|
109
117
|
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
110
118
|
selected_services.should == ["a:b"]
|
111
119
|
selected_stage.should == "staging"
|
112
|
-
task.should == "a:d"
|
120
|
+
task.should == "a:d deploy:start"
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should parse one stage, multiple services and task" do
|
124
|
+
args = ["staging","a:b", "a:c", "deploy:start"]
|
125
|
+
selected_stage, selected_services, task = @configuration.parse_args(args, @stages, @services)
|
126
|
+
selected_services.should == ["a:b", "a:c"]
|
127
|
+
selected_stage.should == "staging"
|
128
|
+
task.should == "deploy:start"
|
113
129
|
end
|
114
130
|
|
115
131
|
it "should parse single stage with one or more services" do
|
@@ -128,23 +144,48 @@ describe Capistrano::Ext::SOA, "loaded into a configuration" do
|
|
128
144
|
task.should == "deploy:start"
|
129
145
|
end
|
130
146
|
|
131
|
-
it "should
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
@configuration.
|
147
|
+
it "should build task with multiple services" do
|
148
|
+
stage = "staging"
|
149
|
+
services = ["a:b", "a:c"]
|
150
|
+
task = "fake:thing"
|
151
|
+
|
152
|
+
@configuration.build_task(stage, services, task)
|
153
|
+
@configuration.find_task("fake:al_thing").should_not be_nil
|
154
|
+
@configuration.find_task("fake:thing").should_not be_nil
|
137
155
|
end
|
138
156
|
|
139
|
-
it "should build
|
140
|
-
|
157
|
+
it "should build multiple task with multiple services" do
|
158
|
+
stage = "staging"
|
159
|
+
services = ["a:b", "a:c"]
|
160
|
+
task = "fake:thing fake:foo"
|
141
161
|
|
142
|
-
@configuration.build_task(
|
143
|
-
|
144
|
-
@configuration.find_task("fake:
|
145
|
-
@configuration.find_task("fake:thing").should_not == nil
|
162
|
+
@configuration.build_task(stage, services, task)
|
163
|
+
@configuration.find_task("fake:al_thing").should_not be_nil
|
164
|
+
@configuration.find_task("fake:thing").should_not be_nil
|
146
165
|
|
147
|
-
@configuration.
|
148
|
-
@configuration.
|
166
|
+
@configuration.find_task("fake:al_foo").should_not be_nil
|
167
|
+
@configuration.find_task("fake:foo").should_not be_nil
|
149
168
|
end
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
# it "should run one stage and service on load" do
|
173
|
+
# args = ["staging"]
|
174
|
+
# ARGV = args
|
175
|
+
# @configuration.trigger(:load)
|
176
|
+
# @configuration.fetch(:stage).should == "staging"
|
177
|
+
# @configuration.fetch(:services).should == []
|
178
|
+
# end
|
179
|
+
|
180
|
+
# it "should build a task for services" do
|
181
|
+
# @configuration.stub(:services).and_return(["a:b", "a:c"])
|
182
|
+
|
183
|
+
# @configuration.build_task("staging", ["a:b", "a:c"],"fake:thing")
|
184
|
+
|
185
|
+
# @configuration.find_task("fake:_thing").should_not == nil
|
186
|
+
# @configuration.find_task("fake:thing").should_not == nil
|
187
|
+
|
188
|
+
# @configuration.find_and_execute_task("fake:thing")
|
189
|
+
# @configuration.fetch(:bar).should == "baz"
|
190
|
+
# end
|
150
191
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-soa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
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-09-
|
12
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Capistrano SOA let you management services group in SOA architecuture
|
15
15
|
with multi-stage support.
|
@@ -20,6 +20,7 @@ extensions: []
|
|
20
20
|
extra_rdoc_files:
|
21
21
|
- README.md
|
22
22
|
files:
|
23
|
+
- Guardfile
|
23
24
|
- README.md
|
24
25
|
- capistrano-soa.gemspec
|
25
26
|
- lib/capistrano/ext/soa.rb
|
@@ -27,7 +28,7 @@ files:
|
|
27
28
|
- spec/recipes/fake_recipe.rb
|
28
29
|
- spec/soa_spec.rb
|
29
30
|
- spec/spec_helper.rb
|
30
|
-
homepage: http://github.com/
|
31
|
+
homepage: http://github.com/cheokman/capistrano-soa
|
31
32
|
licenses: []
|
32
33
|
post_install_message:
|
33
34
|
rdoc_options: []
|