kontena-cli 0.14.7 → 0.15.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/VERSION +1 -1
- data/bin/kontena +3 -50
- data/examples/kontena-plugin-hello/.gitignore +9 -0
- data/examples/kontena-plugin-hello/Gemfile +4 -0
- data/examples/kontena-plugin-hello/README.md +3 -0
- data/examples/kontena-plugin-hello/bin/console +14 -0
- data/examples/kontena-plugin-hello/bin/setup +8 -0
- data/examples/kontena-plugin-hello/kontena-plugin-hello.gemspec +22 -0
- data/examples/kontena-plugin-hello/lib/kontena/plugin/hello.rb +7 -0
- data/examples/kontena-plugin-hello/lib/kontena/plugin/hello/world_command.rb +6 -0
- data/examples/kontena-plugin-hello/lib/kontena/plugin/hello_command.rb +9 -0
- data/examples/kontena-plugin-hello/lib/kontena_cli_plugin.rb +5 -0
- data/kontena-cli.gemspec +1 -3
- data/lib/kontena/cli/apps/build_command.rb +3 -0
- data/lib/kontena/cli/apps/common.rb +6 -1
- data/lib/kontena/cli/apps/deploy_command.rb +1 -1
- data/lib/kontena/cli/apps/docker_helper.rb +13 -14
- data/lib/kontena/cli/apps/service_generator.rb +19 -11
- data/lib/kontena/cli/apps/service_generator_v2.rb +1 -0
- data/lib/kontena/cli/apps/yaml/reader.rb +15 -0
- data/lib/kontena/cli/apps/yaml/service_extender.rb +28 -0
- data/lib/kontena/cli/apps/yaml/validations.rb +38 -24
- data/lib/kontena/cli/apps/yaml/validator.rb +7 -7
- data/lib/kontena/cli/apps/yaml/validator_v2.rb +7 -6
- data/lib/kontena/cli/certificate/authorize_command.rb +23 -0
- data/lib/kontena/cli/certificate/get_command.rb +25 -0
- data/lib/kontena/cli/certificate/register_command.rb +19 -0
- data/lib/kontena/cli/certificate_command.rb +14 -0
- data/lib/kontena/cli/containers/containers_helper.rb +22 -0
- data/lib/kontena/cli/containers/exec_command.rb +9 -2
- data/lib/kontena/cli/grids/logs_command.rb +14 -3
- data/lib/kontena/cli/master_command.rb +1 -12
- data/lib/kontena/cli/node_command.rb +0 -16
- data/lib/kontena/cli/plugin_command.rb +15 -0
- data/lib/kontena/cli/plugins/install_command.rb +28 -0
- data/lib/kontena/cli/plugins/list_command.rb +13 -0
- data/lib/kontena/cli/plugins/search_command.rb +29 -0
- data/lib/kontena/cli/plugins/uninstall_command.rb +30 -0
- data/lib/kontena/cli/registry/create_command.rb +1 -1
- data/lib/kontena/cli/services/create_command.rb +16 -0
- data/lib/kontena/cli/services/list_command.rb +17 -3
- data/lib/kontena/cli/services/logs_command.rb +63 -18
- data/lib/kontena/cli/services/services_helper.rb +47 -4
- data/lib/kontena/cli/services/update_command.rb +16 -0
- data/lib/kontena/cli/stack_command.rb +20 -0
- data/lib/kontena/cli/stacks/common.rb +39 -0
- data/lib/kontena/cli/stacks/create_command.rb +27 -0
- data/lib/kontena/cli/stacks/deploy_command.rb +26 -0
- data/lib/kontena/cli/stacks/list_command.rb +38 -0
- data/lib/kontena/cli/stacks/remove_command.rb +26 -0
- data/lib/kontena/cli/stacks/show_command.rb +38 -0
- data/lib/kontena/cli/stacks/update_command.rb +27 -0
- data/lib/kontena/client.rb +11 -4
- data/lib/kontena/command.rb +4 -0
- data/lib/kontena/main_command.rb +61 -0
- data/lib/kontena/plugin_manager.rb +38 -0
- data/lib/kontena/util.rb +17 -0
- data/lib/kontena_cli.rb +6 -0
- data/spec/fixtures/health.yml +26 -0
- data/spec/fixtures/kontena-build.yml +16 -0
- data/spec/fixtures/kontena_build_v2.yaml +26 -0
- data/spec/kontena/cli/app/build_command_spec.rb +13 -1
- data/spec/kontena/cli/app/common_spec.rb +11 -0
- data/spec/kontena/cli/app/deploy_command_spec.rb +1 -1
- data/spec/kontena/cli/app/docker_helper_spec.rb +45 -0
- data/spec/kontena/cli/app/service_generator_spec.rb +52 -1
- data/spec/kontena/cli/app/yaml/service_extender_spec.rb +24 -0
- data/spec/kontena/cli/app/yaml/validator_spec.rb +97 -14
- data/spec/kontena/cli/common_spec.rb +0 -5
- data/spec/kontena/cli/containers/containers_helper_spec.rb +16 -0
- data/spec/kontena/cli/services/services_helper_spec.rb +50 -1
- data/spec/kontena/cli/version_command_spec.rb +1 -1
- data/spec/kontena/client_spec.rb +156 -0
- data/spec/kontena/plugin_manager_spec.rb +22 -0
- data/spec/spec_helper.rb +1 -0
- metadata +54 -125
- data/lib/kontena/cli/master/aws/create_command.rb +0 -48
- data/lib/kontena/cli/master/aws_command.rb +0 -8
- data/lib/kontena/cli/master/azure/create_command.rb +0 -37
- data/lib/kontena/cli/master/azure_command.rb +0 -13
- data/lib/kontena/cli/master/digital_ocean/create_command.rb +0 -38
- data/lib/kontena/cli/master/digital_ocean_command.rb +0 -13
- data/lib/kontena/cli/master/packet/create_command.rb +0 -42
- data/lib/kontena/cli/master/packet_command.rb +0 -14
- data/lib/kontena/cli/master/upcloud/create_command.rb +0 -39
- data/lib/kontena/cli/master/upcloud_command.rb +0 -13
- data/lib/kontena/cli/master/vagrant/create_command.rb +0 -25
- data/lib/kontena/cli/master/vagrant/restart_command.rb +0 -20
- data/lib/kontena/cli/master/vagrant/ssh_command.rb +0 -15
- data/lib/kontena/cli/master/vagrant/start_command.rb +0 -20
- data/lib/kontena/cli/master/vagrant/stop_command.rb +0 -20
- data/lib/kontena/cli/master/vagrant/terminate_command.rb +0 -13
- data/lib/kontena/cli/master/vagrant_command.rb +0 -23
- data/lib/kontena/cli/nodes/aws/create_command.rb +0 -44
- data/lib/kontena/cli/nodes/aws/restart_command.rb +0 -29
- data/lib/kontena/cli/nodes/aws/terminate_command.rb +0 -21
- data/lib/kontena/cli/nodes/aws_command.rb +0 -15
- data/lib/kontena/cli/nodes/azure/create_command.rb +0 -38
- data/lib/kontena/cli/nodes/azure/restart_command.rb +0 -32
- data/lib/kontena/cli/nodes/azure/terminate_command.rb +0 -21
- data/lib/kontena/cli/nodes/azure_command.rb +0 -15
- data/lib/kontena/cli/nodes/digital_ocean/create_command.rb +0 -32
- data/lib/kontena/cli/nodes/digital_ocean/restart_command.rb +0 -27
- data/lib/kontena/cli/nodes/digital_ocean/terminate_command.rb +0 -19
- data/lib/kontena/cli/nodes/digital_ocean_command.rb +0 -15
- data/lib/kontena/cli/nodes/packet/create_command.rb +0 -35
- data/lib/kontena/cli/nodes/packet/restart_command.rb +0 -17
- data/lib/kontena/cli/nodes/packet/terminate_command.rb +0 -20
- data/lib/kontena/cli/nodes/packet_command.rb +0 -15
- data/lib/kontena/cli/nodes/upcloud/create_command.rb +0 -33
- data/lib/kontena/cli/nodes/upcloud/restart_command.rb +0 -20
- data/lib/kontena/cli/nodes/upcloud/terminate_command.rb +0 -20
- data/lib/kontena/cli/nodes/upcloud_command.rb +0 -15
- data/lib/kontena/cli/nodes/vagrant/create_command.rb +0 -27
- data/lib/kontena/cli/nodes/vagrant/restart_command.rb +0 -26
- data/lib/kontena/cli/nodes/vagrant/ssh_command.rb +0 -21
- data/lib/kontena/cli/nodes/vagrant/start_command.rb +0 -26
- data/lib/kontena/cli/nodes/vagrant/stop_command.rb +0 -26
- data/lib/kontena/cli/nodes/vagrant/terminate_command.rb +0 -17
- data/lib/kontena/cli/nodes/vagrant_command.rb +0 -21
- data/lib/kontena/machine/aws.rb +0 -13
- data/lib/kontena/machine/aws/cloudinit.yml +0 -71
- data/lib/kontena/machine/aws/cloudinit_master.yml +0 -118
- data/lib/kontena/machine/aws/common.rb +0 -58
- data/lib/kontena/machine/aws/master_provisioner.rb +0 -187
- data/lib/kontena/machine/aws/node_destroyer.rb +0 -51
- data/lib/kontena/machine/aws/node_provisioner.rb +0 -204
- data/lib/kontena/machine/azure.rb +0 -13
- data/lib/kontena/machine/azure/cloudinit.yml +0 -64
- data/lib/kontena/machine/azure/cloudinit_master.yml +0 -106
- data/lib/kontena/machine/azure/logger.rb +0 -27
- data/lib/kontena/machine/azure/master_provisioner.rb +0 -128
- data/lib/kontena/machine/azure/node_destroyer.rb +0 -53
- data/lib/kontena/machine/azure/node_provisioner.rb +0 -132
- data/lib/kontena/machine/digital_ocean.rb +0 -13
- data/lib/kontena/machine/digital_ocean/cloudinit.yml +0 -64
- data/lib/kontena/machine/digital_ocean/cloudinit_master.yml +0 -118
- data/lib/kontena/machine/digital_ocean/master_provisioner.rb +0 -99
- data/lib/kontena/machine/digital_ocean/node_destroyer.rb +0 -40
- data/lib/kontena/machine/digital_ocean/node_provisioner.rb +0 -88
- data/lib/kontena/machine/packet.rb +0 -17
- data/lib/kontena/machine/packet/cloudinit.yml +0 -66
- data/lib/kontena/machine/packet/cloudinit_master.yml +0 -118
- data/lib/kontena/machine/packet/master_provisioner.rb +0 -93
- data/lib/kontena/machine/packet/node_destroyer.rb +0 -42
- data/lib/kontena/machine/packet/node_provisioner.rb +0 -77
- data/lib/kontena/machine/packet/node_restarter.rb +0 -41
- data/lib/kontena/machine/packet/packet_common.rb +0 -89
- data/lib/kontena/machine/upcloud.rb +0 -9
- data/lib/kontena/machine/upcloud/cloudinit.yml +0 -64
- data/lib/kontena/machine/upcloud/cloudinit_master.yml +0 -118
- data/lib/kontena/machine/upcloud/master_provisioner.rb +0 -138
- data/lib/kontena/machine/upcloud/node_destroyer.rb +0 -85
- data/lib/kontena/machine/upcloud/node_provisioner.rb +0 -121
- data/lib/kontena/machine/upcloud/node_restarter.rb +0 -49
- data/lib/kontena/machine/upcloud/upcloud_common.rb +0 -74
- data/lib/kontena/machine/vagrant.rb +0 -12
- data/lib/kontena/machine/vagrant/Vagrantfile.master.rb.erb +0 -104
- data/lib/kontena/machine/vagrant/Vagrantfile.node.rb.erb +0 -32
- data/lib/kontena/machine/vagrant/cloudinit.yml +0 -73
- data/lib/kontena/machine/vagrant/master_destroyer.rb +0 -37
- data/lib/kontena/machine/vagrant/master_provisioner.rb +0 -79
- data/lib/kontena/machine/vagrant/node_destroyer.rb +0 -40
- data/lib/kontena/machine/vagrant/node_provisioner.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2097ac9b19a1b3ffe77759d51f750de06bab2af
|
4
|
+
data.tar.gz: 0484b872ce20c995506cba6cc651716b7a4ffec3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fce1e0c1cac772357d580e0c05284130ad1632a234c47e48f722028d37bc5ec6c025628e343fe5cc6567e9703775c64bd04a34e46ee71d072c52525d1ace02e
|
7
|
+
data.tar.gz: 929389765338d0c8db3dbc56973052f4cb5b7c384ea37f6ba2125a393436b83260161c1ff9aa0111aa1f6446e1afe8d9fe3cd5a7f6ccb2928e7369ef03938421
|
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.15.0.rc1
|
data/bin/kontena
CHANGED
@@ -8,59 +8,12 @@ bin_file = Pathname.new(__FILE__).realpath
|
|
8
8
|
# add self to libpath
|
9
9
|
$:.unshift File.expand_path('../../lib', bin_file)
|
10
10
|
|
11
|
+
require 'kontena_cli'
|
11
12
|
STDOUT.sync = true
|
12
13
|
|
13
|
-
require 'clamp'
|
14
|
-
require 'ruby_dig'
|
15
|
-
require 'kontena/client'
|
16
|
-
require 'kontena/cli/common'
|
17
|
-
require 'kontena/cli/bytes_helper'
|
18
|
-
require 'kontena/cli/grid_options'
|
19
|
-
require 'kontena/cli/app_command'
|
20
|
-
require 'kontena/cli/register_command'
|
21
|
-
require 'kontena/cli/login_command'
|
22
|
-
require 'kontena/cli/logout_command'
|
23
|
-
require 'kontena/cli/whoami_command'
|
24
|
-
require 'kontena/cli/container_command'
|
25
|
-
require 'kontena/cli/grid_command'
|
26
|
-
require 'kontena/cli/master_command'
|
27
|
-
require 'kontena/cli/node_command'
|
28
|
-
require 'kontena/cli/service_command'
|
29
|
-
require 'kontena/cli/vpn_command'
|
30
|
-
require 'kontena/cli/registry_command'
|
31
|
-
require 'kontena/cli/external_registry_command'
|
32
|
-
require 'kontena/cli/app_command'
|
33
|
-
require 'kontena/cli/etcd_command'
|
34
|
-
require 'kontena/cli/vault_command'
|
35
|
-
require 'kontena/cli/user_command'
|
36
|
-
require 'kontena/cli/version_command'
|
37
|
-
|
38
|
-
class MainCommand < Clamp::Command
|
39
|
-
|
40
|
-
subcommand "grid", "Grid specific commands", Kontena::Cli::GridCommand
|
41
|
-
subcommand "app", "App specific commands", Kontena::Cli::AppCommand
|
42
|
-
subcommand "service", "Service specific commands", Kontena::Cli::ServiceCommand
|
43
|
-
subcommand "vault", "Vault specific commands", Kontena::Cli::VaultCommand
|
44
|
-
subcommand "node", "Node specific commands", Kontena::Cli::NodeCommand
|
45
|
-
subcommand "master", "Master specific commands", Kontena::Cli::MasterCommand
|
46
|
-
subcommand "vpn", "VPN specific commands", Kontena::Cli::VpnCommand
|
47
|
-
subcommand "registry", "Registry specific commands", Kontena::Cli::RegistryCommand
|
48
|
-
subcommand "container", "Container specific commands", Kontena::Cli::ContainerCommand
|
49
|
-
subcommand "etcd", "Etcd specific commands", Kontena::Cli::EtcdCommand
|
50
|
-
subcommand "external-registry", "External registry specific commands", Kontena::Cli::ExternalRegistryCommand
|
51
|
-
subcommand "register", "Register Kontena Account", Kontena::Cli::RegisterCommand
|
52
|
-
subcommand "login", "Login to Kontena Master", Kontena::Cli::LoginCommand
|
53
|
-
subcommand "logout", "Logout from Kontena Master", Kontena::Cli::LogoutCommand
|
54
|
-
subcommand "whoami", "Shows current logged in user", Kontena::Cli::WhoamiCommand
|
55
|
-
subcommand "user", "User related commands", Kontena::Cli::UserCommand
|
56
|
-
subcommand "version", "Show version", Kontena::Cli::VersionCommand
|
57
|
-
|
58
|
-
def execute
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
14
|
begin
|
63
|
-
|
15
|
+
Kontena::PluginManager.instance.load_plugins
|
16
|
+
Kontena::MainCommand.run
|
64
17
|
rescue Excon::Errors::SocketError => exc
|
65
18
|
if exc.message.include?('Unable to verify certificate')
|
66
19
|
$stderr.puts "The server uses a certificate signed by an unknown authority.".colorize(:red)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "kontena/plugin/hello"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kontena/plugin/hello'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kontena-plugin-hello"
|
8
|
+
spec.version = Kontena::Plugin::Hello::VERSION
|
9
|
+
spec.authors = ["Kontena, Inc."]
|
10
|
+
spec.email = ["info@kontena.io"]
|
11
|
+
|
12
|
+
spec.summary = "Kontena hello world plugin"
|
13
|
+
spec.description = "This plugin is just an example"
|
14
|
+
spec.homepage = "https://github.com/kontena/kontena/cli/examples/kontena-plugin-hello"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency 'kontena-cli', '~> 0.14', '>= 0.14.0'
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
data/kontena-cli.gemspec
CHANGED
@@ -28,7 +28,5 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_runtime_dependency "highline"
|
29
29
|
spec.add_runtime_dependency "shell-spinner"
|
30
30
|
spec.add_runtime_dependency "ruby_dig"
|
31
|
-
spec.add_runtime_dependency "dry-validation", "0.
|
32
|
-
spec.add_runtime_dependency "dry-types", "0.7.1"
|
33
|
-
spec.add_runtime_dependency "dry-logic", "0.2.2"
|
31
|
+
spec.add_runtime_dependency "dry-validation", "~> 0.8.0"
|
34
32
|
end
|
@@ -17,6 +17,9 @@ module Kontena::Cli::Apps
|
|
17
17
|
def execute
|
18
18
|
require_config_file(filename)
|
19
19
|
@services = services_from_yaml(filename, service_list, service_prefix)
|
20
|
+
if services.none?{ |name, service| service['build'] }
|
21
|
+
abort 'Not found any service with build option'.colorize(:red)
|
22
|
+
end
|
20
23
|
process_docker_images(services, true, no_cache?)
|
21
24
|
end
|
22
25
|
end
|
@@ -45,6 +45,12 @@ module Kontena::Cli::Apps
|
|
45
45
|
services
|
46
46
|
end
|
47
47
|
|
48
|
+
def read_yaml(filename)
|
49
|
+
reader = YAML::Reader.new(filename)
|
50
|
+
outcome = reader.execute
|
51
|
+
outcome
|
52
|
+
end
|
53
|
+
|
48
54
|
def set_env_variables(project, grid)
|
49
55
|
ENV['project'] = project
|
50
56
|
ENV['grid'] = grid
|
@@ -64,7 +70,6 @@ module Kontena::Cli::Apps
|
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
67
|
-
|
68
73
|
# @return [String]
|
69
74
|
def token
|
70
75
|
@token ||= require_token
|
@@ -23,7 +23,7 @@ module Kontena::Cli::Apps
|
|
23
23
|
require_api_url
|
24
24
|
require_token
|
25
25
|
require_config_file(filename)
|
26
|
-
@deploy_queue = []
|
26
|
+
@deploy_queue = []
|
27
27
|
@services = services_from_yaml(filename, service_list, service_prefix)
|
28
28
|
process_docker_images(services) if !no_build?
|
29
29
|
create_or_update_services(services)
|
@@ -5,11 +5,6 @@ module Kontena::Cli::Apps
|
|
5
5
|
# @param [Boolean] force_build
|
6
6
|
# @param [Boolean] no_cache
|
7
7
|
def process_docker_images(services, force_build = false, no_cache = false)
|
8
|
-
if services.none?{|name, service| service['build']}
|
9
|
-
puts "Not found any service with build option"
|
10
|
-
return
|
11
|
-
end
|
12
|
-
|
13
8
|
services.each do |name, service|
|
14
9
|
if service['build'] && (!image_exist?(service['image']) || force_build)
|
15
10
|
dockerfile = service['build']['dockerfile'] || 'Dockerfile'
|
@@ -20,7 +15,7 @@ module Kontena::Cli::Apps
|
|
20
15
|
run_pre_build_hook(service['hooks']['pre_build'])
|
21
16
|
end
|
22
17
|
puts "Building image #{service['image'].colorize(:cyan)}"
|
23
|
-
build_docker_image(service
|
18
|
+
build_docker_image(service, no_cache)
|
24
19
|
puts "Pushing image #{service['image'].colorize(:cyan)} to registry"
|
25
20
|
push_docker_image(service['image'])
|
26
21
|
end
|
@@ -33,18 +28,22 @@ module Kontena::Cli::Apps
|
|
33
28
|
!(/^[\w.\/\-:]+:?+[\w+.]+$/ =~ name).nil?
|
34
29
|
end
|
35
30
|
|
36
|
-
# @param [
|
37
|
-
# @param [String] path
|
38
|
-
# @param [String] dockerfile
|
31
|
+
# @param [Hash] service
|
39
32
|
# @param [Boolean] no_cache
|
40
33
|
# @return [Integer]
|
41
|
-
def build_docker_image(
|
42
|
-
|
43
|
-
|
34
|
+
def build_docker_image(service, no_cache = false)
|
35
|
+
dockerfile = dockerfile = service['build']['dockerfile'] || 'Dockerfile'
|
36
|
+
build_context = service['build']['context']
|
37
|
+
cmd = ["docker build -t #{service['image']}"]
|
38
|
+
cmd << "-f #{File.join(File.expand_path(build_context), dockerfile)}" if dockerfile != "Dockerfile"
|
44
39
|
cmd << "--no-cache" if no_cache
|
45
|
-
|
40
|
+
args = service['build']['args'] || {}
|
41
|
+
args.each do |k, v|
|
42
|
+
cmd << "--build-arg #{k}=#{v}"
|
43
|
+
end
|
44
|
+
cmd << build_context
|
46
45
|
ret = system(cmd.join(' '))
|
47
|
-
abort("Failed to build image #{
|
46
|
+
abort("Failed to build image #{service['image'].colorize(:cyan)}") unless ret
|
48
47
|
ret
|
49
48
|
end
|
50
49
|
|
@@ -30,7 +30,7 @@ module Kontena::Cli::Apps
|
|
30
30
|
data['container_count'] = options['instances']
|
31
31
|
data['links'] = parse_links(options['links'] || [])
|
32
32
|
data['external_links'] = parse_links(options['external_links'] || [])
|
33
|
-
data['ports'] =
|
33
|
+
data['ports'] = parse_stringified_ports(options['ports'] || [])
|
34
34
|
data['memory'] = parse_memory(options['mem_limit'].to_s) if options['mem_limit']
|
35
35
|
data['memory_swap'] = parse_memory(options['memswap_limit'].to_s) if options['memswap_limit']
|
36
36
|
data['cpu_shares'] = options['cpu_shares'] if options['cpu_shares']
|
@@ -59,6 +59,17 @@ module Kontena::Cli::Apps
|
|
59
59
|
data['hooks'] = options['hooks'] || {}
|
60
60
|
data['secrets'] = options['secrets'] if options['secrets']
|
61
61
|
data['build'] = parse_build_options(options) if options['build']
|
62
|
+
health_check = {}
|
63
|
+
health_opts = options['health_check'] || {}
|
64
|
+
health_check['protocol'] = health_opts['protocol'] if health_opts.has_key?('protocol')
|
65
|
+
health_check['uri'] = health_opts['uri'] if health_opts.has_key?('uri')
|
66
|
+
health_check['port'] = health_opts['port'] if health_opts.has_key?('port')
|
67
|
+
health_check['timeout'] = health_opts['timeout'] if health_opts.has_key?('timeout')
|
68
|
+
health_check['interval'] = health_opts['interval'] if health_opts.has_key?('interval')
|
69
|
+
health_check['initial_delay'] = health_opts['initial_delay'] if health_opts.has_key?('initial_delay')
|
70
|
+
unless health_check.empty?
|
71
|
+
data['health_check'] = health_check
|
72
|
+
end
|
62
73
|
data
|
63
74
|
end
|
64
75
|
|
@@ -77,21 +88,18 @@ module Kontena::Cli::Apps
|
|
77
88
|
|
78
89
|
# @param [String] path
|
79
90
|
def read_env_file(path)
|
80
|
-
File.readlines(path).delete_if { |line| line.start_with?('#') || line.empty? }
|
91
|
+
File.readlines(path).delete_if { |line| line.start_with?('#') || line.strip.empty? }
|
81
92
|
end
|
82
93
|
|
83
94
|
# @param [Array<String>] port_options
|
84
95
|
# @return [Array<Hash>]
|
85
|
-
def
|
86
|
-
port_options.map{|p|
|
87
|
-
node_port, container_port, protocol = p.split(':')
|
88
|
-
if node_port.nil? || container_port.nil?
|
89
|
-
raise ArgumentError.new("Invalid port value #{p}")
|
90
|
-
end
|
96
|
+
def parse_stringified_ports(port_options)
|
97
|
+
parse_ports(port_options).map {|p|
|
91
98
|
{
|
92
|
-
|
93
|
-
|
94
|
-
|
99
|
+
'ip' => p[:ip],
|
100
|
+
'container_port' => p[:container_port],
|
101
|
+
'node_port' => p[:node_port],
|
102
|
+
'protocol' => p[:protocol]
|
95
103
|
}
|
96
104
|
}
|
97
105
|
end
|
@@ -89,6 +89,7 @@ module Kontena::Cli::Apps
|
|
89
89
|
# @param [Hash] service_config
|
90
90
|
def process_config(service_config)
|
91
91
|
normalize_env_vars(service_config)
|
92
|
+
normalize_build_args(service_config)
|
92
93
|
service_config = extend_config(service_config) if service_config.key?('extends')
|
93
94
|
service_config
|
94
95
|
end
|
@@ -145,6 +146,20 @@ module Kontena::Cli::Apps
|
|
145
146
|
options['environment'] = options['environment'].map { |k, v| "#{k}=#{v}" }
|
146
147
|
end
|
147
148
|
end
|
149
|
+
|
150
|
+
# @param [Hash] options - service config
|
151
|
+
def normalize_build_args(options)
|
152
|
+
if v2? && options.dig('build', 'args')
|
153
|
+
if options['build']['args'].is_a?(Array)
|
154
|
+
args = options['build']['args'].dup
|
155
|
+
options['build']['args'] = {}
|
156
|
+
args.each do |arg|
|
157
|
+
k,v = arg.split('=')
|
158
|
+
options['build']['args'][k] = v
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
148
163
|
end
|
149
164
|
end
|
150
165
|
end
|
@@ -21,11 +21,29 @@ module Kontena::Cli::Apps
|
|
21
21
|
from['secrets'],
|
22
22
|
service_config['secrets']
|
23
23
|
)
|
24
|
+
build_args = extend_build_args(safe_dig(from, 'build', 'args'), safe_dig(service_config, 'build', 'args'))
|
25
|
+
unless build_args.empty?
|
26
|
+
service_config['build'] = {} unless service_config['build']
|
27
|
+
service_config['build']['args'] = build_args
|
28
|
+
end
|
29
|
+
|
24
30
|
from.merge(service_config)
|
25
31
|
end
|
26
32
|
|
27
33
|
private
|
28
34
|
|
35
|
+
# Compatibility between ruby_dig and Ruby 2.3. Ruby_dig returns
|
36
|
+
# nil when trying to dig into a string, Ruby 2.3 dig raises
|
37
|
+
# TypeError.
|
38
|
+
#
|
39
|
+
# @param [Hash] source_hash
|
40
|
+
# @param [*keys] list_of_keys
|
41
|
+
def safe_dig(hash, *keys)
|
42
|
+
hash.dig(*keys)
|
43
|
+
rescue TypeError
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
29
47
|
# @param [Array] from
|
30
48
|
# @param [Array] to
|
31
49
|
# @return [Array]
|
@@ -55,6 +73,16 @@ module Kontena::Cli::Apps
|
|
55
73
|
end
|
56
74
|
secrets
|
57
75
|
end
|
76
|
+
|
77
|
+
def extend_build_args(from, to)
|
78
|
+
args = to || {}
|
79
|
+
if from
|
80
|
+
from.each do |k,v|
|
81
|
+
args[k] = v unless args.has_key?(k)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
args
|
85
|
+
end
|
58
86
|
end
|
59
87
|
end
|
60
88
|
end
|
@@ -3,16 +3,18 @@ module Kontena::Cli::Apps::YAML
|
|
3
3
|
|
4
4
|
def append_common_validations(base)
|
5
5
|
base.optional('image').maybe(:str?)
|
6
|
+
|
6
7
|
base.optional('extends').schema do
|
7
|
-
|
8
|
-
optional('file')
|
9
|
-
end
|
8
|
+
required('service').filled(:str?)
|
9
|
+
optional('file').value(:str?)
|
10
|
+
end
|
11
|
+
|
10
12
|
base.optional('stateful') { bool? }
|
11
13
|
base.optional('affinity') { array? { each { format?(/(?<=\!|\=)=/) } } }
|
12
|
-
base.optional('cap_add')
|
13
|
-
base.optional('cap_drop')
|
14
|
-
base.optional('command')
|
15
|
-
base.optional('cpu_shares')
|
14
|
+
base.optional('cap_add').maybe(:array?)
|
15
|
+
base.optional('cap_drop').maybe(:array?)
|
16
|
+
base.optional('command').maybe(:str?)
|
17
|
+
base.optional('cpu_shares').maybe(:int?)
|
16
18
|
base.optional('external_links') { array? }
|
17
19
|
base.optional('mem_limit') { int? | str? }
|
18
20
|
base.optional('memswap_limit') { int? | str? }
|
@@ -20,30 +22,42 @@ module Kontena::Cli::Apps::YAML
|
|
20
22
|
base.optional('env_file') { str? | array? }
|
21
23
|
base.optional('instances') { int? }
|
22
24
|
base.optional('links') { array? | empty? }
|
23
|
-
base.optional('ports')
|
24
|
-
base.optional('volumes')
|
25
|
-
base.optional('volumes_from')
|
25
|
+
base.optional('ports').value(:array?)
|
26
|
+
base.optional('volumes').value(:array?)
|
27
|
+
base.optional('volumes_from').value(:array?)
|
28
|
+
|
26
29
|
base.optional('deploy').schema do
|
27
|
-
optional('strategy')
|
28
|
-
optional('wait_for_port')
|
29
|
-
optional('min_health')
|
30
|
-
optional('interval')
|
30
|
+
optional('strategy').value(included_in?: %w(ha daemon random))
|
31
|
+
optional('wait_for_port').value(:int?)
|
32
|
+
optional('min_health').value(:float?)
|
33
|
+
optional('interval').value(format?: /^\d+(min|h|d|)$/)
|
31
34
|
end
|
35
|
+
|
32
36
|
base.optional('hooks').schema do
|
33
37
|
optional('post_start').each do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
optional('oneshot')
|
38
|
+
required('name').filled
|
39
|
+
required('cmd').filled
|
40
|
+
required('instances') { int? | eql?('*') }
|
41
|
+
optional('oneshot').value(:bool?)
|
38
42
|
end
|
43
|
+
|
39
44
|
optional('pre_build').each do
|
40
|
-
|
45
|
+
required('cmd').filled
|
41
46
|
end
|
42
47
|
end
|
48
|
+
|
43
49
|
base.optional('secrets').each do
|
44
|
-
|
45
|
-
|
46
|
-
|
50
|
+
required('secret').filled
|
51
|
+
required('name').filled
|
52
|
+
required('type').filled
|
53
|
+
end
|
54
|
+
base.optional('health_check').schema do
|
55
|
+
required('protocol').filled(format?: /^(http|tcp)$/)
|
56
|
+
required('port').filled(:int?)
|
57
|
+
optional('uri').value(format?: /\/[\S]*/)
|
58
|
+
optional('timeout').value(:int?)
|
59
|
+
optional('interval').value(:int?)
|
60
|
+
optional('initial_delay').value(:int?)
|
47
61
|
end
|
48
62
|
end
|
49
63
|
|
@@ -59,7 +73,7 @@ module Kontena::Cli::Apps::YAML
|
|
59
73
|
def validate_keys(service_config)
|
60
74
|
errors = {}
|
61
75
|
service_config.keys.each do |key|
|
62
|
-
error =
|
76
|
+
error = validate_required(key)
|
63
77
|
errors[key] = error if error
|
64
78
|
end
|
65
79
|
errors
|
@@ -67,7 +81,7 @@ module Kontena::Cli::Apps::YAML
|
|
67
81
|
|
68
82
|
##
|
69
83
|
# @param [String] key
|
70
|
-
def
|
84
|
+
def validate_required(key)
|
71
85
|
if self.class::UNSUPPORTED_KEYS.include?(key)
|
72
86
|
['unsupported option']
|
73
87
|
elsif !self.class::VALID_KEYS.include?(key)
|