chap 0.0.3 → 0.0.4
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/README.md +17 -1
- data/lib/chap/cli.rb +14 -0
- data/lib/chap/config.rb +16 -6
- data/lib/chap/runner.rb +6 -0
- data/lib/chap/special_methods.rb +1 -1
- data/lib/chap/version.rb +1 -1
- data/spec/fixtures/chapdemo/chap/deploy +1 -0
- data/spec/fixtures/chapdemo/chap/restart +1 -1
- data/spec/lib/chap_spec.rb +28 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Chap
|
2
2
|
|
3
|
+
[![Build History][2]][1]
|
4
|
+
|
5
|
+
[1]: http://travis-ci.org/tongueroo/chap
|
6
|
+
[2]: https://secure.travis-ci.org/tongueroo/chap.png?branch=master
|
7
|
+
|
3
8
|
chef + capistrano = chap: deploy your app with either chef or capistrano. This was written to solve the issue between having 2 deployment systems that are very similar but not exactly the same. With chap you can deploy to a single server by running one command:
|
4
9
|
|
5
10
|
<pre>
|
@@ -118,4 +123,15 @@ Special variables:
|
|
118
123
|
Special methods:
|
119
124
|
|
120
125
|
* run - output the command to be ran and runs command.
|
121
|
-
* log - log messages to [shared_path]/chap/chap.log.
|
126
|
+
* log - log messages to [shared_path]/chap/chap.log.
|
127
|
+
|
128
|
+
### Test deploy hooks
|
129
|
+
|
130
|
+
When a chap hook fails, you want 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:
|
131
|
+
|
132
|
+
<pre>
|
133
|
+
$ cap hook deploy
|
134
|
+
$ cap hook restart
|
135
|
+
</pre>
|
136
|
+
|
137
|
+
This will test the hooks on the latest timestamp release at [deploy_to]/releases/[timestamp].
|
data/lib/chap/cli.rb
CHANGED
@@ -22,5 +22,19 @@ module Chap
|
|
22
22
|
def deploy
|
23
23
|
Chap::Task.deploy(options)
|
24
24
|
end
|
25
|
+
|
26
|
+
desc "hook", "Run chap hook"
|
27
|
+
long_desc <<-EOL
|
28
|
+
Example:
|
29
|
+
|
30
|
+
$ chap hook deploy
|
31
|
+
|
32
|
+
A way to test the chap hooks
|
33
|
+
EOL
|
34
|
+
method_option :quiet, :aliases => '-q', :type => :boolean, :desc => "Quiet commands"
|
35
|
+
method_option :config, :aliases => '-c', :default => '/etc/chef/chap.yml', :desc => "chap.yml config to use"
|
36
|
+
def hook(name)
|
37
|
+
Chap::Runner.new(options).test_hook(name)
|
38
|
+
end
|
25
39
|
end
|
26
40
|
end
|
data/lib/chap/config.rb
CHANGED
@@ -51,24 +51,26 @@ module Chap
|
|
51
51
|
@timestamp ||= Time.now.strftime("%Y%m%d%H%M%S")
|
52
52
|
end
|
53
53
|
|
54
|
+
# useful so we can test hooks
|
55
|
+
def override_timestamp(timestamp)
|
56
|
+
@timestamp = timestamp
|
57
|
+
end
|
58
|
+
|
54
59
|
def deploy_to
|
55
60
|
chap[:deploy_to]
|
56
61
|
end
|
57
62
|
|
58
63
|
# special attributes added to chap
|
59
64
|
def release_path
|
60
|
-
|
61
|
-
@release_path = "#{deploy_to}/releases/#{timestamp}"
|
65
|
+
"#{deploy_to}/releases/#{timestamp}"
|
62
66
|
end
|
63
67
|
|
64
68
|
def current_path
|
65
|
-
|
66
|
-
@current_path = "#{deploy_to}/current"
|
69
|
+
"#{deploy_to}/current"
|
67
70
|
end
|
68
71
|
|
69
72
|
def shared_path
|
70
|
-
|
71
|
-
@shared_path = "#{deploy_to}/shared"
|
73
|
+
"#{deploy_to}/shared"
|
72
74
|
end
|
73
75
|
|
74
76
|
def cached_path
|
@@ -77,6 +79,14 @@ module Chap
|
|
77
79
|
@cached_path = "#{shared_path}/cache/#{strategy}/#{path}"
|
78
80
|
end
|
79
81
|
|
82
|
+
def latest_release
|
83
|
+
return @latest_release if @latest_release
|
84
|
+
@latest_release = Dir.glob("#{deploy_to}/releases/*").
|
85
|
+
select {|p| File.directory?(p) }.
|
86
|
+
sort.
|
87
|
+
last
|
88
|
+
end
|
89
|
+
|
80
90
|
def strategy
|
81
91
|
chap[:strategy] || 'checkout'
|
82
92
|
end
|
data/lib/chap/runner.rb
CHANGED
@@ -116,6 +116,12 @@ module Chap
|
|
116
116
|
dirs.map! {|p| "#{shared_path}/#{p}"}
|
117
117
|
end
|
118
118
|
|
119
|
+
def test_hook(name)
|
120
|
+
timestamp = File.basename(latest_release)
|
121
|
+
config.override_timestamp(timestamp)
|
122
|
+
hook(name)
|
123
|
+
end
|
124
|
+
|
119
125
|
def hook(name)
|
120
126
|
log "Running hook: #{name}".colorize(:green)
|
121
127
|
path = "#{release_path}/chap/#{name}"
|
data/lib/chap/special_methods.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Chap
|
2
2
|
module SpecialMethods
|
3
|
-
SPECIAL_METHODS = %w/deploy_to release_path current_path shared_path cached_path node chap log run/
|
3
|
+
SPECIAL_METHODS = %w/deploy_to release_path current_path shared_path cached_path latest_release node chap log run/
|
4
4
|
|
5
5
|
def self.included(base)
|
6
6
|
base.send(:extend, ClassMethods)
|
data/lib/chap/version.rb
CHANGED
data/spec/lib/chap_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Chap do
|
|
6
6
|
@system_root = "#{@root}/spec/fixtures/system_root"
|
7
7
|
end
|
8
8
|
|
9
|
-
describe "deploy" do
|
9
|
+
describe "internal code deploy" do
|
10
10
|
before(:each) do
|
11
11
|
setup_files
|
12
12
|
|
@@ -27,6 +27,12 @@ describe Chap do
|
|
27
27
|
releases.should >= 1
|
28
28
|
releases.should <= 2 # test the keep option
|
29
29
|
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "cli deploy" do
|
33
|
+
before(:each) do
|
34
|
+
setup_files
|
35
|
+
end
|
30
36
|
|
31
37
|
it "should deploy code via command line" do
|
32
38
|
system("cd #{@root} && ./bin/chap deploy -q -c #{@system_root}/etc/chef/chap.yml")
|
@@ -40,5 +46,26 @@ describe Chap do
|
|
40
46
|
releases = Dir.glob("#{@system_root}/data/chapdemo/releases/*").size
|
41
47
|
releases.should >= 1
|
42
48
|
end
|
49
|
+
|
50
|
+
it "should deploy code and test hook" do
|
51
|
+
system("cd #{@root} && ./bin/chap deploy -q -c #{@system_root}/etc/chef/chap.yml")
|
52
|
+
releases = Dir.glob("#{@system_root}/data/chapdemo/releases/*").sort
|
53
|
+
timestamp = releases.last.split('/').last
|
54
|
+
release_path = "#{@system_root}/data/chapdemo/releases/#{timestamp}"
|
55
|
+
current_path = "#{@system_root}/data/chapdemo/current"
|
56
|
+
File.exist?(release_path).should be_true
|
57
|
+
File.exist?("#{release_path}/deploy.txt").should be_true
|
58
|
+
|
59
|
+
# test hook deploy
|
60
|
+
FileUtils.rm_f("#{release_path}/deploy.txt")
|
61
|
+
File.exist?("#{release_path}/deploy.txt").should be_false
|
62
|
+
system("cd #{@root} && ./bin/chap hook deploy -q -c #{@system_root}/etc/chef/chap.yml")
|
63
|
+
File.exist?("#{release_path}/deploy.txt").should be_true
|
64
|
+
|
65
|
+
# test hook restart
|
66
|
+
FileUtils.rm_f("#{current_path}/restart.txt")
|
67
|
+
system("cd #{@root} && ./bin/chap hook restart -q -c #{@system_root}/etc/chef/chap.yml")
|
68
|
+
File.exist?("#{current_path}/restart.txt").should be_true
|
69
|
+
end
|
43
70
|
end
|
44
71
|
end
|
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.0.4
|
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-
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|