engineyard-serverside 1.5.28.pre.timestamps4 → 1.5.28
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/engineyard-serverside.rb +0 -2
- data/lib/engineyard-serverside/cli.rb +27 -36
- data/lib/engineyard-serverside/configuration.rb +0 -4
- data/lib/engineyard-serverside/deploy.rb +34 -33
- data/lib/engineyard-serverside/deploy_hook.rb +2 -2
- data/lib/engineyard-serverside/deprecation.rb +17 -7
- data/lib/engineyard-serverside/logged_output.rb +90 -0
- data/lib/engineyard-serverside/rails_asset_support.rb +5 -5
- data/lib/engineyard-serverside/server.rb +12 -9
- data/lib/engineyard-serverside/strategies/git.rb +15 -12
- data/lib/engineyard-serverside/task.rb +4 -8
- data/lib/engineyard-serverside/version.rb +1 -1
- data/lib/vendor/open4/lib/open4.rb +80 -51
- data/spec/basic_deploy_spec.rb +9 -9
- data/spec/bundler_deploy_spec.rb +1 -1
- data/spec/custom_deploy_spec.rb +3 -3
- data/spec/deprecation_spec.rb +26 -4
- data/spec/git_strategy_spec.rb +2 -6
- data/spec/logged_output_spec.rb +55 -0
- data/spec/nodejs_deploy_spec.rb +2 -2
- data/spec/services_deploy_spec.rb +10 -9
- data/spec/spec_helper.rb +27 -35
- data/spec/sqlite3_deploy_spec.rb +1 -0
- data/spec/support/integration.rb +13 -1
- metadata +24 -29
- data/lib/engineyard-serverside/shell.rb +0 -150
- data/spec/fixtures/gitrepo/bar +0 -0
- data/spec/shell_spec.rb +0 -46
@@ -1,150 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
module EY
|
4
|
-
module Serverside
|
5
|
-
# FileIO
|
6
|
-
|
7
|
-
class Shell
|
8
|
-
# Compatibility with old LoggedOutput where the module was included into the class.
|
9
|
-
module Helpers
|
10
|
-
def verbose?
|
11
|
-
shell.verbose?
|
12
|
-
end
|
13
|
-
|
14
|
-
def warning(*a)
|
15
|
-
shell.warning(*a)
|
16
|
-
end
|
17
|
-
|
18
|
-
def info(*a)
|
19
|
-
shell.info(*a)
|
20
|
-
end
|
21
|
-
|
22
|
-
def debug(*a)
|
23
|
-
shell.debug(*a)
|
24
|
-
end
|
25
|
-
|
26
|
-
def logged_system(*a)
|
27
|
-
shell.logged_system(*a)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class Formatter
|
32
|
-
|
33
|
-
def initialize(stdout, stderr, start_time, verbose)
|
34
|
-
@stdout, @stderr = stdout, stderr
|
35
|
-
@start = start_time.to_i
|
36
|
-
@verbose = verbose
|
37
|
-
end
|
38
|
-
|
39
|
-
def call(severity, time, _, message)
|
40
|
-
if %w[WARN ERROR FATAL].include?(severity)
|
41
|
-
msg = prepend("#{timestamp(time)}!> ", "#{severity_name(severity)}#{message}")
|
42
|
-
else
|
43
|
-
msg = prepend(timestamp(time), message)
|
44
|
-
end
|
45
|
-
|
46
|
-
put_to_io(severity, msg)
|
47
|
-
msg
|
48
|
-
end
|
49
|
-
|
50
|
-
def prepend(pre, str)
|
51
|
-
str.gsub(/^/, pre).sub(/\n?\z/m,"\n")
|
52
|
-
end
|
53
|
-
|
54
|
-
def put_to_io(severity, msg)
|
55
|
-
if severity == "DEBUG" && !@verbose
|
56
|
-
# quiet
|
57
|
-
elsif severity == "INFO"
|
58
|
-
#@stdout << msg
|
59
|
-
#@stdout.flush
|
60
|
-
else
|
61
|
-
#@stderr << msg
|
62
|
-
#@stderr.flush
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def timestamp(datetime)
|
67
|
-
diff = datetime.to_i - @start
|
68
|
-
diff = 0 if diff < 0
|
69
|
-
"+%2dm %02ds " % diff.divmod(60)
|
70
|
-
end
|
71
|
-
|
72
|
-
def severity_name(severity)
|
73
|
-
if %w[INFO DEBUG ANY].include?(severity)
|
74
|
-
""
|
75
|
-
elsif severity =='WARN'
|
76
|
-
"WARNING: "
|
77
|
-
else
|
78
|
-
"#{severity}: "
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
class YieldIO
|
84
|
-
def initialize(&block)
|
85
|
-
@block = block
|
86
|
-
end
|
87
|
-
|
88
|
-
def <<(str)
|
89
|
-
@block.call str
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
attr_reader :logger
|
94
|
-
|
95
|
-
def initialize(options)
|
96
|
-
@start_time = options[:start_time]
|
97
|
-
@verbose = options[:verbose]
|
98
|
-
|
99
|
-
@log_pathname = Pathname.new(options[:log_path])
|
100
|
-
@log_pathname.unlink if @log_pathname.exist? # start fresh
|
101
|
-
|
102
|
-
@stdout = options[:stdout] || $stdout
|
103
|
-
@stderr = options[:stderr] || $stderr
|
104
|
-
|
105
|
-
@logger = Logger.new(@log_pathname.to_s)
|
106
|
-
@logger.level = Logger::DEBUG # Always log to the file at debug, formatter hides debug for non-verbose
|
107
|
-
@logger.formatter = Formatter.new(@stdout, @stderr, start_time, @verbose)
|
108
|
-
end
|
109
|
-
|
110
|
-
def start_time
|
111
|
-
@start_time ||= Time.now
|
112
|
-
end
|
113
|
-
|
114
|
-
# a nice info outputter that prepends spermy operators for some reason.
|
115
|
-
def status(msg)
|
116
|
-
info msg.gsub(/^/, '~> ')
|
117
|
-
end
|
118
|
-
|
119
|
-
# a debug outputter that displays a command being run
|
120
|
-
def running(cmd)
|
121
|
-
debug ":: running #{cmd}"
|
122
|
-
end
|
123
|
-
|
124
|
-
def fatal(msg) logger.fatal msg end
|
125
|
-
def error(msg) logger.error msg end
|
126
|
-
def warning(msg) logger.warn msg end
|
127
|
-
def info(msg) logger.info msg end
|
128
|
-
def debug(msg) logger.debug msg end
|
129
|
-
|
130
|
-
def logged_system(cmd)
|
131
|
-
running(cmd)
|
132
|
-
# :quiet means don't raise an error on nonzero exit status
|
133
|
-
status = Open4.spawn cmd, 0 => '', 1 => out, 2 => err, :quiet => true
|
134
|
-
status.exitstatus == 0
|
135
|
-
end
|
136
|
-
|
137
|
-
# Return an IO that outputs to stdout or not according to the verbosity settings
|
138
|
-
# debug is hidden in non-verbose mode
|
139
|
-
def out
|
140
|
-
YieldIO.new { |msg| logger.debug(msg) }
|
141
|
-
end
|
142
|
-
|
143
|
-
# Return an IO that outputs to stderr
|
144
|
-
# unknown always shows, but without a severity title
|
145
|
-
def err
|
146
|
-
YieldIO.new { |msg| logger.unknown(msg) }
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
data/spec/fixtures/gitrepo/bar
DELETED
File without changes
|
data/spec/shell_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'tempfile'
|
3
|
-
require 'timecop'
|
4
|
-
|
5
|
-
describe EY::Serverside::Shell do
|
6
|
-
it "has a timestamp before each line" do
|
7
|
-
time1 = Time.local(2008, 9, 1, 12, 0, 0)
|
8
|
-
time2 = Time.local(2008, 9, 1, 12, 3, 5)
|
9
|
-
time3 = Time.local(2008, 9, 1, 12, 10, 25)
|
10
|
-
|
11
|
-
@output = StringIO.new
|
12
|
-
@shell = EY::Serverside::Shell.new(:verbose => true, :stdout => @output, :stderr => @output, :log_path => Pathname.new(Dir.tmpdir).join("engineyard-serverside-#{Time.now.to_i}-${$$}.log"), :start_time => time1)
|
13
|
-
|
14
|
-
Timecop.freeze(time1) do
|
15
|
-
@shell.debug('test1')
|
16
|
-
@shell.warning('test2')
|
17
|
-
end
|
18
|
-
Timecop.freeze(time2) do
|
19
|
-
@shell.info('test3')
|
20
|
-
@shell.debug("test11\ntest12\ntest13")
|
21
|
-
@shell.warning("test21\ntest22\ntest23")
|
22
|
-
end
|
23
|
-
Timecop.freeze(time3) do
|
24
|
-
@shell.info("test31\ntest32\ntest33")
|
25
|
-
end
|
26
|
-
|
27
|
-
timestamp_1 = "+ 0m 00s "
|
28
|
-
timestamp_2 = "+ 3m 05s "
|
29
|
-
timestamp_3 = "+10m 25s "
|
30
|
-
@output.rewind
|
31
|
-
@output.read.should == <<-OUTPUT
|
32
|
-
#{timestamp_1}test1
|
33
|
-
#{timestamp_1}!> WARNING: test2
|
34
|
-
#{timestamp_2}test3
|
35
|
-
#{timestamp_2}test11
|
36
|
-
#{timestamp_2}test12
|
37
|
-
#{timestamp_2}test13
|
38
|
-
#{timestamp_2}!> WARNING: test21
|
39
|
-
#{timestamp_2}!> test22
|
40
|
-
#{timestamp_2}!> test23
|
41
|
-
#{timestamp_3}test31
|
42
|
-
#{timestamp_3}test32
|
43
|
-
#{timestamp_3}test33
|
44
|
-
OUTPUT
|
45
|
-
end
|
46
|
-
end
|