kontena-cli 0.15.4 → 0.15.5.rc1

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: 23539e03b622f33edc9607ab98af092b191d154d
4
- data.tar.gz: 9ae1dc2c686f48abe68974a475350bbad66c72e3
3
+ metadata.gz: ed3274a66dc5dcee8f9e8fa4ee7841664910fc88
4
+ data.tar.gz: 52690daf0a91bba1cbbd2e1578366aa4955b28c6
5
5
  SHA512:
6
- metadata.gz: aa487d49f1f2efc5b11148ab2e275fbdea6f883536e9c00cf5d77721a63236b313de4b6a09510ad833b00e953506c20fca04c8a942010778879bdd066c0fbfec
7
- data.tar.gz: 32b2a556d786634fb2c3ff0d776cdffc3ad0d1c338309d3cb90bea4693b36d3c9e86e49c11a6d37446ca42ea64388d0ca37cc844fe690fd42f45a774c6c914cd
6
+ metadata.gz: 5cb2fe4b739883ad79eb9cc411de73772924a6b43a9d2df560051759566edb85d9f40be029d87ac2226a9fa5bfe23ae26d28994cf32465872932d616d65578b6
7
+ data.tar.gz: 6620468258c43d296b89cfa297044c2159692643770b0ef986cdd04941c8e76b5683a1fd6807b3fb150ee6ac1a4d200f657c6f171874adbb62b800f0662ce09d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.15.4
1
+ 0.15.5.rc1
@@ -62,12 +62,7 @@ module Kontena::Cli::Apps
62
62
 
63
63
  def project_name_from_yaml(file)
64
64
  reader = YAML::Reader.new(file, true)
65
- outcome = reader.execute
66
- if outcome[:version].to_i == 2
67
- outcome[:name]
68
- else
69
- nil
70
- end
65
+ reader.stack_name
71
66
  end
72
67
 
73
68
  # @return [String]
@@ -27,13 +27,17 @@ module Kontena::Cli::Apps
27
27
  Dir.chdir(File.dirname(File.expand_path(file))) do
28
28
  result[:version] = yaml['version'] || '1'
29
29
  result[:name] = yaml['name']
30
- result[:services] = parse_services(service_name)
31
30
  result[:errors] = errors
32
31
  result[:notifications] = notifications
32
+ result[:services] = parse_services(service_name) unless errors.count > 0
33
33
  end
34
34
  result
35
35
  end
36
36
 
37
+ def stack_name
38
+ yaml['name'] if v2?
39
+ end
40
+
37
41
  ##
38
42
  # @return [true|false]
39
43
  def v2?
@@ -47,7 +51,11 @@ module Kontena::Cli::Apps
47
51
  content = content % { project: ENV['project'], grid: ENV['grid'] }
48
52
  interpolate(content)
49
53
  replace_dollar_dollars(content)
50
- @yaml = ::YAML.load(content)
54
+ begin
55
+ @yaml = ::YAML.load(content)
56
+ rescue Psych::SyntaxError => e
57
+ abort("Error while parsing #{file}".colorize(:red)+ " "+e.message)
58
+ end
51
59
  end
52
60
 
53
61
  # @return [Array] array of validation errors
@@ -80,7 +88,9 @@ module Kontena::Cli::Apps
80
88
  # @return [Hash]
81
89
  def parse_services(service_name = nil)
82
90
  if service_name.nil?
83
- services.each { |name, config| services[name] = process_config(config) }
91
+ services.each do |name, config|
92
+ services[name] = process_config(config)
93
+ end
84
94
  services
85
95
  else
86
96
  abort("Service '#{service_name}' not found in #{file}".colorize(:red)) unless services.key?(service_name)
@@ -43,6 +43,10 @@ module Kontena::Cli::Apps
43
43
  }
44
44
 
45
45
  yaml.each do |service, options|
46
+ unless options.is_a?(Hash)
47
+ result[:errors] << { service => { 'options' => 'must be a mapping not a string'} }
48
+ next
49
+ end
46
50
  key_errors = validate_keys(options)
47
51
  option_errors = validate_options(options)
48
52
  result[:errors] << { service => option_errors.messages } if option_errors.failure?
@@ -53,7 +53,11 @@ module Kontena::Cli::Apps
53
53
  notifications: []
54
54
  }
55
55
  if yaml.key?('services')
56
- yaml['services'].each do |service, options|
56
+ yaml['services'].each do |service, options|
57
+ unless options.is_a?(Hash)
58
+ result[:errors] << { service => { 'options' => 'must be a mapping not a string'} }
59
+ next
60
+ end
57
61
  key_errors = validate_keys(options)
58
62
  option_errors = validate_options(options)
59
63
  result[:errors] << { service => option_errors.messages } if option_errors.failure?
@@ -5,29 +5,24 @@ module Kontena::Cli::Master
5
5
  parameter "NAME", "Master name to use"
6
6
 
7
7
  def execute
8
- master = find_master_by_name(name)
9
- if !master.nil?
8
+ master = settings['servers'].find { |s| s['name'] == name }
9
+
10
+ if master
10
11
  self.current_master = master['name']
11
12
  puts "Using master: #{master['name'].cyan} (#{master['url']})"
12
13
  puts "Using grid: #{current_grid.cyan}" if current_grid
14
+
13
15
  grids = client(require_token).get('grids')['grids']
14
16
  if grids.size > 1
15
17
  puts ""
16
- puts "You have access to following grids and can switch between them using 'kontena grid use <name>'"
18
+ puts "You have access to following grids:"
17
19
  puts ""
18
20
  grids.each do |grid|
19
21
  puts " * #{grid['name']}"
20
22
  end
21
- puts ""
22
23
  end
23
24
  else
24
- abort "Could not resolve master by name [#{name}]. For a list of known masters please run: kontena master list".colorize(:red)
25
- end
26
- end
27
-
28
- def find_master_by_name(name)
29
- settings['servers'].each do |server|
30
- return server if server['name'] == name
25
+ abort "Could not resolve master with name: #{name}".colorize(:red)
31
26
  end
32
27
  end
33
28
 
@@ -97,11 +97,7 @@ module Kontena
97
97
  if service['env'].to_a.size > 0
98
98
  puts " env: "
99
99
  service['env'].to_a.each do |e|
100
- if e.length > 50
101
- puts " - #{e[0..50]}..."
102
- else
103
- puts " - #{e}"
104
- end
100
+ puts " - #{e}"
105
101
  end
106
102
  end
107
103
 
@@ -0,0 +1,6 @@
1
+ version: '2'
2
+ services:
3
+ wordpress:
4
+ build: .
5
+ context: .
6
+ dockerfile: Dockerfile.alternative
@@ -0,0 +1,3 @@
1
+ version: '2'
2
+ services:
3
+ wordpress: 'service config cannot be string'
@@ -156,6 +156,28 @@ describe Kontena::Cli::Apps::YAML::Reader do
156
156
  end
157
157
  end
158
158
 
159
+ context 'when yaml file is malformed' do
160
+ it 'exits the execution' do
161
+ allow(File).to receive(:read)
162
+ .with(absolute_yaml_path)
163
+ .and_return(fixture('kontena-malformed-yaml.yml'))
164
+ expect {
165
+ subject.execute
166
+ }.to raise_error(SystemExit)
167
+ end
168
+ end
169
+
170
+ context 'when service config is not hash' do
171
+ it 'returns error' do
172
+ allow(File).to receive(:read)
173
+ .with(absolute_yaml_path)
174
+ .and_return(fixture('kontena-not-hash-service-config.yml'))
175
+
176
+ outcome = subject.execute
177
+ expect(outcome[:errors].size).to eq(1)
178
+ end
179
+ end
180
+
159
181
  describe '#v2?' do
160
182
  context 'version 1' do
161
183
  it 'returns false' do
@@ -407,4 +429,30 @@ describe Kontena::Cli::Apps::YAML::Reader do
407
429
  end
408
430
  end
409
431
  end
432
+
433
+ describe '#stack_name' do
434
+ it 'returns nil for v1' do
435
+ allow(File).to receive(:read)
436
+ .with(absolute_yaml_path('kontena.yml'))
437
+ .and_return(fixture('kontena.yml'))
438
+ name = subject.stack_name
439
+ expect(name).to be_nil
440
+ end
441
+
442
+ it 'returns name for v2 if defined' do
443
+ allow(File).to receive(:read)
444
+ .with(absolute_yaml_path('kontena.yml'))
445
+ .and_return(fixture('kontena_v2.yml'))
446
+ name = subject.stack_name
447
+ expect(name).to eq('test-project')
448
+ end
449
+
450
+ it 'returns nil for v2 if not defined' do
451
+ allow(File).to receive(:read)
452
+ .with(absolute_yaml_path('kontena.yml'))
453
+ .and_return(fixture('docker-compose.yml'))
454
+ name = subject.stack_name
455
+ expect(name).to be_nil
456
+ end
457
+ end
410
458
  end
@@ -34,5 +34,10 @@ describe Kontena::Cli::Master::UseCommand do
34
34
  expect(client).to receive(:get).with('grids')
35
35
  subject.run(['some_master'])
36
36
  end
37
+
38
+ it 'should abort with error message if master is not configured' do
39
+ expect { subject.run(['not_existing']) }.to raise_error(
40
+ SystemExit, /Could not resolve master with name: not_existing/)
41
+ end
37
42
  end
38
43
  end
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.15.4
4
+ version: 0.15.5.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2016-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -397,6 +397,8 @@ files:
397
397
  - spec/fixtures/kontena-build.yml
398
398
  - spec/fixtures/kontena-internal-extend.yml
399
399
  - spec/fixtures/kontena-invalid.yml
400
+ - spec/fixtures/kontena-malformed-yaml.yml
401
+ - spec/fixtures/kontena-not-hash-service-config.yml
400
402
  - spec/fixtures/kontena-with-env-file.yml
401
403
  - spec/fixtures/kontena-with-variables.yml
402
404
  - spec/fixtures/kontena.yml
@@ -466,9 +468,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
466
468
  version: 2.0.0
467
469
  required_rubygems_version: !ruby/object:Gem::Requirement
468
470
  requirements:
469
- - - ">="
471
+ - - ">"
470
472
  - !ruby/object:Gem::Version
471
- version: '0'
473
+ version: 1.3.1
472
474
  requirements: []
473
475
  rubyforge_project:
474
476
  rubygems_version: 2.5.1
@@ -483,6 +485,8 @@ test_files:
483
485
  - spec/fixtures/kontena-build.yml
484
486
  - spec/fixtures/kontena-internal-extend.yml
485
487
  - spec/fixtures/kontena-invalid.yml
488
+ - spec/fixtures/kontena-malformed-yaml.yml
489
+ - spec/fixtures/kontena-not-hash-service-config.yml
486
490
  - spec/fixtures/kontena-with-env-file.yml
487
491
  - spec/fixtures/kontena-with-variables.yml
488
492
  - spec/fixtures/kontena.yml