kontena-cli 1.4.0.pre6 → 1.4.0.pre7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/bin/kontena +1 -1
- data/kontena-cli.gemspec +3 -3
- data/lib/kontena/cli/certificate/authorize_command.rb +67 -6
- data/lib/kontena/cli/certificate/get_command.rb +7 -0
- data/lib/kontena/cli/certificate/list_command.rb +75 -0
- data/lib/kontena/cli/certificate/register_command.rb +13 -2
- data/lib/kontena/cli/certificate/request_command.rb +20 -0
- data/lib/kontena/cli/certificate/show_command.rb +19 -0
- data/lib/kontena/cli/certificate_command.rb +4 -1
- data/lib/kontena/cli/cloud/master/add_command.rb +1 -1
- data/lib/kontena/cli/common.rb +21 -33
- data/lib/kontena/cli/etcd/health_command.rb +21 -27
- data/lib/kontena/cli/helpers/exec_helper.rb +15 -6
- data/lib/kontena/cli/helpers/health_helper.rb +12 -0
- data/lib/kontena/cli/helpers/log_helper.rb +2 -2
- data/lib/kontena/cli/helpers/time_helper.rb +29 -0
- data/lib/kontena/cli/master/init_cloud_command.rb +19 -0
- data/lib/kontena/cli/master/list_command.rb +1 -1
- data/lib/kontena/cli/master/ssh_command.rb +3 -1
- data/lib/kontena/cli/master/use_command.rb +1 -2
- data/lib/kontena/cli/node_command.rb +1 -0
- data/lib/kontena/cli/nodes/health_command.rb +28 -13
- data/lib/kontena/cli/nodes/list_command.rb +19 -3
- data/lib/kontena/cli/nodes/show_command.rb +4 -2
- data/lib/kontena/cli/nodes/ssh_command.rb +5 -2
- data/lib/kontena/cli/nodes/update_command.rb +2 -0
- data/lib/kontena/cli/plugins/install_command.rb +11 -8
- data/lib/kontena/cli/plugins/list_command.rb +5 -3
- data/lib/kontena/cli/plugins/search_command.rb +4 -2
- data/lib/kontena/cli/plugins/show_command.rb +17 -0
- data/lib/kontena/cli/plugins/uninstall_command.rb +9 -13
- data/lib/kontena/cli/registry/create_command.rb +1 -1
- data/lib/kontena/cli/services/create_command.rb +6 -0
- data/lib/kontena/cli/services/services_helper.rb +33 -6
- data/lib/kontena/cli/services/update_command.rb +6 -0
- data/lib/kontena/cli/stacks/build_command.rb +3 -3
- data/lib/kontena/cli/stacks/common.rb +105 -90
- data/lib/kontena/cli/stacks/deploy_command.rb +7 -3
- data/lib/kontena/cli/stacks/install_command.rb +39 -6
- data/lib/kontena/cli/stacks/list_command.rb +36 -4
- data/lib/kontena/cli/stacks/logs_command.rb +9 -2
- data/lib/kontena/cli/stacks/registry/pull_command.rb +2 -2
- data/lib/kontena/cli/stacks/registry/push_command.rb +20 -9
- data/lib/kontena/cli/stacks/registry/remove_command.rb +4 -4
- data/lib/kontena/cli/stacks/registry/show_command.rb +4 -4
- data/lib/kontena/cli/stacks/remove_command.rb +27 -1
- data/lib/kontena/cli/stacks/service_generator.rb +12 -2
- data/lib/kontena/cli/stacks/show_command.rb +35 -5
- data/lib/kontena/cli/stacks/stack_name.rb +71 -0
- data/lib/kontena/cli/stacks/upgrade_command.rb +127 -14
- data/lib/kontena/cli/stacks/validate_command.rb +38 -10
- data/lib/kontena/cli/stacks/yaml/custom_validators/certificates_validator.rb +22 -0
- data/lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb +1 -2
- data/lib/kontena/cli/stacks/yaml/reader.rb +211 -185
- data/lib/kontena/cli/stacks/yaml/service_extender.rb +6 -12
- data/lib/kontena/cli/stacks/yaml/stack_file_loader.rb +97 -0
- data/lib/kontena/cli/stacks/yaml/stack_file_loader/file_loader.rb +41 -0
- data/lib/kontena/cli/stacks/yaml/stack_file_loader/registry_loader.rb +24 -0
- data/lib/kontena/cli/stacks/yaml/stack_file_loader/uri_loader.rb +23 -0
- data/lib/kontena/cli/stacks/yaml/validations.rb +16 -0
- data/lib/kontena/cli/stacks/yaml/validator_v3.rb +25 -8
- data/lib/kontena/client.rb +2 -2
- data/lib/kontena/command.rb +11 -0
- data/lib/kontena/main_command.rb +3 -1
- data/lib/kontena/plugin_manager.rb +11 -198
- data/lib/kontena/plugin_manager/cleaner.rb +33 -0
- data/lib/kontena/plugin_manager/common.rb +86 -0
- data/lib/kontena/plugin_manager/installer.rb +54 -0
- data/lib/kontena/plugin_manager/loader.rb +93 -0
- data/lib/kontena/plugin_manager/rubygems_client.rb +42 -23
- data/lib/kontena/plugin_manager/uninstaller.rb +34 -0
- data/lib/kontena/util.rb +24 -0
- data/lib/kontena_cli.rb +1 -0
- data/omnibus/config/projects/kontena.rb +7 -1
- data/omnibus/config/software/{kontena.rb → kontena-cli.rb} +2 -0
- data/spec/fixtures/api/node.json +2 -1
- data/spec/fixtures/stack-internal-extend.yml +6 -1
- data/spec/fixtures/stack-with-dependencies-dep-1-1.yml +8 -0
- data/spec/fixtures/stack-with-dependencies-dep-1.yml +17 -0
- data/spec/fixtures/stack-with-dependencies-dep-2.yml +8 -0
- data/spec/fixtures/stack-with-dependencies-dep-3.yml +5 -0
- data/spec/fixtures/stack-with-dependencies-dep_2-removed.yml +17 -0
- data/spec/fixtures/stack-with-dependencies-dep_3-added.yml +25 -0
- data/spec/fixtures/stack-with-dependencies.yml +22 -0
- data/spec/fixtures/stack-with-variables.yml +3 -0
- data/spec/kontena/cli/etcd/health_command_spec.rb +45 -33
- data/spec/kontena/cli/helpers/exec_helper_spec.rb +2 -1
- data/spec/kontena/cli/master/init_cloud_command_spec.rb +14 -0
- data/spec/kontena/cli/nodes/health_command_spec.rb +74 -10
- data/spec/kontena/cli/nodes/list_command_spec.rb +381 -232
- data/spec/kontena/cli/nodes/show_command_spec.rb +31 -0
- data/spec/kontena/cli/nodes/ssh_command_spec.rb +18 -3
- data/spec/kontena/cli/plugins/install_command_spec.rb +1 -1
- data/spec/kontena/cli/stacks/build_command_spec.rb +6 -12
- data/spec/kontena/cli/stacks/common_spec.rb +42 -69
- data/spec/kontena/cli/stacks/install_command_spec.rb +57 -31
- data/spec/kontena/cli/stacks/list_command_spec.rb +44 -0
- data/spec/kontena/cli/stacks/logs_command_spec.rb +12 -1
- data/spec/kontena/cli/stacks/remove_command_spec.rb +39 -0
- data/spec/kontena/cli/stacks/show_command_spec.rb +16 -0
- data/spec/kontena/cli/stacks/stack_name_spec.rb +21 -0
- data/spec/kontena/cli/stacks/upgrade_command_spec.rb +73 -56
- data/spec/kontena/cli/stacks/validate_command_spec.rb +81 -0
- data/spec/kontena/cli/stacks/yaml/custom_validators/affinities_validator_spec.rb +22 -0
- data/spec/kontena/cli/stacks/yaml/reader_spec.rb +173 -169
- data/spec/kontena/cli/stacks/yaml/service_extender_spec.rb +12 -3
- data/spec/kontena/cli/stacks/yaml/stack_file_loader/file_loader_spec.rb +47 -0
- data/spec/kontena/cli/stacks/yaml/stack_file_loader/registry_loader_spec.rb +53 -0
- data/spec/kontena/cli/stacks/yaml/stack_file_loader/uri_loader_spec.rb +53 -0
- data/spec/kontena/cli/stacks/yaml/stack_file_loader_spec.rb +104 -0
- data/spec/kontena/cli/stacks/yaml/validator_v3_spec.rb +19 -0
- data/spec/kontena/plugin_manager/cleaner_spec.rb +20 -0
- data/spec/kontena/plugin_manager/common_spec.rb +39 -0
- data/spec/kontena/plugin_manager/installer_spec.rb +50 -0
- data/spec/kontena/plugin_manager/loader_spec.rb +5 -0
- data/spec/kontena/plugin_manager/rubygems_client_spec.rb +11 -25
- data/spec/kontena/plugin_manager/uninstaller_spec.rb +19 -0
- data/spec/kontena/plugin_manager_spec.rb +7 -7
- metadata +64 -97
- data/lib/kontena/cli/app_command.rb +0 -22
- data/lib/kontena/cli/apps/build_command.rb +0 -28
- data/lib/kontena/cli/apps/common.rb +0 -172
- data/lib/kontena/cli/apps/config_command.rb +0 -25
- data/lib/kontena/cli/apps/deploy_command.rb +0 -137
- data/lib/kontena/cli/apps/docker_compose_generator.rb +0 -61
- data/lib/kontena/cli/apps/docker_helper.rb +0 -80
- data/lib/kontena/cli/apps/dockerfile_generator.rb +0 -16
- data/lib/kontena/cli/apps/init_command.rb +0 -89
- data/lib/kontena/cli/apps/kontena_yml_generator.rb +0 -105
- data/lib/kontena/cli/apps/list_command.rb +0 -59
- data/lib/kontena/cli/apps/logs_command.rb +0 -37
- data/lib/kontena/cli/apps/monitor_command.rb +0 -93
- data/lib/kontena/cli/apps/remove_command.rb +0 -74
- data/lib/kontena/cli/apps/restart_command.rb +0 -39
- data/lib/kontena/cli/apps/scale_command.rb +0 -33
- data/lib/kontena/cli/apps/service_generator.rb +0 -114
- data/lib/kontena/cli/apps/service_generator_v2.rb +0 -27
- data/lib/kontena/cli/apps/show_command.rb +0 -23
- data/lib/kontena/cli/apps/start_command.rb +0 -40
- data/lib/kontena/cli/apps/stop_command.rb +0 -40
- data/lib/kontena/cli/apps/yaml/custom_validators/affinities_validator.rb +0 -19
- data/lib/kontena/cli/apps/yaml/custom_validators/build_validator.rb +0 -22
- data/lib/kontena/cli/apps/yaml/custom_validators/extends_validator.rb +0 -20
- data/lib/kontena/cli/apps/yaml/custom_validators/hooks_validator.rb +0 -54
- data/lib/kontena/cli/apps/yaml/custom_validators/secrets_validator.rb +0 -22
- data/lib/kontena/cli/apps/yaml/reader.rb +0 -213
- data/lib/kontena/cli/apps/yaml/service_extender.rb +0 -77
- data/lib/kontena/cli/apps/yaml/validations.rb +0 -71
- data/lib/kontena/cli/apps/yaml/validator.rb +0 -38
- data/lib/kontena/cli/apps/yaml/validator_v2.rb +0 -53
- data/spec/fixtures/app.json +0 -42
- data/spec/fixtures/health.yml +0 -26
- data/spec/fixtures/kontena-build.yml +0 -16
- data/spec/fixtures/kontena-internal-extend.yml +0 -8
- data/spec/fixtures/kontena-invalid.yml +0 -4
- data/spec/fixtures/kontena-with-env-file.yml +0 -18
- data/spec/fixtures/kontena-with-variables.yml +0 -19
- data/spec/fixtures/kontena.yml +0 -17
- data/spec/fixtures/kontena_build_v2.yml +0 -26
- data/spec/fixtures/kontena_numeric_version.yml +0 -9
- data/spec/fixtures/kontena_v2.yml +0 -35
- data/spec/fixtures/mysql.yml +0 -3
- data/spec/fixtures/wordpress-scaled.yml +0 -3
- data/spec/fixtures/wordpress.yml +0 -2
- data/spec/kontena/cli/app/build_command_spec.rb +0 -55
- data/spec/kontena/cli/app/common_spec.rb +0 -110
- data/spec/kontena/cli/app/config_command_spec.rb +0 -78
- data/spec/kontena/cli/app/deploy_command_spec.rb +0 -217
- data/spec/kontena/cli/app/docker_helper_spec.rb +0 -155
- data/spec/kontena/cli/app/init_command_spec.rb +0 -109
- data/spec/kontena/cli/app/logs_command_spec.rb +0 -131
- data/spec/kontena/cli/app/scale_spec.rb +0 -51
- data/spec/kontena/cli/app/service_generator_spec.rb +0 -384
- data/spec/kontena/cli/app/service_generator_v2_spec.rb +0 -73
- data/spec/kontena/cli/app/yaml/reader_spec.rb +0 -457
- data/spec/kontena/cli/app/yaml/service_extender_spec.rb +0 -127
- data/spec/kontena/cli/app/yaml/validator_spec.rb +0 -380
- data/spec/kontena/cli/app/yaml/validator_v2_spec.rb +0 -301
@@ -1,213 +0,0 @@
|
|
1
|
-
require_relative 'service_extender'
|
2
|
-
require_relative 'validator'
|
3
|
-
require_relative 'validator_v2'
|
4
|
-
require_relative '../../../util'
|
5
|
-
|
6
|
-
module Kontena::Cli::Apps
|
7
|
-
module YAML
|
8
|
-
class Reader
|
9
|
-
include Kontena::Util
|
10
|
-
attr_reader :yaml, :file, :errors, :notifications
|
11
|
-
|
12
|
-
def initialize(file, skip_validation = false)
|
13
|
-
@file = file
|
14
|
-
@errors = []
|
15
|
-
@notifications = []
|
16
|
-
@skip_validation = skip_validation
|
17
|
-
load_yaml
|
18
|
-
validate unless skip_validation?
|
19
|
-
end
|
20
|
-
|
21
|
-
##
|
22
|
-
# @param [String] service_name
|
23
|
-
# @return [Hash]
|
24
|
-
def execute(service_name = nil)
|
25
|
-
result = {}
|
26
|
-
Dir.chdir(File.dirname(File.expand_path(file))) do
|
27
|
-
result[:version] = yaml['version'] || '1'
|
28
|
-
result[:name] = yaml['name']
|
29
|
-
result[:errors] = errors
|
30
|
-
result[:notifications] = notifications
|
31
|
-
result[:services] = errors.count == 0 ? parse_services(service_name) : {}
|
32
|
-
end
|
33
|
-
result
|
34
|
-
end
|
35
|
-
|
36
|
-
def stack_name
|
37
|
-
yaml['name'] if v2?
|
38
|
-
end
|
39
|
-
|
40
|
-
##
|
41
|
-
# @return [true|false]
|
42
|
-
def v2?
|
43
|
-
yaml['version'].to_s == '2'
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def load_yaml
|
49
|
-
content = File.read(File.expand_path(file))
|
50
|
-
content = content % { project: ENV['project'], grid: ENV['grid'] }
|
51
|
-
interpolate(content)
|
52
|
-
replace_dollar_dollars(content)
|
53
|
-
begin
|
54
|
-
@yaml = ::YAML.safe_load(content)
|
55
|
-
rescue Psych::SyntaxError => ex
|
56
|
-
raise ex.class, "Error while parsing #{file} : #{ex.message}"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# @return [Array] array of validation errors
|
61
|
-
def validate
|
62
|
-
result = validator.validate(yaml)
|
63
|
-
store_failures(result)
|
64
|
-
result
|
65
|
-
end
|
66
|
-
|
67
|
-
def skip_validation?
|
68
|
-
@skip_validation == true
|
69
|
-
end
|
70
|
-
|
71
|
-
def store_failures(data)
|
72
|
-
errors << { file => data[:errors] } unless data[:errors].empty?
|
73
|
-
notifications << { file => data[:notifications] } unless data[:notifications].empty?
|
74
|
-
end
|
75
|
-
|
76
|
-
# @return [Kontena::Cli::Apps::YAML::Validator]
|
77
|
-
def validator
|
78
|
-
if @validator.nil?
|
79
|
-
validator_klass = v2? ? YAML::ValidatorV2 : YAML::Validator
|
80
|
-
@validator = validator_klass.new
|
81
|
-
end
|
82
|
-
@validator
|
83
|
-
end
|
84
|
-
|
85
|
-
##
|
86
|
-
# @param [String] service_name - optional service to parse
|
87
|
-
# @return [Hash]
|
88
|
-
def parse_services(service_name = nil)
|
89
|
-
if service_name.nil?
|
90
|
-
services.each do |name, config|
|
91
|
-
services[name] = process_config(config)
|
92
|
-
end
|
93
|
-
services
|
94
|
-
else
|
95
|
-
raise ("Service '#{service_name}' not found in #{file}") unless services.key?(service_name)
|
96
|
-
process_config(services[service_name])
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# @param [Hash] service_config
|
101
|
-
def process_config(service_config)
|
102
|
-
normalize_env_vars(service_config)
|
103
|
-
merge_env_vars(service_config)
|
104
|
-
expand_build_context(service_config)
|
105
|
-
normalize_build_args(service_config)
|
106
|
-
service_config = extend_config(service_config) if service_config.key?('extends')
|
107
|
-
service_config
|
108
|
-
end
|
109
|
-
|
110
|
-
# @return [Hash] - services from YAML file
|
111
|
-
def services
|
112
|
-
if v2?
|
113
|
-
yaml['services']
|
114
|
-
else
|
115
|
-
yaml
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
##
|
120
|
-
# @param [String] text - content of YAML file
|
121
|
-
def interpolate(text)
|
122
|
-
text.gsub!(/(?<!\$)\$(?!\$)\{?\w+\}?/) do |v| # searches $VAR and ${VAR} and not $$VAR
|
123
|
-
var = v.tr('${}', '')
|
124
|
-
puts "The #{var} is not set. Substituting an empty string." if !ENV.key?(var) && !skip_validation?
|
125
|
-
ENV[var] # replace with equivalent ENV variables
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
##
|
130
|
-
# @param [String] text - content of yaml file
|
131
|
-
def replace_dollar_dollars(text)
|
132
|
-
text.gsub!('$$', '$')
|
133
|
-
end
|
134
|
-
|
135
|
-
# @param [Hash] service_config
|
136
|
-
# @return [Hash] updated service config
|
137
|
-
def extend_config(service_config)
|
138
|
-
extended_service = extended_service(service_config['extends'])
|
139
|
-
return unless extended_service
|
140
|
-
filename = service_config['extends']['file']
|
141
|
-
if filename
|
142
|
-
parent_config = from_external_file(filename, extended_service)
|
143
|
-
else
|
144
|
-
raise ("Service '#{extended_service}' not found in #{file}") unless services.key?(extended_service)
|
145
|
-
parent_config = process_config(services[extended_service])
|
146
|
-
end
|
147
|
-
ServiceExtender.new(service_config).extend(parent_config)
|
148
|
-
end
|
149
|
-
|
150
|
-
def extended_service(extend_config)
|
151
|
-
if extend_config.is_a?(Hash)
|
152
|
-
extend_config['service']
|
153
|
-
elsif extend_config.is_a?(String)
|
154
|
-
extend_config
|
155
|
-
else
|
156
|
-
nil
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def from_external_file(filename, service_name)
|
161
|
-
outcome = Reader.new(filename, @skip_validation).execute(service_name)
|
162
|
-
errors.concat outcome[:errors] unless errors.any? { |item| item.key?(filename) }
|
163
|
-
notifications.concat outcome[:notifications] unless notifications.any? { |item| item.key?(filename) }
|
164
|
-
outcome[:services]
|
165
|
-
end
|
166
|
-
|
167
|
-
# @param [Hash] options - service config
|
168
|
-
def normalize_env_vars(options)
|
169
|
-
if options['environment'].is_a?(Hash)
|
170
|
-
options['environment'] = options['environment'].map { |k, v| "#{k}=#{v}" }
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
# @param [Hash] options
|
175
|
-
def merge_env_vars(options)
|
176
|
-
return options['environment'] unless options['env_file']
|
177
|
-
|
178
|
-
options['env_file'] = [options['env_file']] if options['env_file'].is_a?(String)
|
179
|
-
options['environment'] = [] unless options['environment']
|
180
|
-
options['env_file'].each do |env_file|
|
181
|
-
options['environment'].concat(read_env_file(env_file))
|
182
|
-
end
|
183
|
-
options.delete('env_file')
|
184
|
-
options['environment'].uniq! { |s| s.split('=').first }
|
185
|
-
end
|
186
|
-
|
187
|
-
# @param [String] path
|
188
|
-
def read_env_file(path)
|
189
|
-
File.readlines(path).map { |line| line.strip }.delete_if { |line| line.start_with?('#') || line.empty? }
|
190
|
-
end
|
191
|
-
|
192
|
-
def expand_build_context(options)
|
193
|
-
if options['build'].is_a?(String)
|
194
|
-
options['build'] = File.expand_path(options['build'])
|
195
|
-
elsif context = options.dig('build', 'context')
|
196
|
-
options['build']['context'] = File.expand_path(context)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
# @param [Hash] options - service config
|
201
|
-
def normalize_build_args(options)
|
202
|
-
if v2? && safe_dig(options, 'build', 'args').is_a?(Array)
|
203
|
-
args = options['build']['args'].dup
|
204
|
-
options['build']['args'] = {}
|
205
|
-
args.each do |arg|
|
206
|
-
k,v = arg.split('=')
|
207
|
-
options['build']['args'][k] = v
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require_relative '../../../util'
|
2
|
-
|
3
|
-
module Kontena::Cli::Apps
|
4
|
-
module YAML
|
5
|
-
class ServiceExtender
|
6
|
-
include Kontena::Util
|
7
|
-
attr_reader :service_config
|
8
|
-
|
9
|
-
# @param [Hash] service_config
|
10
|
-
def initialize(service_config)
|
11
|
-
@service_config = service_config
|
12
|
-
end
|
13
|
-
|
14
|
-
# @param [Hash] from
|
15
|
-
# @return [Hash]
|
16
|
-
def extend(from)
|
17
|
-
service_config['environment'] = extend_env_vars(
|
18
|
-
from['environment'],
|
19
|
-
service_config['environment']
|
20
|
-
)
|
21
|
-
service_config['secrets'] = extend_secrets(
|
22
|
-
from['secrets'],
|
23
|
-
service_config['secrets']
|
24
|
-
)
|
25
|
-
build_args = extend_build_args(safe_dig(from, 'build', 'args'), safe_dig(service_config, 'build', 'args'))
|
26
|
-
unless build_args.empty?
|
27
|
-
service_config['build'] = {} unless service_config['build']
|
28
|
-
service_config['build']['args'] = build_args
|
29
|
-
end
|
30
|
-
|
31
|
-
from.merge(service_config)
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
# @param [Array] from
|
37
|
-
# @param [Array] to
|
38
|
-
# @return [Array]
|
39
|
-
def extend_env_vars(from, to)
|
40
|
-
env_vars = to || []
|
41
|
-
if from
|
42
|
-
from.each do |env|
|
43
|
-
env_vars << env unless to && to.find do |key|
|
44
|
-
key.split('=').first == env.split('=').first
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
env_vars
|
49
|
-
end
|
50
|
-
|
51
|
-
# @param [Array] from
|
52
|
-
# @param [Array] to
|
53
|
-
# @return [Array]
|
54
|
-
def extend_secrets(from, to)
|
55
|
-
secrets = to || []
|
56
|
-
if from
|
57
|
-
from.each do |from_secret|
|
58
|
-
secrets << from_secret unless to && to.any? do |to_secret|
|
59
|
-
to_secret['secret'] == from_secret['secret']
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
secrets
|
64
|
-
end
|
65
|
-
|
66
|
-
def extend_build_args(from, to)
|
67
|
-
args = to || {}
|
68
|
-
if from
|
69
|
-
from.each do |k,v|
|
70
|
-
args[k] = v unless args.has_key?(k)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
args
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
module Kontena::Cli::Apps::YAML
|
2
|
-
module Validations
|
3
|
-
module CustomValidators
|
4
|
-
require_relative 'custom_validators/affinities_validator'
|
5
|
-
require_relative 'custom_validators/build_validator'
|
6
|
-
require_relative 'custom_validators/extends_validator'
|
7
|
-
require_relative 'custom_validators/hooks_validator'
|
8
|
-
require_relative 'custom_validators/secrets_validator'
|
9
|
-
|
10
|
-
def self.load
|
11
|
-
return if @loaded
|
12
|
-
HashValidator.append_validator(AffinitiesValidator.new)
|
13
|
-
HashValidator.append_validator(BuildValidator.new)
|
14
|
-
HashValidator.append_validator(ExtendsValidator.new)
|
15
|
-
HashValidator.append_validator(SecretsValidator.new)
|
16
|
-
HashValidator.append_validator(HooksValidator.new)
|
17
|
-
@loaded = true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def common_validations
|
22
|
-
{
|
23
|
-
'image' => optional('string'), # it's optional because some base yml file might contain image option
|
24
|
-
'extends' => optional('valid_extends'),
|
25
|
-
'stateful' => optional('boolean'),
|
26
|
-
'affinity' => optional('valid_affinities'),
|
27
|
-
'cap_add' => optional('array'),
|
28
|
-
'cap_drop' => optional('array'),
|
29
|
-
'command' => optional('string'),
|
30
|
-
'cpu_shares' => optional('integer'),
|
31
|
-
'external_links' => optional('array'),
|
32
|
-
'mem_limit' => optional('string'),
|
33
|
-
'mem_swaplimit' => optional('string'),
|
34
|
-
'environment' => optional(-> (value) { value.is_a?(Array) || value.is_a?(Hash) }),
|
35
|
-
'env_file' => optional(-> (value) { value.is_a?(String) || value.is_a?(Array) }),
|
36
|
-
'instances' => optional('integer'),
|
37
|
-
'links' => optional(-> (value) { value.is_a?(Array) || value.nil? }),
|
38
|
-
'ports' => optional('array'),
|
39
|
-
'pid' => optional('string'),
|
40
|
-
'privileged' => optional('boolean'),
|
41
|
-
'user' => optional('string'),
|
42
|
-
'volumes' => optional('array'),
|
43
|
-
'volumes_from' => optional('array'),
|
44
|
-
'secrets' => optional('valid_secrets'),
|
45
|
-
'hooks' => optional('valid_hooks'),
|
46
|
-
'deploy' => optional({
|
47
|
-
'strategy' => optional(%w(ha daemon random)),
|
48
|
-
'wait_for_port' => optional('integer'),
|
49
|
-
'min_health' => optional('float'),
|
50
|
-
'interval' => optional(/^\d+(min|h|d|)$/)
|
51
|
-
}),
|
52
|
-
'health_check' => optional({
|
53
|
-
'protocol' => /^(http|tcp)$/,
|
54
|
-
'port' => 'integer',
|
55
|
-
'uri' => optional(/\/[\S]*/),
|
56
|
-
'timeout' => optional('integer'),
|
57
|
-
'interval' => optional('integer'),
|
58
|
-
'initial_delay' => optional('integer')
|
59
|
-
})
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
def optional(type)
|
64
|
-
HashValidator.optional(type)
|
65
|
-
end
|
66
|
-
|
67
|
-
def validate_options(service_config)
|
68
|
-
HashValidator.validate(service_config, @schema, true)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'hash_validator'
|
2
|
-
module Kontena::Cli::Apps
|
3
|
-
module YAML
|
4
|
-
class Validator
|
5
|
-
require_relative 'validations'
|
6
|
-
include Validations
|
7
|
-
|
8
|
-
def initialize(need_image=false)
|
9
|
-
@schema = common_validations
|
10
|
-
@schema['build'] = optional('string')
|
11
|
-
@schema['dockerfile'] = optional('string')
|
12
|
-
@schema['net'] = optional(%w(host bridge))
|
13
|
-
@schema['log_driver'] = optional('string')
|
14
|
-
@schema['log_opts'] = optional({})
|
15
|
-
Validations::CustomValidators.load
|
16
|
-
end
|
17
|
-
|
18
|
-
##
|
19
|
-
# @param [Hash] yaml
|
20
|
-
# @return [Array] validation_errors
|
21
|
-
def validate(yaml)
|
22
|
-
result = {
|
23
|
-
errors: [],
|
24
|
-
notifications: []
|
25
|
-
}
|
26
|
-
yaml.each do |service, options|
|
27
|
-
unless options.is_a?(Hash)
|
28
|
-
result[:errors] << { service => { 'options' => 'must be a mapping not a string'} }
|
29
|
-
next
|
30
|
-
end
|
31
|
-
option_errors = validate_options(options)
|
32
|
-
result[:errors] << { service => option_errors.errors } unless option_errors.valid?
|
33
|
-
end
|
34
|
-
result
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'hash_validator'
|
2
|
-
require_relative 'validator'
|
3
|
-
|
4
|
-
module Kontena::Cli::Apps
|
5
|
-
module YAML
|
6
|
-
class ValidatorV2
|
7
|
-
require_relative 'validations'
|
8
|
-
include Validations
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@schema = common_validations
|
12
|
-
@schema['build'] = optional('valid_build')
|
13
|
-
@schema['depends_on'] = optional('array')
|
14
|
-
@schema['network_mode'] = optional(%w(host bridge))
|
15
|
-
@schema['logging'] = optional({
|
16
|
-
'driver' => optional('string'),
|
17
|
-
'options' => optional(-> (value) { value.is_a?(Hash) })
|
18
|
-
})
|
19
|
-
Validations::CustomValidators.load
|
20
|
-
end
|
21
|
-
|
22
|
-
##
|
23
|
-
# @param [Hash] yaml
|
24
|
-
# @param [TrueClass|FalseClass] strict
|
25
|
-
# @return [Array] validation_errors
|
26
|
-
def validate(yaml)
|
27
|
-
result = {
|
28
|
-
errors: [],
|
29
|
-
notifications: []
|
30
|
-
}
|
31
|
-
if yaml.key?('services')
|
32
|
-
yaml['services'].each do |service, options|
|
33
|
-
unless options.is_a?(Hash)
|
34
|
-
result[:errors] << { service => { 'options' => 'must be a mapping not a string'} }
|
35
|
-
next
|
36
|
-
end
|
37
|
-
option_errors = validate_options(options)
|
38
|
-
result[:errors] << { service => option_errors.errors } unless option_errors.valid?
|
39
|
-
end
|
40
|
-
else
|
41
|
-
result[:errors] << { 'file' => 'services missing' }
|
42
|
-
end
|
43
|
-
if yaml.key?('volumes')
|
44
|
-
result[:notifications] << { 'volumes' => 'Kontena does not support volumes yet. To persist data just define service as stateful (stateful: true)' }
|
45
|
-
end
|
46
|
-
if yaml.key?('networks')
|
47
|
-
result[:notifications] << { 'networks' => 'Kontena does not support multiple networks yet. You can reference services with Kontena\'s internal DNS (service_name.kontena.local)' }
|
48
|
-
end
|
49
|
-
result
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|