cnvrg 0.8.8 → 0.8.9

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: fa06cc99ce48fbc702512cef391170adb96c7551
4
- data.tar.gz: a796655bb7816ae274b0e2318b1b07c3f13f4b70
3
+ metadata.gz: a68bff6bfb11b5c5ec5a1a79a457a6c77885c0b2
4
+ data.tar.gz: a9caf9fa18a3097369b895a3bf073620a09a8901
5
5
  SHA512:
6
- metadata.gz: 69373b1b73682ff11400cec9cb23d0a7491b56e7ca8fc32f7a63da95819f4a10efac4fcbf80744ea45bb1797f1e2b54ce56fdeee7046472f6daf68e3ac36272a
7
- data.tar.gz: d9ca87a00116dbbc7d63651addd0e9f296b8e5b21e613bd33253575d632d0e5990644790182fec19198756eba872198a5e8d327ee0da58aab339e9bf3238a395
6
+ metadata.gz: 2f7754c7c39d0ed23b99c74ed3d371a16fcd45d6c65a60a45fe7672e516293546ee723784fb99ab794b04f13cf64c8856380f8d44b3d7cefd373851b6985bf5a
7
+ data.tar.gz: eeccb807877a72ad1522d82fe63c060fc801ebe16ac79c8130409e3827f9a1057b8ad0f78bc23931003b599d63ad5852c84f506b6180a82f41774640b010d78a
@@ -7,50 +7,81 @@ require 'mimemagic'
7
7
 
8
8
  module Cnvrg
9
9
  class Images
10
- attr_reader :image_name, :image_tag, :is_docker, :project_slug, :commit_id, :owner, :port, :image_slug
10
+ # attr_reader :image_name, :image_tag, :is_docker, :project_slug, :commit_id, :owner, :port, :image_slug
11
11
 
12
12
 
13
- def initialize(working_dir, image_name="")
13
+ def initialize()
14
14
  begin
15
- config = YAML.load_file(working_dir+"/.cnvrg/config.yml")
16
- idx = YAML.load_file(working_dir + "/.cnvrg/idx.yml")
17
-
18
- @working_dir = working_dir
19
- @commit_id =idx[:commit]
20
- @project_title = config[:project_name]
21
- @project_slug = config[:project_slug]
22
- @owner = config[:owner]
23
- @is_docker = config[:docker]
24
- if image_name.empty?
25
- @image_name = config[:image_base]
26
- @image_tag = config[:image_tag]
27
- @image_slug = find_image()
15
+ home_dir = File.expand_path('~')
16
+ config = YAML.load_file(home_dir+"/.cnvrg/config.yml")
17
+ @owner = config.to_h[:owner]
18
+ @username = config.to_h[:username]
19
+ rescue => e
20
+ @owner = ""
21
+ @username = ""
22
+ Cnvrg::Logger.log_info("cnvrg is not configured")
28
23
 
29
- else
24
+ end
30
25
 
31
- @image_name = image_name
32
- if !@image_name.nil? and !@image_name.empty?
33
- if image_name.include? ":"
34
- @image_name = image_name[0, image_name.index(":")]
35
- @image_tag = image_name[image_name.index(":")+1, image_name.size]
36
- else
37
- @image_name = image_name
38
- @image_tag = "lastest"
39
- end
26
+ end
40
27
 
41
- end
42
- @image_slug = find_image(false)
43
- update_image_activity(@commit_id, nil)
44
- config = {project_name: config[:project_name],
45
- project_slug: config[:project_slug],
46
- owner: config[:owner],
47
- docker: true, image_base: @image_name, image_tag: @image_tag, image_slug: image_slug}
48
- File.open(working_dir+"/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
28
+ def upload_docker_image(image_path, image_name,workdir, user, description, is_gpu )
29
+ if image_name.present? and image_name.include? ":"
30
+ image_split = image_name.split(":")
31
+ image_name = image_split[0]
32
+ image_tag = image_split[1]
33
+ if image_tag.blank?
34
+ image_tag = "latest"
35
+ end
36
+ if image_name.blank?
37
+ Cnvrg::Logger.log_info("image_name: #{image_name} is not valid")
38
+ return false
49
39
  end
40
+ end
41
+ if !File.exist? image_path
42
+ Cnvrg::Logger.log_info("image_path: #{image_path} was not found")
43
+ return
44
+ end
45
+ is_dockerfile = (!image_path.end_with? ".tar") ? true : false
46
+ file_name = File.basename image_path
47
+ file_size = File.size(image_path).to_f
48
+ mime_type = MimeMagic.by_path(image_path)
49
+ content_type = mime_type.present? ? mime_type.type : "application/x-tar"
50
+
51
+ image_res = Cnvrg::API.request("users/#{@owner}/images/upload" , 'POST', {image_name: image_name, image_tag: image_tag,
52
+ workdir: workdir, user: user, description:description, is_gpu:is_gpu,
53
+ file_name: file_name,
54
+ file_size: file_size, file_content_type: content_type, is_dockerfile: is_dockerfile
55
+ })
56
+ Cnvrg::CLI.is_response_success(image_res, true
57
+ )
58
+
59
+ path = image_res["result"]["path"]
60
+ image_id = image_res["result"]["image_id"]
61
+
62
+
63
+ props = Cnvrg::Helpers.get_s3_props(image_res["result"])
64
+ if props.is_a? Cnvrg::Result
65
+ return false
66
+ end
50
67
 
51
- rescue => e
68
+ client = props[:client]
69
+ upload_options = props[:upload_options]
70
+ bucket = Aws::S3::Resource.new(client: client).bucket(props[:bucket])
71
+
72
+ resp = bucket.object(path).
73
+ upload_file(image_path, upload_options)
74
+ unless resp
75
+ raise Exception.new("Cant upload #{image_path}")
52
76
  end
77
+ return save_docker_image(image_id)
78
+
79
+
80
+ end
53
81
 
82
+ def save_docker_image(image_id)
83
+ image_res = Cnvrg::API.request("users/#{@owner}/images/#{image_id}/save" , 'POST', {})
84
+ return Cnvrg::CLI.is_response_success(image_res, true)
54
85
  end
55
86
 
56
87
  def is_container_exist()
@@ -4483,9 +4483,9 @@ module Cnvrg
4483
4483
  end
4484
4484
 
4485
4485
 
4486
- desc 'upload_image', 'commit notebook changes to create a new notebook image'
4486
+ desc 'upload_image', 'commit notebook changes to create a new notebook image', :hide =>true
4487
4487
 
4488
- def upload_image(image_id, is_public, is_base, *message)
4488
+ def upload_image_old(image_id, is_public, is_base, *message)
4489
4489
  verify_logged_in(true)
4490
4490
  log_start(__method__, args, options)
4491
4491
  image = Docker::Image.get(image_id)
@@ -4848,6 +4848,38 @@ module Cnvrg
4848
4848
  end
4849
4849
 
4850
4850
 
4851
+ end
4852
+
4853
+ desc 'upload_docker_image', 'Upload new docker image to cnvrg'
4854
+ method_option :workdir, :type => :string, :aliases => ["-w","--workdir"], :desc => "workdir of docker image", :default => "/root"
4855
+ method_option :description, :type => :string, :aliases => ["-d", "--description"], :desc => "description for docker image", :default => ""
4856
+ method_option :user, :type => :string, :aliases => ["-u","--user"], :default => "root"
4857
+ method_option :gpu, :type => :boolean, :aliases => ["-g","--gpu"], :default => false
4858
+ def upload_image(image_name,image_path)
4859
+ begin
4860
+ verify_logged_in(true)
4861
+ log_start(__method__, args, options)
4862
+
4863
+ @image = Cnvrg::Images.new()
4864
+ say "Uploading new docker image file", Thor::Shell::Color::BLUE
4865
+ workdir = options[:workdir]
4866
+ description = options[:description]
4867
+ user = options[:user]
4868
+ is_gpu = options[:gpu]
4869
+ 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)
4872
+
4873
+
4874
+ else
4875
+ log_message("Couldn't upload image: #{image_name}", Thor::Shell::Color::RED, true)
4876
+
4877
+ end
4878
+ rescue => e
4879
+ log_error(e)
4880
+ end
4881
+
4882
+
4851
4883
  end
4852
4884
 
4853
4885
 
@@ -5403,7 +5435,7 @@ module Cnvrg
5403
5435
  log_message('Server Error', Thor::Shell::Color::RED)
5404
5436
  else
5405
5437
  $LOG.error message: error, type: "error"
5406
- log_message("error", Thor::Shell::Color::RED)
5438
+ log_message(error, Thor::Shell::Color::RED)
5407
5439
  end
5408
5440
 
5409
5441
  if should_exit
@@ -1,4 +1,4 @@
1
1
  module Cnvrg
2
- VERSION = '0.8.8'
2
+ VERSION = '0.8.9'
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.8.8
4
+ version: 0.8.9
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-10 00:00:00.000000000 Z
12
+ date: 2018-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler