cnvrg 0.8.8 → 0.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cnvrg/Images.rb +65 -34
- data/lib/cnvrg/cli.rb +35 -3
- data/lib/cnvrg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a68bff6bfb11b5c5ec5a1a79a457a6c77885c0b2
|
4
|
+
data.tar.gz: a9caf9fa18a3097369b895a3bf073620a09a8901
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f7754c7c39d0ed23b99c74ed3d371a16fcd45d6c65a60a45fe7672e516293546ee723784fb99ab794b04f13cf64c8856380f8d44b3d7cefd373851b6985bf5a
|
7
|
+
data.tar.gz: eeccb807877a72ad1522d82fe63c060fc801ebe16ac79c8130409e3827f9a1057b8ad0f78bc23931003b599d63ad5852c84f506b6180a82f41774640b010d78a
|
data/lib/cnvrg/Images.rb
CHANGED
@@ -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(
|
13
|
+
def initialize()
|
14
14
|
begin
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
|
20
|
-
@
|
21
|
-
@
|
22
|
-
|
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
|
-
|
24
|
+
end
|
30
25
|
|
31
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
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()
|
data/lib/cnvrg/cli.rb
CHANGED
@@ -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
|
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(
|
5438
|
+
log_message(error, Thor::Shell::Color::RED)
|
5407
5439
|
end
|
5408
5440
|
|
5409
5441
|
if should_exit
|
data/lib/cnvrg/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2018-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|