cnvrg 0.0.15 → 0.0.140
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cnvrg.gemspec +5 -9
- data/lib/cnvrg/Images.rb +15 -76
- data/lib/cnvrg/api.rb +4 -7
- data/lib/cnvrg/cli.rb +527 -2149
- data/lib/cnvrg/experiment.rb +10 -19
- data/lib/cnvrg/files.rb +208 -302
- data/lib/cnvrg/helpers.rb +1 -42
- data/lib/cnvrg/job.rb +1 -0
- data/lib/cnvrg/project.rb +15 -55
- data/lib/cnvrg/version.rb +1 -2
- data/lib/cnvrg.rb +1 -0
- metadata +17 -48
- data/lib/cnvrg/data.rb +0 -72
- data/lib/cnvrg/datafiles.rb +0 -509
- data/lib/cnvrg/dataset.rb +0 -296
- data/lib/cnvrg/ssh.rb +0 -95
data/lib/cnvrg/cli.rb
CHANGED
@@ -7,7 +7,7 @@ require 'uri'
|
|
7
7
|
require 'open-uri'
|
8
8
|
require 'json'
|
9
9
|
require 'yaml'
|
10
|
-
require 'digest' #
|
10
|
+
require 'digest' # sha1
|
11
11
|
require "highline/import"
|
12
12
|
require 'socket'
|
13
13
|
include Open4
|
@@ -18,10 +18,6 @@ require 'cnvrg/project'
|
|
18
18
|
require 'cnvrg/files'
|
19
19
|
require 'cnvrg/experiment'
|
20
20
|
require 'cnvrg/Images'
|
21
|
-
require 'cnvrg/dataset'
|
22
|
-
require 'cnvrg/datafiles'
|
23
|
-
require 'cnvrg/data'
|
24
|
-
require 'cnvrg/ssh'
|
25
21
|
require 'etc'
|
26
22
|
require 'logstash-logger'
|
27
23
|
require 'cnvrg/job'
|
@@ -33,116 +29,28 @@ require 'fileutils'
|
|
33
29
|
require 'zip'
|
34
30
|
require 'active_support/all'
|
35
31
|
require 'thor'
|
36
|
-
require '
|
37
|
-
require 'enumerator'
|
38
|
-
|
39
|
-
class Thor
|
40
|
-
module Base
|
41
|
-
def initialize(args = [], local_options = {}, config = {})
|
42
|
-
parse_options = Thor.class_options
|
43
|
-
|
44
|
-
# The start method splits inbound arguments at the first argument
|
45
|
-
# that looks like an option (starts with - or --). It then calls
|
46
|
-
# new, passing in the two halves of the arguments Array as the
|
47
|
-
# first two parameters.
|
48
|
-
|
49
|
-
command_options = config.delete(:command_options) # hook for start
|
50
|
-
parse_options = parse_options.merge(command_options) if command_options
|
51
|
-
if local_options.is_a?(Array)
|
52
|
-
array_options = local_options
|
53
|
-
hash_options = {}
|
54
|
-
else
|
55
|
-
# Handle the case where the class was explicitly instantiated
|
56
|
-
# with pre-parsed options.
|
57
|
-
array_options = []
|
58
|
-
hash_options = local_options
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
# Let Thor::Options parse the options first, so it can remove
|
63
|
-
# declared options from the array. This will leave us with
|
64
|
-
# a list of arguments that weren't declared.
|
65
|
-
stop_on_unknown = Thor.stop_on_unknown_option? config[:current_command]
|
66
|
-
opts = Thor::Options.new(parse_options, hash_options, stop_on_unknown)
|
67
|
-
real_options = []
|
68
|
-
|
69
|
-
real_args = [].replace(array_options)
|
70
|
-
if local_options.is_a? (Array) and !local_options.empty? and args.empty?
|
71
|
-
array_options.each_with_index do |p, i|
|
72
|
-
opt = p
|
73
|
-
if p.include? "="
|
74
|
-
opt = p.split("=")[0]
|
75
|
-
end
|
76
|
-
option = is_option(parse_options.values, opt)
|
77
|
-
if !option
|
78
|
-
break
|
79
|
-
else
|
80
|
-
real_options << p
|
81
|
-
real_args.delete(p)
|
82
|
-
if !p.include? "=" and option.type != :boolean
|
83
|
-
if i+1< array_options.size
|
84
|
-
real_options << array_options[i+1]
|
85
|
-
real_args.delete(array_options[i+1])
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
args = real_args
|
94
|
-
else
|
95
|
-
if !args.empty? and local_options.is_a? Array and !local_options.empty?
|
96
|
-
args = args + local_options
|
97
|
-
else
|
98
|
-
args = args.flatten()
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
self.options = opts.parse(real_options)
|
105
|
-
self.options = config[:class_options].merge(options) if config[:class_options]
|
106
|
-
|
107
|
-
# If unknown options are disallowed, make sure that none of the
|
108
|
-
# remaining arguments looks like an option.
|
109
|
-
opts.check_unknown! if Thor.check_unknown_options?(config)
|
110
|
-
|
111
|
-
# Add the remaining arguments from the options parser to the
|
112
|
-
# arguments passed in to initialize. Then remove any positional
|
113
|
-
# arguments declared using #argument (this is primarily used
|
114
|
-
# by Thor::Group). Tis will leave us with the remaining
|
115
|
-
# positional arguments.
|
116
|
-
to_parse = args
|
117
|
-
to_parse += opts.remaining unless self.class.strict_args_position?(config)
|
118
|
-
thor_args = Thor::Arguments.new(self.class.arguments)
|
119
|
-
thor_args.parse(to_parse).each { |k, v| __send__("#{k}=", v) }
|
120
|
-
@args = thor_args.remaining
|
121
|
-
end
|
122
|
-
|
123
|
-
def is_option (options, p)
|
124
|
-
options.each do |o|
|
125
|
-
if !o.aliases.nil?
|
126
|
-
if (o.aliases.is_a? Array and o.aliases.include? p) or (o.aliases.is_a? Array and o.aliases.size ==1 and o.aliases[0].split(",").include? p) or o.switch_name.eql? p
|
127
|
-
return o
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
return false
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
32
|
+
require 'pry'
|
138
33
|
|
34
|
+
# DEV VERSION
|
35
|
+
#
|
139
36
|
module Cnvrg
|
140
|
-
|
141
37
|
class CLI < Thor
|
142
38
|
|
143
39
|
INSTALLATION_URLS = {docker: "https://docs.docker.com/engine/installation/", jupyter: "http://jupyter.readthedocs.io/en/latest/install.html"}
|
144
40
|
IP="localhost"
|
145
41
|
PORT=7654
|
42
|
+
desc '', ''
|
43
|
+
|
44
|
+
def printable_commands(all = true, subcommand = false)
|
45
|
+
(all ? all_commands : commands).map do |_, command|
|
46
|
+
next if command.hidden? or (command.description.empty? and command.usage.empty?)
|
47
|
+
item = []
|
48
|
+
item << banner(command, false, subcommand)
|
49
|
+
item << (command.description ? "# #{command.description.gsub(/\s+/m, ' ')}" : "")
|
50
|
+
item
|
51
|
+
end.compact
|
52
|
+
end
|
53
|
+
|
146
54
|
class << self
|
147
55
|
# Hackery.Take the run method away from Thor so that we can redefine it.
|
148
56
|
def is_thor_reserved_word?(word, type)
|
@@ -150,10 +58,9 @@ module Cnvrg
|
|
150
58
|
super
|
151
59
|
end
|
152
60
|
end
|
153
|
-
desc "data", "upload and manage datasets", :hide => true
|
154
|
-
subcommand "data", Data
|
155
61
|
|
156
|
-
desc "", ""
|
62
|
+
desc "", ""
|
63
|
+
method_option :schedule, :type => :string, :aliases => ["--s", "-s"], :default => "leahs"
|
157
64
|
|
158
65
|
def test
|
159
66
|
# image_settings = {
|
@@ -171,10 +78,11 @@ module Cnvrg
|
|
171
78
|
# },
|
172
79
|
# },
|
173
80
|
# }
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
81
|
+
container = Docker::Container.get('b4d64bf83f41')
|
82
|
+
s = "/leah/1/2/3/4/5"
|
83
|
+
command = ["/bin/bash","-lc","sed -i 's#c.NotebookApp.base_url = .*#c.NotebookApp.base_url = \"#{s}\"#' /home/ds/.jupyter/jupyter_notebook_config.py"]
|
84
|
+
puts container.exec(command, tty: true)
|
85
|
+
|
178
86
|
end
|
179
87
|
|
180
88
|
|
@@ -187,7 +95,7 @@ module Cnvrg
|
|
187
95
|
|
188
96
|
map %w(-v --version) => :version
|
189
97
|
|
190
|
-
desc 'api', 'set api url
|
98
|
+
desc 'set api url', 'set api url'
|
191
99
|
|
192
100
|
def set_api_url(url)
|
193
101
|
home_dir = File.expand_path('~')
|
@@ -203,19 +111,15 @@ module Cnvrg
|
|
203
111
|
end
|
204
112
|
config = YAML.load_file(home_dir+"/.cnvrg/config.yml")
|
205
113
|
owner = config.to_h[:owner]
|
206
|
-
compression_path = "#{File.expand_path('~')}/.cnvrg/tmp"
|
207
114
|
|
208
115
|
say "Setting default api to be: #{url}", Thor::Shell::Color::BLUE
|
209
116
|
if config.empty?
|
210
|
-
config = {owner: "", username: "", version_last_check: get_start_day(), api: url
|
117
|
+
config = {owner: "", username: "", version_last_check: get_start_day(), api: url}
|
211
118
|
else
|
212
|
-
|
213
|
-
compression_path = config.to_h[:compression_path]
|
214
|
-
end
|
215
|
-
config = {owner: config.to_h[:owner], username: config.to_h[:username], version_last_check: config.to_h[:version_last_check], api: url, compression_path: compression_path}
|
119
|
+
config = {owner: config.to_h[:owner], username: config.to_h[:username], version_last_check: config.to_h[:version_last_check], api: url}
|
216
120
|
end
|
217
121
|
res = Cnvrg::API.request("/users/#{owner}/custom_api", 'POST', {custom_api: url})
|
218
|
-
if Cnvrg::CLI.is_response_success(res
|
122
|
+
if Cnvrg::CLI.is_response_success(res)
|
219
123
|
|
220
124
|
checks = Helpers.checkmark
|
221
125
|
|
@@ -233,7 +137,7 @@ module Cnvrg
|
|
233
137
|
end
|
234
138
|
end
|
235
139
|
|
236
|
-
desc '', ''
|
140
|
+
desc '', ''
|
237
141
|
|
238
142
|
def set_remote_api_url(owner, current_user, url)
|
239
143
|
home_dir = File.expand_path('~')
|
@@ -248,9 +152,7 @@ module Cnvrg
|
|
248
152
|
FileUtils.touch [home_dir+"/.cnvrg/config.yml"]
|
249
153
|
end
|
250
154
|
config = YAML.load_file(home_dir+"/.cnvrg/config.yml")
|
251
|
-
|
252
|
-
compression_path = "#{home_dir}/.cnvrg/tmp"
|
253
|
-
config = {owner: owner, username: current_user, version_last_check: get_start_day(), api: url,compression_path:compression_path}
|
155
|
+
config = {owner: owner, username: current_user, version_last_check: get_start_day(), api: url}
|
254
156
|
File.open(home_dir+"/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
|
255
157
|
say "Done"
|
256
158
|
rescue
|
@@ -260,108 +162,57 @@ module Cnvrg
|
|
260
162
|
|
261
163
|
map %w(-api --api) => :set_api_url
|
262
164
|
|
263
|
-
desc '
|
165
|
+
desc 'set default owner', 'set default owner'
|
264
166
|
|
265
167
|
def set_default_owner
|
266
|
-
begin
|
267
|
-
path = File.expand_path('~')+"/.cnvrg/config.yml"
|
268
|
-
if !File.exist?(path)
|
269
|
-
say "Couldn't find ~/.cnvrg/config.yml file, please logout and login again", Thor::Shell::Color::RED
|
270
|
-
|
271
|
-
exit(0)
|
272
|
-
end
|
273
|
-
config = YAML.load_file(path)
|
274
168
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
owner = username
|
279
|
-
result = res["result"]
|
280
|
-
owners = result["owners"]
|
281
|
-
urls = result["urls"]
|
282
|
-
choose_owner = result["username"]
|
283
|
-
if owners.empty?
|
284
|
-
else
|
285
|
-
owners << choose_owner
|
286
|
-
chosen = false
|
287
|
-
while !chosen
|
288
|
-
owners_id = owners.each_with_index.map { |x, i| "#{i+1}. #{x}" }
|
289
|
-
choose_owner = ask("Choose default owner:\n"+owners_id.join("\n")+"\n")
|
290
|
-
|
291
|
-
if choose_owner =~ /[[:digit:]]/
|
292
|
-
ow_index = choose_owner.to_i-1
|
293
|
-
if ow_index<0 or ow_index >= owners.size
|
294
|
-
say "No such owner, please choose again", Thor::Shell::Color::BLUE
|
295
|
-
chosen = false
|
296
|
-
next
|
297
|
-
end
|
298
|
-
choose_owner = owners[choose_owner.to_i-1]
|
299
|
-
chosen = true
|
169
|
+
path = File.expand_path('~')+"/.cnvrg/config.yml"
|
170
|
+
if !File.exist?(path)
|
171
|
+
say "Couldn't find ~/.cnvrg/config.yml file, please logout and login again", Thor::Shell::Color::RED
|
300
172
|
|
301
|
-
|
173
|
+
exit(0)
|
174
|
+
end
|
175
|
+
config = YAML.load_file(path)
|
302
176
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
177
|
+
username = config.to_h[:username]
|
178
|
+
res = Cnvrg::API.request("/users/#{username}/get_possible_owners", 'GET')
|
179
|
+
if Cnvrg::CLI.is_response_success(res)
|
180
|
+
owner = username
|
181
|
+
result = res["result"]
|
182
|
+
owners = result["owners"]
|
183
|
+
urls = result["urls"]
|
184
|
+
choose_owner = result["username"]
|
311
185
|
|
186
|
+
if owners.empty?
|
187
|
+
else
|
188
|
+
owners << choose_owner
|
189
|
+
chosen = false
|
190
|
+
while !chosen
|
191
|
+
choose_owner = ask("Choose default owner:\n"+owners.join("\n")+"\n")
|
192
|
+
|
193
|
+
owners_lower = owners.map { |o| o.downcase }
|
194
|
+
ow_index = owners_lower.index(choose_owner.downcase)
|
195
|
+
if ow_index.nil?
|
196
|
+
say "Could not find owner named #{choose_owner}", Thor::Shell::Color::RED
|
197
|
+
else
|
198
|
+
chosen = true
|
312
199
|
end
|
313
|
-
|
314
|
-
|
315
|
-
end
|
316
|
-
if set_owner(choose_owner, result["username"], urls[ow_index])
|
317
|
-
say "Setting default owner: #{choose_owner}", Thor::Shell::Color::GREEN
|
318
|
-
else
|
319
|
-
say "Setting default owenr has failed, try to run cnvrg --config-default-owner", Thor::Shell::Color::RED
|
320
200
|
end
|
321
|
-
end
|
322
|
-
rescue SignalException
|
323
|
-
say "\nAborting"
|
324
|
-
exit(1)
|
325
|
-
end
|
326
|
-
end
|
327
201
|
|
328
|
-
desc 'set_compression_path', 'set compression path'
|
329
|
-
method_option :reset, :type => :boolean, :aliases => ["-r","--reset"], :default => false
|
330
202
|
|
331
|
-
def set_compression_path(*compression_path)
|
332
|
-
begin
|
333
|
-
if (compression_path.nil? or compression_path.empty?) and options["reset"]
|
334
|
-
compression_path = ["#{File.expand_path('~')}/.cnvrg/tmp"]
|
335
203
|
end
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
end
|
341
|
-
|
342
|
-
home_dir = File.expand_path('~')
|
343
|
-
path = "#{home_dir}/.cnvrg/config.yml"
|
344
|
-
if !File.exist?(path)
|
345
|
-
say "Couldn't find ~/.cnvrg/config.yml file, please logout and login again", Thor::Shell::Color::RED
|
346
|
-
|
347
|
-
exit(0)
|
204
|
+
if set_owner(owner, username,urls[ow_index])
|
205
|
+
say "Setting default owner: #{owner}", Thor::Shell::Color::GREEN
|
206
|
+
else
|
207
|
+
say "Setting default owenr has failed, try to run cnvrg --config-default-owner", Thor::Shell::Color::RED
|
348
208
|
end
|
349
|
-
config = YAML.load_file(path)
|
350
|
-
config_new = {owner: config.to_h[:owner], username: config.to_h[:username],
|
351
|
-
version_last_check: config.to_h[:version_last_check], api: config.to_h[:api], compression_path: compression_path}
|
352
|
-
File.open(home_dir+"/.cnvrg/config.yml", "w+") { |f| f.write config_new.to_yaml }
|
353
|
-
checks = Helpers.checkmark
|
354
|
-
say "#{checks} Done", Thor::Shell::Color::GREEN
|
355
|
-
|
356
|
-
rescue SignalException
|
357
|
-
say "\nAborting"
|
358
|
-
exit(1)
|
359
209
|
end
|
360
210
|
end
|
361
211
|
|
212
|
+
map %w(--set-default-owner) => :set_default_owner
|
362
213
|
|
363
214
|
|
364
|
-
desc 'login', 'Authenticate with cnvrg.io
|
215
|
+
desc 'login', 'Authenticate with cnvrg.io and store credentials'
|
365
216
|
|
366
217
|
def login
|
367
218
|
begin
|
@@ -389,46 +240,25 @@ module Cnvrg
|
|
389
240
|
owners = result["owners"]
|
390
241
|
urls = result["urls"]
|
391
242
|
choose_owner = result["username"]
|
392
|
-
|
243
|
+
|
393
244
|
if owners.empty?
|
394
|
-
choose_owner = result["username"]
|
395
245
|
else
|
396
|
-
|
397
|
-
|
246
|
+
owners << choose_owner
|
247
|
+
chosen = false
|
248
|
+
while !chosen
|
249
|
+
choose_owner = ask("Choose default owner:\n"+owners.join("\n")+"\n")
|
398
250
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
# if choose_owner =~ /[[:digit:]]/
|
408
|
-
# ow_index = choose_owner.to_i-1
|
409
|
-
# if ow_index<0 or ow_index >= owners.size
|
410
|
-
# say "No such owner, please choose again", Thor::Shell::Color::BLUE
|
411
|
-
# chosen = false
|
412
|
-
# next
|
413
|
-
# end
|
414
|
-
# choose_owner = owners[choose_owner.to_i-1]
|
415
|
-
# chosen = true
|
416
|
-
#
|
417
|
-
# else
|
418
|
-
#
|
419
|
-
# owners_lower = owners.map { |o| o.downcase }
|
420
|
-
# ow_index = owners_lower.index(choose_owner.downcase)
|
421
|
-
# if ow_index.nil?
|
422
|
-
# say "Could not find owner named #{choose_owner}", Thor::Shell::Color::RED
|
423
|
-
# else
|
424
|
-
# chosen = true
|
425
|
-
# end
|
426
|
-
# end
|
427
|
-
#
|
428
|
-
# end
|
251
|
+
owners_lower = owners.map { |o| o.downcase }
|
252
|
+
ow_index = owners_lower.index(choose_owner.downcase)
|
253
|
+
if ow_index.nil?
|
254
|
+
say "Could not find owner named #{choose_owner}", Thor::Shell::Color::RED
|
255
|
+
else
|
256
|
+
chosen = true
|
257
|
+
end
|
258
|
+
end
|
429
259
|
|
430
260
|
|
431
|
-
|
261
|
+
end
|
432
262
|
|
433
263
|
if set_owner(choose_owner, result["username"], urls[ow_index])
|
434
264
|
say "Setting default owner: #{choose_owner}", Thor::Shell::Color::GREEN
|
@@ -444,11 +274,6 @@ module Cnvrg
|
|
444
274
|
|
445
275
|
exit(1)
|
446
276
|
end
|
447
|
-
rescue
|
448
|
-
|
449
|
-
say "Error Occurred, aborting", Thor::Shell::Color::RED
|
450
|
-
logout()
|
451
|
-
exit(1)
|
452
277
|
rescue SignalException
|
453
278
|
|
454
279
|
say "\nAborting"
|
@@ -478,6 +303,7 @@ module Cnvrg
|
|
478
303
|
|
479
304
|
def me()
|
480
305
|
begin
|
306
|
+
|
481
307
|
verify_logged_in(false)
|
482
308
|
log_start(__method__, args, options)
|
483
309
|
auth = Cnvrg::Auth.new
|
@@ -488,7 +314,6 @@ module Cnvrg
|
|
488
314
|
end
|
489
315
|
|
490
316
|
log_end(0)
|
491
|
-
|
492
317
|
rescue SignalException
|
493
318
|
log_end(-1)
|
494
319
|
|
@@ -499,8 +324,8 @@ module Cnvrg
|
|
499
324
|
|
500
325
|
## Projects
|
501
326
|
desc 'new', 'Create a new cnvrg project'
|
502
|
-
method_option :clean, :type => :boolean, :aliases => ["-c"], :default => false
|
503
|
-
method_option :docker_image, :type => :string, :aliases => ["-d"], :default => ""
|
327
|
+
method_option :clean, :type => :boolean, :aliases => ["-c", "--c"], :default => false
|
328
|
+
method_option :docker_image, :type => :string, :aliases => ["-d", "--d"], :default => ""
|
504
329
|
|
505
330
|
def new(project_name)
|
506
331
|
begin
|
@@ -568,8 +393,8 @@ module Cnvrg
|
|
568
393
|
say "created project successfully", Thor::Shell::Color::GREEN
|
569
394
|
say "Linked directory to\t#{@project.url}", Thor::Shell::Color::GREEN
|
570
395
|
rescue => e
|
571
|
-
|
572
|
-
|
396
|
+
puts e
|
397
|
+
log_end(-1)
|
573
398
|
if Dir.exist? working_dir
|
574
399
|
|
575
400
|
@project.revert(working_dir)
|
@@ -587,7 +412,6 @@ module Cnvrg
|
|
587
412
|
exit(1)
|
588
413
|
end
|
589
414
|
end
|
590
|
-
|
591
415
|
desc 'set_image', 'set_image for a project'
|
592
416
|
|
593
417
|
def set_image(docker_image)
|
@@ -624,10 +448,9 @@ module Cnvrg
|
|
624
448
|
@image.update_image_activity(nil, nil)
|
625
449
|
|
626
450
|
end
|
627
|
-
|
628
|
-
|
629
|
-
method_option :
|
630
|
-
method_option :docker_image, :type => :string, :aliases => ["-d"], :default => ""
|
451
|
+
desc 'link', 'Link current directory to a cnvrg project'
|
452
|
+
method_option :sync, :type => :boolean, :aliases => ["-s", "--s"], :default => true
|
453
|
+
method_option :docker_image, :type => :string, :aliases => ["-d", "--d"], :default => ""
|
631
454
|
|
632
455
|
def link
|
633
456
|
begin
|
@@ -651,7 +474,7 @@ module Cnvrg
|
|
651
474
|
end
|
652
475
|
working_dir = Dir.getwd
|
653
476
|
owner = CLI.get_owner
|
654
|
-
if Project.link(owner,
|
477
|
+
if Project.link(owner,project_name, docker)
|
655
478
|
path = Dir.pwd
|
656
479
|
@project = Project.new(path)
|
657
480
|
@project.generate_idx()
|
@@ -708,834 +531,143 @@ module Cnvrg
|
|
708
531
|
exit(1)
|
709
532
|
end
|
710
533
|
end
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
log_start(__method__, args, options)
|
719
|
-
dataset_name =File.basename(Dir.getwd)
|
720
|
-
if File.directory?(Dir.getwd+"/.cnvrg")
|
721
|
-
config = YAML.load_file("#{Dir.getwd}/.cnvrg/config.yml")
|
722
|
-
say "Directory is already linked to #{config[:dataset_slug]}", Thor::Shell::Color::RED
|
723
|
-
|
724
|
-
exit(0)
|
725
|
-
end
|
726
|
-
say "Init dataset: #{dataset_name}", Thor::Shell::Color::BLUE
|
727
|
-
|
728
|
-
working_dir = Dir.getwd
|
729
|
-
owner = CLI.get_owner
|
730
|
-
if Dataset.init(owner, dataset_name, options["public"])
|
731
|
-
path = Dir.pwd
|
732
|
-
@dataset = Dataset.new(path)
|
733
|
-
|
734
|
-
url = @dataset.url
|
735
|
-
check = Helpers.checkmark
|
736
|
-
say "#{check} Link finished successfully", Thor::Shell::Color::GREEN
|
737
|
-
say "#{dataset_name}'s location is: #{url}\n", Thor::Shell::Color::GREEN
|
738
|
-
log_end(0)
|
739
|
-
|
740
|
-
else
|
741
|
-
log_end(1, "can't create dataset")
|
742
|
-
@dataset.revert(working_dir) unless @dataset.nil?
|
743
|
-
say "Error creating dataset, please contact support.", Thor::Shell::Color::RED
|
744
|
-
exit(0)
|
745
|
-
end
|
746
|
-
rescue SignalException
|
747
|
-
log_end(-1)
|
748
|
-
|
749
|
-
say "\nAborting"
|
750
|
-
exit(1)
|
751
|
-
end
|
534
|
+
desc 'unlink','Unlink a porject'
|
535
|
+
def unlink
|
536
|
+
verify_logged_in(false)
|
537
|
+
log_start(__method__, args, options)
|
538
|
+
working_dir = is_cnvrg_dir()
|
539
|
+
list_to_del = [working_dir+"/.cnvrgignore",working_dir+"/.cnvrg"]
|
540
|
+
FileUtils.rm_rf list_to_del
|
752
541
|
end
|
753
542
|
|
754
|
-
desc '
|
755
|
-
method_option :
|
543
|
+
desc 'clone', 'Clone a project'
|
544
|
+
method_option :remote, :type => :boolean, :aliases => ["-r", "--r"], :default => false
|
545
|
+
method_option :commit, :type => :string, :aliases => ["-c", "--c"], :default => nil
|
756
546
|
|
757
|
-
def
|
547
|
+
def clone(project_url)
|
758
548
|
begin
|
759
549
|
verify_logged_in(false)
|
760
550
|
log_start(__method__, args, options)
|
761
|
-
url_parts =
|
762
|
-
project_index = Cnvrg::Helpers.look_for_in_path(
|
551
|
+
url_parts = project_url.split("/")
|
552
|
+
project_index = Cnvrg::Helpers.look_for_in_path(project_url, "projects")
|
763
553
|
slug = url_parts[project_index+1]
|
764
554
|
owner = url_parts[project_index-1]
|
765
|
-
|
766
|
-
|
555
|
+
remote = options["remote"] || false
|
556
|
+
response = Cnvrg::API.request("users/#{owner}/projects/#{slug}/get_project", 'GET')
|
767
557
|
Cnvrg::CLI.is_response_success(response)
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
558
|
+
response = JSON.parse response["result"]
|
559
|
+
project_name = response["title"]
|
560
|
+
commit_to_clone = options["commit"] || nil
|
561
|
+
|
562
|
+
say "Cloning #{project_name}", Thor::Shell::Color::BLUE
|
563
|
+
clone_resp = false
|
564
|
+
if remote
|
565
|
+
clone_resp = Project.clone_dir_remote(slug, owner, project_name)
|
566
|
+
project_home = Dir.pwd
|
567
|
+
else
|
568
|
+
if (Dir.exists? project_name)
|
569
|
+
say "Error: Conflict with dir #{project_name}", Thor::Shell::Color::RED
|
570
|
+
if no? "Sync to repository anyway? (current data might lost)", Thor::Shell::Color::YELLOW
|
571
|
+
say "Remove dir in order to clone #{project_name}", Thor::Shell::Color::RED
|
572
|
+
log_end(1, "conflict with dir #{project_name}")
|
573
|
+
|
574
|
+
exit(1)
|
575
|
+
end
|
774
576
|
|
775
|
-
exit(1)
|
776
577
|
end
|
578
|
+
clone_resp = Project.clone_dir(slug, owner, project_name)
|
579
|
+
project_home = Dir.pwd+"/"+project_name
|
580
|
+
|
777
581
|
|
778
582
|
end
|
779
|
-
if Dataset.clone(owner, dataset_name, slug)
|
780
|
-
say "Cloning #{dataset_name}", Thor::Shell::Color::BLUE
|
781
583
|
|
782
|
-
|
783
|
-
|
784
|
-
@
|
785
|
-
@
|
786
|
-
|
584
|
+
if clone_resp
|
585
|
+
@project = Project.new(project_home)
|
586
|
+
@files = Cnvrg::Files.new(@project.owner, slug)
|
587
|
+
response = @project.clone(remote, commit_to_clone)
|
588
|
+
Cnvrg::CLI.is_response_success response
|
589
|
+
working_dir = project_home
|
590
|
+
docker_image = response["result"]["image"]
|
591
|
+
idx = {commit: response["result"]["commit"], tree: response["result"]["tree"]}
|
592
|
+
File.open(working_dir + "/.cnvrg/idx.yml", "w+") { |f| f.write idx.to_yaml }
|
593
|
+
if !docker_image.nil? and !docker_image.empty? and !remote
|
594
|
+
local_images = Docker::Image.all
|
595
|
+
docker_image_local = local_images.map { |x| x.info["RepoTags"] }.flatten.select { |y| y.eql? "#{docker_image}:latest" }.flatten
|
596
|
+
if docker_image_local.size == 0
|
597
|
+
if yes? "Image wasn't found locally, pull image from cnvrg repository?", Thor::Shell::Color::YELLOW
|
598
|
+
image = pull(docker_image)
|
599
|
+
if image
|
600
|
+
say "downloaded image: #{docker_image}"
|
601
|
+
@image = Images.new(working_dir, docker_image)
|
602
|
+
else
|
603
|
+
say "Could not create a new project with docker, image was not found", Thor::Shell::Color::RED
|
604
|
+
@project.revert(working_dir)
|
605
|
+
exit(1)
|
606
|
+
end
|
607
|
+
end
|
787
608
|
|
609
|
+
elsif docker_image_local.size == 1
|
610
|
+
say "found image: #{docker_image_local[0]}, setting it up..", Thor::Shell::Color::BLUE
|
611
|
+
@image = Images.new(working_dir, docker_image_local[0])
|
612
|
+
elsif docker_image_local.size >1
|
613
|
+
say "found #{docker_image_local.size} images, choose the image name you want to use", Thor::Shell::Color::BLUE
|
614
|
+
image_name = ask "#{docker_image_local.join("\n")}\n", Thor::Shell::Color::BLUE
|
615
|
+
@image = Images.new(working_dir, image_name)
|
616
|
+
end
|
788
617
|
|
789
|
-
|
618
|
+
end
|
790
619
|
|
620
|
+
successful_changes = []
|
621
|
+
say "Downloading files", Thor::Shell::Color::BLUE
|
622
|
+
if !response["result"]["tree"].nil?
|
623
|
+
response["result"]["tree"].each do |f|
|
624
|
+
relative_path = f[0].gsub(/^#{@project.local_path}/, "")
|
625
|
+
if f[0].end_with? "/"
|
626
|
+
# dir
|
627
|
+
if @files.download_dir(f[0], relative_path, project_home)
|
628
|
+
successful_changes << relative_path
|
629
|
+
end
|
630
|
+
else
|
631
|
+
# blob
|
632
|
+
if @files.download_file_s3(f[0], relative_path, project_home)
|
633
|
+
successful_changes << relative_path
|
634
|
+
end
|
635
|
+
end
|
636
|
+
end
|
637
|
+
end
|
791
638
|
|
792
|
-
|
793
|
-
say "#{check} Clone finished successfully", Thor::Shell::Color::GREEN
|
639
|
+
say "Done.\nDownloaded total of #{successful_changes.size} files", Thor::Shell::Color::GREEN
|
794
640
|
log_end(0)
|
795
|
-
|
796
641
|
else
|
797
|
-
log_end(1, "can't create
|
798
|
-
|
799
|
-
say "Error
|
800
|
-
exit(
|
642
|
+
log_end(1, "can't create directory")
|
643
|
+
|
644
|
+
say "Error: Couldn't create directory: #{project_name}", Thor::Shell::Color::RED
|
645
|
+
exit(1)
|
801
646
|
end
|
802
647
|
rescue SignalException
|
803
648
|
log_end(-1)
|
804
|
-
|
805
649
|
say "\nAborting"
|
806
650
|
exit(1)
|
807
651
|
end
|
652
|
+
|
808
653
|
end
|
809
654
|
|
810
|
-
desc 'init_data_container', 'Init dataset directory', :hide => true
|
811
|
-
method_option :login_content, :type => :string, :aliases => ["-l"], :default => ""
|
812
655
|
|
813
|
-
|
656
|
+
desc 'status', 'Show the working tree status'
|
657
|
+
method_option :new_branch, :type => :boolean, :aliases => ["-nb", "--nb"], :desc => "create new branch of commits"
|
658
|
+
|
659
|
+
|
660
|
+
def status
|
814
661
|
begin
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
container.exec(command, tty: true)
|
820
|
-
command = ["/bin/bash", "-lc", "mkdir /home/ds/.cnvrg"]
|
821
|
-
container.exec(command, tty: true)
|
822
|
-
command = ["/bin/bash", "-lc", "mkdir /home/ds/.cnvrg/tmp"]
|
823
|
-
container.exec(command, tty: true)
|
824
|
-
command = ["/bin/bash", "-lc", "sudo chown -R ds /home/ds/.cnvrg /home/ds/.netrc"]
|
825
|
-
container.exec(command, tty: true)
|
826
|
-
command = ["/bin/bash", "-lc", "sudo chmod 0600 /home/ds/.netrc"]
|
827
|
-
container.exec(command, tty: true)
|
828
|
-
|
829
|
-
rescue SignalException
|
830
|
-
log_end(-1)
|
831
|
-
|
832
|
-
say "\nAborting"
|
833
|
-
exit(1)
|
834
|
-
end
|
835
|
-
end
|
836
|
-
|
837
|
-
desc 'data_snap', 'Init dataset directory', :hide => true
|
838
|
-
method_option :public, :type => :boolean, :aliases => ["-p", "--public"], :default => false
|
839
|
-
|
840
|
-
def snap_data
|
841
|
-
begin
|
842
|
-
verify_logged_in(false)
|
843
|
-
log_start(__method__, args, options)
|
844
|
-
|
845
|
-
owner = CLI.get_owner
|
846
|
-
path = Dir.pwd
|
847
|
-
@dataset = Dataset.new(path)
|
848
|
-
|
849
|
-
log_end(0)
|
850
|
-
|
851
|
-
rescue SignalException
|
852
|
-
log_end(-1)
|
853
|
-
|
854
|
-
say "\nAborting"
|
855
|
-
exit(1)
|
856
|
-
end
|
857
|
-
end
|
858
|
-
|
859
|
-
desc 'data_snap', 'Init dataset directory', :hide => true
|
860
|
-
|
861
|
-
def data_init_container(owner, dataset_slug, dataset_name)
|
862
|
-
|
863
|
-
if Dataset.init_container(owner, dataset_slug, dataset_name)
|
864
|
-
|
865
|
-
say "init finished successfully", Thor::Shell::Color::GREEN
|
866
|
-
log_end(0)
|
867
|
-
|
868
|
-
else
|
869
|
-
log_end(1, "can't create dataset")
|
870
|
-
say "error creating dataset, please contact support.", Thor::Shell::Color::RED
|
871
|
-
exit(0)
|
872
|
-
end
|
873
|
-
end
|
874
|
-
|
875
|
-
desc 'data download', 'pull data'
|
876
|
-
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
877
|
-
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
878
|
-
|
879
|
-
def download_data(verbose, sync, path=Dir.pwd, in_dir=true)
|
880
|
-
begin
|
881
|
-
verify_logged_in(in_dir)
|
882
|
-
log_start(__method__, args, options)
|
883
|
-
if path.nil? or path.empty?
|
884
|
-
path = Dir.pwd
|
885
|
-
end
|
886
|
-
dataset_dir = is_cnvrg_dir(path)
|
887
|
-
@dataset = Dataset.new(dataset_dir)
|
888
|
-
|
889
|
-
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
890
|
-
new_branch = options["new_branch"] || false
|
891
|
-
|
892
|
-
res = @dataset.compare_idx(new_branch)["result"]
|
893
|
-
|
894
|
-
result = res["tree"]
|
895
|
-
|
896
|
-
commit = res["commit"]
|
897
|
-
if result["updated_on_server"].empty? and result["conflicts"].empty? and result["deleted"].empty?
|
898
|
-
say "Project is up to date", Thor::Shell::Color::GREEN unless (options["sync"] or sync)
|
899
|
-
log_end(0)
|
900
|
-
return true
|
901
|
-
end
|
902
|
-
result = @dataset.downlowd_updated_data(@dataset.last_local_commit)
|
903
|
-
|
904
|
-
delete = result["result"]["delete"]
|
905
|
-
commits = result["result"]["commits"]
|
906
|
-
updated_idx = result["result"]["idx"]
|
907
|
-
commits.each do |c|
|
908
|
-
file_name = @files.download_data_file(c, dataset_dir)
|
909
|
-
|
910
|
-
if file_name.eql? false or file_name.nil?
|
911
|
-
##RETRY
|
912
|
-
next
|
913
|
-
end
|
914
|
-
file_path = "#{dataset_dir}/#{file_name}"
|
915
|
-
success = extarct_tar(file_path, dataset_dir)
|
916
|
-
if !success
|
917
|
-
#TODO: ?
|
918
|
-
end
|
919
|
-
|
920
|
-
FileUtils.rm_rf([file_path])
|
921
|
-
|
922
|
-
end
|
923
|
-
to_delete = []
|
924
|
-
delete.each do |d|
|
925
|
-
to_delete << "#{dataset_dir}/#{d}"
|
926
|
-
end
|
927
|
-
FileUtils.rm_rf(to_delete)
|
928
|
-
|
929
|
-
@dataset.update_idx(updated_idx)
|
930
|
-
|
931
|
-
|
932
|
-
# result["conflicts"].each do |f|
|
933
|
-
# relative_path = f.gsub(/^#{@dataset.local_path}/, "")
|
934
|
-
# if @files.download_file_s3(f, relative_path, dataset_dir, conflict=true)
|
935
|
-
# successful_changes << relative_path
|
936
|
-
# end
|
937
|
-
#
|
938
|
-
# end
|
939
|
-
# update idx with latest commit
|
940
|
-
# @dataset.update_idx_with_commit!(commit)
|
941
|
-
check = Helpers.checkmark()
|
942
|
-
say "#{check} Downloaded changes successfully", Thor::Shell::Color::GREEN
|
943
|
-
|
944
|
-
|
945
|
-
log_end(0)
|
946
|
-
end
|
947
|
-
rescue
|
948
|
-
log_end(-1)
|
949
|
-
|
950
|
-
say "Error occurd, \nAborting", Thor::Shell::Color::BLUE
|
951
|
-
exit(1)
|
952
|
-
rescue SignalException
|
953
|
-
log_end(-1)
|
954
|
-
say "\nAborting", Thor::Shell::Color::BLUE
|
955
|
-
exit(1)
|
956
|
-
end
|
957
|
-
|
958
|
-
|
959
|
-
desc 'upload_data', 'Upload data files', :hide => true
|
960
|
-
method_option :ignore, :type => :array, :aliases => ["-i", "--i"], :desc => "ignore following files"
|
961
|
-
method_option :new_branch, :type => :boolean, :aliases => ["-nb", "--nb"], :desc => "create new branch of commits"
|
962
|
-
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
963
|
-
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
964
|
-
|
965
|
-
def upload_data(sync=false, direct=false)
|
966
|
-
|
967
|
-
begin
|
968
|
-
verify_logged_in(true)
|
969
|
-
log_start(__method__, args, options)
|
970
|
-
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
971
|
-
@dataset = Dataset.new(dataset_dir)
|
972
|
-
|
973
|
-
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
974
|
-
ignore = options[:ignore] || []
|
975
|
-
if !@dataset.update_ignore_list(ignore)
|
976
|
-
say "Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW
|
977
|
-
end
|
978
|
-
result = @dataset.compare_idx(false)
|
979
|
-
|
980
|
-
commit = result["result"]["commit"]
|
981
|
-
if commit != @dataset.last_local_commit and !@dataset.last_local_commit.nil? and !result["result"]["tree"]["updated_on_server"].empty?
|
982
|
-
log_end(0)
|
983
|
-
|
984
|
-
say "Remote server has an updated version, please run `cnvrg download` first, or alternatively: `cnvrg sync`", Thor::Shell::Color::YELLOW
|
985
|
-
exit(1)
|
986
|
-
end
|
987
|
-
|
988
|
-
say "Comparing local changes with remote version:", Thor::Shell::Color::BLUE if options["verbose"]
|
989
|
-
result = result["result"]["tree"]
|
990
|
-
# if result["added"].any? {|x| x.include? ".conflict"} or !result["conflicts"].empty?
|
991
|
-
# all = result["added"].select {|x| x.include? ".conflict"} +result["conflicts"].flatten
|
992
|
-
# if all.size == 1
|
993
|
-
# num = "conflict"
|
994
|
-
# else
|
995
|
-
# num = "conflicts"
|
996
|
-
# end
|
997
|
-
# say "Project contains #{all.size} #{num}:", Thor::Shell::Color::RED
|
998
|
-
# say "#{all.join("\n")}"
|
999
|
-
# say "Please fix #{num}, and retry", Thor::Shell::Color::RED
|
1000
|
-
# exit(1)
|
1001
|
-
#
|
1002
|
-
# end
|
1003
|
-
check = Helpers.checkmark()
|
1004
|
-
|
1005
|
-
if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty?
|
1006
|
-
log_end(0)
|
1007
|
-
say "#{check} Dataset is up to date", Thor::Shell::Color::GREEN unless ((options["sync"] or sync) and !direct)
|
1008
|
-
return true
|
1009
|
-
end
|
1010
|
-
update_count = 0
|
1011
|
-
update_total = result["added"].size + result["updated_on_local"].size + result["deleted"].size
|
1012
|
-
successful_updates = []
|
1013
|
-
successful_deletions = []
|
1014
|
-
if options["verbose"]
|
1015
|
-
if update_total == 1
|
1016
|
-
say "Updating #{update_total} file", Thor::Shell::Color::BLUE
|
1017
|
-
else
|
1018
|
-
say "Updating #{update_total} files", Thor::Shell::Color::BLUE
|
1019
|
-
end
|
1020
|
-
else
|
1021
|
-
say "Syncing files", Thor::Shell::Color::BLUE unless (options["sync"] or sync)
|
1022
|
-
|
1023
|
-
end
|
1024
|
-
|
1025
|
-
# Start commit
|
1026
|
-
|
1027
|
-
commit_sha1 = @files.start_commit(false)["result"]["commit_sha1"]
|
1028
|
-
# upload / update
|
1029
|
-
begin
|
1030
|
-
(result["added"] + result["updated_on_local"]).each do |f|
|
1031
|
-
absolute_path = "#{@dataset.local_path}/#{f}"
|
1032
|
-
relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "")
|
1033
|
-
if File.directory?(absolute_path)
|
1034
|
-
resDir = @files.create_dir(absolute_path, relative_path, commit_sha1)
|
1035
|
-
if resDir
|
1036
|
-
update_count += 1
|
1037
|
-
successful_updates<< relative_path
|
1038
|
-
end
|
1039
|
-
else
|
1040
|
-
res = @files.upload_file(absolute_path, relative_path, commit_sha1)
|
1041
|
-
|
1042
|
-
if res
|
1043
|
-
update_count += 1
|
1044
|
-
successful_updates<< relative_path
|
1045
|
-
else
|
1046
|
-
@files.rollback_commit(commit_sha1)
|
1047
|
-
log_end(1, "can't upload, Rolling Back all changes")
|
1048
|
-
say "Couldn't upload, Rolling Back all changes.", Thor::Shell::Color::RED
|
1049
|
-
exit(0)
|
1050
|
-
end
|
1051
|
-
end
|
1052
|
-
end
|
1053
|
-
|
1054
|
-
# delete
|
1055
|
-
deleted = update_deleted(result["deleted"])
|
1056
|
-
deleted.each do |f|
|
1057
|
-
relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "")
|
1058
|
-
if relative_path.end_with?("/")
|
1059
|
-
if @files.delete_dir(f, relative_path, commit_sha1)
|
1060
|
-
# update_count += 1
|
1061
|
-
successful_updates<< relative_path
|
1062
|
-
end
|
1063
|
-
else
|
1064
|
-
if @files.delete_file(f, relative_path, commit_sha1)
|
1065
|
-
# update_count += 1
|
1066
|
-
successful_updates<< relative_path
|
1067
|
-
end
|
1068
|
-
end
|
1069
|
-
end
|
1070
|
-
|
1071
|
-
rescue SignalException
|
1072
|
-
log_end(-1)
|
1073
|
-
@files.rollback_commit(commit_sha1)
|
1074
|
-
say "User aborted, Rolling Back all changes.", Thor::Shell::Color::RED
|
1075
|
-
exit(0)
|
1076
|
-
rescue => e
|
1077
|
-
log_end(-1, e.message)
|
1078
|
-
@files.rollback_commit(commit_sha1)
|
1079
|
-
say "Exception while trying to upload, Rolling back", Thor::Shell::Color::RED
|
1080
|
-
exit(0)
|
1081
|
-
end
|
1082
|
-
if !result["deleted"].nil? and !result["deleted"].empty?
|
1083
|
-
update_count += result["deleted"].size
|
1084
|
-
end
|
1085
|
-
if update_count == update_total
|
1086
|
-
res = @files.end_commit(commit_sha1)
|
1087
|
-
if (Cnvrg::CLI.is_response_success(res, false))
|
1088
|
-
# save idx
|
1089
|
-
begin
|
1090
|
-
@dataset.update_idx_with_files_commits!((successful_deletions+successful_updates), res["result"]["commit_time"])
|
1091
|
-
|
1092
|
-
@dataset.update_idx_with_commit!(commit_sha1)
|
1093
|
-
rescue => e
|
1094
|
-
log_end(-1, e.message)
|
1095
|
-
@files.rollback_commit(commit_sha1)
|
1096
|
-
say "Couldn't commit updates, Rolling Back all changes.", Thor::Shell::Color::RED
|
1097
|
-
exit(1)
|
1098
|
-
|
1099
|
-
end
|
1100
|
-
if options["verbose"]
|
1101
|
-
say "#{check} Done", Thor::Shell::Color::BLUE
|
1102
|
-
if successful_updates.size >0
|
1103
|
-
say "Updated:", Thor::Shell::Color::GREEN
|
1104
|
-
suc = successful_updates.map { |x| x=Helpers.checkmark() +" "+x }
|
1105
|
-
say suc.join("\n"), Thor::Shell::Color::GREEN
|
1106
|
-
end
|
1107
|
-
if successful_deletions.size >0
|
1108
|
-
say "Deleted:", Thor::Shell::Color::GREEN
|
1109
|
-
del = successful_updates.map { |x| x=Helpers.checkmark() +" "+x }
|
1110
|
-
say del.join("\n"), Thor::Shell::Color::GREEN
|
1111
|
-
end
|
1112
|
-
say "Total of #{update_count} / #{update_total} files.", Thor::Shell::Color::GREEN
|
1113
|
-
else
|
1114
|
-
if (options["sync"] or sync) and direct
|
1115
|
-
say "#{check} Syncing dataset completed successfully", Thor::Shell::Color::GREEN
|
1116
|
-
|
1117
|
-
else
|
1118
|
-
say "#{check} Changes were updated successfully", Thor::Shell::Color::GREEN
|
1119
|
-
|
1120
|
-
end
|
1121
|
-
|
1122
|
-
end
|
1123
|
-
|
1124
|
-
log_end(0)
|
1125
|
-
else
|
1126
|
-
@files.rollback_commit(commit_sha1)
|
1127
|
-
log_end(1, "error. Rolling Back all changes")
|
1128
|
-
say "Error. Rolling Back all changes.", Thor::Shell::Color::RED
|
1129
|
-
end
|
1130
|
-
else
|
1131
|
-
log_end(1, "error. Rolling Back all changes")
|
1132
|
-
say "Error occurd, \nRolling back", Thor::Shell::Color::RED
|
1133
|
-
|
1134
|
-
@files.rollback_commit(commit_sha1)
|
1135
|
-
end
|
1136
|
-
rescue => e
|
1137
|
-
|
1138
|
-
log_end(-1)
|
1139
|
-
|
1140
|
-
say "Error occurd, \nAborting", Thor::Shell::Color::RED
|
1141
|
-
@files.rollback_commit(commit_sha1)
|
1142
|
-
exit(1)
|
1143
|
-
rescue SignalException
|
1144
|
-
log_end(-1)
|
1145
|
-
|
1146
|
-
say "\nAborting", Thor::Shell::Color::BLUE
|
1147
|
-
say "\nRolling back all changes", Thor::Shell::Color::BLUE
|
1148
|
-
@files.rollback_commit(commit_sha1)
|
1149
|
-
exit(1)
|
1150
|
-
end
|
1151
|
-
|
1152
|
-
end
|
1153
|
-
|
1154
|
-
desc 'data upload', 'push data'
|
1155
|
-
method_option :ignore, :type => :array, :aliases => ["-i", "--i"], :desc => "ignore following files"
|
1156
|
-
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
1157
|
-
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
1158
|
-
method_option :no_compression, :type => :boolean, :aliases => ["-nc", "--no_compression"], :default => false
|
1159
|
-
|
1160
|
-
def upload_data_tar(ignore, verbose, sync,no_compression)
|
1161
|
-
|
1162
|
-
begin
|
1163
|
-
verify_logged_in(true)
|
1164
|
-
log_start(__method__, args, options)
|
1165
|
-
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
1166
|
-
|
1167
|
-
@dataset = Dataset.new(dataset_dir)
|
1168
|
-
|
1169
|
-
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
1170
|
-
if !@dataset.update_ignore_list(ignore)
|
1171
|
-
say "Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::RED
|
1172
|
-
exit(1)
|
1173
|
-
end
|
1174
|
-
say "Checking dataset", Thor::Shell::Color::BLUE
|
1175
|
-
local_idx = @dataset.generate_idx
|
1176
|
-
result = @dataset.compare_idx(false, commit=@dataset.last_local_commit, local_idx= local_idx)
|
1177
|
-
|
1178
|
-
|
1179
|
-
commit = result["result"]["commit"]
|
1180
|
-
if commit != @dataset.last_local_commit and !@dataset.last_local_commit.nil? and !result["result"]["tree"]["updated_on_server"].empty?
|
1181
|
-
log_end(0)
|
1182
|
-
|
1183
|
-
say "Remote server has an updated version, please run `cnvrg data download` first", Thor::Shell::Color::YELLOW
|
1184
|
-
exit(1)
|
1185
|
-
end
|
1186
|
-
|
1187
|
-
say "Comparing local changes with remote version:", Thor::Shell::Color::BLUE if verbose
|
1188
|
-
result = result["result"]["tree"]
|
1189
|
-
check = Helpers.checkmark()
|
1190
|
-
|
1191
|
-
if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty?
|
1192
|
-
log_end(0)
|
1193
|
-
say "#{check} Dataset is up to date", Thor::Shell::Color::GREEN unless (sync)
|
1194
|
-
return true
|
1195
|
-
end
|
1196
|
-
update_count = 0
|
1197
|
-
update_total = result["added"].size + result["updated_on_local"].size + result["deleted"].size
|
1198
|
-
successful_updates = []
|
1199
|
-
successful_deletions = []
|
1200
|
-
|
1201
|
-
# Start commit
|
1202
|
-
res = @files.start_commit(false)["result"]
|
1203
|
-
commit_sha1 =res["commit_sha1"]
|
1204
|
-
commit_time = res["commit_time"]
|
1205
|
-
# upload / update
|
1206
|
-
begin
|
1207
|
-
(result["added"] + result["updated_on_local"]).each do |f|
|
1208
|
-
relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "")
|
1209
|
-
successful_updates<< relative_path
|
1210
|
-
update_count += 1
|
1211
|
-
end
|
1212
|
-
|
1213
|
-
# delete
|
1214
|
-
deleted = update_deleted(result["deleted"])
|
1215
|
-
deleted.each do |f|
|
1216
|
-
relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "")
|
1217
|
-
successful_updates<< relative_path
|
1218
|
-
end
|
1219
|
-
@dataset.update_idx_with_files_commits!((successful_deletions+successful_updates), commit_time)
|
1220
|
-
|
1221
|
-
@dataset.update_idx_with_commit!(commit_sha1)
|
1222
|
-
say "Compressing data", Thor::Shell::Color::BLUE
|
1223
|
-
|
1224
|
-
home_dir = File.expand_path('~')
|
1225
|
-
compression_path = get_compression_path
|
1226
|
-
tar_path = "#{compression_path}#{@dataset.slug}_#{commit_sha1}.tar.gz"
|
1227
|
-
tar_files_path = "#{home_dir}/.cnvrg/tmp/#{@dataset.slug}_#{commit_sha1}.txt"
|
1228
|
-
tar_files = (result["added"] + result["updated_on_local"]).join("\n")
|
1229
|
-
File.open(tar_files_path, 'w') { |f| f.write tar_files }
|
1230
|
-
is_tar = create_tar(dataset_dir, tar_path, tar_files_path,no_compression)
|
1231
|
-
if !is_tar
|
1232
|
-
say "ERROR: Couldn't compress data", Thor::Shell::Color::RED
|
1233
|
-
FileUtils.rm_rf([tar_path]) if File.exist? tar_path
|
1234
|
-
FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
|
1235
|
-
@files.rollback_commit(commit_sha1)
|
1236
|
-
say "Rolling Back all changes.", Thor::Shell::Color::RED
|
1237
|
-
exit(1)
|
1238
|
-
end
|
1239
|
-
say "Uploading data", Thor::Shell::Color::BLUE
|
1240
|
-
res = false
|
1241
|
-
res = @files.upload_tar_file(tar_path, tar_path, commit_sha1)
|
1242
|
-
|
1243
|
-
if res
|
1244
|
-
say "Commiting data", Thor::Shell::Color::BLUE
|
1245
|
-
|
1246
|
-
cur_idx = @dataset.get_idx.to_h
|
1247
|
-
|
1248
|
-
res = @files.end_commit_tar(commit_sha1, cur_idx)
|
1249
|
-
if !Cnvrg::CLI.is_response_success(res, false)
|
1250
|
-
FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
|
1251
|
-
FileUtils.rm_rf([tar_path]) if File.exist? tar_path
|
1252
|
-
|
1253
|
-
|
1254
|
-
@files.rollback_commit(commit_sha1)
|
1255
|
-
say "Can't commit, Rolling Back all changes.", Thor::Shell::Color::RED
|
1256
|
-
exit(1)
|
1257
|
-
end
|
1258
|
-
|
1259
|
-
else
|
1260
|
-
FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
|
1261
|
-
FileUtils.rm_rf([tar_path]) if File.exist? tar_path
|
1262
|
-
|
1263
|
-
|
1264
|
-
@files.rollback_commit(commit_sha1)
|
1265
|
-
say "Can't upload, Rolling Back all changes.", Thor::Shell::Color::RED
|
1266
|
-
exit(1)
|
1267
|
-
end
|
1268
|
-
|
1269
|
-
|
1270
|
-
# delete
|
1271
|
-
FileUtils.rm_rf([tar_path, tar_files_path])
|
1272
|
-
|
1273
|
-
rescue SignalException
|
1274
|
-
log_end(-1)
|
1275
|
-
FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
|
1276
|
-
FileUtils.rm_rf([tar_path]) if File.exist? tar_path
|
1277
|
-
|
1278
|
-
|
1279
|
-
@files.rollback_commit(commit_sha1)
|
1280
|
-
say "User aborted, Rolling Back all changes.", Thor::Shell::Color::RED
|
1281
|
-
exit(0)
|
1282
|
-
rescue => e
|
1283
|
-
puts e.message
|
1284
|
-
if !Cnvrg::Helpers.internet_connection?
|
1285
|
-
say "Seems there is no internet connection", Thor::Shell::Color::RED
|
1286
|
-
|
1287
|
-
end
|
1288
|
-
FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
|
1289
|
-
FileUtils.rm_rf([tar_path]) if File.exist? tar_path
|
1290
|
-
|
1291
|
-
log_end(-1, e.message)
|
1292
|
-
@files.rollback_commit(commit_sha1)
|
1293
|
-
say "Exception while trying to upload, Rolling back", Thor::Shell::Color::RED
|
1294
|
-
exit(0)
|
1295
|
-
end
|
1296
|
-
if verbose
|
1297
|
-
say "#{check} Done", Thor::Shell::Color::BLUE
|
1298
|
-
if successful_updates.size >0
|
1299
|
-
say "Updated:", Thor::Shell::Color::GREEN
|
1300
|
-
suc = successful_updates.map { |x| x=Helpers.checkmark() +" "+x }
|
1301
|
-
say suc.join("\n"), Thor::Shell::Color::GREEN
|
1302
|
-
end
|
1303
|
-
if successful_deletions.size >0
|
1304
|
-
say "Deleted:", Thor::Shell::Color::GREEN
|
1305
|
-
del = successful_updates.map { |x| x=Helpers.checkmark() +" "+x }
|
1306
|
-
say del.join("\n"), Thor::Shell::Color::GREEN
|
1307
|
-
end
|
1308
|
-
|
1309
|
-
|
1310
|
-
say "Total of #{update_count} / #{update_total} files.", Thor::Shell::Color::GREEN
|
1311
|
-
else
|
1312
|
-
say "#{check} Changes were updated successfully", Thor::Shell::Color::GREEN
|
1313
|
-
|
1314
|
-
end
|
1315
|
-
|
1316
|
-
|
1317
|
-
rescue => e
|
1318
|
-
log_end(-1, e.message)
|
1319
|
-
|
1320
|
-
|
1321
|
-
say "Error occurd, \nAborting", Thor::Shell::Color::RED
|
1322
|
-
@files.rollback_commit(commit_sha1)
|
1323
|
-
exit(1)
|
1324
|
-
rescue SignalException
|
1325
|
-
log_end(-1)
|
1326
|
-
|
1327
|
-
say "\nAborting", Thor::Shell::Color::BLUE
|
1328
|
-
say "\nRolling back all changes", Thor::Shell::Color::BLUE
|
1329
|
-
@files.rollback_commit(commit_sha1)
|
1330
|
-
exit(1)
|
1331
|
-
end
|
1332
|
-
|
1333
|
-
log_end(0)
|
1334
|
-
|
1335
|
-
end
|
1336
|
-
|
1337
|
-
|
1338
|
-
desc 'unlink', 'Unlink a project from current directory', :hide => true
|
1339
|
-
|
1340
|
-
def create_volume
|
1341
|
-
verify_logged_in(false)
|
1342
|
-
log_start(__method__, args, options)
|
1343
|
-
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
1344
|
-
@dataset = Dataset.new(dataset_dir)
|
1345
|
-
@dataset.create_volume()
|
1346
|
-
|
1347
|
-
end
|
1348
|
-
|
1349
|
-
desc 'data list', 'List all dataset you currently have'
|
1350
|
-
|
1351
|
-
def list_dataset
|
1352
|
-
verify_logged_in(false)
|
1353
|
-
log_start(__method__, args, options)
|
1354
|
-
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
1355
|
-
@dataset = Dataset.new(dataset_dir)
|
1356
|
-
owner = @dataset.owner
|
1357
|
-
if owner.nil? or owner.empty?
|
1358
|
-
owner = CLI.get_owner()
|
1359
|
-
end
|
1360
|
-
result = @dataset.list(owner)
|
1361
|
-
list = result["result"]["list"]
|
1362
|
-
|
1363
|
-
print_table(list)
|
1364
|
-
|
1365
|
-
end
|
1366
|
-
|
1367
|
-
desc 'data commits', 'List all commits for a specific dataset'
|
1368
|
-
|
1369
|
-
def list_dataset_commits()
|
1370
|
-
verify_logged_in(true)
|
1371
|
-
log_start(__method__, args, options)
|
1372
|
-
|
1373
|
-
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
1374
|
-
@dataset = Dataset.new(dataset_dir)
|
1375
|
-
result = @dataset.list_commits()
|
1376
|
-
list = result["result"]["list"]
|
1377
|
-
|
1378
|
-
print_table(list)
|
1379
|
-
|
1380
|
-
end
|
1381
|
-
|
1382
|
-
desc 'commits', 'List all commits for a specific dataset'
|
1383
|
-
|
1384
|
-
def list_commits()
|
1385
|
-
verify_logged_in(true)
|
1386
|
-
log_start(__method__, args, options)
|
1387
|
-
|
1388
|
-
project_dir = is_cnvrg_dir(Dir.pwd)
|
1389
|
-
@project = Project.new(project_dir)
|
1390
|
-
result = @project.list_commits()
|
1391
|
-
list = result["result"]["list"]
|
1392
|
-
|
1393
|
-
print_table(list)
|
1394
|
-
|
1395
|
-
end
|
1396
|
-
|
1397
|
-
|
1398
|
-
desc 'unlink', 'Unlink a project from current directory'
|
1399
|
-
|
1400
|
-
def unlink
|
1401
|
-
verify_logged_in(false)
|
1402
|
-
log_start(__method__, args, options)
|
1403
|
-
working_dir = is_cnvrg_dir()
|
1404
|
-
list_to_del = [working_dir+"/.cnvrgignore", working_dir+"/.cnvrg"]
|
1405
|
-
FileUtils.rm_rf list_to_del
|
1406
|
-
end
|
1407
|
-
|
1408
|
-
desc 'clone', 'Clone project'
|
1409
|
-
method_option :remote, :type => :boolean, :aliases => ["-r", "--r"], :default => false
|
1410
|
-
method_option :commit, :type => :string, :aliases => ["-c", "--c"], :default => nil
|
1411
|
-
|
1412
|
-
def clone(project_url)
|
1413
|
-
begin
|
1414
|
-
verify_logged_in(false)
|
1415
|
-
log_start(__method__, args, options)
|
1416
|
-
url_parts = project_url.split("/")
|
1417
|
-
project_index = Cnvrg::Helpers.look_for_in_path(project_url, "projects")
|
1418
|
-
slug = url_parts[project_index+1]
|
1419
|
-
owner = url_parts[project_index-1]
|
1420
|
-
remote = options["remote"] || false
|
1421
|
-
response = Cnvrg::API.request("users/#{owner}/projects/#{slug}/get_project", 'GET')
|
1422
|
-
Cnvrg::CLI.is_response_success(response)
|
1423
|
-
response = JSON.parse response["result"]
|
1424
|
-
project_name = response["title"]
|
1425
|
-
commit_to_clone = options["commit"] || nil
|
1426
|
-
|
1427
|
-
say "Cloning #{project_name}", Thor::Shell::Color::BLUE
|
1428
|
-
clone_resp = false
|
1429
|
-
if remote
|
1430
|
-
clone_resp = Project.clone_dir_remote(slug, owner, project_name)
|
1431
|
-
project_home = Dir.pwd
|
1432
|
-
else
|
1433
|
-
if (Dir.exists? project_name)
|
1434
|
-
say "Error: Conflict with dir #{project_name}", Thor::Shell::Color::RED
|
1435
|
-
if no? "Sync to repository anyway? (current data might lost)", Thor::Shell::Color::YELLOW
|
1436
|
-
say "Remove dir in order to clone #{project_name}", Thor::Shell::Color::RED
|
1437
|
-
log_end(1, "conflict with dir #{project_name}")
|
1438
|
-
|
1439
|
-
exit(1)
|
1440
|
-
end
|
1441
|
-
|
1442
|
-
end
|
1443
|
-
clone_resp = Project.clone_dir(slug, owner, project_name)
|
1444
|
-
project_home = Dir.pwd+"/"+project_name
|
1445
|
-
|
1446
|
-
|
1447
|
-
end
|
1448
|
-
|
1449
|
-
if clone_resp
|
1450
|
-
@project = Project.new(project_home)
|
1451
|
-
@files = Cnvrg::Files.new(@project.owner, slug)
|
1452
|
-
response = @project.clone(remote, commit_to_clone)
|
1453
|
-
Cnvrg::CLI.is_response_success response
|
1454
|
-
working_dir = project_home
|
1455
|
-
docker_image = response["result"]["image"]
|
1456
|
-
current_commit = response["result"]["commit"]
|
1457
|
-
idx = {commit: response["result"]["commit"], tree: response["result"]["tree"]}
|
1458
|
-
File.open(working_dir + "/.cnvrg/idx.yml", "w+") { |f| f.write idx.to_yaml }
|
1459
|
-
if !docker_image.nil? and !docker_image.empty? and !remote
|
1460
|
-
local_images = Docker::Image.all
|
1461
|
-
docker_image_local = local_images.map { |x| x.info["RepoTags"] }.flatten.select { |y| y.eql? "#{docker_image}:latest" }.flatten
|
1462
|
-
if docker_image_local.size == 0
|
1463
|
-
if yes? "Image wasn't found locally, pull image from cnvrg repository?", Thor::Shell::Color::YELLOW
|
1464
|
-
image = pull(docker_image)
|
1465
|
-
if image
|
1466
|
-
say "downloaded image: #{docker_image}"
|
1467
|
-
@image = Images.new(working_dir, docker_image)
|
1468
|
-
else
|
1469
|
-
say "Could not create a new project with docker, image was not found", Thor::Shell::Color::RED
|
1470
|
-
@project.revert(working_dir)
|
1471
|
-
exit(1)
|
1472
|
-
end
|
1473
|
-
end
|
1474
|
-
|
1475
|
-
elsif docker_image_local.size == 1
|
1476
|
-
say "found image: #{docker_image_local[0]}, setting it up..", Thor::Shell::Color::BLUE
|
1477
|
-
@image = Images.new(working_dir, docker_image_local[0])
|
1478
|
-
elsif docker_image_local.size >1
|
1479
|
-
say "found #{docker_image_local.size} images, choose the image name you want to use", Thor::Shell::Color::BLUE
|
1480
|
-
image_name = ask "#{docker_image_local.join("\n")}\n", Thor::Shell::Color::BLUE
|
1481
|
-
@image = Images.new(working_dir, image_name)
|
1482
|
-
end
|
1483
|
-
|
1484
|
-
end
|
1485
|
-
|
1486
|
-
successful_changes = []
|
1487
|
-
say "Downloading files", Thor::Shell::Color::BLUE
|
1488
|
-
if !response["result"]["tree"].nil?
|
1489
|
-
response["result"]["tree"].each do |f|
|
1490
|
-
relative_path = f[0].gsub(/^#{@project.local_path}/, "")
|
1491
|
-
if f[0].end_with? "/"
|
1492
|
-
# dir
|
1493
|
-
if @files.download_dir(f[0], relative_path, project_home)
|
1494
|
-
successful_changes << relative_path
|
1495
|
-
end
|
1496
|
-
else
|
1497
|
-
# blob
|
1498
|
-
|
1499
|
-
if @files.download_file_s3(f[0], relative_path, project_home, commit_sha1=current_commit)
|
1500
|
-
successful_changes << relative_path
|
1501
|
-
end
|
1502
|
-
end
|
1503
|
-
end
|
1504
|
-
end
|
1505
|
-
|
1506
|
-
say "Done.\nDownloaded total of #{successful_changes.size} files", Thor::Shell::Color::GREEN
|
1507
|
-
log_end(0)
|
1508
|
-
else
|
1509
|
-
log_end(1, "can't create directory")
|
1510
|
-
|
1511
|
-
say "Error: Couldn't create directory: #{project_name}", Thor::Shell::Color::RED
|
1512
|
-
exit(1)
|
1513
|
-
end
|
1514
|
-
rescue SignalException
|
1515
|
-
log_end(-1)
|
1516
|
-
say "\nAborting"
|
1517
|
-
exit(1)
|
1518
|
-
end
|
1519
|
-
|
1520
|
-
end
|
1521
|
-
|
1522
|
-
|
1523
|
-
desc 'status', 'Show the working tree status'
|
1524
|
-
method_option :new_branch, :type => :boolean, :aliases => ["-nb", "--nb"], :desc => "create new branch of commits"
|
1525
|
-
|
1526
|
-
|
1527
|
-
def status
|
1528
|
-
begin
|
1529
|
-
verify_logged_in()
|
1530
|
-
log_start(__method__, args, options)
|
1531
|
-
@project = Project.new(get_project_home)
|
1532
|
-
new_branch = options["new_branch"] || false
|
662
|
+
verify_logged_in()
|
663
|
+
log_start(__method__, args, options)
|
664
|
+
@project = Project.new(get_project_home)
|
665
|
+
new_branch = options["new_branch"] || false
|
1533
666
|
|
1534
667
|
result = @project.compare_idx(new_branch)["result"]
|
1535
668
|
commit = result["commit"]
|
1536
669
|
result = result["tree"]
|
1537
670
|
say "Comparing local changes with remote version:", Thor::Shell::Color::BLUE
|
1538
|
-
|
1539
671
|
if result["added"].empty? and result["updated_on_local"].empty? and result["updated_on_server"].empty? and result["deleted"].empty? and result["conflicts"].empty?
|
1540
672
|
say "Project is up to date", Thor::Shell::Color::GREEN
|
1541
673
|
log_end(0)
|
@@ -1582,36 +714,14 @@ module Cnvrg
|
|
1582
714
|
end
|
1583
715
|
end
|
1584
716
|
|
1585
|
-
desc '', '', :hide => true
|
1586
|
-
|
1587
|
-
def revert_exp
|
1588
|
-
begin
|
1589
|
-
log_start(__method__, args, options)
|
1590
|
-
@project = Project.new(get_project_home)
|
1591
|
-
|
1592
|
-
result = @project.compare_idx(false)["result"]
|
1593
|
-
result = result["tree"]
|
1594
|
-
if result["added"].size > 0
|
1595
|
-
FileUtils.rm_rf(result["added"])
|
1596
|
-
end
|
1597
|
-
say "Changes were removed successfully", Thor::Shell::Color::GREEN
|
1598
|
-
|
1599
|
-
|
1600
|
-
rescue SignalException
|
1601
|
-
log_end(-1)
|
1602
|
-
say "\nAborting"
|
1603
|
-
exit(1)
|
1604
|
-
end
|
1605
|
-
end
|
1606
|
-
|
1607
717
|
|
1608
718
|
desc 'upload', 'Upload updated files'
|
1609
|
-
method_option :ignore, :type => :
|
1610
|
-
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
1611
|
-
method_option :verbose, :type => :boolean, :aliases => ["
|
1612
|
-
method_option :sync, :type => :boolean, :aliases => ["
|
719
|
+
method_option :ignore, :type => :array, :aliases => ["-i", "--i"], :desc => "ignore following files"
|
720
|
+
method_option :new_branch, :type => :boolean, :aliases => ["-nb", "--nb"], :desc => "create new branch of commits"
|
721
|
+
method_option :verbose, :type => :boolean, :aliases => ["--v"], :default => false
|
722
|
+
method_option :sync, :type => :boolean, :aliases => ["--v"], :default => false
|
1613
723
|
|
1614
|
-
def upload(link=false, sync=false
|
724
|
+
def upload(link=false, sync=false)
|
1615
725
|
|
1616
726
|
begin
|
1617
727
|
verify_logged_in(true)
|
@@ -1620,30 +730,12 @@ module Cnvrg
|
|
1620
730
|
@project = Project.new(get_project_home)
|
1621
731
|
|
1622
732
|
@files = Cnvrg::Files.new(@project.owner, @project.slug)
|
1623
|
-
ignore = options[:ignore] ||
|
1624
|
-
|
1625
|
-
if ignore.nil? or ignore.empty?
|
1626
|
-
ignore = ignore_list
|
1627
|
-
end
|
1628
|
-
data_ignore = data_dir_include()
|
1629
|
-
if !data_ignore.nil?
|
1630
|
-
if ignore.nil? or ignore.empty?
|
1631
|
-
ignore = data_ignore
|
1632
|
-
else
|
1633
|
-
ignore ="#{ignore},#{data_ignore}"
|
1634
|
-
end
|
1635
|
-
end
|
733
|
+
ignore = options[:ignore] || []
|
1636
734
|
if !@project.update_ignore_list(ignore)
|
1637
735
|
say "Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW
|
1638
736
|
end
|
1639
737
|
new_branch = options["new_branch"] || false
|
1640
738
|
|
1641
|
-
if options["sync"] or sync
|
1642
|
-
new_branch_exp = @project.get_new_branch
|
1643
|
-
if new_branch_exp
|
1644
|
-
new_branch = new_branch_exp
|
1645
|
-
end
|
1646
|
-
end
|
1647
739
|
result = @project.compare_idx(new_branch)
|
1648
740
|
commit = result["result"]["commit"]
|
1649
741
|
if !link
|
@@ -1657,23 +749,9 @@ module Cnvrg
|
|
1657
749
|
say "Comparing local changes with remote version:", Thor::Shell::Color::BLUE if options["verbose"]
|
1658
750
|
end
|
1659
751
|
result = result["result"]["tree"]
|
1660
|
-
# if result["added"].any? {|x| x.include? ".conflict"} or !result["conflicts"].empty?
|
1661
|
-
# all = result["added"].select {|x| x.include? ".conflict"} +result["conflicts"].flatten
|
1662
|
-
# if all.size == 1
|
1663
|
-
# num = "conflict"
|
1664
|
-
# else
|
1665
|
-
# num = "conflicts"
|
1666
|
-
# end
|
1667
|
-
# say "Project contains #{all.size} #{num}:", Thor::Shell::Color::RED
|
1668
|
-
# say "#{all.join("\n")}"
|
1669
|
-
# say "Please fix #{num}, and retry", Thor::Shell::Color::RED
|
1670
|
-
# exit(1)
|
1671
|
-
#
|
1672
|
-
# end
|
1673
|
-
check = Helpers.checkmark()
|
1674
752
|
if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty?
|
1675
753
|
log_end(0)
|
1676
|
-
say "
|
754
|
+
say "Project is up to date", Thor::Shell::Color::GREEN unless options["sync"]
|
1677
755
|
return true
|
1678
756
|
end
|
1679
757
|
update_count = 0
|
@@ -1687,7 +765,7 @@ module Cnvrg
|
|
1687
765
|
say "Updating #{update_total} files", Thor::Shell::Color::BLUE
|
1688
766
|
end
|
1689
767
|
else
|
1690
|
-
say "Syncing files", Thor::Shell::Color::BLUE unless
|
768
|
+
say "Syncing files", Thor::Shell::Color::BLUE unless options["sync"]
|
1691
769
|
|
1692
770
|
end
|
1693
771
|
|
@@ -1721,21 +799,21 @@ module Cnvrg
|
|
1721
799
|
end
|
1722
800
|
|
1723
801
|
# delete
|
1724
|
-
|
1725
|
-
deleted.each do |f|
|
802
|
+
result["deleted"].each do |f|
|
1726
803
|
relative_path = f.gsub(/^#{@project.local_path + "/"}/, "")
|
1727
804
|
if relative_path.end_with?("/")
|
1728
805
|
if @files.delete_dir(f, relative_path, commit_sha1)
|
1729
|
-
|
806
|
+
update_count += 1
|
1730
807
|
successful_updates<< relative_path
|
1731
808
|
end
|
1732
809
|
else
|
1733
810
|
if @files.delete_file(f, relative_path, commit_sha1)
|
1734
|
-
|
811
|
+
update_count += 1
|
1735
812
|
successful_updates<< relative_path
|
1736
813
|
end
|
1737
814
|
end
|
1738
815
|
end
|
816
|
+
log_end(0)
|
1739
817
|
|
1740
818
|
rescue SignalException
|
1741
819
|
log_end(-1)
|
@@ -1743,14 +821,11 @@ module Cnvrg
|
|
1743
821
|
say "User aborted, Rolling Back all changes.", Thor::Shell::Color::RED
|
1744
822
|
exit(0)
|
1745
823
|
rescue => e
|
1746
|
-
log_end(
|
824
|
+
log_end(1, e.message)
|
1747
825
|
@files.rollback_commit(commit_sha1)
|
1748
826
|
say "Exception while trying to upload, Rolling back", Thor::Shell::Color::RED
|
1749
827
|
exit(0)
|
1750
828
|
end
|
1751
|
-
if !result["deleted"].nil? and !result["deleted"].empty?
|
1752
|
-
update_count += result["deleted"].size
|
1753
|
-
end
|
1754
829
|
if update_count == update_total
|
1755
830
|
res = @files.end_commit(commit_sha1)
|
1756
831
|
if (Cnvrg::CLI.is_response_success(res, false))
|
@@ -1760,7 +835,7 @@ module Cnvrg
|
|
1760
835
|
|
1761
836
|
@project.update_idx_with_commit!(commit_sha1)
|
1762
837
|
rescue => e
|
1763
|
-
log_end(
|
838
|
+
log_end(1, e.message)
|
1764
839
|
@files.rollback_commit(commit_sha1)
|
1765
840
|
say "Couldn't commit updates, Rolling Back all changes.", Thor::Shell::Color::RED
|
1766
841
|
exit(1)
|
@@ -1770,6 +845,7 @@ module Cnvrg
|
|
1770
845
|
if image and image.is_docker
|
1771
846
|
image.update_image_activity(commit_sha1, nil)
|
1772
847
|
end
|
848
|
+
check = Helpers.checkmark()
|
1773
849
|
|
1774
850
|
if options["verbose"]
|
1775
851
|
say "#{check} Done", Thor::Shell::Color::BLUE
|
@@ -1785,13 +861,7 @@ module Cnvrg
|
|
1785
861
|
end
|
1786
862
|
say "Total of #{update_count} / #{update_total} files.", Thor::Shell::Color::GREEN
|
1787
863
|
else
|
1788
|
-
|
1789
|
-
say "#{check} Syncing project completed successfully", Thor::Shell::Color::GREEN
|
1790
|
-
|
1791
|
-
else
|
1792
|
-
say "#{check} Changes were updated successfully", Thor::Shell::Color::GREEN
|
1793
|
-
|
1794
|
-
end
|
864
|
+
say "#{check} Changes were updated successfully", Thor::Shell::Color::GREEN unless options["sync"]
|
1795
865
|
|
1796
866
|
end
|
1797
867
|
|
@@ -1803,14 +873,13 @@ module Cnvrg
|
|
1803
873
|
end
|
1804
874
|
else
|
1805
875
|
log_end(1, "error. Rolling Back all changes")
|
1806
|
-
say "Error occurd, \nRolling back", Thor::Shell::Color::RED
|
1807
876
|
|
1808
877
|
@files.rollback_commit(commit_sha1)
|
1809
878
|
end
|
1810
|
-
rescue
|
879
|
+
rescue
|
1811
880
|
log_end(-1)
|
1812
881
|
|
1813
|
-
say "Error occurd, \nAborting", Thor::Shell::Color::
|
882
|
+
say "Error occurd, \nAborting", Thor::Shell::Color::BLUE
|
1814
883
|
@files.rollback_commit(commit_sha1)
|
1815
884
|
exit(1)
|
1816
885
|
rescue SignalException
|
@@ -1825,57 +894,27 @@ module Cnvrg
|
|
1825
894
|
end
|
1826
895
|
|
1827
896
|
desc 'download', 'Download updated files'
|
1828
|
-
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
1829
|
-
method_option :verbose, :type => :boolean, :aliases => ["
|
1830
|
-
method_option :sync, :type => :boolean, :aliases => ["
|
1831
|
-
method_option :ignore, :type => :string, :aliases => ["-i"], :desc => "ignore following files", :default => ""
|
897
|
+
method_option :new_branch, :type => :boolean, :aliases => ["-nb", "--nb"], :desc => "create new branch of commits"
|
898
|
+
method_option :verbose, :type => :boolean, :aliases => ["--v"], :default => false
|
899
|
+
method_option :sync, :type => :boolean, :aliases => ["--v"], :default => false
|
1832
900
|
|
1833
|
-
def download
|
901
|
+
def download
|
1834
902
|
begin
|
1835
903
|
verify_logged_in(true)
|
1836
904
|
log_start(__method__, args, options)
|
1837
905
|
project_home = get_project_home
|
1838
|
-
@project = Project.new(project_home)
|
1839
|
-
@files = Cnvrg::Files.new(@project.owner, @project.slug)
|
1840
|
-
ignore = options[:ignore] || ""
|
1841
|
-
if ignore.nil? or ignore.empty?
|
1842
|
-
ignore = ignore_list
|
1843
|
-
end
|
1844
|
-
data_ignore = data_dir_include()
|
1845
|
-
if !data_ignore.nil?
|
1846
|
-
if ignore.nil? or ignore.empty?
|
1847
|
-
ignore = data_ignore
|
1848
|
-
else
|
1849
|
-
ignore ="#{ignore},#{data_ignore}"
|
1850
|
-
end
|
1851
|
-
end
|
1852
|
-
if !@project.update_ignore_list(ignore)
|
1853
|
-
say "Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW
|
1854
|
-
end
|
906
|
+
@project = Project.new(project_home)
|
907
|
+
@files = Cnvrg::Files.new(@project.owner, @project.slug)
|
1855
908
|
new_branch = options["new_branch"] || false
|
1856
909
|
|
1857
910
|
res = @project.compare_idx(new_branch)["result"]
|
1858
|
-
|
1859
911
|
result = res["tree"]
|
1860
|
-
|
1861
912
|
commit = res["commit"]
|
1862
|
-
if result["updated_on_server"].empty? and result["conflicts"]
|
1863
|
-
say "Project is up to date", Thor::Shell::Color::GREEN unless
|
913
|
+
if result["updated_on_server"].empty? and result["conflicts"] and result["deleted"].empty?
|
914
|
+
say "Project is up to date", Thor::Shell::Color::GREEN unless options["sync"]
|
1864
915
|
log_end(0)
|
1865
916
|
return true
|
1866
917
|
end
|
1867
|
-
# if result["added"].any? {|x| x.include? ".conflict"} or !result["conflicts"].empty?
|
1868
|
-
# all = result["added"].select {|x| x.include? ".conflict"} +result["conflicts"].flatten
|
1869
|
-
# if all.size == 1
|
1870
|
-
# num = "1 conflict"
|
1871
|
-
# else
|
1872
|
-
# num = "#{result["conflicts"].size} conflicts"
|
1873
|
-
# end
|
1874
|
-
# say "Project contains #{num}:", Thor::Shell::Color::RED
|
1875
|
-
# say "#{all.join("\n")}"
|
1876
|
-
# say "Please fix them, and retry", Thor::Shell::Color::RED
|
1877
|
-
# exit(1)
|
1878
|
-
# end
|
1879
918
|
update_count = 0
|
1880
919
|
update_total = result["updated_on_server"].size + result["conflicts"].size
|
1881
920
|
|
@@ -1897,7 +936,7 @@ module Cnvrg
|
|
1897
936
|
|
1898
937
|
result["conflicts"].each do |f|
|
1899
938
|
relative_path = f.gsub(/^#{@project.local_path}/, "")
|
1900
|
-
if @files.download_file_s3(f, relative_path, project_home,
|
939
|
+
if @files.download_file_s3(f, relative_path, project_home, conflict=true)
|
1901
940
|
successful_changes << relative_path
|
1902
941
|
end
|
1903
942
|
|
@@ -1928,35 +967,12 @@ module Cnvrg
|
|
1928
967
|
say successful_changes.join("\n"), Thor::Shell::Color::GREEN
|
1929
968
|
say "Total of #{successful_changes.size} / #{update_total} files.", Thor::Shell::Color::GREEN
|
1930
969
|
else
|
1931
|
-
say "#{check} Downloaded changes successfully", Thor::Shell::Color::GREEN
|
970
|
+
say "#{check} Downloaded changes successfully", Thor::Shell::Color::GREEN
|
1932
971
|
end
|
1933
972
|
|
1934
973
|
|
1935
974
|
log_end(0)
|
1936
975
|
end
|
1937
|
-
rescue => e
|
1938
|
-
log_end(-1)
|
1939
|
-
|
1940
|
-
say "Error occurd, \nAborting", Thor::Shell::Color::BLUE
|
1941
|
-
if successful_changes.nil?
|
1942
|
-
exit(1)
|
1943
|
-
end
|
1944
|
-
successful_changes.each do |f|
|
1945
|
-
|
1946
|
-
abs_path = "#{@project.local_path}/#{f}"
|
1947
|
-
filename = File.basename abs_path
|
1948
|
-
say "revoking #{filename}"
|
1949
|
-
if result["conflicts"].include? f
|
1950
|
-
@files.revoke_download_file(abs_path, f, filename, true)
|
1951
|
-
elsif result["updated_on_server"].include? f
|
1952
|
-
if File.directory? abs_path
|
1953
|
-
@files.revoke_download_dir(abs_path, f, project_home)
|
1954
|
-
else
|
1955
|
-
@files.revoke_download_file(project_home, abs_path, filename)
|
1956
|
-
end
|
1957
|
-
end
|
1958
|
-
end
|
1959
|
-
exit(1)
|
1960
976
|
rescue SignalException
|
1961
977
|
log_end(-1)
|
1962
978
|
say "\nAborting", Thor::Shell::Color::BLUE
|
@@ -2010,7 +1026,6 @@ module Cnvrg
|
|
2010
1026
|
if !response["result"]["tree"].nil?
|
2011
1027
|
idx = {commit: response["result"]["commit"], tree: response["result"]["tree"]}
|
2012
1028
|
File.open(project_home + "/.cnvrg/idx.yml", "w+") { |f| f.write idx.to_yaml }
|
2013
|
-
current_tree = Dir.entries(".").reject { |file| file.start_with? '.' or file.eql? "__init__.py" or file.eql? "uwsgi.ini" }
|
2014
1029
|
|
2015
1030
|
response["result"]["tree"].each do |f|
|
2016
1031
|
relative_path = f[0].gsub(/^#{@project.local_path}/, "")
|
@@ -2022,7 +1037,7 @@ module Cnvrg
|
|
2022
1037
|
end
|
2023
1038
|
else
|
2024
1039
|
# blob
|
2025
|
-
if @files.download_file_s3(f[0], relative_path, project_home
|
1040
|
+
if @files.download_file_s3(f[0], relative_path, project_home)
|
2026
1041
|
current_tree.delete(relative_path)
|
2027
1042
|
|
2028
1043
|
successful_changes << relative_path
|
@@ -2040,100 +1055,43 @@ module Cnvrg
|
|
2040
1055
|
end
|
2041
1056
|
|
2042
1057
|
|
2043
|
-
desc 'data_jump', 'jump to specific commit', :hide => true
|
2044
|
-
|
2045
|
-
def data_jump(*commit_sha1)
|
2046
|
-
begin
|
2047
|
-
verify_logged_in()
|
2048
|
-
log_start(__method__, args, options)
|
2049
|
-
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
2050
|
-
@dataset = Dataset.new(dataset_dir)
|
2051
|
-
|
2052
|
-
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
2053
|
-
if commit_sha1.nil? or commit_sha1.empty?
|
2054
|
-
commit_sha1 = @dataset.last_local_commit
|
2055
|
-
end
|
2056
|
-
response = @dataset.compare_commits(commit_sha1)
|
2057
|
-
successful_changes = []
|
2058
|
-
if !response["result"]["status"].nil?
|
2059
|
-
idx = {commit: response["result"]["commit"], tree: response["result"]["tree"]}
|
2060
|
-
File.open(dataset_dir + "/.cnvrg/idx.yml", "w+") { |f| f.write idx.to_yaml }
|
2061
|
-
status = response["result"]["status"]
|
2062
|
-
(status["delete"]).each do |f|
|
2063
|
-
relative_path = f[0].gsub(/^#{@dataset.local_path}/, "")
|
2064
|
-
FileUtils.rm_rf(relative_path)
|
2065
|
-
end
|
2066
|
-
# current_tree = Dir.entries(".").reject { |file| file.start_with? '.' }
|
2067
|
-
(status["dirs"]).each do |f|
|
2068
|
-
relative_path = f[0].gsub(/^#{@dataset.local_path}/, "")
|
2069
|
-
# dir
|
2070
|
-
if @files.download_dir(dataset_dir, relative_path)
|
2071
|
-
# current_tree.delete(relative_path[0, relative_path.size-1])
|
2072
|
-
successful_changes << relative_path
|
2073
|
-
end
|
2074
|
-
end
|
2075
|
-
(status["download"]).each do |f|
|
2076
|
-
relative_path = f["name"].gsub(/^#{@dataset.local_path}/, "")
|
2077
|
-
# dir
|
2078
|
-
if @files.download_file_s3(f["name"], relative_path, dataset_dir, f["sha1"])
|
2079
|
-
successful_changes << relative_path
|
2080
|
-
end
|
2081
|
-
end
|
2082
|
-
|
2083
|
-
|
2084
|
-
say "Done. Jumped completed successfully", Thor::Shell::Color::GREEN
|
2085
|
-
log_end(0)
|
2086
|
-
end
|
2087
|
-
|
2088
|
-
rescue SignalException
|
2089
|
-
log_end(-1)
|
2090
|
-
exi(1)
|
2091
|
-
end
|
2092
|
-
end
|
2093
|
-
|
2094
1058
|
desc 'sync', 'Sync with remote server'
|
2095
|
-
method_option :new_branch, :type => :boolean, :aliases => ["
|
2096
|
-
method_option :verbose, :type => :boolean, :aliases => ["
|
2097
|
-
method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :default => ""
|
1059
|
+
method_option :new_branch, :type => :boolean, :aliases => ["--nb"], :desc => "create new branch of commits"
|
1060
|
+
method_option :verbose, :type => :boolean, :aliases => ["--v"], :default => false
|
2098
1061
|
|
2099
|
-
def sync
|
2100
|
-
verify_logged_in(true) if direct
|
1062
|
+
def sync
|
2101
1063
|
if options["verbose"]
|
2102
|
-
|
1064
|
+
say 'Checking for new updates from remote version', Thor::Shell::Color::BLUE
|
2103
1065
|
else
|
2104
1066
|
say 'Syncing project', Thor::Shell::Color::BLUE
|
2105
1067
|
end
|
2106
1068
|
|
2107
1069
|
|
2108
|
-
invoke :download, [], :new_branch => options["new_branch"], :verbose => options["verbose"], :sync
|
2109
|
-
invoke :upload, [
|
2110
|
-
|
1070
|
+
invoke :download, [], :new_branch => options["new_branch"], :verbose => options["verbose"], :sync=>true
|
1071
|
+
invoke :upload, [], :new_branch => options["new_branch"], :verbose => options["verbose"],:sync=>true
|
1072
|
+
check = Helpers.checkmark()
|
2111
1073
|
|
1074
|
+
say "#{check} Syncing project completed successfully", Thor::Shell::Color::GREEN
|
2112
1075
|
|
2113
1076
|
end
|
2114
1077
|
|
2115
1078
|
|
2116
1079
|
desc 'run cmd', 'Runs an experiment'
|
2117
|
-
method_option :local, :type => :boolean, :aliases => ["
|
2118
|
-
method_option :small, :type => :boolean, :aliases => ["
|
2119
|
-
method_option :medium, :type => :boolean, :aliases => ["
|
2120
|
-
method_option :large, :type => :boolean, :aliases => ["
|
1080
|
+
method_option :local, :type => :boolean, :aliases => ["--l"], :default => false
|
1081
|
+
method_option :small, :type => :boolean, :aliases => ["--sm"], :default => false
|
1082
|
+
method_option :medium, :type => :boolean, :aliases => ["--med"], :default => false
|
1083
|
+
method_option :large, :type => :boolean, :aliases => ["--lg"], :default => false
|
2121
1084
|
method_option :gpu, :type => :boolean, :aliases => ["--gpu"], :default => false
|
2122
|
-
method_option :gpuxl, :type => :boolean, :aliases => ["--
|
2123
|
-
method_option :
|
2124
|
-
method_option :
|
2125
|
-
method_option :
|
2126
|
-
method_option :title, :type => :string, :aliases => ["-t", "--title"], :default => ""
|
1085
|
+
method_option :gpuxl, :type => :boolean, :aliases => ["--gxl"], :default => false
|
1086
|
+
method_option :sync_before, :type => :boolean, :aliases => ["--sb"], :default => true
|
1087
|
+
method_option :sync_after, :type => :boolean, :aliases => ["--sa"], :default => true
|
1088
|
+
method_option :title, :type => :string, :aliases => ["--t"], :default => ""
|
2127
1089
|
method_option :log, :type => :boolean, :aliases => ["--log"], :default => false
|
2128
|
-
method_option :email_notification, :type => :boolean, :aliases => ["
|
2129
|
-
method_option :upload_output, :type => :string, :aliases => ["
|
2130
|
-
method_option :commit, :type => :string, :aliases => ["
|
2131
|
-
method_option :schedule, :type => :string, :aliases => ["
|
2132
|
-
method_option :image, :type => :string, :aliases => ["
|
2133
|
-
method_option :grid, :type => :string, :aliases => ["-g", "--grid"], :default => ""
|
2134
|
-
method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
|
2135
|
-
method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
|
2136
|
-
method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :desc => "ignore following files", :default => ""
|
1090
|
+
method_option :email_notification, :type => :boolean, :aliases => ["--en"], :default => false
|
1091
|
+
method_option :upload_output, :type => :string, :aliases => ["--uo"], :default => ""
|
1092
|
+
method_option :commit, :type => :string, :aliases => ["--c"], :default => ""
|
1093
|
+
method_option :schedule, :type => :string, :aliases => ["--s"], :default => ""
|
1094
|
+
method_option :image, :type => :string, :aliases => ["--i"], :default => ""
|
2137
1095
|
|
2138
1096
|
def run(*cmd)
|
2139
1097
|
sync_before = options["sync_before"]
|
@@ -2146,73 +1104,38 @@ module Cnvrg
|
|
2146
1104
|
local = options["local"]
|
2147
1105
|
schedule = options["schedule"]
|
2148
1106
|
image = options["image"]
|
2149
|
-
grid = options["grid"]
|
2150
|
-
data = options["data"]
|
2151
|
-
data_commit = options["data_commit"]
|
2152
|
-
ignore = options["ignore"]
|
2153
|
-
options_hash = Hash[options]
|
2154
|
-
real_options = []
|
2155
|
-
options_hash.each do |o|
|
2156
|
-
real_options << o if (!o[1].eql? "" and !["small", "medium", "large", "gpu", "gpuxl", "gpuxxl"].include? o[0])
|
2157
|
-
end
|
2158
1107
|
if local
|
2159
1108
|
invoke :exec, [cmd], :sync_before => sync_before, :sync_after => sync_after, :title => title,
|
2160
|
-
:log => log, :email_notification => email_notification, :upload_output => upload_output,
|
2161
|
-
:commit => commit, :image => image, :data => data, :data_commit => data_commit, :ignore => ignore
|
1109
|
+
:log => log, :email_notification => email_notification, :upload_output => upload_output, :commit => commit, :image => image
|
2162
1110
|
return
|
2163
1111
|
else
|
2164
|
-
|
2165
|
-
instances = {"small" => options["small"], "medium" => options["medium"], "large" => options["large"],
|
2166
|
-
"gpu" => options["gpu"], "gpuxl" => options["gpuxl"], "gpuxxl" => options["gpuxxl"]}
|
1112
|
+
instances = {"small" => options["small"], "medium" => options["medium"], "large" => options["large"], "gpu" => options["gpu"], "gpuxl" => options["gpuxl"]}
|
2167
1113
|
instance_type = get_instance_type(instances)
|
2168
|
-
if !instance_type.nil? and !instance_type.empty?
|
2169
|
-
real_options << ["machine_type", instance_type]
|
2170
|
-
end
|
2171
|
-
exec_options = real_options.map { |x| "--#{x[0]}=#{x[1]}" }.flatten.join(" ")
|
2172
|
-
cmd_to_exec = "#{exec_options} #{cmd.join(" ")}"
|
2173
1114
|
invoke :exec_remote, [cmd], :sync_before => sync_before, :sync_after => sync_after, :title => title, :machine_type => instance_type,
|
2174
|
-
:schedule => schedule, :log => log, :email_notification => email_notification, :upload_output => upload_output, :commit => commit,
|
2175
|
-
:image => image, :grid => grid, :data => data, :data_commit => data_commit, :ignore => ignore
|
1115
|
+
:schedule => schedule, :log => log, :email_notification => email_notification, :upload_output => upload_output, :commit => commit, :image =>image
|
2176
1116
|
return
|
2177
1117
|
end
|
2178
|
-
|
2179
|
-
# if local
|
2180
|
-
#
|
2181
|
-
# else
|
2182
|
-
|
2183
|
-
|
2184
|
-
# invoke :exec_remote, [cmd_to_exec.split(" ")], :sync_before => sync_before, :sync_after => sync_after, :title => title, :machine_type => instance_type,
|
2185
|
-
# :schedule => schedule, :log => log, :email_notification => email_notification, :upload_output => upload_output, :commit => commit,
|
2186
|
-
# :image => image, :grid => grid, :data => data, :data_commit => data_commit, :ignore => ignore
|
2187
|
-
# return
|
2188
|
-
# end
|
2189
1118
|
end
|
2190
1119
|
|
2191
1120
|
|
2192
|
-
desc '', ''
|
2193
|
-
method_option :sync_before, :type => :boolean, :aliases => ["-sb
|
2194
|
-
method_option :sync_after, :type => :boolean, :aliases => ["-sa
|
2195
|
-
method_option :title, :type => :string, :aliases => ["-t", "--
|
2196
|
-
method_option :log, :type => :boolean, :aliases => ["--
|
2197
|
-
method_option :email_notification, :type => :boolean, :aliases => ["-en
|
2198
|
-
method_option :upload_output, :type => :string, :aliases => ["-uo
|
2199
|
-
method_option :commit, :type => :string, :aliases => ["
|
2200
|
-
method_option :image, :type => :string, :aliases => ["
|
2201
|
-
method_option :indocker, :type => :boolean,
|
2202
|
-
method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
|
2203
|
-
method_option :data_commit, :type => :string, :aliases => ["-dc", "--data_commit"], :default => ""
|
2204
|
-
method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :desc => "ignore following files", :default => ""
|
2205
|
-
method_option :remote, :type => :boolean, :aliases => ["--remote"], :default => false
|
2206
|
-
method_option :gpu, :type => :boolean, :aliases => ["--gpu"], :default => false
|
2207
|
-
def exec(*cmd)
|
1121
|
+
desc '', ''
|
1122
|
+
method_option :sync_before, :type => :boolean, :aliases => ["-sb", "--sb"], :default => true
|
1123
|
+
method_option :sync_after, :type => :boolean, :aliases => ["-sa", "--sa"], :default => true
|
1124
|
+
method_option :title, :type => :string, :aliases => ["-t", "--t"], :default => ""
|
1125
|
+
method_option :log, :type => :boolean, :aliases => ["-l", "--l"], :default => false
|
1126
|
+
method_option :email_notification, :type => :boolean, :aliases => ["-en", "--en"], :default => false
|
1127
|
+
method_option :upload_output, :type => :string, :aliases => ["--uo", "-uo"], :default => ""
|
1128
|
+
method_option :commit, :type => :string, :aliases => ["--c", "-c"], :default => ""
|
1129
|
+
method_option :image, :type => :string, :aliases => ["--i"], :default => ""
|
1130
|
+
method_option :indocker, :type => :boolean, :default => false
|
2208
1131
|
|
1132
|
+
def exec(*cmd)
|
2209
1133
|
log = []
|
2210
1134
|
cpu_average =0
|
2211
1135
|
memory_average = 0
|
2212
1136
|
verify_logged_in(true)
|
2213
1137
|
log_start(__method__, args, options)
|
2214
|
-
working_dir =
|
2215
|
-
script_path = get_cmd_path_in_dir(working_dir, Dir.pwd)
|
1138
|
+
working_dir = Dir.pwd
|
2216
1139
|
|
2217
1140
|
|
2218
1141
|
sync_before = options["sync_before"]
|
@@ -2220,14 +1143,11 @@ module Cnvrg
|
|
2220
1143
|
print_log = options["log"]
|
2221
1144
|
title = options["title"]
|
2222
1145
|
commit = options["commit"] || nil
|
2223
|
-
image = options["image"]
|
2224
|
-
indocker = options["indocker"]
|
2225
|
-
ignore = options[:ignore] || ""
|
2226
|
-
|
1146
|
+
image = options["image"] || nil
|
1147
|
+
indocker = options["indocker"] || false
|
2227
1148
|
|
2228
1149
|
email_notification = options["email_notification"]
|
2229
1150
|
upload_output = options["upload_output"]
|
2230
|
-
upload_output = "1m" if upload_output.nil? or upload_output.empty?
|
2231
1151
|
time_to_upload = calc_output_time(upload_output)
|
2232
1152
|
project_home = get_project_home
|
2233
1153
|
@project = Project.new(project_home)
|
@@ -2239,8 +1159,7 @@ module Cnvrg
|
|
2239
1159
|
else
|
2240
1160
|
if sync_before
|
2241
1161
|
# Sync before run
|
2242
|
-
|
2243
|
-
invoke :sync, [false], :new_branch => is_new_branch, :ignore => ignore
|
1162
|
+
invoke :sync, [], :new_branch => is_new_branch
|
2244
1163
|
end
|
2245
1164
|
end
|
2246
1165
|
#set image for the project
|
@@ -2248,46 +1167,40 @@ module Cnvrg
|
|
2248
1167
|
invoke :set_image, [image]
|
2249
1168
|
end
|
2250
1169
|
if !indocker
|
2251
|
-
|
1170
|
+
image_proj = is_project_with_docker(working_dir)
|
2252
1171
|
|
2253
1172
|
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2259
|
-
|
1173
|
+
if image_proj and image_proj.is_docker
|
1174
|
+
container= image_proj.get_container
|
1175
|
+
if !container
|
1176
|
+
say "Couldn't create container with image #{image_proj.image_name}:#{image_proj.image_tag}", Thor::Shell::Color::RED
|
1177
|
+
exit(1)
|
1178
|
+
end
|
2260
1179
|
|
2261
1180
|
|
2262
|
-
|
2263
|
-
|
2264
|
-
|
2265
|
-
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
2270
|
-
|
2271
|
-
end
|
1181
|
+
exec_args = args.flatten.join(" ")
|
1182
|
+
options_hash = Hash[options]
|
1183
|
+
options_hash.except!("image", "indocker")
|
1184
|
+
exec_options = options_hash.map { |x| "--#{x[0]}=#{x[1]}" }.flatten.join(" ")
|
1185
|
+
command_to_run = cmd.join(" ")
|
1186
|
+
command = ["/bin/bash", "-lc", "cnvrg exec --indocker #{exec_options} #{command_to_run} #{exec_args}"]
|
1187
|
+
puts container.exec(command, tty: true)
|
1188
|
+
container.stop()
|
1189
|
+
exit(0)
|
2272
1190
|
end
|
2273
|
-
remote = options["remote"]
|
2274
|
-
if remote
|
2275
|
-
docker_id = `cat /etc/hostname`
|
2276
|
-
docker_id = docker_id.strip()
|
2277
1191
|
end
|
2278
|
-
is_on_gpu = options["gpu"]
|
2279
1192
|
start_commit = @project.last_local_commit
|
2280
1193
|
cmd = cmd.join("\s")
|
2281
1194
|
|
1195
|
+
say "Running: #{cmd}\n", Thor::Shell::Color::BLUE
|
1196
|
+
|
2282
1197
|
@exp = Experiment.new(@project.owner, @project.slug)
|
2283
1198
|
|
2284
1199
|
platform = RUBY_PLATFORM
|
2285
1200
|
machine_name = Socket.gethostname
|
2286
1201
|
begin
|
2287
|
-
machine_activity = @exp.get_machine_activity(
|
2288
|
-
@exp.start(cmd, platform, machine_name, start_commit, title, email_notification, machine_activity
|
2289
|
-
say "Experiment's live results: #{Cnvrg::Helpers.remote_url}/#{@project.owner}/projects/#{@project.slug}/experiments/#{@exp.slug}", Thor::Shell::Color::GREEN
|
2290
|
-
say "Running: #{cmd}\n", Thor::Shell::Color::BLUE
|
1202
|
+
machine_activity = @exp.get_machine_activity(Dir.pwd)
|
1203
|
+
@exp.start(cmd, platform, machine_name, start_commit, title, email_notification, machine_activity)
|
2291
1204
|
unless @exp.slug.nil?
|
2292
1205
|
real = Time.now
|
2293
1206
|
exp_success = true
|
@@ -2299,34 +1212,19 @@ module Cnvrg
|
|
2299
1212
|
begin
|
2300
1213
|
stdout.each do |line|
|
2301
1214
|
cur_time = Time.now
|
2302
|
-
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
else
|
2307
|
-
memory = memory_usage()
|
2308
|
-
cpu = cpu_usage()
|
2309
|
-
end
|
2310
|
-
|
1215
|
+
monitor = %x{ps aux|awk '{print $2,$3,$4}'|grep #{pid} }
|
1216
|
+
monitor_by = monitor.split(" ")
|
1217
|
+
memory = monitor_by[2]
|
1218
|
+
cpu = monitor_by[1]
|
2311
1219
|
memory_total << memory.to_f
|
2312
1220
|
cpu_total << cpu.to_f
|
2313
1221
|
real_time= Time.now-real
|
2314
1222
|
|
2315
|
-
cur_log = {
|
1223
|
+
cur_log = {time: cur_time,
|
2316
1224
|
message: line,
|
2317
1225
|
type: "stdout",
|
2318
|
-
real: real_time
|
2319
|
-
|
2320
|
-
memory: memory
|
2321
|
-
}
|
2322
|
-
if is_on_gpu
|
2323
|
-
gpu_stats = gpu_util
|
2324
|
-
gpu_utilization = gpu_stats[0]
|
2325
|
-
gpu_memory_util = gpu_stats[1]
|
2326
|
-
cur_log.merge!(gpu_util:gpu_utilization,gpu_memory_util:gpu_memory_util)
|
2327
|
-
end
|
2328
|
-
|
2329
|
-
if print_log
|
1226
|
+
real: real_time}
|
1227
|
+
if print_log
|
2330
1228
|
puts cur_log
|
2331
1229
|
end
|
2332
1230
|
log << cur_log
|
@@ -2335,8 +1233,8 @@ module Cnvrg
|
|
2335
1233
|
if time_to_upload !=0
|
2336
1234
|
if time_to_upload <= Time.now - start_loop
|
2337
1235
|
#upload current log
|
2338
|
-
|
2339
|
-
|
1236
|
+
cpu_average = cpu_total.inject(0) { |sum, el| sum + el }.to_f / cpu_total.size
|
1237
|
+
memory_average = memory_total.inject(0) { |sum, el| sum + el }.to_f / memory_total.size
|
2340
1238
|
|
2341
1239
|
@exp.upload_temp_log(log, cpu_average, memory_average)
|
2342
1240
|
log = []
|
@@ -2360,7 +1258,8 @@ module Cnvrg
|
|
2360
1258
|
end
|
2361
1259
|
|
2362
1260
|
rescue Errno::EIO => e
|
2363
|
-
|
1261
|
+
puts e
|
1262
|
+
# break
|
2364
1263
|
rescue Errno::ENOENT
|
2365
1264
|
log_end(1, "command #{cmd} isn't valid")
|
2366
1265
|
|
@@ -2372,11 +1271,8 @@ module Cnvrg
|
|
2372
1271
|
exp_success = false
|
2373
1272
|
say "The process exited!", Thor::Shell::Color::RED
|
2374
1273
|
rescue => e
|
2375
|
-
|
2376
|
-
|
2377
|
-
|
2378
|
-
say "Error occurred,aborting", Thor::Shell::Color::RED
|
2379
|
-
exit(0)
|
1274
|
+
puts e
|
1275
|
+
log_end(1, e.message)
|
2380
1276
|
end
|
2381
1277
|
::Process.wait pid
|
2382
1278
|
cpu_average = cpu_total.inject(0) { |sum, el| sum + el }.to_f / cpu_total.size
|
@@ -2387,7 +1283,7 @@ module Cnvrg
|
|
2387
1283
|
end
|
2388
1284
|
if !exp_success
|
2389
1285
|
if !Cnvrg::Helpers.internet_connection?
|
2390
|
-
wait_offline = agree "Seems like you're offline, wait until
|
1286
|
+
wait_offline = agree "Seems like you're offline, wait until your'e back online?", Thor::Shell::Color::YELLOW
|
2391
1287
|
if wait_offline
|
2392
1288
|
say "Waiting until your'e online..", Thor::Shell::Color::BLUE
|
2393
1289
|
while !Cnvrg::Helpers.internet_connection?
|
@@ -2410,21 +1306,23 @@ module Cnvrg
|
|
2410
1306
|
end
|
2411
1307
|
if sync_after
|
2412
1308
|
# Sync after run
|
1309
|
+
if !commit.nil?
|
1310
|
+
invoke :sync, [], :new_branch => true
|
2413
1311
|
|
2414
|
-
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
1312
|
+
else
|
1313
|
+
invoke :sync, [], :new_branch => true
|
1314
|
+
end
|
2418
1315
|
end
|
2419
1316
|
end_commit = @project.last_local_commit
|
2420
1317
|
|
2421
1318
|
res = @exp.end(log, exit_status, end_commit, cpu_average, memory_average)
|
2422
1319
|
check = Helpers.checkmark()
|
2423
|
-
say "#{check} Done. Experiment's
|
1320
|
+
say "#{check} Done. Experiment's result: #{Cnvrg::Helpers.remote_url}/#{@project.owner}/projects/#{@project.slug}/experiments/#{@exp.slug}", Thor::Shell::Color::GREEN
|
2424
1321
|
log_end(0)
|
2425
1322
|
end
|
2426
1323
|
rescue => e
|
2427
|
-
|
1324
|
+
puts e
|
1325
|
+
log_end(1, e.message)
|
2428
1326
|
if container
|
2429
1327
|
container.stop()
|
2430
1328
|
end
|
@@ -2451,7 +1349,7 @@ module Cnvrg
|
|
2451
1349
|
end
|
2452
1350
|
end
|
2453
1351
|
|
2454
|
-
desc '', ''
|
1352
|
+
desc '', ''
|
2455
1353
|
method_option :sync_before, :type => :boolean, :aliases => ["-sb", "--sb"], :default => true
|
2456
1354
|
method_option :sync_after, :type => :boolean, :aliases => ["-sa", "--sa"], :default => true
|
2457
1355
|
method_option :title, :type => :string, :aliases => ["-t", "--t"], :default => ""
|
@@ -2490,7 +1388,7 @@ module Cnvrg
|
|
2490
1388
|
machine_name = Socket.gethostname
|
2491
1389
|
begin
|
2492
1390
|
|
2493
|
-
@exp.start(cmd, platform, machine_name, start_commit, title, email_notification, machine_activity
|
1391
|
+
@exp.start(cmd, platform, machine_name, start_commit, title, email_notification, machine_activity)
|
2494
1392
|
unless @exp.slug.nil?
|
2495
1393
|
real = Time.now
|
2496
1394
|
exp_success = true
|
@@ -2560,9 +1458,7 @@ module Cnvrg
|
|
2560
1458
|
exp_success = false
|
2561
1459
|
say "The process exited!", Thor::Shell::Color::RED
|
2562
1460
|
rescue => e
|
2563
|
-
log_end(
|
2564
|
-
say "Error occurred, aborting", Thor::Shell::Color::RED
|
2565
|
-
exit(0)
|
1461
|
+
log_end(1, e.message)
|
2566
1462
|
end
|
2567
1463
|
::Process.wait pid
|
2568
1464
|
cpu_average = cpu_total.inject(0) { |sum, el| sum + el }.to_f / cpu_total.size
|
@@ -2612,7 +1508,7 @@ module Cnvrg
|
|
2612
1508
|
log_end(0)
|
2613
1509
|
end
|
2614
1510
|
rescue => e
|
2615
|
-
log_end(
|
1511
|
+
log_end(1, e.message)
|
2616
1512
|
say "Couldn't run #{cmd}, check your input parameters", Thor::Shell::Color::RED
|
2617
1513
|
exit(1)
|
2618
1514
|
end
|
@@ -2636,33 +1532,23 @@ module Cnvrg
|
|
2636
1532
|
end
|
2637
1533
|
end
|
2638
1534
|
|
2639
|
-
desc '', ''
|
2640
|
-
method_option :sync_before, :type => :boolean, :aliases => ["-sb", "--
|
2641
|
-
method_option :sync_after, :type => :boolean, :aliases => ["-sa", "--
|
2642
|
-
method_option :title, :type => :string, :aliases => ["-t", "--
|
2643
|
-
method_option :log, :type => :boolean, :aliases => ["--
|
2644
|
-
method_option :email_notification, :type => :boolean, :aliases => ["-en", "--
|
2645
|
-
method_option :upload_output, :type => :string, :aliases => ["
|
2646
|
-
method_option :machine_type, :type => :string, :default => ""
|
2647
|
-
method_option :schedule, :type => :string, :aliases => ["
|
2648
|
-
method_option :commit, :type => :string, :aliases => ["
|
2649
|
-
method_option :image, :type => :string, :aliases => ["
|
2650
|
-
method_option :grid, :type => :string, :aliases => ["-g", "--grid"], :default => ""
|
2651
|
-
method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
|
2652
|
-
method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
|
2653
|
-
method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :desc => "ignore following files", :default => ""
|
1535
|
+
desc '', ''
|
1536
|
+
method_option :sync_before, :type => :boolean, :aliases => ["-sb", "--sb"], :default => true
|
1537
|
+
method_option :sync_after, :type => :boolean, :aliases => ["-sa", "--sa"], :default => true
|
1538
|
+
method_option :title, :type => :string, :aliases => ["-t", "--t"], :default => ""
|
1539
|
+
method_option :log, :type => :boolean, :aliases => ["-l", "--l"], :default => false
|
1540
|
+
method_option :email_notification, :type => :boolean, :aliases => ["-en", "--en"], :default => false
|
1541
|
+
method_option :upload_output, :type => :string, :aliases => ["--uo", "-uo"], :default => ""
|
1542
|
+
method_option :machine_type, :type => :string, :aliases => ["--i", "-i"], :default => ""
|
1543
|
+
method_option :schedule, :type => :string, :aliases => ["--s", "-s"], :default => ""
|
1544
|
+
method_option :commit, :type => :string, :aliases => ["--c", "-c"], :default => nil
|
1545
|
+
method_option :image, :type => :string, :aliases => ["--i"], :default => ""
|
2654
1546
|
|
2655
1547
|
def exec_remote(*cmd)
|
2656
1548
|
verify_logged_in(true)
|
2657
1549
|
log_start(__method__, args, options)
|
2658
1550
|
working_dir = is_cnvrg_dir
|
2659
|
-
path_to_cmd = get_cmd_path_in_dir(working_dir, Dir.pwd)
|
2660
|
-
|
2661
1551
|
begin
|
2662
|
-
grid = options["grid"] || nil
|
2663
|
-
data = options["data"] || nil
|
2664
|
-
data_commit = options["data_commit"] || nil
|
2665
|
-
sync_before = options["sync_before"]
|
2666
1552
|
|
2667
1553
|
instance_type = options["machine_type"] || nil
|
2668
1554
|
schedule = options["schedule"] || ""
|
@@ -2684,22 +1570,10 @@ module Cnvrg
|
|
2684
1570
|
new_time = new_time[0, new_time.size-6] #remove timezone
|
2685
1571
|
schedule = "at #{new_time}"
|
2686
1572
|
end
|
2687
|
-
upload_output = options["upload_output"]
|
2688
|
-
time_to_upload = calc_output_time(upload_output)
|
2689
|
-
if time_to_upload==0 or time_to_upload==-1
|
2690
|
-
upload_output_option = "--upload_output=1m"
|
2691
|
-
else
|
2692
|
-
upload_output_option = "--upload_output=#{upload_output}"
|
2693
|
-
end
|
2694
|
-
remote = "--remote=true"
|
2695
|
-
if !instance_type.nil? and instance_type.include? "gpu"
|
2696
|
-
remote= "#{remote} --gpu=true"
|
2697
|
-
end
|
2698
|
-
|
2699
1573
|
options_hash = Hash[options]
|
2700
|
-
options_hash.except!("schedule", "machine_type", "image"
|
1574
|
+
options_hash.except!("schedule", "machine_type", "image")
|
2701
1575
|
exec_options = options_hash.map { |x| "--#{x[0]}=#{x[1]}" }.flatten.join(" ")
|
2702
|
-
command = "#{exec_options}
|
1576
|
+
command = "#{exec_options} --uo=1m #{cmd.flatten.join(" ")}"
|
2703
1577
|
commit_to_run = options["commit"] || nil
|
2704
1578
|
if !schedule.nil? and !schedule.empty?
|
2705
1579
|
|
@@ -2710,20 +1584,19 @@ module Cnvrg
|
|
2710
1584
|
choose_image = options["image"]
|
2711
1585
|
|
2712
1586
|
if !choose_image.nil? and !choose_image.empty?
|
2713
|
-
invoke :set_image,
|
1587
|
+
invoke :set_image,[choose_image]
|
2714
1588
|
end
|
2715
1589
|
image = is_project_with_docker(working_dir)
|
2716
1590
|
if !image or !image.is_docker
|
2717
1591
|
# say "Couldn't find image related to project", Thor::Shell::Color::RED
|
2718
|
-
|
2719
|
-
image_slug = "cnvrg"
|
1592
|
+
default_image_name = "cnvrg"
|
2720
1593
|
if instance_type.eql? "gpu" or instance_type.eql? "gpuxl"
|
2721
|
-
|
1594
|
+
default_image_name = "cnvrg-gpu"
|
2722
1595
|
end
|
2723
1596
|
# default = yes? "use #{default_image_name} default image?", Thor::Shell::Color::YELLOW
|
2724
1597
|
# if default
|
2725
|
-
|
2726
|
-
|
1598
|
+
image = Images.new(working_dir, default_image_name)
|
1599
|
+
image_slug = image.image_slug
|
2727
1600
|
# else
|
2728
1601
|
# exit(0)
|
2729
1602
|
# end
|
@@ -2731,27 +1604,16 @@ module Cnvrg
|
|
2731
1604
|
image_slug = image.image_slug
|
2732
1605
|
end
|
2733
1606
|
|
2734
|
-
invoke :sync, [false], [] if sync_before
|
2735
|
-
|
2736
1607
|
|
2737
|
-
if command.include? "'"
|
2738
|
-
oc = command.to_enum(:scan, /'/).map { Regexp.last_match }
|
2739
|
-
pairs = oc.enum_for(:each_slice, 2).to_a
|
2740
|
-
pairs.each_with_index do |p,i|
|
2741
|
-
add=0
|
2742
|
-
if i!=0
|
2743
|
-
add=2*i
|
2744
|
-
end
|
2745
|
-
total_loc = command[p[0].offset(0)[0]+add..p[1].offset(0)[0]+add]
|
2746
|
-
command[p[0].offset(0)[0]+add..p[1].offset(0)[0]+add] = "\"#{total_loc}\""
|
2747
|
-
end
|
2748
1608
|
|
1609
|
+
invoke :sync, [], []
|
2749
1610
|
|
2750
|
-
end
|
2751
1611
|
say "Running remote experiment", Thor::Shell::Color::BLUE
|
2752
1612
|
exp = Experiment.new(project.owner, project.slug)
|
2753
|
-
|
1613
|
+
|
1614
|
+
res = exp.exec_remote(command, commit_to_run, instance_type, image_slug, schedule, local_timestamp)
|
2754
1615
|
if Cnvrg::CLI.is_response_success(res)
|
1616
|
+
|
2755
1617
|
# if res["result"]["machine"] == -1
|
2756
1618
|
# say "There are no available machines", Thor::Shell::Color::BLUE
|
2757
1619
|
# create = yes? "create new machine?", Thor::Shell::Color::YELLOW
|
@@ -2783,13 +1645,7 @@ module Cnvrg
|
|
2783
1645
|
# end
|
2784
1646
|
# else
|
2785
1647
|
check = Helpers.checkmark()
|
2786
|
-
|
2787
|
-
|
2788
|
-
if res["result"]["grid"]
|
2789
|
-
str = "Running grid search. #{Cnvrg::Helpers.remote_url}/#{project.owner}/projects/#{project.slug}/experiments?grid=#{res["result"]["exp_url"]} "
|
2790
|
-
end
|
2791
|
-
|
2792
|
-
say str, Thor::Shell::Color::GREEN
|
1648
|
+
say "#{check} Experiment's is on: #{Cnvrg::Helpers.remote_url}/#{project.owner}/projects/#{project.slug}/experiments/#{res["result"]["exp_url"]}", Thor::Shell::Color::GREEN
|
2793
1649
|
|
2794
1650
|
exit(0)
|
2795
1651
|
# end
|
@@ -2809,30 +1665,21 @@ module Cnvrg
|
|
2809
1665
|
end
|
2810
1666
|
|
2811
1667
|
desc 'deploy', 'Deploys model to production'
|
2812
|
-
method_option :
|
2813
|
-
method_option :
|
2814
|
-
method_option :
|
2815
|
-
method_option :gpu, :type => :boolean, :aliases => ["--gpu"], :default => false
|
2816
|
-
method_option :gpuxl, :type => :boolean, :aliases => ["--gpuxl"], :default => false
|
2817
|
-
method_option :gpuxxl, :type => :boolean, :aliases => ["--gpuxxl"], :default => false
|
2818
|
-
method_option :schedule, :type => :string, :aliases => ["--schedule", "-s"], :default => ""
|
2819
|
-
|
2820
|
-
method_option :commit, :type => :string, :aliases => ["--commit", "-c"], :default => ""
|
2821
|
-
method_option :workers, :type => :string, :aliases => ["--workers", "-w"], :default => ""
|
2822
|
-
method_option :file_as_input, :type => :boolean, :aliases => ["--input", "-i"], :default => false
|
1668
|
+
method_option :machine_type, :type => :string, :aliases => ["--i", "-i"], :default => ""
|
1669
|
+
method_option :schedule, :type => :string, :aliases => ["--s", "-s"], :default => ""
|
1670
|
+
method_option :commit, :type => :string, :aliases => ["--c", "-c"], :default => ""
|
2823
1671
|
|
2824
1672
|
def deploy(file_to_run, function)
|
2825
1673
|
verify_logged_in(true)
|
2826
1674
|
log_start(__method__, args, options)
|
2827
1675
|
working_dir = is_cnvrg_dir
|
2828
1676
|
begin
|
2829
|
-
instances = {"small" => options["small"], "medium" => options["medium"], "large" => options["large"],
|
2830
|
-
"gpu" => options["gpu"], "gpuxl" => options["gpuxl"], "gpuxxl" => options["gpuxxl"]}
|
2831
|
-
instance_type = get_instance_type(instances)
|
2832
1677
|
|
1678
|
+
instance_type = options["machine_type"] || nil
|
2833
1679
|
schedule = options["schedule"] || ""
|
2834
1680
|
|
2835
1681
|
|
1682
|
+
|
2836
1683
|
if !schedule.nil? and !schedule.empty?
|
2837
1684
|
|
2838
1685
|
local_timestamp = get_schedule_date
|
@@ -2841,34 +1688,26 @@ module Cnvrg
|
|
2841
1688
|
project = Project.new(working_dir)
|
2842
1689
|
commit_to_run = options["commit"] || nil
|
2843
1690
|
|
2844
|
-
workers = options["workers"] || nil
|
2845
|
-
begin
|
2846
|
-
num_workers = workers.to_i
|
2847
|
-
rescue
|
2848
|
-
say "Number of workers should be a number between 1 to 10", Thor::Shell::Color::RED
|
2849
|
-
exit(1)
|
2850
|
-
end
|
2851
|
-
file_as_input = options["file_as_input"] || false
|
2852
|
-
|
2853
1691
|
|
2854
1692
|
image = is_project_with_docker(working_dir)
|
2855
1693
|
if !image or !image.is_docker
|
2856
|
-
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
2860
|
-
|
2861
|
-
|
2862
|
-
|
2863
|
-
|
1694
|
+
say "Couldn't find image related to project", Thor::Shell::Color::RED
|
1695
|
+
default = yes? "use cnvrg default image?", Thor::Shell::Color::YELLOW
|
1696
|
+
if default
|
1697
|
+
image = Images.new(working_dir, "cnvrg")
|
1698
|
+
image_slug = image.image_slug
|
1699
|
+
else
|
1700
|
+
exit(0)
|
1701
|
+
end
|
2864
1702
|
else
|
2865
1703
|
image_slug = image.image_slug
|
2866
1704
|
end
|
2867
1705
|
|
2868
1706
|
|
2869
|
-
invoke :sync, [false], []
|
2870
1707
|
|
2871
|
-
|
1708
|
+
invoke :sync, [], []
|
1709
|
+
|
1710
|
+
res = project.deploy(file_to_run, function, nil, commit_to_run, instance_type, image_slug, schedule, local_timestamp)
|
2872
1711
|
|
2873
1712
|
if Cnvrg::CLI.is_response_success(res)
|
2874
1713
|
|
@@ -2924,37 +1763,27 @@ module Cnvrg
|
|
2924
1763
|
|
2925
1764
|
method_option :kernel, :type => :string, :aliases => ["--k", "-k"], :default => ""
|
2926
1765
|
method_option :notebook_dir, :type => :string, :aliases => ["-n", "--n"], :default => "", :desc => "relative path to notebook dir from current directory"
|
2927
|
-
method_option :local, :type => :boolean, :aliases => ["
|
2928
|
-
method_option :small, :type => :boolean, :aliases => ["
|
2929
|
-
method_option :medium, :type => :boolean, :aliases => ["
|
2930
|
-
method_option :large, :type => :boolean, :aliases => ["
|
1766
|
+
method_option :local, :type => :boolean, :aliases => ["--l"], :default => false
|
1767
|
+
method_option :small, :type => :boolean, :aliases => ["--sm"], :default => false
|
1768
|
+
method_option :medium, :type => :boolean, :aliases => ["--med"], :default => false
|
1769
|
+
method_option :large, :type => :boolean, :aliases => ["--lg"], :default => false
|
2931
1770
|
method_option :gpu, :type => :boolean, :aliases => ["--gpu"], :default => false
|
2932
|
-
method_option :gpuxl, :type => :boolean, :aliases => ["--
|
2933
|
-
|
2934
|
-
method_option :image, :type => :string, :aliases => ["-i", "--image"], :default => ""
|
2935
|
-
method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
|
2936
|
-
method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
|
2937
|
-
|
1771
|
+
method_option :gpuxl, :type => :boolean, :aliases => ["--gxl"], :default => false
|
1772
|
+
desc 'starts a notebook session', 'starts a notebook session remotely or locally'
|
2938
1773
|
|
2939
|
-
|
2940
|
-
|
2941
|
-
def notebook
|
1774
|
+
def notebook()
|
2942
1775
|
local = options["local"]
|
2943
1776
|
notebook_dir = options["notebook_dir"]
|
2944
1777
|
kernel = options["kernel"]
|
2945
|
-
|
2946
|
-
data = options["data"]
|
2947
|
-
data_commit = options["data_commit"]
|
1778
|
+
|
2948
1779
|
if local
|
2949
|
-
invoke :run_notebook, [], :notebook_dir => notebook_dir, :remote => false, :kernel => kernel
|
1780
|
+
invoke :run_notebook, [], :notebook_dir => notebook_dir, :remote => false, :kernel => kernel
|
2950
1781
|
return
|
2951
1782
|
else
|
2952
|
-
instances = {"small" => options["small"], "medium" => options["medium"], "large" => options["large"],
|
2953
|
-
"gpu" => options["gpu"], "gpuxl" => options["gpuxl"], "gpuxxl" => options["gpuxxl"]}
|
1783
|
+
instances = {"small" => options["small"], "medium" => options["medium"], "large" => options["large"], "gpu" => options["gpu"], "gpuxl" => options["gpuxl"]}
|
2954
1784
|
instance_type = get_instance_type(instances)
|
2955
1785
|
|
2956
|
-
invoke :remote_notebook, [], :notebook_dir => notebook_dir, :kernel => kernel, :machine_type => instance_type
|
2957
|
-
:data => data, :data_commit => data_commit
|
1786
|
+
invoke :remote_notebook, [], :notebook_dir => notebook_dir, :kernel => kernel, :machine_type => instance_type
|
2958
1787
|
return
|
2959
1788
|
|
2960
1789
|
end
|
@@ -2963,12 +1792,10 @@ module Cnvrg
|
|
2963
1792
|
end
|
2964
1793
|
|
2965
1794
|
desc 'remote_notebook', 'run notebook server on remote server'
|
2966
|
-
method_option :notebook_dir, :type => :string, :aliases => ["-n"], :default => "", :desc => "relative path to notebook dir from current directory"
|
2967
|
-
method_option :machine_type, :type => :string, :default => ""
|
2968
|
-
method_option :kernel, :type => :string, :aliases => ["--
|
2969
|
-
method_option :image, :type => :string, :aliases => ["
|
2970
|
-
method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
|
2971
|
-
method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
|
1795
|
+
method_option :notebook_dir, :type => :string, :aliases => ["-n", "--n"], :default => "", :desc => "relative path to notebook dir from current directory"
|
1796
|
+
method_option :machine_type, :type => :string, :aliases => ["--i", "-i"], :default => ""
|
1797
|
+
method_option :kernel, :type => :string, :aliases => ["--k", "-k"], :default => ""
|
1798
|
+
method_option :image, :type => :string, :aliases => ["--i"], :default => ""
|
2972
1799
|
|
2973
1800
|
|
2974
1801
|
def remote_notebook()
|
@@ -2980,15 +1807,13 @@ module Cnvrg
|
|
2980
1807
|
notebook_dir = options["notebook_dir"]
|
2981
1808
|
instance_type = options["machine_type"] || nil
|
2982
1809
|
kernel = options["kernel"] || nil
|
2983
|
-
data = options["data"]
|
2984
|
-
data_commit = options["data_commit"]
|
2985
1810
|
|
2986
1811
|
|
2987
1812
|
begin
|
2988
1813
|
choose_image = options["image"]
|
2989
1814
|
|
2990
1815
|
if !choose_image.nil? and !choose_image.empty?
|
2991
|
-
invoke :set_image,
|
1816
|
+
invoke :set_image,[choose_image]
|
2992
1817
|
end
|
2993
1818
|
@image = is_project_with_docker(working_dir)
|
2994
1819
|
if !@image or !@image.is_docker
|
@@ -2999,16 +1824,17 @@ module Cnvrg
|
|
2999
1824
|
end
|
3000
1825
|
# default = yes? "use #{default_image_name} default image?", Thor::Shell::Color::YELLOW
|
3001
1826
|
# if default
|
3002
|
-
|
1827
|
+
@image = Images.new(working_dir, default_image_name)
|
3003
1828
|
# else
|
3004
1829
|
# exit(0)
|
3005
1830
|
# end
|
3006
1831
|
end
|
3007
1832
|
|
3008
|
-
invoke :sync, [
|
1833
|
+
invoke :sync, [], []
|
1834
|
+
|
3009
1835
|
|
3010
1836
|
|
3011
|
-
res = @image.remote_notebook(notebook_dir, instance_type, kernel
|
1837
|
+
res = @image.remote_notebook(notebook_dir, instance_type, kernel)
|
3012
1838
|
if Cnvrg::CLI.is_response_success(res)
|
3013
1839
|
if res["result"]["machine"] == -1
|
3014
1840
|
say "There are no available machines", Thor::Shell::Color::BLUE
|
@@ -3047,7 +1873,7 @@ module Cnvrg
|
|
3047
1873
|
note_url = res["result"]["notebook_url"]
|
3048
1874
|
@image.set_note_url(note_url)
|
3049
1875
|
check = Helpers.checkmark()
|
3050
|
-
say "#{check} Notebook is on: #{Cnvrg::Helpers.remote_url}/#{@
|
1876
|
+
say "#{check} Notebook is on: #{Cnvrg::Helpers.remote_url}/#{@project.owner}/projects/#{@project.slug}/notebook_sessions/show/#{note_url}", Thor::Shell::Color::GREEN
|
3051
1877
|
# Launchy.open(url)
|
3052
1878
|
|
3053
1879
|
exit(0)
|
@@ -3115,8 +1941,9 @@ module Cnvrg
|
|
3115
1941
|
|
3116
1942
|
end
|
3117
1943
|
rescue => e
|
3118
|
-
|
3119
|
-
|
1944
|
+
puts e
|
1945
|
+
log_end(-1)
|
1946
|
+
say "Error occurd, Aborting"
|
3120
1947
|
if container
|
3121
1948
|
container.stop()
|
3122
1949
|
end
|
@@ -3177,8 +2004,9 @@ module Cnvrg
|
|
3177
2004
|
end
|
3178
2005
|
end
|
3179
2006
|
rescue => e
|
3180
|
-
|
3181
|
-
|
2007
|
+
puts e
|
2008
|
+
log_end(-1)
|
2009
|
+
say "Error occurd, Aborting"
|
3182
2010
|
if container
|
3183
2011
|
container.stop()
|
3184
2012
|
end
|
@@ -3195,7 +2023,6 @@ module Cnvrg
|
|
3195
2023
|
method_option :remote, :type => :boolean, :aliases => ["-r", "--r"], :default => false, :desc => "run on remote machine"
|
3196
2024
|
method_option :kernel, :type => :string, :aliases => ["-k", "--k"], :default => "", :desc => "default kernel"
|
3197
2025
|
method_option :verbose, :type => :boolean, :aliases => ["--v"], :default => false
|
3198
|
-
method_option :image, :type => :string, :aliases => ["-i"], :default => ""
|
3199
2026
|
|
3200
2027
|
def run_notebook
|
3201
2028
|
|
@@ -3209,7 +2036,7 @@ module Cnvrg
|
|
3209
2036
|
notebook_dir = options["notebook_dir"]
|
3210
2037
|
remote = options["remote"] || false
|
3211
2038
|
kernel = options["kernel"] || ""
|
3212
|
-
|
2039
|
+
|
3213
2040
|
|
3214
2041
|
if notebook_dir.empty?
|
3215
2042
|
notebook_dir = project_dir
|
@@ -3217,148 +2044,107 @@ module Cnvrg
|
|
3217
2044
|
|
3218
2045
|
notebook_dir = project_dir+ notebook_dir
|
3219
2046
|
end
|
3220
|
-
|
3221
|
-
|
3222
|
-
if !choose_image.nil? and !choose_image.empty?
|
3223
|
-
invoke :set_image, [choose_image]
|
3224
|
-
end
|
3225
|
-
|
2047
|
+
say "Linking notebook directory to: #{File.basename notebook_dir}", Thor::Shell::Color::BLUE
|
3226
2048
|
image = is_project_with_docker(Dir.pwd)
|
3227
|
-
if !
|
3228
|
-
|
3229
|
-
if
|
3230
|
-
say "Could not find jupyter, Is it installed?", Thor::Shell::Color::RED
|
3231
|
-
exit(1)
|
3232
|
-
end
|
3233
|
-
|
3234
|
-
|
3235
|
-
cmd = "jupyter-notebook --port=8888"
|
3236
|
-
PTY.spawn(cmd) do |stdout, stdin, pid, stderr|
|
3237
|
-
begin
|
3238
|
-
notebooks_pid = pid
|
3239
|
-
stdout.each do |line|
|
3240
|
-
puts line
|
3241
|
-
|
3242
|
-
end
|
3243
|
-
|
3244
|
-
rescue Errno::EIO => e
|
3245
|
-
# break
|
3246
|
-
rescue Errno::ENOENT
|
3247
|
-
log_end(1, "command #{cmd} isn't valid")
|
3248
|
-
|
3249
|
-
|
3250
|
-
say "command \"#{cmd}\" couldn't be executed, verify command is valid", Thor::Shell::Color::RED
|
3251
|
-
rescue PTY::ChildExited
|
3252
|
-
log_end(1, "proccess exited")
|
3253
|
-
say "The process exited!", Thor::Shell::Color::RED
|
3254
|
-
rescue => e
|
3255
|
-
log_end(-1, e.message)
|
3256
|
-
say "Error occurred,aborting", Thor::Shell::Color::RED
|
3257
|
-
exit(0)
|
3258
|
-
|
3259
|
-
end
|
3260
|
-
|
2049
|
+
if image and image.is_docker and !remote
|
2050
|
+
container= image.get_container
|
2051
|
+
if !container
|
3261
2052
|
|
2053
|
+
say "Couldn't create container with image #{image.image_name}:#{image.image_tag}", Thor::Shell::Color::RED
|
2054
|
+
exit(1)
|
3262
2055
|
end
|
2056
|
+
else
|
2057
|
+
say "Project is not configured with any image", Thor::Shell::Color::RED
|
2058
|
+
exit(1)
|
3263
2059
|
|
3264
2060
|
end
|
2061
|
+
if options["verbose"]
|
2062
|
+
say "Syncing project before running", Thor::Shell::Color::BLUE
|
2063
|
+
say 'Checking for new updates from remote version', Thor::Shell::Color::BLUE
|
2064
|
+
end
|
2065
|
+
@project = Project.new(project_dir)
|
3265
2066
|
|
3266
|
-
|
3267
|
-
container= image.get_container
|
3268
|
-
if !container
|
3269
|
-
say "Couldn't start docker container", Thor::Shell::Color::RED
|
3270
|
-
exit(1)
|
2067
|
+
start_commit = @project.last_local_commit
|
3271
2068
|
|
2069
|
+
if (note_slug=image.note_slug)
|
2070
|
+
say "There is a running notebook session in: https://cnvrg.io/#{@project.owner}/projects/#{@project.slug}/notebook_sessions/show/#{note_slug}", Thor::Shell::Color::BLUE
|
2071
|
+
new = yes? "Create a new session?", Thor::Shell::Color::YELLOW
|
2072
|
+
if !new
|
2073
|
+
exit(0)
|
3272
2074
|
end
|
3273
2075
|
|
3274
|
-
|
3275
|
-
|
3276
|
-
|
3277
|
-
|
3278
|
-
|
2076
|
+
end
|
2077
|
+
invoke :sync, [], :verbose => options["verbose"]
|
2078
|
+
say "Done Syncing", Thor::Shell::Color::BLUE if options["verbose"]
|
2079
|
+
#replace url
|
2080
|
+
base_url = get_base_url()
|
3279
2081
|
|
3280
|
-
|
2082
|
+
local_url = "/#{@project.owner}/projects/#{@project.slug}/notebook_sessions/view/local"
|
2083
|
+
command = ["/bin/bash","-lc","sed -i 's#c.NotebookApp.base_url = .*#c.NotebookApp.base_url = \"#{local_url}\"#' /home/ds/.jupyter/jupyter_notebook_config.py"]
|
2084
|
+
container.exec(command, tty: true)
|
2085
|
+
container.stop()
|
2086
|
+
container.start()
|
3281
2087
|
|
3282
|
-
|
3283
|
-
|
3284
|
-
new = yes? "Create a new session?", Thor::Shell::Color::YELLOW
|
3285
|
-
if !new
|
3286
|
-
exit(0)
|
3287
|
-
end
|
2088
|
+
@note = Experiment.new(@project.owner, @project.slug)
|
2089
|
+
port = image.container_port()
|
3288
2090
|
|
3289
|
-
|
3290
|
-
|
3291
|
-
|
3292
|
-
|
3293
|
-
|
3294
|
-
|
3295
|
-
|
3296
|
-
command = ["/bin/bash", "-lc", "sed -i 's#c.NotebookApp.base_url = .*#c.NotebookApp.base_url = \"#{local_url}\"#' /home/ds/.jupyter/jupyter_notebook_config.py"]
|
3297
|
-
container.exec(command, tty: true)
|
3298
|
-
container.stop()
|
3299
|
-
container.start()
|
3300
|
-
sleep(7)
|
3301
|
-
@note = Experiment.new(@project.owner, @project.slug)
|
3302
|
-
port = image.container_port()
|
3303
|
-
|
3304
|
-
command = ["/bin/bash", "-lc", "jupyter notebook list"]
|
3305
|
-
list = container.exec(command, tty: true)[0]
|
3306
|
-
if list.empty? or list.nil?
|
3307
|
-
say "Couldn't start notebook server", Thor::Shell::Color::RED
|
3308
|
-
log_end(1, "can't start notebook server")
|
3309
|
-
exit(1)
|
3310
|
-
end
|
2091
|
+
command = ["/bin/bash", "-lc", "jupyter notebook list"]
|
2092
|
+
list = container.exec(command, tty: true)[0]
|
2093
|
+
if list.empty? or list.nil?
|
2094
|
+
say "Couldn't start notebook server", Thor::Shell::Color::RED
|
2095
|
+
log_end(1, "can't start notebook server")
|
2096
|
+
exit(1)
|
2097
|
+
end
|
3311
2098
|
|
3312
|
-
|
3313
|
-
|
3314
|
-
if r.include? "http"
|
3315
|
-
result = r
|
3316
|
-
end
|
3317
|
-
end
|
3318
|
-
token = result.to_s.split("::")[0].to_s.match(/(token=)(.+)\s/)[2]
|
2099
|
+
url = list[list.size-1].split(" ::")
|
2100
|
+
token = url[0][(url[0].index("=")+1)..-1]
|
3319
2101
|
|
3320
|
-
|
2102
|
+
# machine_activity = @note.get_machine_activity(project_dir)
|
3321
2103
|
|
3322
2104
|
|
3323
|
-
|
3324
|
-
|
3325
|
-
|
2105
|
+
slug = @note.start_notebook_session(kernel, start_commit, token, port, false, notebook_dir)
|
2106
|
+
image.set_note_url(slug)
|
2107
|
+
note_url = "http://localhost:#{port}/#{@project.owner}/projects/#{@project.slug}/notebook_sessions/view/local/?token=#{token}"
|
3326
2108
|
|
3327
2109
|
|
3328
|
-
|
3329
|
-
|
2110
|
+
if !note_url.empty?
|
2111
|
+
check = Helpers.checkmark()
|
3330
2112
|
|
3331
|
-
|
3332
|
-
|
3333
|
-
|
3334
|
-
|
3335
|
-
|
3336
|
-
|
3337
|
-
end
|
2113
|
+
say "#{check} Notebook server started successfully", Thor::Shell::Color::GREEN
|
2114
|
+
Launchy.open(note_url)
|
2115
|
+
else
|
2116
|
+
say "Couldn't start notebook server", Thor::Shell::Color::RED
|
2117
|
+
log_end(1, "can't start notebook server")
|
2118
|
+
exit(1)
|
3338
2119
|
end
|
3339
2120
|
|
3340
|
-
|
2121
|
+
# jup =verify_software_installed("jupyter-notebook")
|
2122
|
+
# logs = `#{jup} --no-browser --ip=0.0.0.0 --notebook-dir=#{notebook_dir}`
|
2123
|
+
# url = URI.extract(logs).reject { |x| x if !x.include? "http" }.uniq![0]
|
2124
|
+
# if !url.empty?
|
2125
|
+
# check = Helpers.checkmark()
|
2126
|
+
#
|
2127
|
+
# say "#{check} Notebook server started successfully, view notebook in url: #{url}", Thor::Shell::Color::GREEN
|
2128
|
+
# log_end(0)
|
2129
|
+
# else
|
2130
|
+
# say "Couldn't start notebook server", Thor::Shell::Color::RED
|
2131
|
+
# log_end(1, "can't start notebook server")
|
2132
|
+
# exit(1)
|
2133
|
+
# end
|
3341
2134
|
rescue => e
|
3342
|
-
log_end(-1
|
2135
|
+
log_end(-1)
|
2136
|
+
puts e
|
3343
2137
|
say "Error occurd, aborting", Thor::Shell::Color::RED
|
3344
2138
|
if container
|
3345
2139
|
container.stop()
|
3346
2140
|
end
|
3347
2141
|
rescue SignalException
|
3348
|
-
|
3349
|
-
|
3350
|
-
|
3351
|
-
|
3352
|
-
|
3353
|
-
invoke :sync, [false], []
|
3354
|
-
else
|
3355
|
-
log_end(-1)
|
3356
|
-
|
3357
|
-
if container
|
3358
|
-
container.stop()
|
3359
|
-
end
|
2142
|
+
log_end(-1)
|
2143
|
+
if container
|
2144
|
+
container.stop()
|
3360
2145
|
end
|
3361
|
-
|
2146
|
+
say "Aborting"
|
2147
|
+
exit(1)
|
3362
2148
|
end
|
3363
2149
|
|
3364
2150
|
|
@@ -3379,7 +2165,7 @@ module Cnvrg
|
|
3379
2165
|
|
3380
2166
|
|
3381
2167
|
say 'Checking for new updates from remote version', Thor::Shell::Color::BLUE if options["verbose"]
|
3382
|
-
invoke :sync, [
|
2168
|
+
invoke :sync, [], :verbose => options["verbose"]
|
3383
2169
|
|
3384
2170
|
say "Done Syncing", Thor::Shell::Color::BLUE if options["verbose"]
|
3385
2171
|
|
@@ -3424,7 +2210,8 @@ module Cnvrg
|
|
3424
2210
|
exit(0)
|
3425
2211
|
end
|
3426
2212
|
rescue => e
|
3427
|
-
|
2213
|
+
puts e
|
2214
|
+
log_end(-1)
|
3428
2215
|
say "Error occurd, aborting"
|
3429
2216
|
if container
|
3430
2217
|
container.stop()
|
@@ -3474,7 +2261,8 @@ module Cnvrg
|
|
3474
2261
|
|
3475
2262
|
log_end(0)
|
3476
2263
|
rescue => e
|
3477
|
-
log_end(-1
|
2264
|
+
log_end(-1)
|
2265
|
+
puts e
|
3478
2266
|
say "Error occurd, aborting"
|
3479
2267
|
if container
|
3480
2268
|
container.stop()
|
@@ -3537,12 +2325,14 @@ module Cnvrg
|
|
3537
2325
|
|
3538
2326
|
log_end(0)
|
3539
2327
|
rescue => e
|
3540
|
-
log_end(-1
|
2328
|
+
log_end(-1)
|
2329
|
+
puts e
|
3541
2330
|
say "Error occurd, aborting"
|
3542
2331
|
if container
|
3543
2332
|
container.stop()
|
3544
2333
|
end
|
3545
2334
|
rescue SignalException
|
2335
|
+
log_End(-1)
|
3546
2336
|
if container
|
3547
2337
|
container.stop()
|
3548
2338
|
end
|
@@ -3551,100 +2341,7 @@ module Cnvrg
|
|
3551
2341
|
end
|
3552
2342
|
|
3553
2343
|
end
|
3554
|
-
|
3555
|
-
method_option :small, :type => :boolean, :aliases => ["-sm", "--small"], :default => false
|
3556
|
-
method_option :medium, :type => :boolean, :aliases => ["-md", "--medium"], :default => false
|
3557
|
-
method_option :large, :type => :boolean, :aliases => ["-lg", "--large"], :default => false
|
3558
|
-
method_option :gpu, :type => :boolean, :aliases => ["--gpu"], :default => false
|
3559
|
-
method_option :gpuxl, :type => :boolean, :aliases => ["--gpuxl"], :default => false
|
3560
|
-
method_option :gpuxxl, :type => :boolean, :aliases => ["--gpuxxl"], :default => false
|
3561
|
-
method_option :image, :type => :string, :aliases => ["-i","--image"], :default => ""
|
3562
|
-
method_option :public, :type => :boolean, :aliases => ["-p","--public"], :default => false
|
3563
|
-
method_option :base, :type => :boolean, :aliases => ["-b","--base"], :default => false
|
3564
|
-
method_option :python3, :type => :boolean, :aliases => ["--python3"], :default => false
|
3565
|
-
|
3566
|
-
desc 'create_custom_image', 'run commands inside containers', :hide=>true
|
3567
|
-
|
3568
|
-
def create_custom_image(image_name)
|
3569
|
-
begin
|
3570
|
-
verify_logged_in(false)
|
3571
|
-
log_start(__method__, args, options)
|
3572
|
-
instances = {"small" => options["small"], "medium" => options["medium"], "large" => options["large"],
|
3573
|
-
"gpu" => options["gpu"], "gpuxl" => options["gpuxl"], "gpuxxl" => options["gpuxxl"]}
|
3574
|
-
instance_type = get_instance_type(instances)
|
3575
|
-
image_extend = options["image"]
|
3576
|
-
public = options["public"]
|
3577
|
-
base = options["base"]
|
3578
|
-
python3 = options["python3"]
|
3579
|
-
owner = CLI.get_owner
|
3580
|
-
checks = Helpers.checkmark()
|
3581
|
-
|
3582
|
-
say "Creating machine for custom image, this may take a few moments...", Thor::Shell::Color::BLUE
|
3583
|
-
|
3584
|
-
resp = Images.create_new_custom_image(instance_type,owner,image_name,public,base,image_extend,python3)
|
3585
|
-
if Cnvrg::CLI.is_response_success(resp,false)
|
3586
|
-
image_slug = resp["result"]["slug"]
|
3587
|
-
container = resp["result"]["machine_c"]
|
3588
|
-
say "#{checks} Created image and machine successfully", Thor::Shell::Color::GREEN
|
3589
|
-
say "Connecting to machine", Thor::Shell::Color::BLUE
|
3590
|
-
ssh = Ssh.new(resp)
|
3591
|
-
if !ssh.is_ssh
|
3592
|
-
say "Couldn't connect to machine,aborting", Thor::Shell::Color::RED
|
3593
|
-
Images.revoke_custom_new_image(owner, image_slug)
|
3594
|
-
log_end(-1,"Couldn't connect to machine,aborting")
|
3595
|
-
end
|
3596
|
-
say "run command until ctrl + c initiates", Thor::Shell::Color::BLUE
|
3597
|
-
begin
|
3598
|
-
|
3599
|
-
while true
|
3600
|
-
command = ask("$>")
|
3601
|
-
puts ssh.exec_command(command)
|
3602
|
-
end
|
3603
|
-
|
3604
|
-
rescue SignalException
|
3605
|
-
say "Commiting Image..", Thor::Shell::Color::BLUE
|
3606
|
-
|
3607
|
-
end
|
3608
|
-
resp = Images.commit_custom_image(owner,image_slug)
|
3609
|
-
if Cnvrg::CLI.is_response_success(resp,false)
|
3610
|
-
say "#{checks} Image commited successfuly, email will be sent when image is ready", Thor::Shell::Color::GREEN
|
3611
|
-
end
|
3612
|
-
if ssh
|
3613
|
-
ssh.close_ssh()
|
3614
|
-
end
|
3615
|
-
|
3616
|
-
|
3617
|
-
|
3618
|
-
|
3619
|
-
|
3620
|
-
|
3621
|
-
|
3622
|
-
end
|
3623
|
-
rescue =>e
|
3624
|
-
puts e
|
3625
|
-
if image_slug
|
3626
|
-
Images.revoke_custom_new_image(owner, image_slug)
|
3627
|
-
end
|
3628
|
-
if ssh
|
3629
|
-
ssh.close_ssh()
|
3630
|
-
end
|
3631
|
-
|
3632
|
-
|
3633
|
-
rescue SignalException
|
3634
|
-
if image_slug
|
3635
|
-
Images.revoke_custom_new_image(owner, image_slug)
|
3636
|
-
end
|
3637
|
-
if ssh
|
3638
|
-
ssh.close_ssh
|
3639
|
-
end
|
3640
|
-
say "\nAborting"
|
3641
|
-
exit(1)
|
3642
|
-
end
|
3643
|
-
|
3644
|
-
end
|
3645
|
-
|
3646
|
-
|
3647
|
-
desc 'build', 'run commands inside containers'
|
2344
|
+
desc 'run commands inside containers', 'run commands inside containers'
|
3648
2345
|
method_option :install, :type => :string, :aliases => ["--i"], :default => nil, :desc => "Install from the given instructions file"
|
3649
2346
|
|
3650
2347
|
def build(*cmd)
|
@@ -3655,10 +2352,10 @@ module Cnvrg
|
|
3655
2352
|
working_dir = is_cnvrg_dir
|
3656
2353
|
install_file = options["install"] || nil
|
3657
2354
|
if !install_file.nil?
|
3658
|
-
commands = File.open(install_file).read.chop.gsub!("\n",
|
2355
|
+
commands = File.open(install_file).read.chop.gsub!("\n",",").split(",")
|
3659
2356
|
|
3660
2357
|
else
|
3661
|
-
commands
|
2358
|
+
commands = [cmd.join(" ")]
|
3662
2359
|
end
|
3663
2360
|
|
3664
2361
|
|
@@ -3676,25 +2373,25 @@ module Cnvrg
|
|
3676
2373
|
|
3677
2374
|
end
|
3678
2375
|
commands.each do |c|
|
3679
|
-
|
3680
|
-
|
3681
|
-
|
3682
|
-
|
3683
|
-
|
3684
|
-
|
2376
|
+
if c.include? "pip"
|
2377
|
+
c.sub("pip","/opt/ds/bin/pip")
|
2378
|
+
end
|
2379
|
+
if c.include? "pip3"
|
2380
|
+
c.sub("pip3","/opt/ds3/bin/pip3")
|
2381
|
+
end
|
3685
2382
|
|
3686
|
-
|
3687
|
-
|
3688
|
-
|
3689
|
-
|
3690
|
-
|
3691
|
-
|
3692
|
-
|
2383
|
+
say "Running #{c}", Thor::Shell::Color::BLUE
|
2384
|
+
command = ["/bin/bash", "-lc", "#{c}"]
|
2385
|
+
res = container.exec(command, tty: false)
|
2386
|
+
if res[2] != 0
|
2387
|
+
say "Could not run command: #{c}, #{res[1][0]}" , Thor::Shell::Color::RED
|
2388
|
+
container.stop()
|
2389
|
+
log_end(0)
|
3693
2390
|
|
3694
|
-
|
3695
|
-
|
3696
|
-
|
3697
|
-
|
2391
|
+
exit(1)
|
2392
|
+
end
|
2393
|
+
say res[0].join("\n")
|
2394
|
+
image.store_image_build_commands(working_dir,c)
|
3698
2395
|
end
|
3699
2396
|
|
3700
2397
|
checks = Helpers.checkmark()
|
@@ -3705,7 +2402,8 @@ module Cnvrg
|
|
3705
2402
|
|
3706
2403
|
log_end(0)
|
3707
2404
|
rescue => e
|
3708
|
-
log_end(-1
|
2405
|
+
log_end(-1)
|
2406
|
+
puts e
|
3709
2407
|
say "Error occurd, aborting", Thor::Shell::Color::RED
|
3710
2408
|
if container
|
3711
2409
|
container.stop()
|
@@ -3754,9 +2452,8 @@ module Cnvrg
|
|
3754
2452
|
log_end(0)
|
3755
2453
|
return new_image.id
|
3756
2454
|
rescue => e
|
3757
|
-
|
3758
|
-
|
3759
|
-
exit(1)
|
2455
|
+
puts e
|
2456
|
+
|
3760
2457
|
rescue SignalException
|
3761
2458
|
log_end(-1)
|
3762
2459
|
say "\nAborting"
|
@@ -3799,7 +2496,7 @@ module Cnvrg
|
|
3799
2496
|
|
3800
2497
|
end
|
3801
2498
|
|
3802
|
-
desc 'push', 'push image to cnvrg repository'
|
2499
|
+
desc 'push image to cnvrg repository', 'push image to cnvrg repository'
|
3803
2500
|
|
3804
2501
|
def push(*name)
|
3805
2502
|
verify_logged_in(true)
|
@@ -3817,24 +2514,22 @@ module Cnvrg
|
|
3817
2514
|
end
|
3818
2515
|
if !name.nil? and !name.empty?
|
3819
2516
|
if name.include? " "
|
3820
|
-
name.gsub!(" ",
|
2517
|
+
name.gsub!(" ","_")
|
3821
2518
|
end
|
3822
2519
|
end
|
3823
|
-
stored_commands = File.open(working_dir+"/.cnvrg/custom_image.txt").read.chop.gsub("\n",
|
2520
|
+
stored_commands = File.open(working_dir+"/.cnvrg/custom_image.txt").read.chop.gsub("\n",",")
|
3824
2521
|
if stored_commands.nil? or stored_commands.empty?
|
3825
2522
|
say "Nothing to push", Thor::Shell::Color::BLUE
|
3826
2523
|
exit(0)
|
3827
2524
|
end
|
3828
2525
|
|
3829
2526
|
say "Pushing new image", Thor::Shell::Color::BLUE
|
3830
|
-
if image.create_custom_image(name,
|
2527
|
+
if image.create_custom_image(name,working_dir,stored_commands)
|
3831
2528
|
|
3832
2529
|
say "Image was updated successfully", Thor::Shell::Color::GREEN
|
3833
2530
|
end
|
3834
2531
|
rescue => e
|
3835
|
-
|
3836
|
-
say "error occurred, aborting"
|
3837
|
-
|
2532
|
+
puts e
|
3838
2533
|
end
|
3839
2534
|
end
|
3840
2535
|
|
@@ -3896,8 +2591,8 @@ module Cnvrg
|
|
3896
2591
|
exit(1)
|
3897
2592
|
end
|
3898
2593
|
rescue => e
|
3899
|
-
|
3900
|
-
|
2594
|
+
puts e
|
2595
|
+
|
3901
2596
|
rescue SignalException
|
3902
2597
|
log_end(-1)
|
3903
2598
|
|
@@ -3906,7 +2601,7 @@ module Cnvrg
|
|
3906
2601
|
end
|
3907
2602
|
end
|
3908
2603
|
|
3909
|
-
desc '', ''
|
2604
|
+
desc '', ''
|
3910
2605
|
|
3911
2606
|
def upload_log()
|
3912
2607
|
log_path = '/home/ds/app/uwsgi.log'
|
@@ -3915,32 +2610,28 @@ module Cnvrg
|
|
3915
2610
|
|
3916
2611
|
end
|
3917
2612
|
|
3918
|
-
desc '', ''
|
2613
|
+
desc '', ''
|
3919
2614
|
|
3920
2615
|
def exec_container(container_id, *cmd)
|
3921
2616
|
container = Docker::Container.get(container_id)
|
3922
2617
|
container.start()
|
3923
2618
|
cnvrg_command = cmd.join(" ")
|
3924
2619
|
command = ["/bin/bash", "-lc", "#{cnvrg_command}"]
|
3925
|
-
res = container.exec(command, tty: true,
|
2620
|
+
res = container.exec(command, tty: true,wait:5400)[0]
|
3926
2621
|
say res
|
2622
|
+
|
3927
2623
|
end
|
3928
2624
|
|
3929
|
-
desc '', ''
|
2625
|
+
desc '', ''
|
3930
2626
|
|
3931
2627
|
def port_container(container_id)
|
3932
2628
|
container = Docker::Container.get(container_id)
|
3933
2629
|
say container.json["HostConfig"]["PortBindings"]["8888/tcp"][0]["HostPort"]
|
3934
|
-
end
|
3935
2630
|
|
3936
|
-
desc '', '', :hide => true
|
3937
2631
|
|
3938
|
-
def tensor_port_container(container_id)
|
3939
|
-
container = Docker::Container.get(container_id)
|
3940
|
-
say container.json["HostConfig"]["PortBindings"]["6006/tcp"][0]["HostPort"]
|
3941
2632
|
end
|
3942
2633
|
|
3943
|
-
desc '', ''
|
2634
|
+
desc '', ''
|
3944
2635
|
|
3945
2636
|
def stop_container(container_id)
|
3946
2637
|
container = Docker::Container.get(container_id)
|
@@ -3949,13 +2640,13 @@ module Cnvrg
|
|
3949
2640
|
|
3950
2641
|
end
|
3951
2642
|
|
3952
|
-
desc '', ''
|
3953
|
-
method_option :login, :type => :string, :aliases => ["-l"], :default => ""
|
3954
|
-
method_option :app_dir, :type => :string, :aliases => ["-d"], :default => "/home/ds/notebooks"
|
3955
|
-
method_option :cmd, :type => :string, :aliases => ["-c"], :default => "/usr/local/cnvrg/run_ipython.sh"
|
2643
|
+
desc '', ''
|
2644
|
+
method_option :login, :type => :string, :aliases => ["-l", "--l"], :default => ""
|
2645
|
+
method_option :app_dir, :type => :string, :aliases => ["-d", "--d"], :default => "/home/ds/notebooks"
|
2646
|
+
method_option :cmd, :type => :string, :aliases => ["-c", "--c"], :default => "/usr/local/cnvrg/run_ipython.sh"
|
3956
2647
|
|
3957
2648
|
|
3958
|
-
def config_remote(image_name, port=7654
|
2649
|
+
def config_remote(image_name, port=7654)
|
3959
2650
|
local_images = Docker::Image.all
|
3960
2651
|
|
3961
2652
|
docker_image_local = local_images.map { |x| x.info["RepoTags"] }.flatten.select { |y| y.eql? "#{image_name}:latest" }.flatten
|
@@ -3968,25 +2659,20 @@ module Cnvrg
|
|
3968
2659
|
login_content = options["login"]
|
3969
2660
|
app_dir = options["app_dir"]
|
3970
2661
|
cmd= options["cmd"]
|
3971
|
-
volume_from = options["volume"]
|
3972
2662
|
|
3973
2663
|
image_settings = {
|
3974
2664
|
'Image' => "#{image_name}:latest",
|
3975
|
-
|
2665
|
+
'User' => 'ds',
|
3976
2666
|
'Cmd' => cmd,
|
3977
2667
|
'WorkingDir' => app_dir,
|
3978
2668
|
'ExposedPorts' => {
|
3979
2669
|
'8888/tcp' => {},
|
3980
2670
|
},
|
3981
2671
|
'HostConfig' => {
|
3982
|
-
'Binds'=> ["/var/run/docker.sock:/var/run/docker.sock","/usr/bin/docker:/usr/bin/docker" ],
|
3983
2672
|
'PortBindings' => {
|
3984
2673
|
'8888/tcp' => [
|
3985
2674
|
{'HostPort' => "#{port}", 'HostIp' => 'localhost'}
|
3986
2675
|
],
|
3987
|
-
'6006/tcp' => [
|
3988
|
-
{'HostPort' => "#{tensport}", 'HostIp' => 'localhost'}
|
3989
|
-
],
|
3990
2676
|
},
|
3991
2677
|
},
|
3992
2678
|
}
|
@@ -3994,104 +2680,21 @@ module Cnvrg
|
|
3994
2680
|
container.start()
|
3995
2681
|
command = ["/bin/bash", "-lc", "sudo echo -e \"#{login_content}\" >/home/ds/.netrc"]
|
3996
2682
|
container.exec(command, tty: true)
|
3997
|
-
|
3998
|
-
# container.exec(command, tty: true)
|
3999
|
-
# command = ["/bin/bash", "-lc", "mkdir /home/ds/.cnvrg/tmp"]
|
4000
|
-
# container.exec(command, tty: true)
|
4001
|
-
command = ["/bin/bash", "-lc", "sudo chown -R ds:ds /home/ds/.netrc"]
|
4002
|
-
container.exec(command, tty: true)
|
4003
|
-
command = ["/bin/bash", "-lc", "sudo chmod 0600 /home/ds/.netrc"]
|
2683
|
+
command = ["/bin/bash", "-lc", "mkdir /home/ds/.cnvrg"]
|
4004
2684
|
container.exec(command, tty: true)
|
4005
|
-
|
4006
|
-
rescue => e
|
4007
|
-
puts e
|
4008
|
-
if e.message.include? "is not running"
|
4009
|
-
return config_remote(image_name, port-1, tensport-1)
|
4010
|
-
end
|
4011
|
-
|
4012
|
-
if container
|
4013
|
-
container.kill()
|
4014
|
-
end
|
4015
|
-
return false
|
4016
|
-
end
|
4017
|
-
end
|
4018
|
-
|
4019
|
-
|
4020
|
-
desc '', '', :hide => true
|
4021
|
-
method_option :login, :type => :string, :aliases => ["-l"], :default => ""
|
4022
|
-
|
4023
|
-
def config_netrc(container)
|
4024
|
-
|
4025
|
-
login_content = options["login"]
|
4026
|
-
|
4027
|
-
container = Docker::Container.get(container)
|
4028
|
-
command = ["/bin/bash", "-lc", "sudo echo -e \"#{login_content}\" >/home/ds/.netrc"]
|
4029
|
-
container.exec(command, tty: true)
|
4030
|
-
command = ["/bin/bash", "-lc", "sudo chown -R ds:ds /home/ds/.netrc"]
|
4031
|
-
container.exec(command, tty: true)
|
4032
|
-
command = ["/bin/bash", "-lc", "sudo chmod 0600 /home/ds/.netrc"]
|
4033
|
-
container.exec(command, tty: true)
|
4034
|
-
say "OK"
|
4035
|
-
|
4036
|
-
end
|
4037
|
-
|
4038
|
-
desc '', '', :hide => true
|
4039
|
-
method_option :login, :type => :string, :aliases => ["-l", "--l"], :default => ""
|
4040
|
-
method_option :app_dir, :type => :string, :aliases => ["-d", "--d"], :default => "/home/ds/notebooks"
|
4041
|
-
method_option :cmd, :type => :string, :aliases => ["-c", "--c"], :default => "/usr/local/cnvrg/run_ipython.sh"
|
4042
|
-
|
4043
|
-
|
4044
|
-
def config_remote_gpu(image_name, port=7654, tensport=6006)
|
4045
|
-
local_images = Docker::Image.all
|
4046
|
-
|
4047
|
-
docker_image_local = local_images.map { |x| x.info["RepoTags"] }.flatten.select { |y| y.eql? "#{image_name}:latest" }.flatten
|
4048
|
-
if docker_image_local.empty?
|
4049
|
-
say "no image"
|
4050
|
-
exit(1)
|
4051
|
-
end
|
4052
|
-
|
4053
|
-
begin
|
4054
|
-
login_content = options["login"]
|
4055
|
-
app_dir = options["app_dir"]
|
4056
|
-
cmd= options["cmd"]
|
4057
|
-
|
4058
|
-
# image_settings = {
|
4059
|
-
# 'Image' => "#{image_name}:latest",
|
4060
|
-
# 'User' => 'ds',
|
4061
|
-
# 'Cmd' => cmd,
|
4062
|
-
# 'WorkingDir' => app_dir,
|
4063
|
-
# 'ExposedPorts' => {
|
4064
|
-
# '8888/tcp' => {},
|
4065
|
-
# },
|
4066
|
-
# 'HostConfig' => {
|
4067
|
-
# 'PortBindings' => {
|
4068
|
-
# '8888/tcp' => [
|
4069
|
-
# {'HostPort' => "#{port}", 'HostIp' => 'localhost'}
|
4070
|
-
# ],
|
4071
|
-
# '6006/tcp' => [
|
4072
|
-
# {'HostPort' => "6006", 'HostIp' => 'localhost'}
|
4073
|
-
# ],
|
4074
|
-
# },
|
4075
|
-
# },
|
4076
|
-
# }
|
4077
|
-
|
4078
|
-
container_id = `nvidia-docker run -itd -p #{port}:8888 -p #{tensport}:6006 -w #{app_dir} -v /usr/bin/nvidia-smi:/usr/bin/nvidia-smi -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker #{image_name}:latest #{cmd} `
|
4079
|
-
container_id = container_id.gsub("\n", "")
|
4080
|
-
container = Docker::Container.get(container_id)
|
4081
|
-
# container.start()
|
4082
|
-
command = ["/bin/bash", "-lc", "sudo echo -e \"#{login_content}\" >/home/ds/.netrc"]
|
2685
|
+
command = ["/bin/bash", "-lc", "mkdir /home/ds/.cnvrg/tmp"]
|
4083
2686
|
container.exec(command, tty: true)
|
4084
|
-
command = ["/bin/bash", "-lc", "sudo chown -R ds
|
2687
|
+
command = ["/bin/bash", "-lc", "sudo chown -R ds /home/ds/.cnvrg /home/ds/.netrc"]
|
4085
2688
|
container.exec(command, tty: true)
|
4086
2689
|
command = ["/bin/bash", "-lc", "sudo chmod 0600 /home/ds/.netrc"]
|
4087
2690
|
container.exec(command, tty: true)
|
4088
|
-
say "#{container.id}:#{port}
|
2691
|
+
say "#{container.id}:#{port}"
|
4089
2692
|
rescue => e
|
4090
2693
|
if e.message.include? "is not running"
|
4091
|
-
|
4092
|
-
return config_remote_gpu(image_name, port-1, tensport-1)
|
2694
|
+
return config_remote(image_name, port-1)
|
4093
2695
|
end
|
4094
|
-
|
2696
|
+
puts "error"
|
2697
|
+
puts e
|
4095
2698
|
if container
|
4096
2699
|
container.kill()
|
4097
2700
|
end
|
@@ -4099,8 +2702,8 @@ module Cnvrg
|
|
4099
2702
|
end
|
4100
2703
|
end
|
4101
2704
|
|
4102
|
-
desc '', ''
|
4103
|
-
method_option :login, :type => :string, :aliases => ["-l"], :default => ""
|
2705
|
+
desc '', ''
|
2706
|
+
method_option :login, :type => :string, :aliases => ["-l", "--l"], :default => ""
|
4104
2707
|
|
4105
2708
|
def config_flask_remote(image_name, port=80)
|
4106
2709
|
local_images = Docker::Image.all
|
@@ -4133,54 +2736,21 @@ module Cnvrg
|
|
4133
2736
|
container.start()
|
4134
2737
|
command = ["/bin/bash", "-lc", "sudo echo -e \"#{login_content}\" >/home/ds/.netrc"]
|
4135
2738
|
container.exec(command, tty: true)
|
4136
|
-
command = ["/bin/bash", "-lc", "
|
4137
|
-
container.exec(command, tty: true)
|
4138
|
-
command = ["/bin/bash", "-lc", "sudo chmod 0600 /home/ds/.netrc"]
|
2739
|
+
command = ["/bin/bash", "-lc", "mkdir /home/ds/.cnvrg"]
|
4139
2740
|
container.exec(command, tty: true)
|
4140
|
-
|
4141
|
-
rescue => e
|
4142
|
-
pus e
|
4143
|
-
if e.message.include? "is not running"
|
4144
|
-
return "port is taken"
|
4145
|
-
end
|
4146
|
-
puts "error"
|
4147
|
-
if container
|
4148
|
-
container.kill()
|
4149
|
-
end
|
4150
|
-
return false
|
4151
|
-
end
|
4152
|
-
end
|
4153
|
-
|
4154
|
-
desc '', '', :hide => true
|
4155
|
-
method_option :login, :type => :string, :aliases => ["-l"], :default => ""
|
4156
|
-
|
4157
|
-
def config_flask_remote_gpu(image_name, port=80)
|
4158
|
-
local_images = Docker::Image.all
|
4159
|
-
|
4160
|
-
docker_image_local = local_images.map { |x| x.info["RepoTags"] }.flatten.select { |y| y.eql? "#{image_name}:latest" }.flatten
|
4161
|
-
if docker_image_local.empty?
|
4162
|
-
say "no image"
|
4163
|
-
exit(1)
|
4164
|
-
end
|
4165
|
-
|
4166
|
-
begin
|
4167
|
-
login_content = options["login"]
|
4168
|
-
container_id = `nvidia-docker run -itd -p 80:80 -w /home/ds/app #{image_name}:latest /usr/local/cnvrg/start_super.sh`
|
4169
|
-
container_id = container_id.gsub("\n", "")
|
4170
|
-
container = Docker::Container.get(container_id)
|
4171
|
-
command = ["/bin/bash", "-lc", "sudo echo -e \"#{login_content}\" >/home/ds/.netrc"]
|
2741
|
+
command = ["/bin/bash", "-lc", "mkdir /home/ds/.cnvrg/tmp"]
|
4172
2742
|
container.exec(command, tty: true)
|
4173
|
-
command = ["/bin/bash", "-lc", "sudo chown -R ds
|
2743
|
+
command = ["/bin/bash", "-lc", "sudo chown -R ds /home/ds/.cnvrg /home/ds/.netrc"]
|
4174
2744
|
container.exec(command, tty: true)
|
4175
2745
|
command = ["/bin/bash", "-lc", "sudo chmod 0600 /home/ds/.netrc"]
|
4176
2746
|
container.exec(command, tty: true)
|
4177
2747
|
say "#{container.id}:#{port}"
|
4178
2748
|
rescue => e
|
4179
|
-
puts e
|
4180
2749
|
if e.message.include? "is not running"
|
4181
2750
|
return "port is taken"
|
4182
2751
|
end
|
4183
2752
|
puts "error"
|
2753
|
+
puts e
|
4184
2754
|
if container
|
4185
2755
|
container.kill()
|
4186
2756
|
end
|
@@ -4188,7 +2758,7 @@ module Cnvrg
|
|
4188
2758
|
end
|
4189
2759
|
end
|
4190
2760
|
|
4191
|
-
desc '', ''
|
2761
|
+
desc '', ''
|
4192
2762
|
|
4193
2763
|
def upload_cnvrg_image(image_name)
|
4194
2764
|
verify_logged_in(false)
|
@@ -4198,12 +2768,12 @@ module Cnvrg
|
|
4198
2768
|
|
4199
2769
|
path = File.expand_path('~')+"/.cnvrg/tmp/#{image_name}.zip"
|
4200
2770
|
@files = Cnvrg::Files.new("", "")
|
4201
|
-
|
4202
|
-
|
4203
|
-
|
4204
|
-
|
2771
|
+
python_arr = Cnvrg::Images.get_installed_packages("python")
|
2772
|
+
py = python_arr.join(",") unless python_arr.nil? or python_arr.empty?
|
2773
|
+
system_arr = Cnvrg::Images.get_installed_packages("system")
|
2774
|
+
sys = system_arr.join(",") unless system_arr.nil? or system_arr.empty?
|
4205
2775
|
# bash_history = Cnvrg::Images.get_bash_history
|
4206
|
-
res = @files.upload_image(path, image_name, owner, true, true,
|
2776
|
+
res = @files.upload_image(path, image_name, owner, true, true, sys, py, "", "Image made by cnvrg.io team", "")
|
4207
2777
|
|
4208
2778
|
end
|
4209
2779
|
|
@@ -4249,7 +2819,7 @@ module Cnvrg
|
|
4249
2819
|
end
|
4250
2820
|
end
|
4251
2821
|
|
4252
|
-
desc '', ''
|
2822
|
+
desc '', ''
|
4253
2823
|
|
4254
2824
|
def download_image(image_name, image_slug)
|
4255
2825
|
begin
|
@@ -4275,6 +2845,8 @@ module Cnvrg
|
|
4275
2845
|
end
|
4276
2846
|
end
|
4277
2847
|
|
2848
|
+
|
2849
|
+
|
4278
2850
|
return dir_path
|
4279
2851
|
|
4280
2852
|
else
|
@@ -4308,13 +2880,13 @@ module Cnvrg
|
|
4308
2880
|
owner = Cnvrg::CLI.get_owner()
|
4309
2881
|
res = Cnvrg::API.request("users/#{owner}/images/list", 'GET')
|
4310
2882
|
if Cnvrg::CLI.is_response_success(res)
|
4311
|
-
printf "%-20s %-20s %-30s %-20s %-20s\n", "name", "project",
|
2883
|
+
printf "%-20s %-20s %-30s %-20s %-20s\n", "name", "project", "created by", "is_public", "last updated"
|
4312
2884
|
res["result"]["images"].each do |u|
|
4313
2885
|
time = Time.parse(u["created_at"])
|
4314
2886
|
update_at = get_local_time(time)
|
4315
2887
|
created_by = u["created_by"]
|
4316
2888
|
|
4317
|
-
printf "%-20s %-20s %-30s %-20s %-20s\n", u["name"], u["project"],
|
2889
|
+
printf "%-20s %-20s %-30s %-20s %-20s\n", u["name"], u["project"], created_by, u["is_public"], update_at
|
4318
2890
|
end
|
4319
2891
|
end
|
4320
2892
|
log_end(0)
|
@@ -4396,7 +2968,7 @@ module Cnvrg
|
|
4396
2968
|
|
4397
2969
|
desc 'pull_image', 'downloads and loads an image'
|
4398
2970
|
|
4399
|
-
def
|
2971
|
+
def pull(image_name)
|
4400
2972
|
begin
|
4401
2973
|
verify_logged_in(false)
|
4402
2974
|
log_start(__method__, args, options)
|
@@ -4409,18 +2981,8 @@ module Cnvrg
|
|
4409
2981
|
path = download_image(image_name, image["slug"])
|
4410
2982
|
if path
|
4411
2983
|
say "Building image", Thor::Shell::Color::BLUE
|
4412
|
-
Docker.options[:read_timeout]=
|
4413
|
-
image = Docker::Image.build_from_dir(path, {'dockerfile' => 'Dockerfile
|
4414
|
-
begin
|
4415
|
-
if (log = JSON.parse(v)) && log.has_key?("stream")
|
4416
|
-
next if log["stream"].starts_with? "Step"
|
4417
|
-
$stdout.puts log["stream"]
|
4418
|
-
end
|
4419
|
-
rescue
|
4420
|
-
end
|
4421
|
-
|
4422
|
-
end
|
4423
|
-
|
2984
|
+
Docker.options[:read_timeout]=1200
|
2985
|
+
image = Docker::Image.build_from_dir(path, {'dockerfile' => 'Dockerfile', 't' => "#{image_name}:lastest"})
|
4424
2986
|
if not image.nil?
|
4425
2987
|
FileUtils.rm_rf(path)
|
4426
2988
|
checks = Helpers.checkmark()
|
@@ -4429,13 +2991,11 @@ module Cnvrg
|
|
4429
2991
|
return image
|
4430
2992
|
log_end(0)
|
4431
2993
|
else
|
4432
|
-
|
4433
2994
|
say "Could not build image", Thor::Shell::Color::RED
|
4434
2995
|
log_end(1, "Could build image")
|
4435
2996
|
return false
|
4436
2997
|
end
|
4437
2998
|
else
|
4438
|
-
|
4439
2999
|
say "Could not download image", Thor::Shell::Color::RED
|
4440
3000
|
log_end(1, "Could build image")
|
4441
3001
|
return false
|
@@ -4463,9 +3023,7 @@ module Cnvrg
|
|
4463
3023
|
#
|
4464
3024
|
# end
|
4465
3025
|
# end
|
4466
|
-
rescue
|
4467
|
-
|
4468
|
-
|
3026
|
+
rescue
|
4469
3027
|
say "Couldn't build image", Thor::Shell::Color::RED
|
4470
3028
|
|
4471
3029
|
rescue SignalException
|
@@ -4572,12 +3130,7 @@ module Cnvrg
|
|
4572
3130
|
if url.nil? or url.empty?
|
4573
3131
|
url = "https://cnvrg.io/api"
|
4574
3132
|
end
|
4575
|
-
config =
|
4576
|
-
compression_path = "#{home_dir}/.cnvrg/tmp"
|
4577
|
-
if config and !config.nil? and !config.empty? and !config.to_h[:compression_path].nil?
|
4578
|
-
compression_path = config.to_h[:compression_path]
|
4579
|
-
end
|
4580
|
-
config = {owner: owner, username: username, version_last_check: get_start_day(), api: url,compression_path:compression_path}
|
3133
|
+
config = {owner: owner, username: username, version_last_check: get_start_day(), api: url}
|
4581
3134
|
|
4582
3135
|
File.open(home_dir+"/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
|
4583
3136
|
return true
|
@@ -4631,7 +3184,7 @@ module Cnvrg
|
|
4631
3184
|
|
4632
3185
|
def log_end(exit_status=0, error=nil)
|
4633
3186
|
begin
|
4634
|
-
if exit_status
|
3187
|
+
if exit_status==1
|
4635
3188
|
$LOG.error exit_status: exit_status, error: error
|
4636
3189
|
else
|
4637
3190
|
$LOG.info exit_status: exit_status
|
@@ -4643,6 +3196,7 @@ module Cnvrg
|
|
4643
3196
|
def self.is_response_success(response, should_exit=true)
|
4644
3197
|
if response.nil?
|
4645
3198
|
if !Cnvrg::Helpers.internet_connection?
|
3199
|
+
# Cnvrg::CLI.log_end(1,"no internet connection")
|
4646
3200
|
say("<%= color('Error:You seems to be offline', RED) %>")
|
4647
3201
|
else
|
4648
3202
|
say("<%= color('Error', RED) %>")
|
@@ -4677,26 +3231,12 @@ module Cnvrg
|
|
4677
3231
|
return owner
|
4678
3232
|
end
|
4679
3233
|
end
|
4680
|
-
|
4681
3234
|
def get_base_url
|
4682
3235
|
home_dir = File.expand_path('~')
|
4683
3236
|
|
4684
3237
|
config = YAML.load_file(home_dir+ "/.cnvrg/config.yml")
|
4685
3238
|
api = config.to_h[:api]
|
4686
|
-
return api.gsub!("/api",
|
4687
|
-
end
|
4688
|
-
def get_compression_path
|
4689
|
-
home_dir = File.expand_path('~')
|
4690
|
-
|
4691
|
-
config = YAML.load_file(home_dir+ "/.cnvrg/config.yml")
|
4692
|
-
compression_path = config.to_h[:compression_path]
|
4693
|
-
if compression_path.nil?
|
4694
|
-
compression_path = "#{home_dir}/.cnvrg/tmp/"
|
4695
|
-
end
|
4696
|
-
if !compression_path.ends_with? "/"
|
4697
|
-
compression_path = compression_path + "/"
|
4698
|
-
end
|
4699
|
-
return compression_path
|
3239
|
+
return api.gsub!("/api","")
|
4700
3240
|
end
|
4701
3241
|
|
4702
3242
|
def get_project_home
|
@@ -4750,6 +3290,7 @@ module Cnvrg
|
|
4750
3290
|
end
|
4751
3291
|
$LOG = LogStashLogger.new(type: :file, path: logfile, sync: true)
|
4752
3292
|
rescue => e
|
3293
|
+
# puts e
|
4753
3294
|
end
|
4754
3295
|
end
|
4755
3296
|
|
@@ -4777,9 +3318,6 @@ module Cnvrg
|
|
4777
3318
|
|
4778
3319
|
config = YAML.load_file(File.expand_path('~')+"/.cnvrg/config.yml")
|
4779
3320
|
version_date = config.to_h[:version_last_check]
|
4780
|
-
if version_date.nil?
|
4781
|
-
version_date = get_start_day()
|
4782
|
-
end
|
4783
3321
|
next_day = get_start_day+ 86399
|
4784
3322
|
if not (version_date..next_day).cover?(Time.now)
|
4785
3323
|
if should_update_version()
|
@@ -4805,15 +3343,11 @@ module Cnvrg
|
|
4805
3343
|
def is_cnvrg_dir(dir=Dir.pwd)
|
4806
3344
|
current_dir = dir
|
4807
3345
|
home_dir = File.expand_path('~')
|
4808
|
-
if current_dir.eql? home_dir
|
4809
|
-
return false
|
4810
|
-
end
|
4811
3346
|
is_cnvrg = Dir.exist? current_dir+"/.cnvrg"
|
4812
3347
|
until is_cnvrg == true
|
4813
3348
|
current_dir = File.expand_path("..", current_dir)
|
4814
3349
|
is_cnvrg = Dir.exist? current_dir+"/.cnvrg"
|
4815
|
-
if
|
4816
|
-
is_cnvrg = false
|
3350
|
+
if File.expand_path("..", current_dir).eql? home_dir
|
4817
3351
|
break
|
4818
3352
|
end
|
4819
3353
|
end
|
@@ -4824,19 +3358,6 @@ module Cnvrg
|
|
4824
3358
|
end
|
4825
3359
|
end
|
4826
3360
|
|
4827
|
-
def data_dir_include()
|
4828
|
-
all_dirs = Dir.glob("**/*/", File::FNM_DOTMATCH)
|
4829
|
-
all_dirs.flatten!
|
4830
|
-
all_dirs.each do |a|
|
4831
|
-
if a.include? "/.cnvrg"
|
4832
|
-
ignore = File.dirname(a)
|
4833
|
-
return ignore
|
4834
|
-
end
|
4835
|
-
end
|
4836
|
-
return nil
|
4837
|
-
|
4838
|
-
end
|
4839
|
-
|
4840
3361
|
def verify_software_installed(software)
|
4841
3362
|
begin
|
4842
3363
|
install_url = Cnvrg::CLI::INSTALLATION_URLS[software.to_sym]
|
@@ -5012,151 +3533,8 @@ module Cnvrg
|
|
5012
3533
|
|
5013
3534
|
end
|
5014
3535
|
|
5015
|
-
def update_deleted(deleted)
|
5016
|
-
final = []
|
5017
|
-
deleted.each do |d|
|
5018
|
-
all_subs = d.split("/")
|
5019
|
-
to_add = true
|
5020
|
-
value = all_subs[0]
|
5021
|
-
all_subs.each_with_index do |a, i|
|
5022
|
-
if final.include? value+"/"
|
5023
|
-
to_add = false
|
5024
|
-
break
|
5025
|
-
end
|
5026
|
-
value = value+"/"+all_subs[i+1] if i <all_subs.size-1
|
5027
|
-
end
|
5028
|
-
final << d if to_add
|
5029
|
-
|
5030
|
-
|
5031
|
-
end
|
5032
|
-
|
5033
|
-
|
5034
|
-
return final
|
5035
|
-
end
|
5036
|
-
|
5037
|
-
def get_cmd_path_in_dir(main_dir, sub_dir)
|
5038
|
-
first = Pathname.new main_dir
|
5039
|
-
second = Pathname.new sub_dir
|
5040
|
-
relative = second.relative_path_from first
|
5041
|
-
if relative.eql? "."
|
5042
|
-
return ""
|
5043
|
-
else
|
5044
|
-
return relative
|
5045
|
-
end
|
5046
|
-
end
|
5047
|
-
|
5048
|
-
def create_tar(path_in, path_out, tar_files,no_compression=false)
|
5049
|
-
#The cd is meant for cases when running cnvrg data uplaod not in the main folder
|
5050
|
-
begin
|
5051
|
-
if no_compression
|
5052
|
-
`cd #{path_in} && tar -cf #{path_out} -T #{tar_files}`
|
5053
|
-
else
|
5054
|
-
`cd #{path_in} && tar -czf #{path_out} -T #{tar_files}`
|
5055
|
-
end
|
5056
|
-
rescue => e
|
5057
|
-
puts "Exception while compressing data: #{e.message}"
|
5058
|
-
end
|
5059
|
-
|
5060
|
-
return $?.success?
|
5061
|
-
end
|
5062
|
-
|
5063
|
-
def extarct_tar(file_path, dir_path)
|
5064
|
-
`tar -xvf #{file_path} -C #{dir_path} > /dev/null 2>&1`
|
5065
|
-
return $?.success?
|
5066
|
-
end
|
5067
|
-
def cpu_usage
|
5068
|
-
cpu_usage = 0.0
|
5069
|
-
begin
|
5070
|
-
cpu = `top b -n 2 -d 2 |grep %Cpu |tail -1 |awk '{print $2+$3}'`
|
5071
|
-
if !cpu.nil?
|
5072
|
-
cpu_usage = cpu.to_f
|
5073
|
-
end
|
5074
|
-
rescue
|
5075
|
-
cpu_usage = 0.0
|
5076
|
-
end
|
5077
|
-
|
5078
|
-
return cpu_usage
|
5079
|
-
end
|
5080
|
-
def memory_usage
|
5081
|
-
prec = 0.0
|
5082
|
-
begin
|
5083
|
-
used = `free -mt |grep Mem: |awk '{print $3}'`
|
5084
|
-
total = `free -mt |grep Mem: |awk '{print $2}'`
|
5085
|
-
|
5086
|
-
used_f = used.to_f if !used.nil?
|
5087
|
-
total_f = total.to_f if !total.nil?
|
5088
|
-
prec = (used_f / total_f)*100
|
5089
|
-
prec = prec.round(2)
|
5090
|
-
rescue
|
5091
|
-
prec = 0.0
|
5092
|
-
end
|
5093
|
-
return prec
|
5094
|
-
|
5095
|
-
|
5096
|
-
end
|
5097
|
-
def gpu_util
|
5098
|
-
gpu = [0.0, 0.0]
|
5099
|
-
begin
|
5100
|
-
gpu_stats = `nvidia-smi --query-gpu=utilization.gpu,utilization.memory --format=csv |tail -1`
|
5101
|
-
|
5102
|
-
if !gpu_stats.nil?
|
5103
|
-
gpu = gpu_stats.strip
|
5104
|
-
gpu = gpu_stats.gsub!("%","").split(",")
|
5105
|
-
gpu[0] = gpu[0].to_f
|
5106
|
-
gpu[1] = gpu[1].to_f
|
5107
|
-
return gpu
|
5108
|
-
end
|
5109
|
-
|
5110
|
-
rescue
|
5111
|
-
return gpu
|
5112
|
-
end
|
5113
|
-
|
5114
|
-
|
5115
|
-
end
|
5116
|
-
def usage_metrics_in_docker(docker_id)
|
5117
|
-
res = [0.0,0.0]
|
5118
|
-
begin
|
5119
|
-
if docker_id.nil?
|
5120
|
-
docker_id = `cat /etc/hostname`
|
5121
|
-
end
|
5122
|
-
stats = `sudo docker stats #{docker_id} --no-stream --format "{{.CPUPerc}},{{.MemPerc}},{{.BlockIO}}"`
|
5123
|
-
if !stats.nil?
|
5124
|
-
conv = stats.split(",")
|
5125
|
-
cpu = conv[0].gsub!("%","").to_f
|
5126
|
-
memory = conv[1].gsub!("%","").to_f
|
5127
|
-
res = [cpu,memory]
|
5128
|
-
return res
|
5129
|
-
end
|
5130
|
-
rescue
|
5131
|
-
return res
|
5132
|
-
end
|
5133
|
-
|
5134
|
-
|
5135
|
-
|
5136
|
-
end
|
5137
|
-
|
5138
|
-
def with_progress_bar
|
5139
|
-
not_done = true
|
5140
|
-
upload_progress_bar = ProgressBar.create(:title => "Upload progress",
|
5141
|
-
:format => '%a <%B> %p%% %t',
|
5142
|
-
:starting_at => 0,
|
5143
|
-
:total => 600)
|
5144
|
-
pb = Thread.new do
|
5145
|
-
while not_done do
|
5146
|
-
upload_progress_bar.increment
|
5147
|
-
sleep(1)
|
5148
|
-
|
5149
|
-
end
|
5150
|
-
end
|
5151
3536
|
|
5152
|
-
yield.tap do # After yielding to the block, save the return value
|
5153
|
-
not_done = false # Tell the thread to exit, cleaning up after itself…
|
5154
|
-
pb.join # …and wait for it to do so.
|
5155
|
-
end
|
5156
|
-
end
|
5157
3537
|
end
|
5158
|
-
|
5159
|
-
|
5160
3538
|
end
|
5161
3539
|
end
|
5162
3540
|
|