kontena-cli 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/kontena +3 -2
  4. data/lib/kontena/cli/app_command.rb +6 -2
  5. data/lib/kontena/cli/apps/build_command.rb +0 -1
  6. data/lib/kontena/cli/apps/common.rb +1 -0
  7. data/lib/kontena/cli/apps/deploy_command.rb +17 -13
  8. data/lib/kontena/cli/apps/init_command.rb +1 -2
  9. data/lib/kontena/cli/apps/list_command.rb +13 -5
  10. data/lib/kontena/cli/apps/logs_command.rb +22 -13
  11. data/lib/kontena/cli/apps/monitor_command.rb +91 -0
  12. data/lib/kontena/cli/apps/remove_command.rb +0 -2
  13. data/lib/kontena/cli/apps/scale_command.rb +32 -0
  14. data/lib/kontena/cli/apps/show_command.rb +22 -0
  15. data/lib/kontena/cli/apps/start_command.rb +0 -1
  16. data/lib/kontena/cli/apps/stop_command.rb +0 -1
  17. data/lib/kontena/cli/common.rb +12 -0
  18. data/lib/kontena/cli/containers/inspect_command.rb +8 -3
  19. data/lib/kontena/cli/etcd/common.rb +8 -0
  20. data/lib/kontena/cli/etcd/get_command.rb +4 -0
  21. data/lib/kontena/cli/etcd/list_command.rb +4 -0
  22. data/lib/kontena/cli/etcd/mkdir_command.rb +5 -0
  23. data/lib/kontena/cli/etcd/remove_command.rb +5 -0
  24. data/lib/kontena/cli/etcd/set_command.rb +5 -0
  25. data/lib/kontena/cli/grid_command.rb +2 -0
  26. data/lib/kontena/cli/grids/env_command.rb +22 -0
  27. data/lib/kontena/cli/grids/logs_command.rb +12 -1
  28. data/lib/kontena/cli/node_command.rb +2 -0
  29. data/lib/kontena/cli/nodes/ssh_command.rb +30 -0
  30. data/lib/kontena/cli/service_command.rb +4 -0
  31. data/lib/kontena/cli/services/create_command.rb +9 -0
  32. data/lib/kontena/cli/services/deploy_command.rb +1 -7
  33. data/lib/kontena/cli/services/envs_command.rb +19 -0
  34. data/lib/kontena/cli/services/list_command.rb +15 -3
  35. data/lib/kontena/cli/services/monitor_command.rb +57 -0
  36. data/lib/kontena/cli/services/scale_command.rb +2 -6
  37. data/lib/kontena/cli/services/services_helper.rb +94 -43
  38. data/lib/kontena/cli/services/update_command.rb +12 -1
  39. data/lib/kontena/machine/aws/cloudinit_master.yml +2 -2
  40. data/lib/kontena/machine/azure/cloudinit_master.yml +2 -2
  41. data/lib/kontena/machine/digital_ocean/cloudinit_master.yml +2 -2
  42. data/lib/kontena/scripts/completer +4 -2
  43. data/spec/kontena/cli/app/deploy_command_spec.rb +24 -7
  44. data/spec/kontena/cli/app/scale_spec.rb +64 -0
  45. data/spec/kontena/cli/services/services_helper_spec.rb +0 -7
  46. metadata +12 -2
@@ -8,7 +8,7 @@ module Kontena::Cli::Services
8
8
  parameter "NAME", "Service name"
9
9
 
10
10
  option "--image", "IMAGE", "Docker image to use"
11
- option ["-p", "--ports"], "PORTS", "Publish a service's port to the host", multivalued: true
11
+ option ["-p", "--ports"], "PORT", "Publish a service's port to the host", multivalued: true
12
12
  option ["-e", "--env"], "ENV", "Set environment variables", multivalued: true
13
13
  option ["-l", "--link"], "LINK", "Add link to another service in the form of name:alias", multivalued: true
14
14
  option ["-a", "--affinity"], "AFFINITY", "Set service affinity", multivalued: true
@@ -24,6 +24,11 @@ module Kontena::Cli::Services
24
24
  option "--net", "NET", "Network mode"
25
25
  option "--log-driver", "LOG_DRIVER", "Set logging driver"
26
26
  option "--log-opt", "LOG_OPT", "Add logging options", multivalued: true
27
+ option "--deploy-strategy", "STRATEGY", "Deploy strategy to use (ha, random)"
28
+ option "--deploy-wait-for-port", "PORT", "Wait for port to respond when deploying"
29
+ option "--deploy-min-health", "FLOAT", "The minimum percentage (0.0 - 1.0) of healthy instances that do not sacrifice overall service availability while deploying"
30
+ option "--pid", "PID", "Pid namespace to use"
31
+
27
32
 
28
33
  def execute
29
34
  require_api_url
@@ -38,6 +43,7 @@ module Kontena::Cli::Services
38
43
  # @return [Hash]
39
44
  def parse_service_data_from_options
40
45
  data = {}
46
+ data[:strategy] = deploy_strategy if deploy_strategy
41
47
  data[:ports] = parse_ports(ports_list) unless ports_list.empty?
42
48
  data[:links] = parse_links(link_list) unless link_list.empty?
43
49
  data[:memory] = parse_memory(memory) if memory
@@ -55,6 +61,11 @@ module Kontena::Cli::Services
55
61
  data[:net] = net if net
56
62
  data[:log_driver] = log_driver if log_driver
57
63
  data[:log_opts] = parse_log_opts(log_opt_list)
64
+ data[:deploy_opts] = {}
65
+ data[:deploy_opts][:min_health] = deploy_min_health.to_f if deploy_min_health
66
+ data[:deploy_opts][:wait_for_port] = deploy_wait_for_port.to_i if deploy_wait_for_port
67
+ data.delete(:deploy_opts) if data[:deploy_opts].empty?
68
+ data[:pid] = pid if pid
58
69
  data
59
70
  end
60
71
  end
@@ -24,7 +24,7 @@ write_files:
24
24
  fi
25
25
  /usr/bin/docker run --name=kontena-server-haproxy \
26
26
  --link kontena-server-api:kontena-server-api \
27
- -e SSL_CERT="$SSL_CERT" -e BACKEND_PORT=9292 \
27
+ -e SSL_CERT="$SSL_CERT" \
28
28
  -p 80:80 -p 443:443 kontena/haproxy:latest
29
29
  coreos:
30
30
  update:
@@ -102,4 +102,4 @@ coreos:
102
102
  ExecStartPre=-/usr/bin/docker stop kontena-server-haproxy
103
103
  ExecStartPre=-/usr/bin/docker rm kontena-server-haproxy
104
104
  ExecStartPre=/usr/bin/docker pull kontena/haproxy:latest
105
- ExecStart=/opt/bin/kontena-haproxy.sh
105
+ ExecStart=/opt/bin/kontena-haproxy.sh
@@ -24,7 +24,7 @@ write_files:
24
24
  fi
25
25
  /usr/bin/docker run --name=kontena-server-haproxy \
26
26
  --link kontena-server-api:kontena-server-api \
27
- -e SSL_CERT="$SSL_CERT" -e BACKEND_PORT=9292 \
27
+ -e SSL_CERT="$SSL_CERT" \
28
28
  -p 80:80 -p 443:443 kontena/haproxy:latest
29
29
  coreos:
30
30
  update:
@@ -102,4 +102,4 @@ coreos:
102
102
  ExecStartPre=-/usr/bin/docker stop kontena-server-haproxy
103
103
  ExecStartPre=-/usr/bin/docker rm kontena-server-haproxy
104
104
  ExecStartPre=/usr/bin/docker pull kontena/haproxy:latest
105
- ExecStart=/opt/bin/kontena-haproxy.sh
105
+ ExecStart=/opt/bin/kontena-haproxy.sh
@@ -24,7 +24,7 @@ write_files:
24
24
  fi
25
25
  /usr/bin/docker run --name=kontena-server-haproxy \
26
26
  --link kontena-server-api:kontena-server-api \
27
- -e SSL_CERT="$SSL_CERT" -e BACKEND_PORT=9292 \
27
+ -e SSL_CERT="$SSL_CERT" \
28
28
  -p 80:80 -p 443:443 kontena/haproxy:latest
29
29
  coreos:
30
30
  update:
@@ -102,4 +102,4 @@ coreos:
102
102
  ExecStartPre=-/usr/bin/docker stop kontena-server-haproxy
103
103
  ExecStartPre=-/usr/bin/docker rm kontena-server-haproxy
104
104
  ExecStartPre=/usr/bin/docker pull kontena/haproxy:latest
105
- ExecStart=/opt/bin/kontena-haproxy.sh
105
+ ExecStart=/opt/bin/kontena-haproxy.sh
@@ -103,7 +103,8 @@ if words.size > 0
103
103
  end
104
104
  when 'service'
105
105
  completion.clear
106
- sub_commands = %w(containers create delete deploy list logs restart scale show start stats stop update)
106
+ sub_commands = %w(containers create delete deploy list logs restart
107
+ scale show start stats stop update monitor)
107
108
  if words[1]
108
109
  completion.push(sub_commands) unless sub_commands.include?(words[1])
109
110
  completion.push helper.services
@@ -127,7 +128,8 @@ if words.size > 0
127
128
  completion.push %w(add list delete)
128
129
  when 'app'
129
130
  completion.clear
130
- sub_commands = %w(init build deploy start stop remove rm ps list logs)
131
+ sub_commands = %w(init build deploy start stop remove rm ps list
132
+ logs monitor show)
131
133
  if words[1]
132
134
  completion.push(sub_commands) unless sub_commands.include?(words[1])
133
135
  completion.push helper.yml_services
@@ -147,11 +147,12 @@ yml
147
147
  :env=>["MYSQL_ADMIN_PASSWORD=password", "TEST_ENV_VAR=test", "TEST_ENV_VAR2=test3"],
148
148
  :container_count=>2,
149
149
  :stateful=>false,
150
+ :strategy=>'ha',
150
151
  :links=>[{:name=>"kontena-test-mysql", :alias=>"db"}],
151
152
  :ports=>[{:container_port=>"80", :node_port=>"80", :protocol=>"tcp"}]
152
153
  }
153
154
 
154
- expect(subject).to receive(:create_service).with('1234567', '1', data)
155
+ expect(subject).to receive(:create_service).with('1234567', '1', hash_including(data))
155
156
  subject.run([])
156
157
  end
157
158
  end
@@ -171,11 +172,12 @@ yml
171
172
  :env=>["MYSQL_ADMIN_PASSWORD=password", "TEST_ENV_VAR=test"],
172
173
  :container_count=>2,
173
174
  :stateful=>false,
175
+ :strategy=>'ha',
174
176
  :links=>[{:name=>"kontena-test-mysql", :alias=>"db"}],
175
177
  :ports=>[{:container_port=>"80", :node_port=>"80", :protocol=>"tcp"}]
176
178
  }
177
179
 
178
- expect(subject).to receive(:create_service).with('1234567', '1', data)
180
+ expect(subject).to receive(:create_service).with('1234567', '1', hash_including(data))
179
181
  subject.run([])
180
182
  end
181
183
  end
@@ -190,18 +192,25 @@ yml
190
192
  :env=> nil,
191
193
  :container_count=>2,
192
194
  :stateful=>false,
195
+ :strategy=>'ha',
193
196
  :links=>[{:name => "kontena-test-mysql", :alias => "db"}, {:name => "loadbalancer", :alias => "loadbalancer"}],
194
197
  :ports=>[{:container_port => "80", :node_port => "80", :protocol => "tcp"}]
195
198
  }
196
199
 
197
- expect(subject).to receive(:create_service).with('1234567', '1', data)
200
+ expect(subject).to receive(:create_service).with('1234567', '1', hash_including(data))
198
201
  subject.run([])
199
202
  end
200
203
 
201
204
  it 'creates mysql service before wordpress' do
202
205
  allow(subject).to receive(:current_dir).and_return("kontena-test")
203
- data = {:name =>"kontena-test-mysql", :image=>'mysql:5.6', :env=>["MYSQL_ROOT_PASSWORD=kontena-test_secret"], :container_count=>nil, :stateful=>true}
204
- expect(subject).to receive(:create_service).with('1234567', '1', data)
206
+ data = {
207
+ :name =>"kontena-test-mysql",
208
+ :image=>'mysql:5.6',
209
+ :env=>["MYSQL_ROOT_PASSWORD=kontena-test_secret"],
210
+ :container_count=>nil,
211
+ :stateful=>true,
212
+ }
213
+ expect(subject).to receive(:create_service).with('1234567', '1', hash_including(data))
205
214
 
206
215
  subject.run([])
207
216
  end
@@ -215,10 +224,11 @@ yml
215
224
  :env=>["WORDPRESS_DB_PASSWORD=kontena-test_secret"],
216
225
  :container_count=>2,
217
226
  :stateful=>true,
227
+ :strategy=>'ha',
218
228
  :links=>[{:name=>"kontena-test-mysql", :alias=>"mysql"}],
219
229
  :ports=>[{:container_port=>"80", :node_port=>"80", :protocol=>"tcp"}]
220
230
  }
221
- expect(subject).to receive(:create_service).with('1234567', '1', data)
231
+ expect(subject).to receive(:create_service).with('1234567', '1', hash_including(data))
222
232
 
223
233
  subject.run([])
224
234
  end
@@ -226,7 +236,7 @@ yml
226
236
  it 'deploys services' do
227
237
  allow(subject).to receive(:current_dir).and_return("kontena-test")
228
238
  expect(subject).to receive(:deploy_service).with('1234567', 'kontena-test-mysql', {})
229
- expect(subject).to receive(:deploy_service).with('1234567', 'kontena-test-wordpress', {:strategy => 'ha'})
239
+ expect(subject).to receive(:deploy_service).with('1234567', 'kontena-test-wordpress', {})
230
240
  subject.run([])
231
241
  end
232
242
 
@@ -242,4 +252,11 @@ yml
242
252
  end
243
253
  end
244
254
  end
255
+
256
+ describe '#parse_data' do
257
+ it 'adds empty hooks hash if not defined' do
258
+ data = {'image' => 'foo/bar:latest'}
259
+ subject.send(:parse_data, data)
260
+ end
261
+ end
245
262
  end
@@ -0,0 +1,64 @@
1
+ require_relative "../../../spec_helper"
2
+ require "kontena/cli/apps/scale_command"
3
+
4
+ describe Kontena::Cli::Apps::ScaleCommand do
5
+
6
+ let(:subject) do
7
+ described_class.new(File.basename($0))
8
+ end
9
+
10
+ let(:settings) do
11
+ {'server' => {'url' => 'http://kontena.test', 'token' => token}}
12
+ end
13
+
14
+ let(:token) do
15
+ '1234567'
16
+ end
17
+
18
+ let(:kontena_yml) do
19
+ yml_content = <<yml
20
+ wordpress:
21
+ image: wordpress:latest
22
+ instances: 2
23
+ yml
24
+ end
25
+
26
+ let(:kontena_yml_no_instances) do
27
+ yml_content = <<yml
28
+ wordpress:
29
+ image: wordpress:latest
30
+ yml
31
+ end
32
+
33
+ describe '#execute' do
34
+ before(:each) do
35
+ allow(subject).to receive(:settings).and_return(settings)
36
+ allow(subject).to receive(:current_dir).and_return("kontena-test")
37
+ allow(File).to receive(:exists?).and_return(true)
38
+ allow(File).to receive(:read).with("#{Dir.getwd}/kontena.yml").and_return(kontena_yml)
39
+ end
40
+
41
+ context 'when service already contains instances property' do
42
+ it 'aborts execution' do
43
+ expect{
44
+ subject.run(['wordpress', 3])
45
+ }.to raise_error(SystemExit)
46
+ end
47
+ end
48
+
49
+ context 'when service not found in YML' do
50
+ it 'aborts execution' do
51
+ expect{
52
+ subject.run(['mysql', 3])
53
+ }.to raise_error(SystemExit)
54
+ end
55
+ end
56
+
57
+ it 'scales given service' do
58
+ allow(File).to receive(:read).with("#{Dir.getwd}/kontena.yml").and_return(kontena_yml_no_instances)
59
+ expect(subject).to receive(:scale_service).with('1234567','kontena-test-wordpress',3)
60
+ subject.run(['wordpress', 3])
61
+ end
62
+
63
+ end
64
+ end
@@ -47,13 +47,6 @@ module Kontena::Cli::Services
47
47
  expect(client).to receive(:post).with('services/test-grid/1/deploy', {'strategy' => 'ha'})
48
48
  subject.deploy_service(token, '1', {'strategy' => 'ha'})
49
49
  end
50
-
51
- it 'polls Kontena Server until service is running' do
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'})
54
-
55
- subject.deploy_service(token, '1', {'strategy' => 'ha'})
56
- end
57
50
  end
58
51
 
59
52
  describe '#parse_ports' do
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.9.3
4
+ version: 0.10.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-03 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,7 +137,10 @@ files:
137
137
  - lib/kontena/cli/apps/kontena_yml_generator.rb
138
138
  - lib/kontena/cli/apps/list_command.rb
139
139
  - lib/kontena/cli/apps/logs_command.rb
140
+ - lib/kontena/cli/apps/monitor_command.rb
140
141
  - lib/kontena/cli/apps/remove_command.rb
142
+ - lib/kontena/cli/apps/scale_command.rb
143
+ - lib/kontena/cli/apps/show_command.rb
141
144
  - lib/kontena/cli/apps/start_command.rb
142
145
  - lib/kontena/cli/apps/stop_command.rb
143
146
  - lib/kontena/cli/common.rb
@@ -145,6 +148,7 @@ files:
145
148
  - lib/kontena/cli/containers/exec_command.rb
146
149
  - lib/kontena/cli/containers/inspect_command.rb
147
150
  - lib/kontena/cli/deploy_command.rb
151
+ - lib/kontena/cli/etcd/common.rb
148
152
  - lib/kontena/cli/etcd/get_command.rb
149
153
  - lib/kontena/cli/etcd/list_command.rb
150
154
  - lib/kontena/cli/etcd/mkdir_command.rb
@@ -162,6 +166,7 @@ files:
162
166
  - lib/kontena/cli/grids/common.rb
163
167
  - lib/kontena/cli/grids/create_command.rb
164
168
  - lib/kontena/cli/grids/current_command.rb
169
+ - lib/kontena/cli/grids/env_command.rb
165
170
  - lib/kontena/cli/grids/list_command.rb
166
171
  - lib/kontena/cli/grids/list_users_command.rb
167
172
  - lib/kontena/cli/grids/logs_command.rb
@@ -202,6 +207,7 @@ files:
202
207
  - lib/kontena/cli/nodes/list_command.rb
203
208
  - lib/kontena/cli/nodes/remove_command.rb
204
209
  - lib/kontena/cli/nodes/show_command.rb
210
+ - lib/kontena/cli/nodes/ssh_command.rb
205
211
  - lib/kontena/cli/nodes/update_command.rb
206
212
  - lib/kontena/cli/nodes/vagrant/create_command.rb
207
213
  - lib/kontena/cli/nodes/vagrant/restart_command.rb
@@ -222,8 +228,10 @@ files:
222
228
  - lib/kontena/cli/services/create_command.rb
223
229
  - lib/kontena/cli/services/delete_command.rb
224
230
  - lib/kontena/cli/services/deploy_command.rb
231
+ - lib/kontena/cli/services/envs_command.rb
225
232
  - lib/kontena/cli/services/list_command.rb
226
233
  - lib/kontena/cli/services/logs_command.rb
234
+ - lib/kontena/cli/services/monitor_command.rb
227
235
  - lib/kontena/cli/services/remove_env_command.rb
228
236
  - lib/kontena/cli/services/restart_command.rb
229
237
  - lib/kontena/cli/services/scale_command.rb
@@ -277,6 +285,7 @@ files:
277
285
  - spec/kontena/cli/app/common_spec.rb
278
286
  - spec/kontena/cli/app/deploy_command_spec.rb
279
287
  - spec/kontena/cli/app/docker_helper_spec.rb
288
+ - spec/kontena/cli/app/scale_spec.rb
280
289
  - spec/kontena/cli/common_spec.rb
281
290
  - spec/kontena/cli/deploy_command_spec.rb
282
291
  - spec/kontena/cli/login_command_spec.rb
@@ -312,6 +321,7 @@ test_files:
312
321
  - spec/kontena/cli/app/common_spec.rb
313
322
  - spec/kontena/cli/app/deploy_command_spec.rb
314
323
  - spec/kontena/cli/app/docker_helper_spec.rb
324
+ - spec/kontena/cli/app/scale_spec.rb
315
325
  - spec/kontena/cli/common_spec.rb
316
326
  - spec/kontena/cli/deploy_command_spec.rb
317
327
  - spec/kontena/cli/login_command_spec.rb