kontena-cli 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -6
- data/lib/kontena/cli/commands.rb +1 -1
- data/lib/kontena/cli/common.rb +1 -1
- data/lib/kontena/cli/containers/containers.rb +1 -1
- data/lib/kontena/cli/grids/commands.rb +55 -3
- data/lib/kontena/cli/grids/external_registries.rb +40 -0
- data/lib/kontena/cli/grids/grids.rb +16 -13
- data/lib/kontena/cli/grids/registry.rb +90 -0
- data/lib/kontena/cli/grids/vpn.rb +6 -6
- data/lib/kontena/cli/nodes/nodes.rb +5 -3
- data/lib/kontena/cli/server/commands.rb +5 -28
- data/lib/kontena/cli/server/user.rb +84 -31
- data/lib/kontena/cli/services/commands.rb +1 -1
- data/lib/kontena/cli/services/containers.rb +2 -2
- data/lib/kontena/cli/services/logs.rb +3 -3
- data/lib/kontena/cli/services/services.rb +27 -9
- data/lib/kontena/cli/services/services_helper.rb +5 -7
- data/lib/kontena/cli/services/stats.rb +5 -3
- data/lib/kontena/cli/stacks/commands.rb +1 -0
- data/lib/kontena/cli/stacks/stacks.rb +14 -7
- data/lib/kontena/cli/version.rb +1 -1
- data/lib/kontena/scripts/completer +115 -0
- data/lib/kontena/scripts/init +11 -0
- data/spec/kontena/cli/server/user_spec.rb +59 -0
- data/spec/kontena/cli/services/services_helper_spec.rb +11 -10
- data/spec/kontena/cli/stacks/stacks_spec.rb +44 -12
- data/spec/spec_helper.rb +0 -1
- metadata +8 -2
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
_kontena_complete() {
|
4
|
+
COMPREPLY=()
|
5
|
+
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
6
|
+
local word="${COMP_WORDS[COMP_CWORD]}"
|
7
|
+
local completions="$(${DIR}/completer ${COMP_WORDS[*]})"
|
8
|
+
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
|
9
|
+
}
|
10
|
+
|
11
|
+
complete -F _kontena_complete kontena
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative "../../../spec_helper"
|
2
|
+
require "kontena/cli/server/user"
|
3
|
+
|
4
|
+
module Kontena::Cli::Server
|
5
|
+
describe User do
|
6
|
+
describe '#register' do
|
7
|
+
|
8
|
+
let(:auth_client) do
|
9
|
+
double(Kontena::Client)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'asks email' do
|
13
|
+
expect(subject).to receive(:ask).once.and_return('john.doe@acme.io')
|
14
|
+
allow(subject).to receive(:password).and_return('secret')
|
15
|
+
allow(Kontena::Client).to receive(:new).and_return(auth_client)
|
16
|
+
allow(auth_client).to receive(:post)
|
17
|
+
subject.register(nil, {})
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'asks password twice' do
|
21
|
+
allow(subject).to receive(:ask).once.and_return('john.doe@acme.io')
|
22
|
+
expect(subject).to receive(:password).twice.and_return('secret')
|
23
|
+
allow(Kontena::Client).to receive(:new).and_return(auth_client)
|
24
|
+
allow(auth_client).to receive(:post)
|
25
|
+
subject.register(nil, {})
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'validates given passwords' do
|
29
|
+
allow(subject).to receive(:ask).once.and_return('john.doe@acme.io')
|
30
|
+
expect(subject).to receive(:password).twice.and_return('secret', 'secret2')
|
31
|
+
expect{subject.register(nil, {})}.to raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'uses https://auth.kontena.io as default auth provider' do
|
35
|
+
allow(subject).to receive(:ask).and_return('john.doe@acme.io')
|
36
|
+
allow(subject).to receive(:password).and_return('secret')
|
37
|
+
expect(Kontena::Client).to receive(:new).with('https://auth.kontena.io').and_return(auth_client)
|
38
|
+
allow(auth_client).to receive(:post)
|
39
|
+
subject.register(nil, {})
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'uses given auth provider' do
|
43
|
+
allow(subject).to receive(:ask).and_return('john.doe@acme.io')
|
44
|
+
allow(subject).to receive(:password).and_return('secret')
|
45
|
+
expect(Kontena::Client).to receive(:new).with('http://custom.auth-provider.io').and_return(auth_client)
|
46
|
+
allow(auth_client).to receive(:post)
|
47
|
+
subject.register('http://custom.auth-provider.io', {})
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'sends register request to auth provider' do
|
51
|
+
allow(subject).to receive(:ask).and_return('john.doe@acme.io')
|
52
|
+
allow(subject).to receive(:password).and_return('secret')
|
53
|
+
allow(Kontena::Client).to receive(:new).with('https://auth.kontena.io').and_return(auth_client)
|
54
|
+
expect(auth_client).to receive(:post).with('users', {email: 'john.doe@acme.io', password: 'secret'})
|
55
|
+
subject.register(nil, {})
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -17,39 +17,40 @@ module Kontena::Cli::Services
|
|
17
17
|
|
18
18
|
before(:each) do
|
19
19
|
allow(subject).to receive(:client).with(token).and_return(client)
|
20
|
+
allow(subject).to receive(:current_grid).and_return('test-grid')
|
20
21
|
end
|
21
22
|
|
22
23
|
describe '#create_service' do
|
23
|
-
it 'creates POST grids/:
|
24
|
-
expect(client).to receive(:post).with('grids/
|
25
|
-
subject.create_service(token, '
|
24
|
+
it 'creates POST grids/:grid/:name/services request to Kontena Server' do
|
25
|
+
expect(client).to receive(:post).with('grids/test-grid/services', {'name' => 'test-service'})
|
26
|
+
subject.create_service(token, 'test-grid', {'name' => 'test-service'})
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
30
|
describe '#update_service' do
|
30
31
|
it 'creates PUT services/:id request to Kontena Server' do
|
31
|
-
expect(client).to receive(:put).with('services/1', {'name' => 'test-service'})
|
32
|
+
expect(client).to receive(:put).with('services/test-grid/1', {'name' => 'test-service'})
|
32
33
|
subject.update_service(token, '1', {'name' => 'test-service'})
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
37
|
describe '#get_service' do
|
37
38
|
it 'creates GET services/:id request to Kontena Server' do
|
38
|
-
expect(client).to receive(:get).with('services/test-service')
|
39
|
+
expect(client).to receive(:get).with('services/test-grid/test-service')
|
39
40
|
subject.get_service(token, 'test-service')
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
44
|
describe '#deploy_service' do
|
44
45
|
it 'creates POST services/:id/deploy request to Kontena Server' do
|
45
|
-
allow(client).to receive(:get).with('services/1').and_return({'state' => 'running'})
|
46
|
-
expect(client).to receive(:post).with('services/1/deploy', {'strategy' => 'ha'})
|
46
|
+
allow(client).to receive(:get).with('services/test-grid/1').and_return({'state' => 'running'})
|
47
|
+
expect(client).to receive(:post).with('services/test-grid/1/deploy', {'strategy' => 'ha'})
|
47
48
|
subject.deploy_service(token, '1', {'strategy' => 'ha'})
|
48
49
|
end
|
49
50
|
|
50
51
|
it 'polls Kontena Server until service is running' do
|
51
|
-
allow(client).to receive(:post).with('services/1/deploy', anything)
|
52
|
-
expect(client).to receive(:get).with('services/1').twice.and_return({'state' => 'deploying'}, {'state' => 'running'})
|
52
|
+
allow(client).to receive(:post).with('services/test-grid/1/deploy', anything)
|
53
|
+
expect(client).to receive(:get).with('services/test-grid/1').twice.and_return({'state' => 'deploying'}, {'state' => 'running'})
|
53
54
|
|
54
55
|
subject.deploy_service(token, '1', {'strategy' => 'ha'})
|
55
56
|
end
|
@@ -100,4 +101,4 @@ module Kontena::Cli::Services
|
|
100
101
|
end
|
101
102
|
end
|
102
103
|
end
|
103
|
-
end
|
104
|
+
end
|
@@ -11,6 +11,28 @@ module Kontena::Cli::Stacks
|
|
11
11
|
'1234567'
|
12
12
|
end
|
13
13
|
|
14
|
+
let(:yml) do
|
15
|
+
content = <<content
|
16
|
+
wordpress:
|
17
|
+
image: wordpress:4.1
|
18
|
+
stateful: true
|
19
|
+
ports:
|
20
|
+
- 80:80
|
21
|
+
links:
|
22
|
+
- mysql:mysql
|
23
|
+
environment:
|
24
|
+
- WORDPRESS_DB_PASSWORD=%{prefix}_secret
|
25
|
+
instances: 2
|
26
|
+
deploy:
|
27
|
+
strategy: ha
|
28
|
+
mysql:
|
29
|
+
image: mysql:5.6
|
30
|
+
stateful: true
|
31
|
+
environment:
|
32
|
+
- MYSQL_ROOT_PASSWORD=%{prefix}_secret
|
33
|
+
content
|
34
|
+
content
|
35
|
+
end
|
14
36
|
|
15
37
|
let(:services) do
|
16
38
|
{
|
@@ -35,7 +57,7 @@ module Kontena::Cli::Stacks
|
|
35
57
|
end
|
36
58
|
|
37
59
|
let(:options) do
|
38
|
-
options = double({prefix: false, file: false})
|
60
|
+
options = double({prefix: false, file: false, service: nil})
|
39
61
|
end
|
40
62
|
|
41
63
|
let(:env_vars) do
|
@@ -64,8 +86,7 @@ module Kontena::Cli::Stacks
|
|
64
86
|
context 'when api url and token are valid' do
|
65
87
|
before(:each) do
|
66
88
|
allow(subject).to receive(:settings).and_return(settings)
|
67
|
-
allow(
|
68
|
-
allow(File).to receive(:read)
|
89
|
+
allow(File).to receive(:read).and_return(yml)
|
69
90
|
allow(subject).to receive(:get_service).and_raise(Kontena::Errors::StandardError.new(404, 'Not Found'))
|
70
91
|
allow(subject).to receive(:create_service).and_return({'id' => 'kontena-test-mysql'},{'id' => 'kontena-test-wordpress'})
|
71
92
|
allow(subject).to receive(:current_grid).and_return('1')
|
@@ -74,28 +95,28 @@ module Kontena::Cli::Stacks
|
|
74
95
|
|
75
96
|
it 'reads ./kontena.yml file by default' do
|
76
97
|
allow(subject).to receive(:settings).and_return(settings)
|
77
|
-
|
78
|
-
expect(File).to receive(:read).with('./kontena.yml')
|
98
|
+
expect(File).to receive(:read).with('./kontena.yml').and_return(yml)
|
79
99
|
expect(options).to receive(:file).once.and_return(false)
|
80
100
|
subject.deploy(options)
|
81
101
|
end
|
82
102
|
|
83
103
|
it 'reads given yml file' do
|
84
104
|
expect(options).to receive(:file).once.and_return('custom.yml')
|
85
|
-
expect(File).to receive(:read).with('custom.yml')
|
105
|
+
expect(File).to receive(:read).with('custom.yml').and_return(yml)
|
86
106
|
subject.deploy(options)
|
87
107
|
end
|
88
108
|
|
89
109
|
it 'uses current directory as service name prefix by default' do
|
90
110
|
current_dir = '/kontena/tests/stacks'
|
91
111
|
allow(Dir).to receive(:getwd).and_return(current_dir)
|
92
|
-
expect(File).to receive(:basename).with(current_dir)
|
112
|
+
expect(File).to receive(:basename).with(current_dir).and_return('stacks')
|
93
113
|
subject.deploy(options)
|
94
114
|
end
|
95
115
|
|
96
116
|
context 'when yml file has multiple env files' do
|
97
117
|
it 'merges environment variables correctly' do
|
98
118
|
allow(subject).to receive(:current_dir).and_return("kontena-test")
|
119
|
+
allow(YAML).to receive(:load).and_return(services)
|
99
120
|
services['wordpress']['environment'] = ['MYSQL_ADMIN_PASSWORD=password']
|
100
121
|
services['wordpress']['env_file'] = %w(/path/to/env_file .env)
|
101
122
|
|
@@ -120,6 +141,7 @@ module Kontena::Cli::Stacks
|
|
120
141
|
context 'when yml file has one env file' do
|
121
142
|
it 'merges environment variables correctly' do
|
122
143
|
allow(subject).to receive(:current_dir).and_return("kontena-test")
|
144
|
+
allow(YAML).to receive(:load).and_return(services)
|
123
145
|
services['wordpress']['environment'] = ['MYSQL_ADMIN_PASSWORD=password']
|
124
146
|
services['wordpress']['env_file'] = '/path/to/env_file'
|
125
147
|
|
@@ -142,7 +164,7 @@ module Kontena::Cli::Stacks
|
|
142
164
|
|
143
165
|
it 'creates mysql service before wordpress' do
|
144
166
|
allow(subject).to receive(:current_dir).and_return("kontena-test")
|
145
|
-
data = {:name =>"kontena-test-mysql", :image=>'mysql:5.6', :env=>
|
167
|
+
data = {:name =>"kontena-test-mysql", :image=>'mysql:5.6', :env=>["MYSQL_ROOT_PASSWORD=kontena-test_secret"], :container_count=>nil, :stateful=>true}
|
146
168
|
expect(subject).to receive(:create_service).with('1234567', '1', data)
|
147
169
|
|
148
170
|
subject.deploy(options)
|
@@ -153,11 +175,11 @@ module Kontena::Cli::Stacks
|
|
153
175
|
|
154
176
|
data = {
|
155
177
|
:name =>"kontena-test-wordpress",
|
156
|
-
:image=>"wordpress:
|
157
|
-
:env=>
|
178
|
+
:image=>"wordpress:4.1",
|
179
|
+
:env=>["WORDPRESS_DB_PASSWORD=kontena-test_secret"],
|
158
180
|
:container_count=>2,
|
159
|
-
:stateful=>
|
160
|
-
:links=>[{:name=>"kontena-test-mysql", :alias=>"
|
181
|
+
:stateful=>true,
|
182
|
+
:links=>[{:name=>"kontena-test-mysql", :alias=>"mysql"}],
|
161
183
|
:ports=>[{:container_port=>"80", :node_port=>"80", :protocol=>"tcp"}]
|
162
184
|
}
|
163
185
|
expect(subject).to receive(:create_service).with('1234567', '1', data)
|
@@ -172,8 +194,18 @@ module Kontena::Cli::Stacks
|
|
172
194
|
subject.deploy(options)
|
173
195
|
end
|
174
196
|
|
197
|
+
context 'when giving service option' do
|
198
|
+
it 'deploys only given services' do
|
199
|
+
allow(subject).to receive(:current_dir).and_return("kontena-test")
|
200
|
+
allow(options).to receive(:service).and_return(['wordpress'])
|
201
|
+
expect(subject).to receive(:create).once.with('wordpress', anything).and_return({})
|
202
|
+
expect(subject).not_to receive(:create).with('mysql', services['mysql'])
|
175
203
|
|
204
|
+
subject.deploy(options)
|
205
|
+
end
|
206
|
+
end
|
176
207
|
end
|
208
|
+
|
177
209
|
end
|
178
210
|
end
|
179
211
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kontena-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kontena, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -103,7 +103,9 @@ files:
|
|
103
103
|
- lib/kontena/cli/containers/containers.rb
|
104
104
|
- lib/kontena/cli/grids/audit_log.rb
|
105
105
|
- lib/kontena/cli/grids/commands.rb
|
106
|
+
- lib/kontena/cli/grids/external_registries.rb
|
106
107
|
- lib/kontena/cli/grids/grids.rb
|
108
|
+
- lib/kontena/cli/grids/registry.rb
|
107
109
|
- lib/kontena/cli/grids/users.rb
|
108
110
|
- lib/kontena/cli/grids/vpn.rb
|
109
111
|
- lib/kontena/cli/nodes/commands.rb
|
@@ -122,6 +124,9 @@ files:
|
|
122
124
|
- lib/kontena/cli/version.rb
|
123
125
|
- lib/kontena/client.rb
|
124
126
|
- lib/kontena/errors.rb
|
127
|
+
- lib/kontena/scripts/completer
|
128
|
+
- lib/kontena/scripts/init
|
129
|
+
- spec/kontena/cli/server/user_spec.rb
|
125
130
|
- spec/kontena/cli/services/services_helper_spec.rb
|
126
131
|
- spec/kontena/cli/stacks/stacks_spec.rb
|
127
132
|
- spec/spec_helper.rb
|
@@ -151,6 +156,7 @@ signing_key:
|
|
151
156
|
specification_version: 4
|
152
157
|
summary: Kontena command line tool
|
153
158
|
test_files:
|
159
|
+
- spec/kontena/cli/server/user_spec.rb
|
154
160
|
- spec/kontena/cli/services/services_helper_spec.rb
|
155
161
|
- spec/kontena/cli/stacks/stacks_spec.rb
|
156
162
|
- spec/spec_helper.rb
|