ubalo 0.21 → 0.22
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ubalo +5 -20
- data/lib/ubalo/container_process.rb +2 -14
- data/lib/ubalo/pod.rb +30 -27
- data/lib/ubalo/tailer.rb +29 -11
- data/lib/ubalo/task.rb +18 -8
- data/lib/ubalo/util.rb +24 -8
- data/lib/ubalo/version.rb +1 -1
- metadata +14 -14
data/bin/ubalo
CHANGED
@@ -21,9 +21,8 @@ end
|
|
21
21
|
|
22
22
|
use_openstruct true
|
23
23
|
|
24
|
-
|
25
24
|
def logger
|
26
|
-
@logger ||= Ubalo::Util::Logger.new
|
25
|
+
@logger ||= Ubalo::Util::Logger.new $stdin.tty?
|
27
26
|
end
|
28
27
|
|
29
28
|
def connect_url
|
@@ -180,7 +179,6 @@ command :run do |c|
|
|
180
179
|
c.action do |global_options,options,args|
|
181
180
|
task = pod.run(options.v2 || pod_dir.v2?, args, options.arg)
|
182
181
|
task.tail_process
|
183
|
-
puts task.printable_result
|
184
182
|
end
|
185
183
|
end
|
186
184
|
|
@@ -205,7 +203,6 @@ command :submit do |c|
|
|
205
203
|
|
206
204
|
c.action do |global_options,options,args|
|
207
205
|
task = pod.run(pod_dir.v2?, args, options.arg)
|
208
|
-
logger.puts " done."
|
209
206
|
puts task.printable_result
|
210
207
|
end
|
211
208
|
end
|
@@ -249,8 +246,6 @@ command 'task:stop' do |c|
|
|
249
246
|
end
|
250
247
|
|
251
248
|
task.stop!
|
252
|
-
task.tail_process
|
253
|
-
puts task.printable_result
|
254
249
|
end
|
255
250
|
end
|
256
251
|
|
@@ -259,11 +254,7 @@ command :push do |c|
|
|
259
254
|
c.switch :detached
|
260
255
|
|
261
256
|
c.action do |global_options,options,args|
|
262
|
-
pod.push_from(pod_dir)
|
263
|
-
unless options.detached
|
264
|
-
pod.tail_process
|
265
|
-
end
|
266
|
-
puts pod.printable_result
|
257
|
+
pod.push_from(pod_dir, options.detached)
|
267
258
|
end
|
268
259
|
end
|
269
260
|
|
@@ -274,21 +265,15 @@ command 'push-run' do |c|
|
|
274
265
|
|
275
266
|
c.action do |global_options,options,args|
|
276
267
|
pod.push_from(pod_dir)
|
277
|
-
pod.tail_process
|
278
|
-
puts pod.printable_result
|
279
|
-
|
280
268
|
task = pod.run(options.v2 || pod_dir.v2?, args, options.arg)
|
281
269
|
task.tail_process
|
282
|
-
puts task.printable_result
|
283
270
|
end
|
284
271
|
end
|
285
272
|
|
286
|
-
desc '
|
287
|
-
command 'push:
|
273
|
+
desc 'Stop a pod compilation'
|
274
|
+
command 'push:stop' do |c|
|
288
275
|
c.action do |global_options,options,args|
|
289
|
-
pod.
|
290
|
-
pod.tail_process
|
291
|
-
puts pod.printable_result
|
276
|
+
pod.stop!
|
292
277
|
end
|
293
278
|
end
|
294
279
|
|
@@ -23,18 +23,10 @@ module Ubalo
|
|
23
23
|
@output = attributes.fetch('output')
|
24
24
|
end
|
25
25
|
|
26
|
-
def tail(
|
27
|
-
tailer = Ubalo::Tailer.new(logger)
|
26
|
+
def tail(tailer, message)
|
28
27
|
logger.poll do
|
28
|
+
tailer.update(message, @output)
|
29
29
|
yield
|
30
|
-
|
31
|
-
message = "(#{runtime}) #{running_message}..."
|
32
|
-
if completed?
|
33
|
-
message << "#{final_message}. Exit status: #{exit_result}"
|
34
|
-
end
|
35
|
-
|
36
|
-
tailer.update(@output, message)
|
37
|
-
completed?
|
38
30
|
end
|
39
31
|
end
|
40
32
|
|
@@ -50,10 +42,6 @@ module Ubalo
|
|
50
42
|
s
|
51
43
|
end
|
52
44
|
|
53
|
-
def completed?
|
54
|
-
@state == 'complete'
|
55
|
-
end
|
56
|
-
|
57
45
|
def runtime
|
58
46
|
if @started_at
|
59
47
|
seconds = ((@stopped_at || DateTime.now) - @started_at) * 86400
|
data/lib/ubalo/pod.rb
CHANGED
@@ -47,8 +47,6 @@ module Ubalo
|
|
47
47
|
argv = ["sh", "run.sh"]
|
48
48
|
end
|
49
49
|
|
50
|
-
logger.print "Running #{Shellwords.join(argv)} inside #{fullname}..."
|
51
|
-
|
52
50
|
params = {
|
53
51
|
:arg_content_type => UbaloJSON.content_type,
|
54
52
|
:arg => UbaloJSON.dump(arg),
|
@@ -56,8 +54,6 @@ module Ubalo
|
|
56
54
|
}
|
57
55
|
task = @account.task_from_json(request(:post, "/tasks", :params => params))
|
58
56
|
|
59
|
-
logger.puts " done."
|
60
|
-
|
61
57
|
task
|
62
58
|
rescue RestClient::Conflict
|
63
59
|
raise Ubalo::Error, "Cannot run pod while compiling"
|
@@ -73,20 +69,44 @@ module Ubalo
|
|
73
69
|
end
|
74
70
|
end
|
75
71
|
|
76
|
-
def push_from(pod_dir)
|
77
|
-
|
72
|
+
def push_from(pod_dir, detached=false)
|
73
|
+
tailer = Ubalo::TimedTailer.new(logger)
|
74
|
+
tailer.update("Pushing files to #{fullname}...")
|
78
75
|
|
79
76
|
pod_dir.assert_not_empty!
|
77
|
+
|
80
78
|
update!
|
81
79
|
new_archive.activate_from(pod_dir)
|
82
|
-
refresh!
|
83
80
|
|
84
|
-
|
81
|
+
|
82
|
+
logger.poll do
|
83
|
+
tailer.update("Pushed files. Waiting to build #{fullname}...")
|
84
|
+
refresh!
|
85
|
+
return if detached
|
86
|
+
compilation_process
|
87
|
+
end
|
88
|
+
|
89
|
+
compilation_process.tail(tailer, "Pushed files. Building #{fullname}...") do
|
90
|
+
refresh!
|
91
|
+
compiled?
|
92
|
+
end
|
93
|
+
|
94
|
+
tailer.update("Pushed #{fullname}. Exit code: #{compilation_process.exit_result}.\n")
|
85
95
|
end
|
86
96
|
|
87
|
-
def
|
97
|
+
def stop!
|
98
|
+
tailer = Ubalo::TimedTailer.new(logger)
|
99
|
+
|
100
|
+
tailer.update("Stopping #{fullname}...")
|
88
101
|
request(:put, "/stop")
|
89
|
-
|
102
|
+
|
103
|
+
logger.poll do
|
104
|
+
tailer.update("Stopping #{fullname}...")
|
105
|
+
refresh!
|
106
|
+
compiled?
|
107
|
+
end
|
108
|
+
|
109
|
+
tailer.update("Stopped #{fullname}. Compilation exit code: #{compilation_process.exit_result}.\n")
|
90
110
|
end
|
91
111
|
|
92
112
|
def clone_to(pod_dir)
|
@@ -99,23 +119,6 @@ module Ubalo
|
|
99
119
|
state == 'compiled'
|
100
120
|
end
|
101
121
|
|
102
|
-
def tail_process
|
103
|
-
logger.poll_on("Waiting for process to start") do
|
104
|
-
refresh!
|
105
|
-
compilation_process
|
106
|
-
end
|
107
|
-
|
108
|
-
logger.puts "Compilation process output:"
|
109
|
-
compilation_process.tail("Compiling #{fullname}", "compiled") do
|
110
|
-
refresh!
|
111
|
-
end
|
112
|
-
|
113
|
-
logger.poll_on("Waiting for container to stop") do
|
114
|
-
refresh!
|
115
|
-
compiled?
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
122
|
def delete!
|
120
123
|
request(:delete, nil, :parse => false)
|
121
124
|
@deleted = true
|
data/lib/ubalo/tailer.rb
CHANGED
@@ -3,30 +3,48 @@ module Ubalo
|
|
3
3
|
def initialize(logger)
|
4
4
|
@logger = logger
|
5
5
|
@output_position = 0
|
6
|
-
@lines = 0
|
7
6
|
end
|
8
7
|
|
9
|
-
def
|
10
|
-
@
|
11
|
-
|
8
|
+
def tty?
|
9
|
+
@logger.tty?
|
10
|
+
end
|
11
|
+
|
12
|
+
def update(message, output=nil)
|
13
|
+
# Erase current line.
|
14
|
+
if tty?
|
15
|
+
@logger.print "\r"
|
12
16
|
@logger.print " " * Integer(ENV.fetch("COLUMNS", 80))
|
13
17
|
@logger.print "\r"
|
14
18
|
end
|
15
19
|
|
16
|
-
@lines = 0
|
17
|
-
|
18
20
|
if output
|
19
21
|
@logger.print output[@output_position..-1]
|
20
22
|
@output_position = output.length
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
if tty?
|
26
|
+
@logger.print Color.blue(wrap(message))
|
27
|
+
else
|
28
|
+
@logger.puts wrap(message)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def wrap(message)
|
34
|
+
message
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class TimedTailer < Tailer
|
39
|
+
def initialize(logger)
|
40
|
+
@start_time = Time.now
|
41
|
+
super
|
25
42
|
end
|
26
43
|
|
27
|
-
|
28
|
-
|
29
|
-
|
44
|
+
private
|
45
|
+
def wrap(message)
|
46
|
+
seconds = Time.now - @start_time
|
47
|
+
"(%.1f s) #{message}" % seconds
|
30
48
|
end
|
31
49
|
end
|
32
50
|
end
|
data/lib/ubalo/task.rb
CHANGED
@@ -27,25 +27,35 @@ module Ubalo
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def tail_process
|
30
|
-
|
31
|
-
refresh!
|
32
|
-
container_process
|
33
|
-
end
|
30
|
+
tailer = Ubalo::TimedTailer.new(logger)
|
34
31
|
|
35
|
-
|
36
|
-
|
32
|
+
logger.poll do
|
33
|
+
tailer.update("Starting...")
|
37
34
|
refresh!
|
35
|
+
container_process
|
38
36
|
end
|
39
37
|
|
40
|
-
|
38
|
+
container_process.tail(tailer, "Running #{label}...") do
|
41
39
|
refresh!
|
42
40
|
complete?
|
43
41
|
end
|
42
|
+
|
43
|
+
tailer.update("Completed #{label}. Exit code: #{container_process.exit_result}.\n")
|
44
44
|
end
|
45
45
|
|
46
46
|
def stop!
|
47
|
+
tailer = Ubalo::TimedTailer.new(logger)
|
48
|
+
|
49
|
+
tailer.update("Stopping #{label}...")
|
47
50
|
request(:put, "/stop")
|
48
|
-
|
51
|
+
|
52
|
+
logger.poll do
|
53
|
+
tailer.update("Stopping #{label}...")
|
54
|
+
refresh!
|
55
|
+
complete?
|
56
|
+
end
|
57
|
+
|
58
|
+
tailer.update("Stopped #{label}. Exit code: #{container_process.exit_result}.\n")
|
49
59
|
end
|
50
60
|
|
51
61
|
def inspect
|
data/lib/ubalo/util.rb
CHANGED
@@ -19,8 +19,13 @@ module Ubalo
|
|
19
19
|
end
|
20
20
|
|
21
21
|
class Logger
|
22
|
-
def initialize
|
22
|
+
def initialize tty
|
23
23
|
@incomplete_line = false
|
24
|
+
@tty = tty
|
25
|
+
end
|
26
|
+
|
27
|
+
def tty?
|
28
|
+
@tty
|
24
29
|
end
|
25
30
|
|
26
31
|
def print(str)
|
@@ -28,7 +33,7 @@ module Ubalo
|
|
28
33
|
$stderr.print(str)
|
29
34
|
end
|
30
35
|
|
31
|
-
def puts(str)
|
36
|
+
def puts(str="")
|
32
37
|
@incomplete_line = false
|
33
38
|
$stderr.print(str + "\n")
|
34
39
|
end
|
@@ -72,11 +77,7 @@ module Ubalo
|
|
72
77
|
end
|
73
78
|
|
74
79
|
def put_targz(url, archive_name)
|
75
|
-
|
76
|
-
|
77
|
-
unless response.code == 200
|
78
|
-
raise Ubalo::Error, "could not upload pod files"
|
79
|
-
end
|
80
|
+
RestClient.put(url, File.open(archive_name, 'rb'), :content_type => 'application/x-tar', :content_encoding => 'x-gzip')
|
80
81
|
end
|
81
82
|
|
82
83
|
def get_targz(url, archive_name)
|
@@ -86,7 +87,7 @@ module Ubalo
|
|
86
87
|
f.write response
|
87
88
|
end
|
88
89
|
else
|
89
|
-
raise Ubalo::Error, "failed to download pod files"
|
90
|
+
raise Ubalo::Error, "failed to download pod files: error #{response.code.inspect}"
|
90
91
|
end
|
91
92
|
end
|
92
93
|
end
|
@@ -163,4 +164,19 @@ module Ubalo
|
|
163
164
|
end
|
164
165
|
end
|
165
166
|
end
|
167
|
+
|
168
|
+
module Color
|
169
|
+
COLORS = {clear: 0, red: 31, green: 32, yellow: 33, blue: 34, gray: 30, grey: 30}
|
170
|
+
def self.method_missing(color_name, *args)
|
171
|
+
if args.first.is_a? String
|
172
|
+
color(color_name) + args.first + color(:clear)
|
173
|
+
else
|
174
|
+
color(color_name) + args.first.inspect + color(:clear)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def self.color(color)
|
179
|
+
"\e[#{COLORS[color.to_sym]}m"
|
180
|
+
end
|
181
|
+
end
|
166
182
|
end
|
data/lib/ubalo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ubalo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.22'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gli
|
16
|
-
requirement: &
|
16
|
+
requirement: &70151076782260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70151076782260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: highline
|
27
|
-
requirement: &
|
27
|
+
requirement: &70151076781820 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70151076781820
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: json
|
38
|
-
requirement: &
|
38
|
+
requirement: &70151076781260 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70151076781260
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rest-client
|
49
|
-
requirement: &
|
49
|
+
requirement: &70151076780740 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.6.3
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70151076780740
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: archive-tar-minitar
|
60
|
-
requirement: &
|
60
|
+
requirement: &70151076780320 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70151076780320
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: launchy
|
71
|
-
requirement: &
|
71
|
+
requirement: &70151076779840 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70151076779840
|
80
80
|
description: CLI and API client for Ubalo
|
81
81
|
email: dev@ubalo.com
|
82
82
|
executables:
|