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.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/VERSION +1 -1
  4. data/bin/kontena +3 -50
  5. data/examples/kontena-plugin-hello/.gitignore +9 -0
  6. data/examples/kontena-plugin-hello/Gemfile +4 -0
  7. data/examples/kontena-plugin-hello/README.md +3 -0
  8. data/examples/kontena-plugin-hello/bin/console +14 -0
  9. data/examples/kontena-plugin-hello/bin/setup +8 -0
  10. data/examples/kontena-plugin-hello/kontena-plugin-hello.gemspec +22 -0
  11. data/examples/kontena-plugin-hello/lib/kontena/plugin/hello.rb +7 -0
  12. data/examples/kontena-plugin-hello/lib/kontena/plugin/hello/world_command.rb +6 -0
  13. data/examples/kontena-plugin-hello/lib/kontena/plugin/hello_command.rb +9 -0
  14. data/examples/kontena-plugin-hello/lib/kontena_cli_plugin.rb +5 -0
  15. data/kontena-cli.gemspec +1 -3
  16. data/lib/kontena/cli/apps/build_command.rb +3 -0
  17. data/lib/kontena/cli/apps/common.rb +6 -1
  18. data/lib/kontena/cli/apps/deploy_command.rb +1 -1
  19. data/lib/kontena/cli/apps/docker_helper.rb +13 -14
  20. data/lib/kontena/cli/apps/service_generator.rb +19 -11
  21. data/lib/kontena/cli/apps/service_generator_v2.rb +1 -0
  22. data/lib/kontena/cli/apps/yaml/reader.rb +15 -0
  23. data/lib/kontena/cli/apps/yaml/service_extender.rb +28 -0
  24. data/lib/kontena/cli/apps/yaml/validations.rb +38 -24
  25. data/lib/kontena/cli/apps/yaml/validator.rb +7 -7
  26. data/lib/kontena/cli/apps/yaml/validator_v2.rb +7 -6
  27. data/lib/kontena/cli/certificate/authorize_command.rb +23 -0
  28. data/lib/kontena/cli/certificate/get_command.rb +25 -0
  29. data/lib/kontena/cli/certificate/register_command.rb +19 -0
  30. data/lib/kontena/cli/certificate_command.rb +14 -0
  31. data/lib/kontena/cli/containers/containers_helper.rb +22 -0
  32. data/lib/kontena/cli/containers/exec_command.rb +9 -2
  33. data/lib/kontena/cli/grids/logs_command.rb +14 -3
  34. data/lib/kontena/cli/master_command.rb +1 -12
  35. data/lib/kontena/cli/node_command.rb +0 -16
  36. data/lib/kontena/cli/plugin_command.rb +15 -0
  37. data/lib/kontena/cli/plugins/install_command.rb +28 -0
  38. data/lib/kontena/cli/plugins/list_command.rb +13 -0
  39. data/lib/kontena/cli/plugins/search_command.rb +29 -0
  40. data/lib/kontena/cli/plugins/uninstall_command.rb +30 -0
  41. data/lib/kontena/cli/registry/create_command.rb +1 -1
  42. data/lib/kontena/cli/services/create_command.rb +16 -0
  43. data/lib/kontena/cli/services/list_command.rb +17 -3
  44. data/lib/kontena/cli/services/logs_command.rb +63 -18
  45. data/lib/kontena/cli/services/services_helper.rb +47 -4
  46. data/lib/kontena/cli/services/update_command.rb +16 -0
  47. data/lib/kontena/cli/stack_command.rb +20 -0
  48. data/lib/kontena/cli/stacks/common.rb +39 -0
  49. data/lib/kontena/cli/stacks/create_command.rb +27 -0
  50. data/lib/kontena/cli/stacks/deploy_command.rb +26 -0
  51. data/lib/kontena/cli/stacks/list_command.rb +38 -0
  52. data/lib/kontena/cli/stacks/remove_command.rb +26 -0
  53. data/lib/kontena/cli/stacks/show_command.rb +38 -0
  54. data/lib/kontena/cli/stacks/update_command.rb +27 -0
  55. data/lib/kontena/client.rb +11 -4
  56. data/lib/kontena/command.rb +4 -0
  57. data/lib/kontena/main_command.rb +61 -0
  58. data/lib/kontena/plugin_manager.rb +38 -0
  59. data/lib/kontena/util.rb +17 -0
  60. data/lib/kontena_cli.rb +6 -0
  61. data/spec/fixtures/health.yml +26 -0
  62. data/spec/fixtures/kontena-build.yml +16 -0
  63. data/spec/fixtures/kontena_build_v2.yaml +26 -0
  64. data/spec/kontena/cli/app/build_command_spec.rb +13 -1
  65. data/spec/kontena/cli/app/common_spec.rb +11 -0
  66. data/spec/kontena/cli/app/deploy_command_spec.rb +1 -1
  67. data/spec/kontena/cli/app/docker_helper_spec.rb +45 -0
  68. data/spec/kontena/cli/app/service_generator_spec.rb +52 -1
  69. data/spec/kontena/cli/app/yaml/service_extender_spec.rb +24 -0
  70. data/spec/kontena/cli/app/yaml/validator_spec.rb +97 -14
  71. data/spec/kontena/cli/common_spec.rb +0 -5
  72. data/spec/kontena/cli/containers/containers_helper_spec.rb +16 -0
  73. data/spec/kontena/cli/services/services_helper_spec.rb +50 -1
  74. data/spec/kontena/cli/version_command_spec.rb +1 -1
  75. data/spec/kontena/client_spec.rb +156 -0
  76. data/spec/kontena/plugin_manager_spec.rb +22 -0
  77. data/spec/spec_helper.rb +1 -0
  78. metadata +54 -125
  79. data/lib/kontena/cli/master/aws/create_command.rb +0 -48
  80. data/lib/kontena/cli/master/aws_command.rb +0 -8
  81. data/lib/kontena/cli/master/azure/create_command.rb +0 -37
  82. data/lib/kontena/cli/master/azure_command.rb +0 -13
  83. data/lib/kontena/cli/master/digital_ocean/create_command.rb +0 -38
  84. data/lib/kontena/cli/master/digital_ocean_command.rb +0 -13
  85. data/lib/kontena/cli/master/packet/create_command.rb +0 -42
  86. data/lib/kontena/cli/master/packet_command.rb +0 -14
  87. data/lib/kontena/cli/master/upcloud/create_command.rb +0 -39
  88. data/lib/kontena/cli/master/upcloud_command.rb +0 -13
  89. data/lib/kontena/cli/master/vagrant/create_command.rb +0 -25
  90. data/lib/kontena/cli/master/vagrant/restart_command.rb +0 -20
  91. data/lib/kontena/cli/master/vagrant/ssh_command.rb +0 -15
  92. data/lib/kontena/cli/master/vagrant/start_command.rb +0 -20
  93. data/lib/kontena/cli/master/vagrant/stop_command.rb +0 -20
  94. data/lib/kontena/cli/master/vagrant/terminate_command.rb +0 -13
  95. data/lib/kontena/cli/master/vagrant_command.rb +0 -23
  96. data/lib/kontena/cli/nodes/aws/create_command.rb +0 -44
  97. data/lib/kontena/cli/nodes/aws/restart_command.rb +0 -29
  98. data/lib/kontena/cli/nodes/aws/terminate_command.rb +0 -21
  99. data/lib/kontena/cli/nodes/aws_command.rb +0 -15
  100. data/lib/kontena/cli/nodes/azure/create_command.rb +0 -38
  101. data/lib/kontena/cli/nodes/azure/restart_command.rb +0 -32
  102. data/lib/kontena/cli/nodes/azure/terminate_command.rb +0 -21
  103. data/lib/kontena/cli/nodes/azure_command.rb +0 -15
  104. data/lib/kontena/cli/nodes/digital_ocean/create_command.rb +0 -32
  105. data/lib/kontena/cli/nodes/digital_ocean/restart_command.rb +0 -27
  106. data/lib/kontena/cli/nodes/digital_ocean/terminate_command.rb +0 -19
  107. data/lib/kontena/cli/nodes/digital_ocean_command.rb +0 -15
  108. data/lib/kontena/cli/nodes/packet/create_command.rb +0 -35
  109. data/lib/kontena/cli/nodes/packet/restart_command.rb +0 -17
  110. data/lib/kontena/cli/nodes/packet/terminate_command.rb +0 -20
  111. data/lib/kontena/cli/nodes/packet_command.rb +0 -15
  112. data/lib/kontena/cli/nodes/upcloud/create_command.rb +0 -33
  113. data/lib/kontena/cli/nodes/upcloud/restart_command.rb +0 -20
  114. data/lib/kontena/cli/nodes/upcloud/terminate_command.rb +0 -20
  115. data/lib/kontena/cli/nodes/upcloud_command.rb +0 -15
  116. data/lib/kontena/cli/nodes/vagrant/create_command.rb +0 -27
  117. data/lib/kontena/cli/nodes/vagrant/restart_command.rb +0 -26
  118. data/lib/kontena/cli/nodes/vagrant/ssh_command.rb +0 -21
  119. data/lib/kontena/cli/nodes/vagrant/start_command.rb +0 -26
  120. data/lib/kontena/cli/nodes/vagrant/stop_command.rb +0 -26
  121. data/lib/kontena/cli/nodes/vagrant/terminate_command.rb +0 -17
  122. data/lib/kontena/cli/nodes/vagrant_command.rb +0 -21
  123. data/lib/kontena/machine/aws.rb +0 -13
  124. data/lib/kontena/machine/aws/cloudinit.yml +0 -71
  125. data/lib/kontena/machine/aws/cloudinit_master.yml +0 -118
  126. data/lib/kontena/machine/aws/common.rb +0 -58
  127. data/lib/kontena/machine/aws/master_provisioner.rb +0 -187
  128. data/lib/kontena/machine/aws/node_destroyer.rb +0 -51
  129. data/lib/kontena/machine/aws/node_provisioner.rb +0 -204
  130. data/lib/kontena/machine/azure.rb +0 -13
  131. data/lib/kontena/machine/azure/cloudinit.yml +0 -64
  132. data/lib/kontena/machine/azure/cloudinit_master.yml +0 -106
  133. data/lib/kontena/machine/azure/logger.rb +0 -27
  134. data/lib/kontena/machine/azure/master_provisioner.rb +0 -128
  135. data/lib/kontena/machine/azure/node_destroyer.rb +0 -53
  136. data/lib/kontena/machine/azure/node_provisioner.rb +0 -132
  137. data/lib/kontena/machine/digital_ocean.rb +0 -13
  138. data/lib/kontena/machine/digital_ocean/cloudinit.yml +0 -64
  139. data/lib/kontena/machine/digital_ocean/cloudinit_master.yml +0 -118
  140. data/lib/kontena/machine/digital_ocean/master_provisioner.rb +0 -99
  141. data/lib/kontena/machine/digital_ocean/node_destroyer.rb +0 -40
  142. data/lib/kontena/machine/digital_ocean/node_provisioner.rb +0 -88
  143. data/lib/kontena/machine/packet.rb +0 -17
  144. data/lib/kontena/machine/packet/cloudinit.yml +0 -66
  145. data/lib/kontena/machine/packet/cloudinit_master.yml +0 -118
  146. data/lib/kontena/machine/packet/master_provisioner.rb +0 -93
  147. data/lib/kontena/machine/packet/node_destroyer.rb +0 -42
  148. data/lib/kontena/machine/packet/node_provisioner.rb +0 -77
  149. data/lib/kontena/machine/packet/node_restarter.rb +0 -41
  150. data/lib/kontena/machine/packet/packet_common.rb +0 -89
  151. data/lib/kontena/machine/upcloud.rb +0 -9
  152. data/lib/kontena/machine/upcloud/cloudinit.yml +0 -64
  153. data/lib/kontena/machine/upcloud/cloudinit_master.yml +0 -118
  154. data/lib/kontena/machine/upcloud/master_provisioner.rb +0 -138
  155. data/lib/kontena/machine/upcloud/node_destroyer.rb +0 -85
  156. data/lib/kontena/machine/upcloud/node_provisioner.rb +0 -121
  157. data/lib/kontena/machine/upcloud/node_restarter.rb +0 -49
  158. data/lib/kontena/machine/upcloud/upcloud_common.rb +0 -74
  159. data/lib/kontena/machine/vagrant.rb +0 -12
  160. data/lib/kontena/machine/vagrant/Vagrantfile.master.rb.erb +0 -104
  161. data/lib/kontena/machine/vagrant/Vagrantfile.node.rb.erb +0 -32
  162. data/lib/kontena/machine/vagrant/cloudinit.yml +0 -73
  163. data/lib/kontena/machine/vagrant/master_destroyer.rb +0 -37
  164. data/lib/kontena/machine/vagrant/master_provisioner.rb +0 -79
  165. data/lib/kontena/machine/vagrant/node_destroyer.rb +0 -40
  166. 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: 4d545f80b75358410ec8c63e5dab5c812b26a5f7
4
- data.tar.gz: dbe846306bd4acb2e9553ae3cb10e818577eaae8
3
+ metadata.gz: d2097ac9b19a1b3ffe77759d51f750de06bab2af
4
+ data.tar.gz: 0484b872ce20c995506cba6cc651716b7a4ffec3
5
5
  SHA512:
6
- metadata.gz: 6eb29482b3ca4974650f298e1ddd08e15743fba9fe65bd22cd32cfce918de3c6718920b3cde4ec1981d5b5147d1dcf5d278c41ccf45c3ed43c3db3ff38aa3c3f
7
- data.tar.gz: c9962f99d9a34403912c449ef6037f27b523c6c22fe511f767f30b8bf56c3fed41a8223c6425be4bcad2858fb482bc97816bccc07d89afe7c9debdcd3d71d8a5
6
+ metadata.gz: 6fce1e0c1cac772357d580e0c05284130ad1632a234c47e48f722028d37bc5ec6c025628e343fe5cc6567e9703775c64bd04a34e46ee71d072c52525d1ace02e
7
+ data.tar.gz: 929389765338d0c8db3dbc56973052f4cb5b7c384ea37f6ba2125a393436b83260161c1ff9aa0111aa1f6446e1afe8d9fe3cd5a7f6ccb2928e7369ef03938421
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
  group :development, :test do
6
6
  gem "rspec"
7
- end
7
+ gem "kontena-plugin-hello", path: "./examples/kontena-plugin-hello"
8
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.7
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
- MainCommand.run
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,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kontena-plugin-hello.gemspec
4
+ gemspec
@@ -0,0 +1,3 @@
1
+ # Kontena Hello World Plugin
2
+
3
+ Just an example how to write Kontena cli plugins.
@@ -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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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
@@ -0,0 +1,7 @@
1
+ module Kontena
2
+ module Plugin
3
+ module Hello
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ class Kontena::Plugin::Hello::WorldCommand < Kontena::Command
2
+
3
+ def execute
4
+ puts "hello world!"
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'hello/world_command'
2
+
3
+ class Kontena::Plugin::HelloCommand < Kontena::Command
4
+
5
+ subcommand 'world', 'Hello world related commands', Kontena::Plugin::Hello::WorldCommand
6
+
7
+ def execute
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ require 'kontena_cli'
2
+ require_relative 'kontena/plugin/hello'
3
+ require_relative 'kontena/plugin/hello_command'
4
+
5
+ Kontena::MainCommand.register("hello", "Hello specific commands", Kontena::Plugin::HelloCommand)
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.7.4"
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['image'], service['build']['context'], dockerfile, no_cache)
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 [String] name
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(name, path, dockerfile, no_cache=false)
42
- cmd = ["docker build -t #{name}"]
43
- cmd << "-f #{File.join(File.expand_path(path), dockerfile)}" if dockerfile != "Dockerfile"
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
- cmd << path
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 #{name.colorize(:cyan)}") unless ret
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'] = parse_ports(options['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 parse_ports(port_options)
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
- 'container_port' => container_port,
93
- 'node_port' => node_port,
94
- 'protocol' => protocol || 'tcp'
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
@@ -20,6 +20,7 @@ module Kontena::Cli::Apps
20
20
  unless options['build'].is_a?(Hash)
21
21
  options['build'] = { 'context' => options['build']}
22
22
  end
23
+ options['build']['args'] = parse_build_args(options['build']['args']) if options['build']['args']
23
24
  options['build']
24
25
  end
25
26
  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
- key('service').required(:str?)
8
- optional('file') { str? }
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') { array? | none? }
13
- base.optional('cap_drop') { array? | none? }
14
- base.optional('command') { str? | none? }
15
- base.optional('cpu_shares') { int? | none? }
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') { array? }
24
- base.optional('volumes') { array? }
25
- base.optional('volumes_from') { array? }
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') { inclusion?(%w(ha daemon random)) }
28
- optional('wait_for_port') { int? }
29
- optional('min_health') { float? }
30
- optional('interval') { format?(/^\d+(min|h|d|)$/) }
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
- key('name').required
35
- key('cmd').required
36
- key('instances') { int? | eql?('*') }
37
- optional('oneshot') { bool? }
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
- key('cmd').required
45
+ required('cmd').filled
41
46
  end
42
47
  end
48
+
43
49
  base.optional('secrets').each do
44
- key('secret').required
45
- key('name').required
46
- key('type').required
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 = validate_key(key)
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 validate_key(key)
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)