chap 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -8
- data/lib/chap.rb +1 -0
- data/lib/chap/benchmarking.rb +76 -0
- data/lib/chap/hook.rb +2 -0
- data/lib/chap/runner.rb +12 -3
- data/lib/chap/strategy/checkout.rb +4 -0
- data/lib/chap/strategy/copy.rb +3 -0
- data/lib/chap/version.rb +1 -1
- data/spec/lib/chap_spec.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -82,6 +82,15 @@ From capistrano, on local or deploy box:
|
|
82
82
|
$ cap deploy # cap recipe calls "chap deploy"
|
83
83
|
</pre>
|
84
84
|
|
85
|
+
Example capistrano deploy
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
namespace :deploy do
|
89
|
+
task :default do
|
90
|
+
run "chap deploy"
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
85
94
|
Chef Chap LWRP:
|
86
95
|
|
87
96
|
<pre>
|
@@ -123,8 +132,7 @@ Special methods:
|
|
123
132
|
* run - output the command to be ran and runs command.
|
124
133
|
* log - log messages to [shared_path]/chap/chap.log.
|
125
134
|
* symlink_configs - useful as a chap/deploy hook. Symlinks any config files in [shared_path]/config/* over to [release_path]/config.
|
126
|
-
* with - used to prepend all commands
|
127
|
-
|
135
|
+
* with - used to prepend all commands within a block with another command. A example is provided below.
|
128
136
|
|
129
137
|
with example:
|
130
138
|
|
@@ -145,7 +153,7 @@ run "cd #{release_path} && RAILS_ENV=#{node[:environment]} rake do:something2"
|
|
145
153
|
|
146
154
|
### Test deploy hooks
|
147
155
|
|
148
|
-
When a chap hook fails, you
|
156
|
+
When a chap hook fails, you might want to quicky test it on the server without having commit new code and running a full deploy. You can edit the chap/* hooks on the spot and test them via:
|
149
157
|
|
150
158
|
<pre>
|
151
159
|
$ cap hook deploy
|
@@ -156,9 +164,11 @@ This will test the hooks on the latest timestamp release at [deploy_to]/releases
|
|
156
164
|
|
157
165
|
### Syncing restart phase
|
158
166
|
|
159
|
-
Some apps require that all the code be available on all the servers before a restart should happen on any of the servers. For example, if you're serving assets on the same server as your app code, you
|
167
|
+
Some apps require that all the code be available on all the servers before a restart should happen on any of the servers. For example, if you're serving assets on the same server as your app code, you want to make sure that all the assets have been download on all servers before any of the servers start serving the new assets. To sync the retart phase you have to break out the capistano recipe so that it calls 2 chap command:
|
160
168
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
169
|
+
```ruby
|
170
|
+
task :chap do
|
171
|
+
run "chap deploy -q --stop-at-symlink"
|
172
|
+
run "chap deploy -q --cont-at-symlink"
|
173
|
+
end
|
174
|
+
```
|
data/lib/chap.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
module Chap
|
4
|
+
module Benchmarking
|
5
|
+
def self.included(base)
|
6
|
+
@@benchmarks = []
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def benchmark(*methods)
|
12
|
+
methods.each do |method|
|
13
|
+
benchmark_each method
|
14
|
+
end
|
15
|
+
end
|
16
|
+
def benchmark_each(method, scope=nil)
|
17
|
+
class_eval <<-EOL
|
18
|
+
def #{method}_with_benchmark(*args,&block)
|
19
|
+
scope=#{scope.inspect}
|
20
|
+
result = nil
|
21
|
+
realtime = Benchmark.realtime do
|
22
|
+
result = #{method}_without_benchmark(*args,&block)
|
23
|
+
end
|
24
|
+
method_name = if args.empty?
|
25
|
+
"#{method}"
|
26
|
+
else
|
27
|
+
name = "#{method}" + '("' + args.join(',') + '")'
|
28
|
+
name = shorten_name(name)
|
29
|
+
end
|
30
|
+
method_name = scope + ': ' + method_name if scope
|
31
|
+
@@benchmarks << [method_name, realtime]
|
32
|
+
result
|
33
|
+
end
|
34
|
+
EOL
|
35
|
+
alias_method "#{method}_without_benchmark", method
|
36
|
+
alias_method method, "#{method}_with_benchmark"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def shorten_name(string)
|
41
|
+
if string.length >= 80
|
42
|
+
preprend = string[0,20]
|
43
|
+
append = string[-55..-1]
|
44
|
+
preprend + ' ... ' + append
|
45
|
+
else
|
46
|
+
string
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def benchmarks
|
51
|
+
@@benchmarks
|
52
|
+
end
|
53
|
+
|
54
|
+
def report_benchmarks
|
55
|
+
return if benchmarks.empty?
|
56
|
+
report = []
|
57
|
+
report << "Benchmark Report:"
|
58
|
+
|
59
|
+
max = benchmarks.collect{|x| x[0]}.max_by{|a| a.length}.length
|
60
|
+
report_block = lambda do |data|
|
61
|
+
name,took = data
|
62
|
+
mins = '%d' % (took / 60.0)
|
63
|
+
secs = '%d' % (took % 60.0)
|
64
|
+
report << " %-#{max}s : %2s mins and %2s secs" % [name,mins,secs]
|
65
|
+
end
|
66
|
+
|
67
|
+
report << "Ordered by slowest:"
|
68
|
+
benchmarks.sort_by {|x| x[1]}.reverse.each(&report_block)
|
69
|
+
|
70
|
+
report.each do |line|
|
71
|
+
log(line) unless options[:quiet]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
data/lib/chap/hook.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Chap
|
2
2
|
class Hook
|
3
3
|
include SpecialMethods
|
4
|
+
include Benchmarking
|
4
5
|
|
5
6
|
attr_reader :options, :config
|
6
7
|
def initialize(path, config)
|
@@ -45,6 +46,7 @@ module Chap
|
|
45
46
|
cmd = "#{@with} #{cmd}"
|
46
47
|
config.run(cmd)
|
47
48
|
end
|
49
|
+
benchmark_each :run, "hook"
|
48
50
|
|
49
51
|
end
|
50
52
|
end
|
data/lib/chap/runner.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Chap
|
2
2
|
class Runner
|
3
3
|
include SpecialMethods
|
4
|
+
include Benchmarking
|
4
5
|
|
5
6
|
attr_reader :options, :config
|
6
7
|
def initialize(options={})
|
@@ -11,11 +12,12 @@ module Chap
|
|
11
12
|
def deploy
|
12
13
|
deploy_to_symlink
|
13
14
|
deploy_from_symlink
|
15
|
+
report_benchmarks
|
14
16
|
end
|
15
17
|
|
16
18
|
def deploy_to_symlink
|
17
19
|
setup
|
18
|
-
|
20
|
+
deploy_via_strategy
|
19
21
|
symlink_shared
|
20
22
|
rm_rvmrc
|
21
23
|
hook(:deploy)
|
@@ -58,6 +60,10 @@ module Chap
|
|
58
60
|
@strategy ||= klass.new(:config => @config)
|
59
61
|
end
|
60
62
|
|
63
|
+
def deploy_via_strategy
|
64
|
+
strategy.deploy
|
65
|
+
end
|
66
|
+
|
61
67
|
def camel_case(string)
|
62
68
|
return string if string !~ /_/ && string =~ /[A-Z]+.*/
|
63
69
|
string.split('_').map{|e| e.capitalize}.join
|
@@ -161,5 +167,8 @@ module Chap
|
|
161
167
|
log "chap/#{name} hook does not exist".colorize(:red)
|
162
168
|
end
|
163
169
|
end
|
164
|
-
|
165
|
-
|
170
|
+
|
171
|
+
benchmark :setup, :symlink_shared, :rm_rvmrc, :hook, :symlink_current, :cleanup, :deploy_via_strategy
|
172
|
+
|
173
|
+
end # eof Runner
|
174
|
+
end # eof Chap
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Chap
|
2
2
|
module Strategy
|
3
3
|
class Checkout < Base
|
4
|
+
include Benchmarking
|
5
|
+
|
4
6
|
def deploy
|
5
7
|
update
|
6
8
|
copy
|
@@ -43,6 +45,8 @@ BASH
|
|
43
45
|
log "Code copied to #{release_path}".colorize(:green)
|
44
46
|
end
|
45
47
|
|
48
|
+
benchmark :update, :copy
|
49
|
+
|
46
50
|
private
|
47
51
|
|
48
52
|
def mark
|
data/lib/chap/strategy/copy.rb
CHANGED
data/lib/chap/version.rb
CHANGED
data/spec/lib/chap_spec.rb
CHANGED
@@ -103,7 +103,7 @@ describe Chap do
|
|
103
103
|
|
104
104
|
it "should only respect keep option" do
|
105
105
|
system("cd #{root} && ./bin/chap deploy -q -c #{system_root}/etc/chef/chap.yml")
|
106
|
-
|
106
|
+
sleep 1
|
107
107
|
system("cd #{root} && ./bin/chap deploy -q -c #{system_root}/etc/chef/chap.yml")
|
108
108
|
releases = Dir.glob("#{system_root}/data/chapdemo/releases/*").size
|
109
109
|
releases.should == 2 # test the keep option
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.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-
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- bin/chap
|
192
192
|
- chap.gemspec
|
193
193
|
- lib/chap.rb
|
194
|
+
- lib/chap/benchmarking.rb
|
194
195
|
- lib/chap/cli.rb
|
195
196
|
- lib/chap/config.rb
|
196
197
|
- lib/chap/hook.rb
|