capistrano-fanfare 0.0.22 → 0.0.23
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/.travis.yml +2 -0
- data/README.md +8 -1
- data/lib/capistrano/fanfare.rb +7 -0
- data/lib/capistrano/fanfare/airbrake.rb +1 -9
- data/lib/capistrano/fanfare/campfire.rb +1 -7
- data/lib/capistrano/fanfare/foreman.rb +2 -8
- data/lib/capistrano/fanfare/log.rb +92 -0
- data/lib/capistrano/fanfare/version.rb +1 -1
- data/spec/log_spec.rb +119 -0
- metadata +7 -4
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# <a name="title"></a> Capistrano::Fanfare [](http://travis-ci.org/fnichol/capistrano-fanfare) [](https://gemnasium.com/fnichol/capistrano-fanfare)
|
1
|
+
# <a name="title"></a> Capistrano::Fanfare [](http://travis-ci.org/fnichol/capistrano-fanfare) [](https://gemnasium.com/fnichol/capistrano-fanfare) [](https://codeclimate.com/github/fnichol/capistrano-fanfare)
|
2
2
|
|
3
3
|
**Notice:** This README is under active development.
|
4
4
|
|
@@ -38,6 +38,7 @@ Create a `Capfile` that looks like:
|
|
38
38
|
fanfare_recipe 'colors'
|
39
39
|
fanfare_recipe 'ssh'
|
40
40
|
fanfare_recipe 'console'
|
41
|
+
fanfare_recipe 'log'
|
41
42
|
fanfare_recipe 'campfire'
|
42
43
|
fanfare_recipe 'airbrake'
|
43
44
|
|
@@ -107,6 +108,8 @@ There are several optional recipes that need additional gems in your Gemfile:
|
|
107
108
|
Connect to your infrastructure nodes without thinking.
|
108
109
|
* [console](#recipes-console):
|
109
110
|
Rails 2/3, Sinatra, and Rack consoles, running in one command.
|
111
|
+
* [log](#recipes-log):
|
112
|
+
Ability to tail logs and load logs into a local editor.
|
110
113
|
* [colors](#recipes-colors):
|
111
114
|
Deploys, but prettier.
|
112
115
|
* [campfire](#recipes-campfire):
|
@@ -172,6 +175,10 @@ a few additional helpers.
|
|
172
175
|
|
173
176
|
> Rails 2/3, Sinatra, and Rack consoles, running in one command.
|
174
177
|
|
178
|
+
#### <a name="recipes-log"></a> log
|
179
|
+
|
180
|
+
> Ability to tail logs and load logs into a local editor.
|
181
|
+
|
175
182
|
#### <a name="recipes-colors"></a> colors
|
176
183
|
|
177
184
|
> Deploys, but prettier.
|
data/lib/capistrano/fanfare.rb
CHANGED
@@ -11,6 +11,13 @@ module Capistrano
|
|
11
11
|
def fanfare_recipe(recipe)
|
12
12
|
require "capistrano/fanfare/#{recipe}"
|
13
13
|
end
|
14
|
+
|
15
|
+
def fanfare_require(gem_name, path = gem_name)
|
16
|
+
require path
|
17
|
+
rescue LoadError => error
|
18
|
+
raise "#{gem_name} gem could not be loaded: (#{error.message}). " +
|
19
|
+
"Please ensure it is in your Gemfile."
|
20
|
+
end
|
14
21
|
end
|
15
22
|
end
|
16
23
|
end
|
@@ -2,15 +2,7 @@ require 'capistrano'
|
|
2
2
|
|
3
3
|
module Capistrano::Fanfare::Airbrake
|
4
4
|
def self.load_into(configuration)
|
5
|
-
configuration.load
|
6
|
-
begin
|
7
|
-
require 'airbrake/capistrano'
|
8
|
-
|
9
|
-
rescue LoadError => error
|
10
|
-
raise "airbrake gem could not be loaded: (#{error.message}). " +
|
11
|
-
"Please ensure it is in your Gemfile."
|
12
|
-
end
|
13
|
-
end
|
5
|
+
configuration.load { fanfare_require 'airbrake', 'airbrake/capistrano' }
|
14
6
|
end
|
15
7
|
end
|
16
8
|
|
@@ -3,13 +3,7 @@ require 'capistrano'
|
|
3
3
|
module Capistrano::Fanfare::Campfire
|
4
4
|
def self.load_into(configuration)
|
5
5
|
configuration.load do
|
6
|
-
|
7
|
-
require 'campy'
|
8
|
-
|
9
|
-
rescue LoadError => error
|
10
|
-
raise "campy gem could not be loaded: (#{error.message}). " +
|
11
|
-
"Please ensure it is in your Gemfile."
|
12
|
-
end
|
6
|
+
fanfare_require 'campy'
|
13
7
|
|
14
8
|
set(:campfire_yaml_file) do
|
15
9
|
yaml_file = File.expand_path(ENV['CAMPFIRE_YAML_FILE'] || '~/.campfire.yml')
|
@@ -1,17 +1,11 @@
|
|
1
1
|
require 'capistrano'
|
2
2
|
require 'capistrano/fanfare/foreman/strategy'
|
3
3
|
|
4
|
-
begin
|
5
|
-
require 'foreman/procfile'
|
6
|
-
|
7
|
-
rescue LoadError => error
|
8
|
-
raise "Foreman gem could not be loaded: (#{error.message}). " +
|
9
|
-
"Please ensure it is in your Gemfile."
|
10
|
-
end
|
11
|
-
|
12
4
|
module Capistrano::Fanfare::Foreman
|
13
5
|
def self.load_into(configuration)
|
14
6
|
configuration.load do
|
7
|
+
fanfare_require 'foreman', 'foreman/procfile'
|
8
|
+
|
15
9
|
set(:local_procfile) { ENV['PROCFILE'] || "Procfile" }
|
16
10
|
set(:user_home) { capture("echo $HOME").chomp }
|
17
11
|
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Capistrano::Fanfare::Log
|
5
|
+
def self.load_into(configuration)
|
6
|
+
configuration.load do
|
7
|
+
set :tail_cmd, "tail"
|
8
|
+
|
9
|
+
def resolve_logfile
|
10
|
+
rack_env = fetch(:rails_env, nil) || fetch(:rack_env, nil) || "production"
|
11
|
+
|
12
|
+
File.join(current_path, "log", "#{rack_env}.log")
|
13
|
+
end
|
14
|
+
|
15
|
+
def resolve_editor
|
16
|
+
ENV['editor'] || ENV['EDITOR'] || ENV['VISUAL'] || "vi"
|
17
|
+
end
|
18
|
+
|
19
|
+
def log_exec(cmd)
|
20
|
+
exec cmd
|
21
|
+
end
|
22
|
+
|
23
|
+
# =========================================================================
|
24
|
+
# These are the tasks that are available to help with deploying web apps.
|
25
|
+
# You can have cap give you a summary of them with `cap -T'.
|
26
|
+
# =========================================================================
|
27
|
+
|
28
|
+
namespace :log do
|
29
|
+
desc <<-DESC
|
30
|
+
Tails the deployed application log.You can set the rails \
|
31
|
+
environment by setting the :rails_env variable. The defaults are:
|
32
|
+
|
33
|
+
set :rails_env, "production"
|
34
|
+
set :tail_cmd, "tail"
|
35
|
+
DESC
|
36
|
+
task :tail, :role => :app, :except => { :no_release => true } do
|
37
|
+
stream("#{tail_cmd} -f #{resolve_logfile}")
|
38
|
+
end
|
39
|
+
|
40
|
+
desc <<-DESC
|
41
|
+
View log files in local editor. You can set the rails environment \
|
42
|
+
and tail command by setting variables. The defaults are:
|
43
|
+
|
44
|
+
set :rails_env, "production"
|
45
|
+
set :tail, "tail"
|
46
|
+
|
47
|
+
To override the default number of lines (500), you can pass in \
|
48
|
+
the `n' environment variable like so:
|
49
|
+
|
50
|
+
$ cap log:view n=900
|
51
|
+
|
52
|
+
To override your EDITOR/VISUAL environment settings for your visual \
|
53
|
+
editor, you can pass in the `editor' environment variable like so:
|
54
|
+
|
55
|
+
$ cap log:view editor=nano
|
56
|
+
|
57
|
+
Otherwise this task will try to resolve your editor in the \
|
58
|
+
following order:
|
59
|
+
|
60
|
+
1) use the `editor' environment override variable value
|
61
|
+
2) use the `EDITOR' shell environment variable value
|
62
|
+
3) use the `VISUAL' shell environment variable value
|
63
|
+
4) use `vi' which should be in almost any PATH
|
64
|
+
DESC
|
65
|
+
task :view, :role => :app, :except => { :no_release => true } do
|
66
|
+
line_nums = ENV["n"] || 500
|
67
|
+
cmd = "#{tail_cmd} -n #{line_nums} #{resolve_logfile}"
|
68
|
+
logs = Hash.new { |h,k| h[k] = '' }
|
69
|
+
|
70
|
+
run(cmd) do |channel, stream, data|
|
71
|
+
logs[channel[:host]] << data
|
72
|
+
break if stream == :err
|
73
|
+
end
|
74
|
+
|
75
|
+
tmpfile = Tempfile.open('w')
|
76
|
+
logs.each do |host, log|
|
77
|
+
tmpfile.write("--- #{host} ---\n\n")
|
78
|
+
tmpfile.write(log + "\n")
|
79
|
+
end
|
80
|
+
tmpfile.flush
|
81
|
+
tmpfile.close
|
82
|
+
|
83
|
+
log_exec "#{resolve_editor} #{tmpfile.path}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if Capistrano::Configuration.instance
|
91
|
+
Capistrano::Fanfare::Log.load_into(Capistrano::Configuration.instance)
|
92
|
+
end
|
data/spec/log_spec.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/capistrano'
|
3
|
+
require 'capistrano/fanfare'
|
4
|
+
require 'capistrano/fanfare/log'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
describe Capistrano::Fanfare::Log do
|
8
|
+
before do
|
9
|
+
@config = Capistrano::Configuration.new
|
10
|
+
Capistrano::Fanfare::Log.load_into(@config)
|
11
|
+
@config.extend(MiniTest::Capistrano::ConfigurationExtension)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "for variables" do
|
15
|
+
it "sets :tail_cmd to 'tail'" do
|
16
|
+
@config.fetch(:tail_cmd).must_equal "tail"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "for namespace :log" do
|
21
|
+
before do
|
22
|
+
@config.set :tail_cmd, "/usr/bin/tail"
|
23
|
+
@config.set :current_path, "/my/path"
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "task :tail" do
|
27
|
+
it "tails a log file based on :rails_env variable" do
|
28
|
+
@config.set :rails_env, "uat"
|
29
|
+
@config.find_and_execute_task("log:tail")
|
30
|
+
|
31
|
+
@config.must_have_streamed "/usr/bin/tail -f /my/path/log/uat.log"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "tails a log file based on :rack_env variable" do
|
35
|
+
@config.set :rack_env, "staging"
|
36
|
+
@config.find_and_execute_task("log:tail")
|
37
|
+
|
38
|
+
@config.must_have_streamed "/usr/bin/tail -f /my/path/log/staging.log"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "tails the production log file if :rails_env and :rack_env does not exist" do
|
42
|
+
@config.find_and_execute_task("log:tail")
|
43
|
+
|
44
|
+
@config.must_have_streamed "/usr/bin/tail -f /my/path/log/production.log"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "task :view" do
|
49
|
+
before do
|
50
|
+
@config.stubs(:log_exec).returns(true)
|
51
|
+
@tempfile = Tempfile.open('w')
|
52
|
+
Tempfile.stubs(:open).with('w').returns(@tempfile)
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "resolving log file" do
|
56
|
+
it "runs a tail on a log file based on :rails_env variable" do
|
57
|
+
@config.set :rails_env, "uat"
|
58
|
+
@config.find_and_execute_task("log:view")
|
59
|
+
|
60
|
+
@config.must_have_run "/usr/bin/tail -n 500 /my/path/log/uat.log"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "runs a tail on a log file based on :rack_env variable" do
|
64
|
+
@config.set :rack_env, "staging"
|
65
|
+
@config.find_and_execute_task("log:view")
|
66
|
+
|
67
|
+
@config.must_have_run "/usr/bin/tail -n 500 /my/path/log/staging.log"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "runs a tail of the production log file if :rails_env and :rack_env does not exist" do
|
71
|
+
@config.find_and_execute_task("log:view")
|
72
|
+
|
73
|
+
@config.must_have_run "/usr/bin/tail -n 500 /my/path/log/production.log"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "runs a tail on a log file with a specified line count" do
|
78
|
+
ENV['_SPEC_n'] = ENV['n']
|
79
|
+
ENV['n'] = '987'
|
80
|
+
@config.find_and_execute_task("log:view")
|
81
|
+
|
82
|
+
@config.must_have_run "/usr/bin/tail -n 987 /my/path/log/production.log"
|
83
|
+
ENV['n'] = ENV.delete('_SPEC_n')
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "resolving an editor" do
|
87
|
+
ENV_EDITORS = %w{VISUAL EDITOR editor}
|
88
|
+
|
89
|
+
before do
|
90
|
+
ENV_EDITORS.each do |e|
|
91
|
+
ENV["_SPEC_#{e}"] = ENV[e]
|
92
|
+
ENV.delete(e)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
after do
|
97
|
+
ENV_EDITORS.each do |e|
|
98
|
+
ENV[e] = ENV.delete("_SPEC_#{e}")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "opens the logfile in vi by default" do
|
103
|
+
@config.expects(:log_exec).with("vi #{@tempfile.path}")
|
104
|
+
|
105
|
+
@config.find_and_execute_task("log:view")
|
106
|
+
end
|
107
|
+
|
108
|
+
ENV_EDITORS.each do |v|
|
109
|
+
it "opens the logfile in the editor in ENV['#{v}']" do
|
110
|
+
ENV[v] = "/this/editor/#{v}"
|
111
|
+
@config.expects(:log_exec).with("#{ENV[v]} #{@tempfile.path}")
|
112
|
+
|
113
|
+
@config.find_and_execute_task("log:view")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-fanfare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.23
|
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
|
+
date: 2012-08-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- lib/capistrano/fanfare/foreman/strategy/runit.rb
|
156
156
|
- lib/capistrano/fanfare/git_style.rb
|
157
157
|
- lib/capistrano/fanfare/info.rb
|
158
|
+
- lib/capistrano/fanfare/log.rb
|
158
159
|
- lib/capistrano/fanfare/multistage.rb
|
159
160
|
- lib/capistrano/fanfare/ssh.rb
|
160
161
|
- lib/capistrano/fanfare/version.rb
|
@@ -178,6 +179,7 @@ files:
|
|
178
179
|
- spec/git_style_strategy_spec.rb
|
179
180
|
- spec/info_spec.rb
|
180
181
|
- spec/loading_spec.rb
|
182
|
+
- spec/log_spec.rb
|
181
183
|
- spec/multistage_spec.rb
|
182
184
|
- spec/ssh_spec.rb
|
183
185
|
homepage: https://github.com/fnichol/capistrano-fanfare
|
@@ -194,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
196
|
version: '0'
|
195
197
|
segments:
|
196
198
|
- 0
|
197
|
-
hash:
|
199
|
+
hash: 1800512189970899155
|
198
200
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
201
|
none: false
|
200
202
|
requirements:
|
@@ -203,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
205
|
version: '0'
|
204
206
|
segments:
|
205
207
|
- 0
|
206
|
-
hash:
|
208
|
+
hash: 1800512189970899155
|
207
209
|
requirements: []
|
208
210
|
rubyforge_project:
|
209
211
|
rubygems_version: 1.8.24
|
@@ -231,5 +233,6 @@ test_files:
|
|
231
233
|
- spec/git_style_strategy_spec.rb
|
232
234
|
- spec/info_spec.rb
|
233
235
|
- spec/loading_spec.rb
|
236
|
+
- spec/log_spec.rb
|
234
237
|
- spec/multistage_spec.rb
|
235
238
|
- spec/ssh_spec.rb
|