23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/kontena/cli/stacks/yaml/validations.rb', line 23
def common_validations
{
'image' => optional('string'), 'extends' => optional('stacks_valid_extends'),
'stateful' => optional('boolean'),
'affinity' => optional('stacks_valid_affinities'),
'cap_add' => optional('array'),
'cap_drop' => optional('array'),
'command' => optional('string'),
'cpus' => optional('float'),
'cpu_shares' => optional('integer'),
'external_links' => optional('array'),
'mem_limit' => optional('string'),
'mem_swaplimit' => optional('string'),
'shm_size' => optional('string'),
'environment' => optional(-> (value) {
if value.is_a?(Hash)
value.all? do |k,v|
k.kind_of?(String) && (
v.kind_of?(String) ||
v.kind_of?(Integer) ||
v.kind_of?(TrueClass) ||
v.kind_of?(FalseClass) ||
v.nil?
)
end
elsif value.is_a?(Array)
value.all? { |v| v.kind_of?(String) && v =~ /\A[^=]+=/ }
else
false
end
}),
'env_file' => optional(-> (value) { value.is_a?(String) || value.is_a?(Array) }),
'instances' => optional('integer'),
'links' => optional(-> (value) { value.is_a?(Array) || value.nil? }),
'ports' => optional(-> (value) { value.is_a?(Array) && value.all? { |v| v.is_a?(String) && v.match(/\A(\d+\.\d+\.\d+\.\d+)?:?(\d+)\:(\d+)\/?(\w+)?\z/) } }),
'pid' => optional('string'),
'privileged' => optional('boolean'),
'user' => optional('string'),
'volumes' => optional('array'),
'volumes_from' => optional('array'),
'secrets' => optional('stacks_valid_secrets'),
'certificates' => optional('stacks_valid_certificates'),
'hooks' => optional('stacks_valid_hooks'),
'only_if' => optional(-> (value) { value.is_a?(String) || value.is_a?(Hash) || value.is_a?(Array) }),
'skip_if' => optional(-> (value) { value.is_a?(String) || value.is_a?(Hash) || value.is_a?(Array) }),
'deploy' => optional({
'strategy' => optional(%w(ha daemon random)),
'wait_for_port' => optional('integer'),
'min_health' => optional('float'),
'interval' => optional(/^\d+(min|h|d|)$/)
}),
'health_check' => optional({
'protocol' => /^(http|tcp)$/,
'port' => 'integer',
'uri' => optional(/\/[\S]*/),
'timeout' => optional('integer'),
'interval' => optional('integer'),
'initial_delay' => optional('integer')
}),
'stop_signal' => optional('string'),
'stop_grace_period' => optional(/(\d+(?:\.\d+)?)([hms])/),
'read_only' => optional('boolean'),
'entrypoint' => optional('string')
}
end
|