cnvrg 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2e26104d7aabe95db17799925bdfdfe35659256
4
- data.tar.gz: 9dab8f4d8bac50ba1683e1a52435cea57bccca30
3
+ metadata.gz: 04d14b6b659ad1bdc05347a594f1a4447334af4f
4
+ data.tar.gz: 5d12cbd7b69bc517cfe06f8f920fce3edcf8fc37
5
5
  SHA512:
6
- metadata.gz: a62e0a0a4656ef1edf1d829e6e9fd97062dcf6e69c9a67394cc883b14b59c9dc8a645affa6d4baa90777b3379deb8d849084e0724a88f7e3a6207e63f08dc277
7
- data.tar.gz: be977bf88bb480097737919977e75adda5b2eb88454d3e8fefc5e4482622b1783dae265013e6dd7f12056b8e35ac9107d32f0b2adc90b4a802247562591b1b66
6
+ metadata.gz: 15526296c7f0a868506e787c4fb8f81753ce9159a9257dbd5e1c423ce80448a8b5eeb5e30df0acc88f4643c3ca2240fb8cbb2f53049244fdc1be0f76b7248144
7
+ data.tar.gz: d5d8953e5d2667e30770e3b48a89b2b9d7482d0acc920a9139b710e178dfc6d5b3484ff47243c222ea3c779e60716e721c8deb3919f8356a2deff0c00c114421
@@ -67,14 +67,18 @@ module Cnvrg
67
67
  client = props[:client]
68
68
  upload_options = props[:upload_options]
69
69
  bucket = Aws::S3::Resource.new(client: client).bucket(props[:bucket])
70
+
70
71
  resp = bucket.object(path).
71
72
  upload_file(image_path, upload_options)
73
+
72
74
  unless resp
73
75
  raise Exception.new("Cant upload #{image_path}")
74
76
  return false
75
77
  end
76
78
  return save_docker_image(image_id)
77
79
  rescue => e
80
+ Cnvrg::Logger.log_error(e)
81
+
78
82
  return false
79
83
  end
80
84
 
@@ -84,7 +88,8 @@ module Cnvrg
84
88
 
85
89
  def save_docker_image(image_id)
86
90
  image_res = Cnvrg::API.request("users/#{@owner}/images/#{image_id}/save" , 'POST', {})
87
- return Cnvrg::CLI.is_response_success(image_res, true)
91
+ Cnvrg::CLI.is_response_success(image_res, true)
92
+ return image_res
88
93
  end
89
94
 
90
95
  def is_container_exist()
@@ -24,6 +24,7 @@ require 'cnvrg/data'
24
24
  require 'cnvrg/ssh'
25
25
  require 'cnvrg/result'
26
26
  require 'cnvrg/logger'
27
+ require 'cnvrg/org_helpers'
27
28
  require 'cnvrg/cli/flow'
28
29
  require 'cnvrg/cli/task'
29
30
  require 'logstash-logger'
@@ -155,6 +156,7 @@ module Cnvrg
155
156
 
156
157
  class << self
157
158
  # Hackery.Take the run method away from Thor so that we can redefine it.
159
+
158
160
  def is_thor_reserved_word?(word, type)
159
161
  return false if word == "run"
160
162
  super
@@ -163,8 +165,8 @@ module Cnvrg
163
165
  desc "data", "upload and manage datasets", :hide => false
164
166
  subcommand "data", Data
165
167
 
166
- # desc "flow", "mange project flows", :hide => true
167
- # subcommand "flow", Cnvrg::Commands::Flow
168
+ desc "flow", "mange project flows", :hide => true
169
+ subcommand "flow", Cnvrg::Commands::Flow
168
170
 
169
171
 
170
172
  def initialize(*args)
@@ -618,39 +620,6 @@ module Cnvrg
618
620
  path = Dir.pwd + "/" + project_name
619
621
  @project = Project.new(path)
620
622
  @project.generate_idx
621
- if docker
622
- local_images = Docker::Image.all
623
- docker_image_local = local_images.map {|x| x.info["RepoTags"]}.flatten.select {|y| y.include? docker_image}.flatten
624
- if docker_image_local.size == 0
625
-
626
- if yes? "Image wasn't found locally, pull image from cnvrg repository?", Thor::Shell::Color::YELLOW
627
- image = pull(docker_image)
628
- if image
629
- log_message("downloaded image: #{docker_image}", Thor::Shell::Color::BLUE)
630
- @image = Images.new(working_dir, docker_image)
631
- else
632
- log_message("Could not create a new project with docker, image was not found", Thor::Shell::Color::RED)
633
- @project.revert(working_dir)
634
- exit(1)
635
- end
636
- else
637
- log_message("Could not create a new project with docker, image was not found", Thor::Shell::Color::RED)
638
- @project.revert(working_dir)
639
- exit(1)
640
-
641
- end
642
- elsif docker_image_local.size == 1
643
- log_message("found image: #{docker_image_local[0]}, setting it up..", Thor::Shell::Color::BLUE)
644
- @image = Images.new(working_dir, docker_image_local[0])
645
- elsif docker_image_local.size > 1
646
- log_message("found #{docker_image_local.size} images, choose the image name you want to use", Thor::Shell::Color::BLUE)
647
- image_name = ask "#{docker_image_local.join("\n")}\n", Thor::Shell::Color::BLUE
648
- image_name = image_name.strip
649
- @image = Images.new(working_dir, image_name)
650
- end
651
- @image.update_image_activity(nil, nil)
652
-
653
- end
654
623
  else
655
624
  log_message("Error creating project, please contact support.", Thor::Shell::Color::RED)
656
625
  @project.revert(working_dir)
@@ -714,35 +683,6 @@ module Cnvrg
714
683
  path = Dir.pwd
715
684
  @project = Project.new(path)
716
685
  @project.generate_idx()
717
- if docker
718
- local_images = Docker::Image.all
719
- docker_image_local = local_images.map {|x| x.info["RepoTags"]}.flatten.select {|y| y.include? docker_image}.flatten
720
- if docker_image_local.size == 0
721
- if yes? "Image wasn't found locally, pull image from cnvrg repository?", Thor::Shell::Color::YELLOW
722
- image = pull(docker_image)
723
- if image
724
- log_message("downloaded image: #{docker_image}", Thor::Shell::Color::BLUE)
725
- @image = Images.new(working_dir, docker_image)
726
- else
727
- log_message("Could not create a new project with docker, image was not found", Thor::Shell::Color::RED)
728
- @project.revert(working_dir)
729
- exit(1)
730
- end
731
- else
732
- log_message("Could not create a new project with docker, image was not found", Thor::Shell::Color::RED)
733
- @project.revert(working_dir)
734
- exit(1)
735
-
736
- end
737
- elsif docker_image_local.size == 1
738
- log_message("found image: #{docker_image_local[0]}, setting it up..", Thor::Shell::Color::BLUE)
739
- @image = Images.new(working_dir, docker_image_local[0])
740
- elsif docker_image_local.size > 1
741
- log_message("found #{docker_image_local.size} images, choose the image name you want to use", Thor::Shell::Color::BLUE)
742
- image_name = ask "#{docker_image_local.join("\n")}\n", Thor::Shell::Color::BLUE
743
- @image = Images.new(working_dir, image_name)
744
- end
745
- end
746
686
  if sync
747
687
  log_message("Syncing project", Thor::Shell::Color::BLUE)
748
688
  upload(true)
@@ -2102,7 +2042,7 @@ module Cnvrg
2102
2042
  dataset_dir = is_cnvrg_dir(Dir.pwd)
2103
2043
  @dataset = Dataset.new(dataset_dir)
2104
2044
  @files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
2105
- new_commit ||= @dataset.get_next_commit()
2045
+ new_commit ||= @dataset.get_next_commit
2106
2046
  partial_commit = @dataset.get_partial_commit
2107
2047
  if new_commit.blank?
2108
2048
  log_message("You must specify commit, run start_commit to create new commit", Thor::Shell::Color::RED)
@@ -2427,14 +2367,21 @@ module Cnvrg
2427
2367
  end
2428
2368
  Cnvrg::Logger.log_info("Current commit: #{@dataset.get_current_commit}, destination commit: #{commit}")
2429
2369
  Cnvrg::Logger.log_info("Compare idx res: #{result}")
2370
+ progressbar = ProgressBar.create(:title => "Download Progress",
2371
+ :progress_mark => '=',
2372
+ :format => "%b>>%i| %p%% %t",
2373
+ :starting_at => 0,
2374
+ :total => update_total,
2375
+ :autofinish => true)
2430
2376
  conflicts = @files.mark_conflicts(result)
2431
2377
 
2432
2378
  log_message("Found some conflicts, check .conflict files.", Thor::Shell::Color::BLUE) if conflicts > 0
2433
- update_res = @files.download_files_in_chunks(result["updated_on_server"]) if result["updated_on_server"].present?
2434
- added_res = @files.download_files_in_chunks(result["added"]) if result["added"].present?
2379
+ update_res = @files.download_files_in_chunks(result["updated_on_server"], progress: progressbar) if result["updated_on_server"].present?
2380
+ added_res = @files.download_files_in_chunks(result["added"], progress: progressbar) if result["added"].present?
2435
2381
  # conflict_res = @files.download_files_in_chunks(result["conflicts"], conflict: true) if result["conflicts"].present?
2436
2382
  deleted = result["deleted"].to_a
2437
2383
  delete_res = @files.delete_commit_files_local(deleted)
2384
+ progressbar.progress += deleted.size if progressbar.present?
2438
2385
  if !delete_res
2439
2386
  log_message("Couldn't delete #{deleted.join(" ")}", Thor::Shell::Color::RED)
2440
2387
  log_message("Couldn't download, Rolling Back all changes.", Thor::Shell::Color::RED)
@@ -2487,8 +2434,15 @@ module Cnvrg
2487
2434
  log_message("No New files to download", Thor::Shell::Color::GREEN)
2488
2435
  return
2489
2436
  end
2490
- download_result = @files.download_multpile_files_s3(files, project_home)
2437
+ progressbar = ProgressBar.create(:title => "Download Progress",
2438
+ :progress_mark => '=',
2439
+ :format => "%b>>%i| %p%% %t",
2440
+ :starting_at => 0,
2441
+ :total => files['keys'].size,
2442
+ :autofinish => true)
2443
+ download_result = @files.download_multpile_files_s3(files, project_home, progress: progressbar)
2491
2444
  if download_result
2445
+ progressbar.finish
2492
2446
  log_message("Done.\nDownloaded finished successfully", Thor::Shell::Color::GREEN)
2493
2447
  else
2494
2448
  log_message("Error while trying to download\n", Thor::Shell::Color::RED)
@@ -2760,7 +2714,7 @@ module Cnvrg
2760
2714
  end
2761
2715
  end
2762
2716
 
2763
- desc 'sync', 'Sync with remote server'
2717
+ desc 'sync', 'Sync with cnvrg'
2764
2718
  method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
2765
2719
  method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
2766
2720
  method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :default => ""
@@ -3564,21 +3518,6 @@ module Cnvrg
3564
3518
  if !choose_image.nil? and !choose_image.empty?
3565
3519
  invoke :set_image, [choose_image]
3566
3520
  end
3567
- @image = is_project_with_docker(working_dir)
3568
- if !@image or !@image.is_docker
3569
- # say "Couldn't find image related to project", Thor::Shell::Color::RED
3570
- default_image_name = "cnvrg"
3571
- if instance_type.eql? "gpu" or instance_type.eql? "gpuxl"
3572
- default_image_name = "cnvrg-gpu"
3573
- end
3574
- # default = yes? "use #{default_image_name} default image?", Thor::Shell::Color::YELLOW
3575
- # if default
3576
- @image = Images.new(working_dir, default_image_name)
3577
- # else
3578
- # exit(0)
3579
- # end
3580
- end
3581
-
3582
3521
  invoke :sync, [false], []
3583
3522
 
3584
3523
 
@@ -4867,8 +4806,11 @@ module Cnvrg
4867
4806
  user = options[:user]
4868
4807
  is_gpu = options[:gpu]
4869
4808
  res = @image.upload_docker_image(image_path, image_name, workdir, user, description, is_gpu)
4870
- if res
4871
- log_message("Successfully uploaded image: #{image_name}", Thor::Shell::Color::GREEN, true)
4809
+ if res["status"] == 200
4810
+ image_slug = res["id"]
4811
+ owner = CLI.get_owner
4812
+ image_url = "#{Cnvrg::Helpers.remote_url}/#{owner}/settings/images/#{image_slug}"
4813
+ log_message("Successfully uploaded image: #{image_url}", Thor::Shell::Color::GREEN, true)
4872
4814
 
4873
4815
 
4874
4816
  else
@@ -41,6 +41,7 @@ module Cnvrg
41
41
  return false
42
42
  end
43
43
  begin
44
+ path = "#{path}.flow.yaml" unless path.end_with? '.flow.yaml'
44
45
  @flow = Cnvrg::Flows.new(@curr_dir, path)
45
46
  url = @flow.run
46
47
  rescue => e
@@ -6,6 +6,8 @@ class SubCommand < Thor
6
6
  super
7
7
  @cli = Cnvrg::CLI.new
8
8
  @curr_dir = @cli.is_cnvrg_dir
9
+ @config = YAML.load_file(@curr_dir + "/.cnvrg/config.yml") if @curr_dir
10
+ @helpers = Cnvrg::OrgHelpers.new();
9
11
  end
10
12
 
11
13
  def self.banner(command, namespace = nil, subcommand = false)
@@ -1,3 +1,4 @@
1
+
1
2
  module Cnvrg
2
3
  module Commands
3
4
  class Task < SubCommand
@@ -34,7 +35,6 @@ module Cnvrg
34
35
 
35
36
  desc "flow task create", "Creates new task"
36
37
  def create
37
-
38
38
  @project = Cnvrg::Project.new(@curr_dir)
39
39
 
40
40
  task = {}
@@ -65,6 +65,7 @@ module Cnvrg
65
65
  desc "flow task run", "Running specific task"
66
66
  def run(path)
67
67
  begin
68
+ path = "#{path}.task.yaml" unless path.end_with? '.task.yaml'
68
69
  @task = Cnvrg::Task.new(@curr_dir, path: path)
69
70
  url = @task.run
70
71
  @cli.log_message("Task: #{@task.title} is running, you can track its performance on #{url}", Thor::Color::GREEN)
@@ -878,11 +878,11 @@ module Cnvrg
878
878
  response['result']['files']
879
879
  end
880
880
 
881
- def download_files_in_chunks(files, chunk_size: 1000, conflict: false, commit: 'latest')
881
+ def download_files_in_chunks(files, chunk_size: 1000, conflict: false, commit: 'latest', progress: nil)
882
882
  begin
883
883
  ttl_files = 0
884
884
  files.each_slice(chunk_size).each do |files|
885
- ttl_files += download_files_chunk(files, conflict: conflict)
885
+ ttl_files += download_files_chunk(files, conflict: conflict, progress: progress)
886
886
  end
887
887
  return Cnvrg::Result.new(true, "Download Completed")
888
888
  rescue Exception => e
@@ -890,19 +890,19 @@ module Cnvrg
890
890
  end
891
891
  end
892
892
 
893
- def download_files_chunk(files, conflict: false)
893
+ def download_files_chunk(files, conflict: false, progress: nil)
894
894
  (1..5).each do |i|
895
895
  response = Cnvrg::API.request("users/#{@owner}/datasets/#{@dataset_slug}/download_multi", 'POST', {files: files})
896
896
  next unless Cnvrg::CLI.is_response_success(response, false) #trying to api request 5 times.
897
897
  files_to_download = response['files']
898
898
  data_home = "#{Dir.pwd}/#{response['name']}"
899
- res = download_multiple_files_s3(files_to_download, data_home, conflict: conflict, read_only: false)
899
+ res = download_multiple_files_s3(files_to_download, data_home, conflict: conflict, read_only: false, progressbar: progress)
900
900
  next unless res.is_success? #try again..
901
901
  return files_to_download['keys'].length
902
902
  end
903
903
  end
904
904
 
905
- def download_multiple_chunks(commit, chunk_size=1000)
905
+ def download_multiple_chunks(commit, chunk_size=1000, progress: nil)
906
906
  begin
907
907
  last_chunk_size = chunk_size
908
908
  q = { commit: commit, chunk_size: chunk_size}
@@ -914,7 +914,7 @@ module Cnvrg
914
914
  data_home = "#{Dir.pwd}/#{response['name']}"
915
915
  last_chunk_size = files['keys'].length
916
916
  break if last_chunk_size == 0
917
- res = download_multiple_files_s3(files, data_home, read_only: false)
917
+ res = download_multiple_files_s3(files, data_home, read_only: false, progressbar: progress)
918
918
  overall += last_chunk_size
919
919
  q[:latest] = files['latest']
920
920
  else
@@ -367,9 +367,12 @@ module Cnvrg
367
367
 
368
368
  def list_all_files(with_ignore=false)
369
369
  list = Dir.glob("#{self.local_path}/**/*", File::FNM_DOTMATCH).reject { |x| (x =~ /\/\.{1,2}$/) or (x =~ /^#{self.local_path}\/\.cnvrg\/*/) or (x =~/^#{self.local_path}\/\.cnvrgignore.conflict*/) and not (x =~/^#{self.local_path}\/\.cnvrgignore/) }
370
+
371
+ #we want that big files will
372
+ list = list.sort_by{|fn| File.size(fn)}
370
373
  return list if with_ignore
371
374
  list_ignore = self.get_ignore_list.map{|ignore_file| "#{self.local_path}/#{ignore_file}"}
372
- list.select{|file| !list_ignore.include? file}
375
+ (list - list_ignore)
373
376
  end
374
377
 
375
378
  def write_idx(tree=nil, commit=nil)
@@ -57,7 +57,7 @@ module Cnvrg
57
57
  files_list = files_list.map{|x| [x,self.parse_file(x)]}.to_h
58
58
  resp = Cnvrg::API.request(@base_resource + "upload_files", 'POST', {files: files_list, commit: commit_sha1})
59
59
  unless Cnvrg::CLI.is_response_success(resp, false)
60
- raise Exception.new("Cant upload files to the server.")
60
+ raise SignalException.new("Cant upload files to the server.")
61
61
  end
62
62
  # resolve bucket
63
63
  res = resp['result']
@@ -72,7 +72,7 @@ module Cnvrg
72
72
  # files.keys.map do |file|
73
73
  Parallel.map(files.keys, self.get_upload_options) do |file|
74
74
  resp = Cnvrg::Helpers.try_until_success{self.upload_single_file(files[file].merge(files_list[file]), s3_bucket, options: upload_options)}
75
- raise Exception.new("Cant upload #{file}") unless resp
75
+ raise SignalException.new("Cant upload #{file}") unless resp
76
76
  progress.progress += 1 if progress.present?
77
77
  end
78
78
 
@@ -80,7 +80,7 @@ module Cnvrg
80
80
  blob_ids = files.values.map {|f| f['bv_id']}
81
81
  resp = Cnvrg::API.request(@base_resource + "upload_files_save", 'POST', {blob_ids: blob_ids, commit: commit_sha1})
82
82
  unless Cnvrg::CLI.is_response_success(resp, false)
83
- raise Exception.new("Cant save uploaded files to the server.")
83
+ raise SignalException.new("Cant save uploaded files to the server.")
84
84
  end
85
85
  end
86
86
 
@@ -108,7 +108,7 @@ module Cnvrg
108
108
  return if files.blank?
109
109
  resp = Cnvrg::API.request(@base_resource + "delete_files", 'DELETE', {files: files, commit: commit_sha1})
110
110
  unless Cnvrg::CLI.is_response_success(resp, false)
111
- raise Exception.new("Cant delete the following files from the server.")
111
+ raise SignalException.new("Cant delete the following files from the server.")
112
112
  end
113
113
  end
114
114
 
@@ -119,7 +119,7 @@ module Cnvrg
119
119
  resp = bucket.object(path).
120
120
  upload_file(absolute_path, options)
121
121
  unless resp
122
- raise Exception.new("Cant upload #{absolute_path}")
122
+ raise SignalException.new("Cant upload #{absolute_path}")
123
123
  end
124
124
  resp
125
125
  end
@@ -665,7 +665,7 @@ module Cnvrg
665
665
  end
666
666
  res = Cnvrg::API.request(@base_resource + "download_files", 'POST', {files: files, commit: commit})
667
667
  unless Cnvrg::CLI.is_response_success(res, false)
668
- raise Exception.new("Cant download files from the server.")
668
+ raise SignalException.new("Cant download files from the server.")
669
669
  end
670
670
  self.download_multpile_files_s3(res['result'], @project_home, postfix: postfix, progress: progress)
671
671
  end
@@ -947,7 +947,7 @@ module Cnvrg
947
947
  end
948
948
  rescue => e
949
949
  Cnvrg::Logger.log_error(e)
950
- raise Exception.new("Cant upload files")
950
+ raise SignalException.new("Cant upload files")
951
951
  end
952
952
  end
953
953
  def rollback_commit(commit_sha1)
@@ -334,7 +334,7 @@ parameters:
334
334
  if !server_side_encryption
335
335
  upload_options = {:use_accelerate_endpoint => use_accelerate_endpoint}
336
336
  else
337
- upload_options = {:use_accelerate_endpoint => use_accelerate_endpoint, :server_side_encryption => server_side_encryption}
337
+ upload_options = {:use_accelerate_endpoint => use_accelerate_endpoint, :server_side_encryption => "AES256"}
338
338
  end
339
339
  return {client: client, key: key, iv: iv, bucket: bucket, upload_options: upload_options}
340
340
  end
@@ -0,0 +1,5 @@
1
+ module Cnvrg
2
+ class OrgHelpers
3
+
4
+ end
5
+ end
@@ -1,4 +1,4 @@
1
1
  module Cnvrg
2
- VERSION = '0.9.3'
2
+ VERSION = '0.9.4'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnvrg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yochay Ettun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-11-29 00:00:00.000000000 Z
12
+ date: 2018-12-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -414,6 +414,7 @@ files:
414
414
  - lib/cnvrg/hyper.rb
415
415
  - lib/cnvrg/job.rb
416
416
  - lib/cnvrg/logger.rb
417
+ - lib/cnvrg/org_helpers.rb
417
418
  - lib/cnvrg/project.rb
418
419
  - lib/cnvrg/result.rb
419
420
  - lib/cnvrg/runner.rb