kontena-plugin-cloud 1.2.0.pre4 → 1.2.0.pre5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9e4eba676152d47b5effc551728bc8d79fa77351e935a0c54ed672695853164
4
- data.tar.gz: 64d1898e5115c26d06058f1ae20787a81e10b7ffa81a819887daa678d5ef8050
3
+ metadata.gz: d4bbe3fc569faeda478e442d9877cbb2e7c06079a60c05b835620dc866569efe
4
+ data.tar.gz: 3cceb0d2d46dcdbf2d63ccb9930d4933f216217273d5ce5a448d1201c41508ec
5
5
  SHA512:
6
- metadata.gz: c701b5421f14192706e66f45e7841e333ad82bd0ed2d347abad402fca4cee0a2c34773fbdb6da72aa1b338a90e352d07f8633b18f32a497dfd4e307f5f77a0ea
7
- data.tar.gz: beeca426616465e23e6996483b5d04c927edf9f589817f214bcb80bf6917bd924338632860123e71afc9f496fcfa78612db2a8ae72eb1da1b54c5487fffcf3ec
6
+ metadata.gz: 0f9956c8b4901fa789f1a8401a4fba86a6fc33d93ef95c3d510e16ca016ffd72d0243904ebdd7b98e6e8d36abc9a84c5997c6eeb0009e9e259383824e70fcdc9
7
+ data.tar.gz: 5ff697f3a1630c894ccd044ef4b3373017e839bcbaa49d1bf0bb95481189a8d9731718ddb55b6be543cf11403436059fb0f113f560a96e6d2ca29f1bc59d395e
@@ -0,0 +1,15 @@
1
+ require_relative 'cloud_api_model'
2
+
3
+ module Kontena::Cli::Models
4
+ class ImageRepo
5
+ include CloudApiModel
6
+
7
+ def created_at
8
+ Time.parse(@api_data.dig('attributes', 'created-at')).to_i
9
+ end
10
+
11
+ def updated_at
12
+ Time.parse(@api_data.dig('attributes', 'updated-at')).to_i
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'cloud_api_model'
2
+
3
+ module Kontena::Cli::Models
4
+ class ImageTag
5
+ include CloudApiModel
6
+
7
+ def created_at
8
+ Time.parse(@api_data.dig('attributes', 'created-at')).to_i
9
+ end
10
+
11
+ def updated_at
12
+ Time.parse(@api_data.dig('attributes', 'updated-at')).to_i
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require_relative '../../../cli/models/image_repo'
2
+ require_relative '../../../cli/models/image_tag'
3
+
4
+ module Kontena::Plugin::Cloud::Image::Common
5
+ def image_registry_client
6
+ @compute_client ||= Kontena::Client.new(image_registry_url, config.current_account.token, prefix: '/')
7
+ end
8
+
9
+ def image_registry_url
10
+ ENV['KONTENA_IMAGE_REGISTRY_URL'] || 'https://image-registry.kontena.io'
11
+ end
12
+
13
+ def image_distribution_url
14
+ ENV['KONTENA_IMAGES_URL'] || 'https://images.kontena.io'
15
+ end
16
+
17
+ def default_org
18
+ unless current_master
19
+ exit_with_error "Organization is required"
20
+ end
21
+ org, _ = current_master.name.split('/')
22
+
23
+ org
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'common'
2
+
3
+ class Kontena::Plugin::Cloud::Image::CreateCommand < Kontena::Command
4
+ include Kontena::Cli::Common
5
+ include Kontena::Util
6
+ include Kontena::Plugin::Cloud::Image::Common
7
+ include Kontena::Cli::TableGenerator::Helper
8
+
9
+ parameter "NAME", "Image repository name"
10
+
11
+ requires_current_account_token
12
+
13
+ def execute
14
+
15
+ body = {
16
+ data: {
17
+ type: 'repositories',
18
+ id: self.name
19
+ }
20
+ }
21
+ spinner "Creating image repository #{pastel.cyan(name)}" do
22
+ image_registry_client.post("/repositories", JSON.dump(body))
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'common'
2
+
3
+ class Kontena::Plugin::Cloud::Image::ListCommand < Kontena::Command
4
+ include Kontena::Cli::Common
5
+ include Kontena::Util
6
+ include Kontena::Plugin::Cloud::Image::Common
7
+ include Kontena::Cli::TableGenerator::Helper
8
+
9
+ option ["--organization", "--org"], "ORG", "Organization", environment_variable: "KONTENA_ORGANIZATION"
10
+
11
+ requires_current_account_token
12
+
13
+ def execute
14
+
15
+ org = self.organization || default_org
16
+
17
+ repos = image_registry_client.get("/organizations/#{org}/repositories")['data']
18
+ print_table(repos) do |r|
19
+ r['pulls'] = r.dig('attributes', 'pulls')
20
+ r['created_at'] = time_ago( Time.parse(r.dig('attributes', 'created-at')).to_i )
21
+ r['public'] = r.dig('attributes', 'public')
22
+ end
23
+ end
24
+
25
+ def fields
26
+ {
27
+ 'name': 'id',
28
+ 'pulls': 'pulls',
29
+ 'public': 'public',
30
+ 'created': 'created_at'
31
+ }
32
+ end
33
+ end
@@ -0,0 +1,58 @@
1
+ require_relative 'common'
2
+ require 'shellwords'
3
+ require 'open3'
4
+
5
+ class Kontena::Plugin::Cloud::Image::LoginCommand < Kontena::Command
6
+ include Kontena::Cli::Common
7
+ include Kontena::Plugin::Cloud::Image::Common
8
+
9
+ requires_current_account_token
10
+
11
+ def execute
12
+ token = nil
13
+ spinner "Creating a new Kontena Cloud token for Docker" do
14
+ data = { attributes: { name: 'docker' } }
15
+ token = cloud_client.post("/user/personal_access_tokens", { data: data })['data']
16
+ end
17
+
18
+ success = spinner "Logging in to the Kontena Cloud Image Registry" do |spin|
19
+ pass = token.dig('attributes', 'access-token')
20
+
21
+ if `docker login --help`['--password-stdin']
22
+ output, stderr, status = Open3.capture3("docker login -u %s --password-stdin %s" % [current_account.username, image_distribution_url].map(&:shellescape), :stdin_data => pass)
23
+ unless status.success?
24
+ exit_with_error stderr
25
+ end
26
+ else
27
+ output, stderr, status = Open3.capture3("docker login -u %s --password \"%s\" %s" % [current_account.username, pass, image_distribution_url])
28
+ unless status.success?
29
+ exit_with_error stderr
30
+ end
31
+ end
32
+ true
33
+ end
34
+
35
+ if success
36
+ puts
37
+ puts " Login succeeded. Now you should be able to push and pull images using docker"
38
+ puts " cli from #{pastel.cyan(image_distribution_url)}"
39
+ puts
40
+ puts " Example:"
41
+ puts
42
+ puts " #{pastel.green.on_black(' docker tag localimage images.kontena.io/organization/imagename ')}"
43
+ puts " #{pastel.green.on_black(' docker push images.kontena.io/organization/imagename ')}"
44
+ puts
45
+ puts " To configure grid nodes to pull from Kontena Cloud Image Registry you should:"
46
+ puts
47
+ puts " 1. Create a non-expiring token for authentication:"
48
+ puts
49
+ puts " #{pastel.green.on_black(' kontena cloud token create <name> ')}"
50
+ puts
51
+ puts " 2. Configure your platform to use Kontena Cloud Image Registry as an external"
52
+ puts " registry:"
53
+ puts
54
+ puts " #{pastel.green.on_black(' kontena external-registry add -u <username> -p <token> https://images.kontena.io ')}"
55
+ puts
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'common'
2
+
3
+ class Kontena::Plugin::Cloud::Image::RemoveCommand < Kontena::Command
4
+ include Kontena::Cli::Common
5
+ include Kontena::Util
6
+ include Kontena::Plugin::Cloud::Image::Common
7
+
8
+ requires_current_account_token
9
+
10
+ parameter "NAME", "Image repository name"
11
+ option "--force", :flag, "Force remove", default: false, attribute_name: :forced
12
+
13
+ def execute
14
+ confirm_command(name) unless forced?
15
+
16
+ spinner "Removing image repository #{pastel.cyan(name)}" do
17
+ image_registry_client.delete("/repositories/#{name}")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'common'
2
+
3
+ class Kontena::Plugin::Cloud::Image::ShowCommand < Kontena::Command
4
+ include Kontena::Cli::Common
5
+ include Kontena::Util
6
+ include Kontena::Plugin::Cloud::Image::Common
7
+
8
+ requires_current_account_token
9
+
10
+ parameter "NAME", "Image repository name"
11
+
12
+ def execute
13
+ repo = Kontena::Cli::Models::ImageRepo.new(image_registry_client.get("/repositories/#{name}")['data'])
14
+ puts "#{name}:"
15
+ puts " created: #{ time_ago(repo.created_at.to_i)}"
16
+ puts " updated: #{ time_ago(repo.updated_at.to_i)}"
17
+ puts " pulls: #{repo.pulls}"
18
+ puts " pushes: #{repo.pushs}"
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../common'
2
+
3
+ class Kontena::Plugin::Cloud::Image::Tag::ListCommand < Kontena::Command
4
+ include Kontena::Cli::Common
5
+ include Kontena::Util
6
+ include Kontena::Plugin::Cloud::Image::Common
7
+ include Kontena::Cli::TableGenerator::Helper
8
+
9
+ requires_current_account_token
10
+
11
+ parameter "NAME", "Image repository name"
12
+
13
+ def execute
14
+ tags = image_registry_client.get("/repositories/#{name}/tags")['data']
15
+ print_table(tags) do |t|
16
+ t['id'] = "#{name}:#{t['id']}"
17
+ t['pulls'] = t.dig('attributes', 'pulls')
18
+ t['pushs'] = t.dig('attributes', 'pushs')
19
+ t['updated_at'] = time_ago( Time.parse(t.dig('attributes', 'updated-at')).to_i )
20
+ end
21
+ end
22
+
23
+ def fields
24
+ {
25
+ 'name': 'id',
26
+ 'pulls': 'pulls',
27
+ 'pushes': 'pushs',
28
+ 'updated': 'updated_at'
29
+ }
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ class Kontena::Plugin::Cloud::Image::TagCommand < Kontena::Command
2
+
3
+ subcommand ['list', 'ls'], 'List image repository tags', load_subcommand('kontena/plugin/cloud/image/tag/list_command')
4
+
5
+ def execute
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ class Kontena::Plugin::Cloud::ImageCommand < Kontena::Command
2
+
3
+ subcommand ['list', 'ls'], 'List image repositories', load_subcommand('kontena/plugin/cloud/image/list_command')
4
+ subcommand ['show'], 'Show image repository details', load_subcommand('kontena/plugin/cloud/image/show_command')
5
+ subcommand ['login-docker'], 'Login docker to image registry', load_subcommand('kontena/plugin/cloud/image/login_command')
6
+ subcommand ['tag'], 'Image repository tag specific commands', load_subcommand('kontena/plugin/cloud/image/tag_command')
7
+ subcommand ['create'], 'Create new image repository', load_subcommand('kontena/plugin/cloud/image/create_command')
8
+ subcommand ['remove', 'rm'], 'Remove image repository', load_subcommand('kontena/plugin/cloud/image/remove_command')
9
+
10
+ def execute
11
+ end
12
+ end
@@ -1,7 +1,7 @@
1
1
  module Kontena
2
2
  module Plugin
3
3
  module Cloud
4
- VERSION = "1.2.0.pre4"
4
+ VERSION = "1.2.0.pre5"
5
5
 
6
6
  module Organization
7
7
  module User; end
@@ -15,6 +15,10 @@ module Kontena
15
15
  module User; end
16
16
  end
17
17
 
18
+ module Image
19
+ module Tag; end
20
+ end
21
+
18
22
  module Token; end;
19
23
  end
20
24
 
@@ -3,6 +3,7 @@ class Kontena::Cli::CloudCommand < Kontena::Command
3
3
  subcommand 'platform', 'Kontena platform specific commands', load_subcommand('kontena/plugin/cloud/platform_command')
4
4
  subcommand 'node', 'Kontena node specific commands', load_subcommand('kontena/plugin/cloud/node_command')
5
5
  subcommand ['organization', 'org'], 'Organization specific commands', load_subcommand('kontena/plugin/cloud/organization_command')
6
+ subcommand ['image-repository', 'ir'], 'Image repository specific commands', load_subcommand('kontena/plugin/cloud/image_command')
6
7
  subcommand 'region', 'Region specific commands', load_subcommand('kontena/plugin/cloud/region_command')
7
8
  subcommand 'token', 'Personal access token specific commands', load_subcommand('kontena/plugin/cloud/token_command')
8
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-plugin-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.pre4
4
+ version: 1.2.0.pre5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kontena-cli
@@ -70,11 +70,22 @@ files:
70
70
  - lib/kontena/cli/master_code_exchanger.rb
71
71
  - lib/kontena/cli/models/cloud_api_model.rb
72
72
  - lib/kontena/cli/models/grid.rb
73
+ - lib/kontena/cli/models/image_repo.rb
74
+ - lib/kontena/cli/models/image_tag.rb
73
75
  - lib/kontena/cli/models/master_api_model.rb
74
76
  - lib/kontena/cli/models/node.rb
75
77
  - lib/kontena/cli/models/organization.rb
76
78
  - lib/kontena/cli/models/platform.rb
77
79
  - lib/kontena/plugin/cloud.rb
80
+ - lib/kontena/plugin/cloud/image/common.rb
81
+ - lib/kontena/plugin/cloud/image/create_command.rb
82
+ - lib/kontena/plugin/cloud/image/list_command.rb
83
+ - lib/kontena/plugin/cloud/image/login_command.rb
84
+ - lib/kontena/plugin/cloud/image/remove_command.rb
85
+ - lib/kontena/plugin/cloud/image/show_command.rb
86
+ - lib/kontena/plugin/cloud/image/tag/list_command.rb
87
+ - lib/kontena/plugin/cloud/image/tag_command.rb
88
+ - lib/kontena/plugin/cloud/image_command.rb
78
89
  - lib/kontena/plugin/cloud/node/common.rb
79
90
  - lib/kontena/plugin/cloud/node/create_command.rb
80
91
  - lib/kontena/plugin/cloud/node/list_command.rb
@@ -135,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
146
  version: 1.3.1
136
147
  requirements: []
137
148
  rubyforge_project:
138
- rubygems_version: 2.7.1
149
+ rubygems_version: 2.7.2
139
150
  signing_key:
140
151
  specification_version: 4
141
152
  summary: Kontena Cloud management for Kontena CLI