kontena-cli 1.1.6 → 1.2.0.dev1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/VERSION +1 -1
  4. data/bin/kontena +8 -28
  5. data/kontena-cli.gemspec +2 -2
  6. data/lib/kontena/cli/app_command.rb +14 -27
  7. data/lib/kontena/cli/certificate_command.rb +4 -7
  8. data/lib/kontena/cli/cloud/master_command.rb +5 -12
  9. data/lib/kontena/cli/cloud_command.rb +4 -7
  10. data/lib/kontena/cli/container_command.rb +4 -9
  11. data/lib/kontena/cli/etcd/health_command.rb +1 -0
  12. data/lib/kontena/cli/etcd_command.rb +6 -13
  13. data/lib/kontena/cli/external_registry_command.rb +3 -7
  14. data/lib/kontena/cli/grid_command.rb +14 -29
  15. data/lib/kontena/cli/grids/cloud_config_command.rb +1 -0
  16. data/lib/kontena/cli/grids/common.rb +2 -0
  17. data/lib/kontena/cli/grids/create_command.rb +5 -0
  18. data/lib/kontena/cli/grids/trusted_subnet_command.rb +6 -8
  19. data/lib/kontena/cli/grids/user_command.rb +3 -6
  20. data/lib/kontena/cli/master/config_command.rb +6 -12
  21. data/lib/kontena/cli/master/token_command.rb +6 -11
  22. data/lib/kontena/cli/master/users/role_command.rb +2 -4
  23. data/lib/kontena/cli/master/users_command.rb +4 -8
  24. data/lib/kontena/cli/master_command.rb +14 -33
  25. data/lib/kontena/cli/node_command.rb +7 -15
  26. data/lib/kontena/cli/nodes/health_command.rb +1 -1
  27. data/lib/kontena/cli/nodes/label_command.rb +3 -9
  28. data/lib/kontena/cli/nodes/show_command.rb +1 -1
  29. data/lib/kontena/cli/nodes/ssh_command.rb +13 -4
  30. data/lib/kontena/cli/plugin_command.rb +5 -9
  31. data/lib/kontena/cli/registry_command.rb +2 -5
  32. data/lib/kontena/cli/service_command.rb +22 -45
  33. data/lib/kontena/cli/services/container_command.rb +2 -3
  34. data/lib/kontena/cli/services/env_command.rb +3 -6
  35. data/lib/kontena/cli/services/secret_command.rb +2 -4
  36. data/lib/kontena/cli/stack_command.rb +11 -24
  37. data/lib/kontena/cli/stacks/registry_command.rb +5 -12
  38. data/lib/kontena/cli/stacks/upgrade_command.rb +6 -0
  39. data/lib/kontena/cli/stacks/yaml/reader.rb +17 -2
  40. data/lib/kontena/cli/subcommand_loader.rb +82 -0
  41. data/lib/kontena/cli/vault_command.rb +7 -15
  42. data/lib/kontena/cli/version.rb +6 -1
  43. data/lib/kontena/cli/vpn_command.rb +3 -7
  44. data/lib/kontena/command.rb +28 -1
  45. data/lib/kontena/machine/cloud_config/cloudinit.yml +1 -1
  46. data/lib/kontena/main_command.rb +22 -38
  47. data/lib/kontena/scripts/completer +2 -233
  48. data/lib/kontena/scripts/completer.rb +230 -0
  49. data/lib/kontena/scripts/init +5 -8
  50. data/lib/kontena/scripts/kontena.bash +8 -0
  51. data/lib/kontena/scripts/kontena.zsh +11 -0
  52. data/lib/kontena_cli.rb +9 -1
  53. data/omnibus/wrappers/sh/kontena +1 -1
  54. data/spec/fixtures/stack-with-liquid-optional.yml +14 -0
  55. data/spec/fixtures/stack-with-liquid-undefined.yml +12 -0
  56. data/spec/kontena/cli/app/build_command_spec.rb +1 -2
  57. data/spec/kontena/cli/app/common_spec.rb +1 -2
  58. data/spec/kontena/cli/app/config_command_spec.rb +0 -1
  59. data/spec/kontena/cli/app/deploy_command_spec.rb +2 -3
  60. data/spec/kontena/cli/app/docker_helper_spec.rb +0 -1
  61. data/spec/kontena/cli/app/init_command_spec.rb +0 -1
  62. data/spec/kontena/cli/app/logs_command_spec.rb +0 -1
  63. data/spec/kontena/cli/app/scale_spec.rb +2 -3
  64. data/spec/kontena/cli/app/service_generator_spec.rb +1 -2
  65. data/spec/kontena/cli/app/service_generator_v2_spec.rb +0 -1
  66. data/spec/kontena/cli/app/yaml/reader_spec.rb +0 -1
  67. data/spec/kontena/cli/app/yaml/service_extender_spec.rb +0 -1
  68. data/spec/kontena/cli/app/yaml/validator_spec.rb +0 -1
  69. data/spec/kontena/cli/app/yaml/validator_v2_spec.rb +0 -1
  70. data/spec/kontena/cli/cloud/login_command_spec.rb +0 -1
  71. data/spec/kontena/cli/cloud/logout_command_spec.rb +0 -1
  72. data/spec/kontena/cli/cloud/master/add_command_spec.rb +0 -1
  73. data/spec/kontena/cli/common_spec.rb +0 -1
  74. data/spec/kontena/cli/containers/list_command_spec.rb +0 -1
  75. data/spec/kontena/cli/containers/logs_command_spec.rb +0 -1
  76. data/spec/kontena/cli/etcd/health_command_spec.rb +2 -0
  77. data/spec/kontena/cli/grids/trusted_subnets/add_command_spec.rb +0 -11
  78. data/spec/kontena/cli/grids/trusted_subnets/list_command_spec.rb +4 -13
  79. data/spec/kontena/cli/grids/trusted_subnets/remove_command_spec.rb +0 -11
  80. data/spec/kontena/cli/grids/use_command_spec.rb +0 -1
  81. data/spec/kontena/cli/helpers/log_helper_spec.rb +0 -1
  82. data/spec/kontena/cli/main_command_spec.rb +2 -3
  83. data/spec/kontena/cli/master/current_command_spec.rb +5 -15
  84. data/spec/kontena/cli/master/init_cloud_command_spec.rb +0 -1
  85. data/spec/kontena/cli/master/login_command_spec.rb +0 -1
  86. data/spec/kontena/cli/master/logout_command_spec.rb +0 -1
  87. data/spec/kontena/cli/master/use_command_spec.rb +0 -1
  88. data/spec/kontena/cli/master/users/invite_command_spec.rb +1 -5
  89. data/spec/kontena/cli/master/users/remove_command_spec.rb +2 -14
  90. data/spec/kontena/cli/master/users/roles/add_command_spec.rb +0 -1
  91. data/spec/kontena/cli/master/users/roles/remove_command_spec.rb +0 -1
  92. data/spec/kontena/cli/nodes/list_command_spec.rb +2 -0
  93. data/spec/kontena/cli/services/containers_command_spec.rb +0 -18
  94. data/spec/kontena/cli/services/exec_command_spec.rb +6 -4
  95. data/spec/kontena/cli/services/link_command_spec.rb +5 -19
  96. data/spec/kontena/cli/services/restart_command_spec.rb +0 -16
  97. data/spec/kontena/cli/services/secrets/link_command_spec.rb +0 -11
  98. data/spec/kontena/cli/services/secrets/unlink_command_spec.rb +1 -12
  99. data/spec/kontena/cli/services/services_helper_spec.rb +0 -1
  100. data/spec/kontena/cli/services/unlink_command_spec.rb +7 -21
  101. data/spec/kontena/cli/services/update_command_spec.rb +0 -15
  102. data/spec/kontena/cli/stacks/build_command_spec.rb +0 -1
  103. data/spec/kontena/cli/stacks/deploy_command_spec.rb +10 -13
  104. data/spec/kontena/cli/stacks/install_command_spec.rb +0 -15
  105. data/spec/kontena/cli/stacks/list_command_spec.rb +4 -10
  106. data/spec/kontena/cli/stacks/remove_command_spec.rb +1 -16
  107. data/spec/kontena/cli/stacks/service_generator_spec.rb +0 -1
  108. data/spec/kontena/cli/stacks/service_generator_v2_spec.rb +0 -1
  109. data/spec/kontena/cli/stacks/show_command_spec.rb +1 -14
  110. data/spec/kontena/cli/stacks/upgrade_command_spec.rb +19 -1
  111. data/spec/kontena/cli/stacks/yaml/reader_spec.rb +163 -130
  112. data/spec/kontena/cli/stacks/yaml/service_extender_spec.rb +0 -1
  113. data/spec/kontena/cli/stacks/yaml/validator_v3_spec.rb +0 -1
  114. data/spec/kontena/cli/vault/export_spec.rb +0 -1
  115. data/spec/kontena/cli/vault/import_spec.rb +4 -5
  116. data/spec/kontena/cli/version_command_spec.rb +8 -6
  117. data/spec/kontena/cli/vpn/create_command_spec.rb +3 -4
  118. data/spec/kontena/client_spec.rb +0 -1
  119. data/spec/kontena/config_spec.rb +0 -1
  120. data/spec/kontena/kontena_cli_spec.rb +1 -1
  121. data/spec/kontena/main_command_spec.rb +0 -1
  122. data/spec/kontena/plugin_manager_spec.rb +0 -1
  123. data/spec/spec_helper.rb +1 -0
  124. data/spec/support/client_helpers.rb +1 -1
  125. data/spec/support/exit_with_error_helper.rb +36 -0
  126. data/spec/support/fixtures_helpers.rb +5 -2
  127. metadata +18 -7
@@ -1,10 +1,8 @@
1
1
  module Kontena::Cli::Master::Users
2
2
 
3
- require_relative 'roles/add_command'
4
- require_relative 'roles/remove_command'
5
3
 
6
4
  class RoleCommand < Kontena::Command
7
- subcommand "add", "Add role to user", Roles::AddCommand
8
- subcommand ["remove", "rm"], "Remove role from user", Roles::RemoveCommand
5
+ subcommand "add", "Add role to user", load_subcommand('master/users/roles/add_command')
6
+ subcommand ["remove", "rm"], "Remove role from user", load_subcommand('master/users/roles/remove_command')
9
7
  end
10
8
  end
@@ -1,14 +1,10 @@
1
1
  module Kontena::Cli::Master
2
2
 
3
- require_relative 'users/invite_command'
4
- require_relative 'users/remove_command'
5
- require_relative 'users/list_command'
6
- require_relative 'users/role_command'
7
3
 
8
4
  class UsersCommand < Kontena::Command
9
- subcommand "invite", "Invite user to Kontena Master", Users::InviteCommand
10
- subcommand ["remove", "rm"], "Remove user from Kontena Master", Users::RemoveCommand
11
- subcommand ["list", "ls"], "List users", Users::ListCommand
12
- subcommand "role", "User role specific commands", Users::RoleCommand
5
+ subcommand "invite", "Invite user to Kontena Master", load_subcommand('master/users/invite_command')
6
+ subcommand ["remove", "rm"], "Remove user from Kontena Master", load_subcommand('master/users/remove_command')
7
+ subcommand ["list", "ls"], "List users", load_subcommand('master/users/list_command')
8
+ subcommand "role", "User role specific commands", load_subcommand('master/users/role_command')
13
9
  end
14
10
  end
@@ -1,39 +1,20 @@
1
- require_relative '../main_command'
2
- require_relative 'master/use_command'
3
- require_relative 'master/remove_command'
4
- require_relative 'master/list_command'
5
- require_relative 'master/users_command'
6
- require_relative 'master/current_command'
7
- require_relative 'master/config_command'
8
- require_relative 'master/login_command'
9
- require_relative 'master/logout_command'
10
- require_relative 'master/join_command'
11
- require_relative 'master/audit_log_command'
12
- require_relative 'master/token_command'
13
- require_relative 'master/init_cloud_command'
14
- require_relative 'master/ssh_command'
15
-
16
1
  class Kontena::Cli::MasterCommand < Kontena::Command
17
2
  include Kontena::Util
18
3
 
19
- subcommand ["list", "ls"], "List masters where client has logged in", Kontena::Cli::Master::ListCommand
20
- subcommand ["remove", "rm"], "Remove a master from configuration file", Kontena::Cli::Master::RemoveCommand
21
- subcommand ["config", "cfg"], "Configure master settings", Kontena::Cli::Master::ConfigCommand
22
- subcommand "use", "Switch to use selected master", Kontena::Cli::Master::UseCommand
23
- subcommand "users", "Users specific commands", Kontena::Cli::Master::UsersCommand
24
- subcommand "current", "Show current master details", Kontena::Cli::Master::CurrentCommand
25
- subcommand "login", "Authenticate to Kontena Master", Kontena::Cli::Master::LoginCommand
26
- subcommand "logout", "Log out of Kontena Master", Kontena::Cli::Master::LogoutCommand
27
- subcommand "token", "Manage Kontena Master access tokens", Kontena::Cli::Master::TokenCommand
28
- subcommand "join", "Join Kontena Master using an invitation code", Kontena::Cli::Master::JoinCommand
29
- subcommand "audit-log", "Show master audit logs", Kontena::Cli::Master::AuditLogCommand
30
- subcommand "init-cloud", "Configure current master to use Kontena Cloud services", Kontena::Cli::Master::InitCloudCommand
31
- subcommand "ssh", "Connect to the master via SSH", Kontena::Cli::Master::SshCommand
32
-
33
- if experimental?
34
- require_relative 'master/create_command'
35
- subcommand "create", "Install a new Kontena Master", Kontena::Cli::Master::CreateCommand
36
- end
4
+ subcommand ["list", "ls"], "List masters where client has logged in", load_subcommand('master/list_command')
5
+ subcommand ["remove", "rm"], "Remove a master from configuration", load_subcommand('master/remove_command')
6
+ subcommand ["config", "cfg"], "Configure master settings", load_subcommand('master/config_command')
7
+ subcommand "use", "Switch to use selected master", load_subcommand('master/use_command')
8
+ subcommand "users", "Users specific commands", load_subcommand('master/users_command')
9
+ subcommand "current", "Show current master details", load_subcommand('master/current_command')
10
+ subcommand "login", "Authenticate to Kontena Master", load_subcommand('master/login_command')
11
+ subcommand "logout", "Log out of Kontena Master", load_subcommand('master/logout_command')
12
+ subcommand "token", "Manage Kontena Master access tokens", load_subcommand('master/token_command')
13
+ subcommand "join", "Join Kontena Master using an invitation code", load_subcommand('master/join_command')
14
+ subcommand "audit-log", "Show master audit logs", load_subcommand('master/audit_log_command')
15
+ subcommand "create", "Install a new Kontena Master", load_subcommand('master/create_command') if experimental?
16
+ subcommand "init-cloud", "Configure current master to use Kontena Cloud services", load_subcommand('master/init_cloud_command')
17
+ subcommand "ssh", "Connect to the master via SSH", load_subcommand('master/ssh_command')
37
18
 
38
19
  def execute
39
20
  end
@@ -1,20 +1,12 @@
1
- require_relative 'nodes/list_command'
2
- require_relative 'nodes/remove_command'
3
- require_relative 'nodes/show_command'
4
- require_relative 'nodes/update_command'
5
- require_relative 'nodes/ssh_command'
6
- require_relative 'nodes/label_command'
7
- require_relative 'nodes/health_command'
8
-
9
1
  class Kontena::Cli::NodeCommand < Kontena::Command
10
2
 
11
- subcommand ["list","ls"], "List grid nodes", Kontena::Cli::Nodes::ListCommand
12
- subcommand "show", "Show node", Kontena::Cli::Nodes::ShowCommand
13
- subcommand "ssh", "Ssh into node", Kontena::Cli::Nodes::SshCommand
14
- subcommand "update", "Update node", Kontena::Cli::Nodes::UpdateCommand
15
- subcommand ["remove","rm"], "Remove node", Kontena::Cli::Nodes::RemoveCommand
16
- subcommand "label", "Node label specific commands", Kontena::Cli::Nodes::LabelCommand
17
- subcommand "health", "Check node health", Kontena::Cli::Nodes::HealthCommand
3
+ subcommand ["list","ls"], "List grid nodes", load_subcommand('nodes/list_command')
4
+ subcommand "show", "Show node", load_subcommand('nodes/show_command')
5
+ subcommand "ssh", "Ssh into node", load_subcommand('nodes/ssh_command')
6
+ subcommand "update", "Update node", load_subcommand('nodes/update_command')
7
+ subcommand ["remove","rm"], "Remove node", load_subcommand('nodes/remove_command')
8
+ subcommand "label", "Node label specific commands", load_subcommand('nodes/label_command')
9
+ subcommand "health", "Check node health", load_subcommand('nodes/health_command')
18
10
 
19
11
  def execute
20
12
  end
@@ -1,4 +1,4 @@
1
- require_relative '../helpers/health_helper'
1
+ require 'kontena/cli/helpers/health_helper'
2
2
 
3
3
  module Kontena::Cli::Nodes
4
4
  class HealthCommand < Kontena::Command
@@ -1,14 +1,8 @@
1
1
  module Kontena::Cli::Nodes
2
-
3
- require_relative 'labels/add_command'
4
- require_relative 'labels/remove_command'
5
- require_relative 'labels/list_command'
6
-
7
2
  class LabelCommand < Kontena::Command
8
-
9
- subcommand ["list", "ls"], "List node labels", Labels::ListCommand
10
- subcommand "add", "Add label to node", Labels::AddCommand
11
- subcommand ["remove", "rm"], "Remove label from node", Labels::RemoveCommand
3
+ subcommand ["list", "ls"], "List node labels", load_subcommand('nodes/labels/list_command')
4
+ subcommand "add", "Add label to node", load_subcommand('nodes/labels/add_command')
5
+ subcommand ["remove", "rm"], "Remove label from node", load_subcommand('nodes/labels/remove_command')
12
6
 
13
7
  def execute
14
8
  end
@@ -21,7 +21,7 @@ module Kontena::Cli::Nodes
21
21
  puts " last seen: #{node['last_seen_at']}"
22
22
  puts " public ip: #{node['public_ip']}"
23
23
  puts " private ip: #{node['private_ip']}"
24
- puts " overlay ip: 10.81.0.#{node['node_number']}"
24
+ puts " overlay ip: #{node['overlay_ip']}"
25
25
  puts " os: #{node['os']}"
26
26
  puts " driver: #{node['driver']}"
27
27
  puts " kernel: #{node['kernel_version']}"
@@ -3,9 +3,9 @@ module Kontena::Cli::Nodes
3
3
  include Kontena::Cli::Common
4
4
  include Kontena::Cli::GridOptions
5
5
 
6
- parameter "NODE_ID", "Node id"
6
+ parameter "[NODE_ID]", "SSH to Grid node. Use --any to connect to the first available node"
7
7
  parameter "[COMMANDS] ...", "Run command on host"
8
-
8
+ option ["-a", "--any"], :flag, "Connect to first available node"
9
9
  option ["-i", "--identity-file"], "IDENTITY_FILE", "Path to ssh private key"
10
10
  option ["-u", "--user"], "USER", "Login as a user", default: "core"
11
11
  option "--private-ip", :flag, "Connect to node's private IP address"
@@ -15,7 +15,16 @@ module Kontena::Cli::Nodes
15
15
  requires_current_grid
16
16
 
17
17
  def execute
18
- node = client.get("nodes/#{current_grid}/#{node_id}")
18
+ exit_with_error "Cannot combine --any with a node name" if node_id && any?
19
+
20
+ if node_id
21
+ node = client.get("grids/#{current_grid}/nodes/#{node_id}")
22
+ elsif any?
23
+ nodes = client.get("grids/#{current_grid}/nodes")['nodes']
24
+ node = nodes.select{ |node| node['connected'] }.first
25
+ else
26
+ exit_with_error "No node name given. Use --any to connect to the first available node"
27
+ end
19
28
 
20
29
  provider = Array(node["labels"]).find{ |l| l.start_with?('provider=')}.to_s.split('=').last
21
30
 
@@ -31,7 +40,7 @@ module Kontena::Cli::Nodes
31
40
  cmd = ['ssh']
32
41
  cmd += ["-i", identity_file] if identity_file
33
42
  if internal_ip?
34
- ip = "10.81.0.#{node['node_number']}"
43
+ ip = node['overlay_ip']
35
44
  elsif private_ip?
36
45
  ip = node['private_ip']
37
46
  else
@@ -1,15 +1,11 @@
1
- require_relative 'plugins/list_command'
2
- require_relative 'plugins/search_command'
3
- require_relative 'plugins/install_command'
4
- require_relative 'plugins/uninstall_command'
5
1
 
6
2
  class Kontena::Cli::PluginCommand < Kontena::Command
7
3
 
8
- subcommand ["list","ls"], "List plugins", Kontena::Cli::Plugins::ListCommand
9
- subcommand "search", "Search plugins", Kontena::Cli::Plugins::SearchCommand
10
- subcommand "install", "Install a plugin", Kontena::Cli::Plugins::InstallCommand
11
- subcommand "uninstall", "Uninstall a plugin", Kontena::Cli::Plugins::UninstallCommand
4
+ subcommand ["list","ls"], "List plugins", load_subcommand('plugins/list_command')
5
+ subcommand "search", "Search plugins", load_subcommand('plugins/search_command')
6
+ subcommand "install", "Install a plugin", load_subcommand('plugins/install_command')
7
+ subcommand "uninstall", "Uninstall a plugin", load_subcommand('plugins/uninstall_command')
12
8
 
13
9
  def execute
14
10
  end
15
- end
11
+ end
@@ -1,10 +1,7 @@
1
- require_relative 'registry/create_command'
2
- require_relative 'registry/remove_command'
3
-
4
1
  class Kontena::Cli::RegistryCommand < Kontena::Command
5
2
 
6
- subcommand "create", "Create Docker image registry service", Kontena::Cli::Registry::CreateCommand
7
- subcommand ["remove","rm"], "Remove Docker image registry service", Kontena::Cli::Registry::RemoveCommand
3
+ subcommand "create", "Create Docker image registry service", load_subcommand('registry/create_command')
4
+ subcommand ["remove","rm"], "Remove Docker image registry service", load_subcommand('registry/remove_command')
8
5
 
9
6
  def execute
10
7
  end
@@ -1,49 +1,26 @@
1
- require_relative 'services/list_command'
2
- require_relative 'services/show_command'
3
- require_relative 'services/update_command'
4
- require_relative 'services/deploy_command'
5
- require_relative 'services/stop_command'
6
- require_relative 'services/start_command'
7
- require_relative 'services/restart_command'
8
- require_relative 'services/create_command'
9
- require_relative 'services/scale_command'
10
- require_relative 'services/remove_command'
11
- require_relative 'services/containers_command'
12
- require_relative 'services/logs_command'
13
- require_relative 'services/stats_command'
14
- require_relative 'services/monitor_command'
15
-
16
- require_relative 'services/env_command'
17
- require_relative 'services/secret_command'
18
-
19
- require_relative 'services/link_command'
20
- require_relative 'services/unlink_command'
21
- require_relative 'services/exec_command'
22
-
23
1
  class Kontena::Cli::ServiceCommand < Kontena::Command
24
-
25
- subcommand ["list","ls"], "List services", Kontena::Cli::Services::ListCommand
26
- subcommand "create", "Create a new service", Kontena::Cli::Services::CreateCommand
27
- subcommand "show", "Show service details", Kontena::Cli::Services::ShowCommand
28
- subcommand "update", "Update service configuration", Kontena::Cli::Services::UpdateCommand
29
- subcommand "deploy", "Deploy service", Kontena::Cli::Services::DeployCommand
30
- subcommand "stop", "Stop service", Kontena::Cli::Services::StopCommand
31
- subcommand "start", "Start service", Kontena::Cli::Services::StartCommand
32
- subcommand "restart", "Restart service", Kontena::Cli::Services::RestartCommand
33
- subcommand "scale", "Scale service", Kontena::Cli::Services::ScaleCommand
34
- subcommand ["remove", "rm"], "Remove service", Kontena::Cli::Services::RemoveCommand
35
- subcommand "containers", "List service containers", Kontena::Cli::Services::ContainersCommand
36
- subcommand "logs", "Show service logs", Kontena::Cli::Services::LogsCommand
37
- subcommand "stats", "Show service statistics", Kontena::Cli::Services::StatsCommand
38
- subcommand "monitor", "Monitor", Kontena::Cli::Services::MonitorCommand
39
-
40
- subcommand "env", "Environment variable specific commands", Kontena::Cli::Services::EnvCommand
41
-
42
- subcommand "secret", "Secret specific commands", Kontena::Cli::Services::SecretCommand
43
-
44
- subcommand "link", "Link service to another service", Kontena::Cli::Services::LinkCommand
45
- subcommand "unlink", "Unlink service from another service", Kontena::Cli::Services::UnlinkCommand
46
- subcommand "exec", "Execute commands in service containers", Kontena::Cli::Services::ExecCommand
2
+ subcommand ["list","ls"], "List services", load_subcommand('services/list_command')
3
+ subcommand "create", "Create a new service", load_subcommand('services/create_command')
4
+ subcommand "show", "Show service details", load_subcommand('services/show_command')
5
+ subcommand "update", "Update service configuration", load_subcommand('services/update_command')
6
+ subcommand "deploy", "Deploy service", load_subcommand('services/deploy_command')
7
+ subcommand "stop", "Stop service", load_subcommand('services/stop_command')
8
+ subcommand "start", "Start service", load_subcommand('services/start_command')
9
+ subcommand "restart", "Restart service", load_subcommand('services/restart_command')
10
+ subcommand "scale", "Scale service", load_subcommand('services/scale_command')
11
+ subcommand ["remove", "rm"], "Remove service", load_subcommand('services/remove_command')
12
+ subcommand "containers", "List service containers", load_subcommand('services/containers_command')
13
+ subcommand "logs", "Show service logs", load_subcommand('services/logs_command')
14
+ subcommand "stats", "Show service statistics", load_subcommand('services/stats_command')
15
+ subcommand "monitor", "Monitor", load_subcommand('services/monitor_command')
16
+
17
+ subcommand "env", "Environment variable specific commands", load_subcommand('services/env_command')
18
+
19
+ subcommand "secret", "Secret specific commands", load_subcommand('services/secret_command')
20
+
21
+ subcommand "link", "Link service to another service", load_subcommand('services/link_command')
22
+ subcommand "unlink", "Unlink service from another service", load_subcommand('services/unlink_command')
23
+ subcommand "exec", "Execute commands in service containers", load_subcommand('services/exec_command')
47
24
 
48
25
  def execute
49
26
  end
@@ -1,9 +1,8 @@
1
- require_relative 'containers/exec_command'
2
1
 
3
2
  class Kontena::Cli::ContainerCommand < Kontena::Command
4
3
 
5
- subcommand "exec", "Execute command inside a container", Kontena::Cli::Containers::ExecCommand
4
+ subcommand "exec", "Execute command inside a container", load_subcommand('containers/exec_command')
6
5
 
7
6
  def execute
8
7
  end
9
- end
8
+ end
@@ -1,12 +1,9 @@
1
1
  module Kontena::Cli::Services
2
2
 
3
- require_relative 'envs/add_command'
4
- require_relative 'envs/list_command'
5
- require_relative 'envs/remove_command'
6
3
 
7
4
  class EnvCommand < Kontena::Command
8
- subcommand ["list", "ls"], "List service environment variables", Envs::ListCommand
9
- subcommand "add", "Add environment variable", Envs::AddCommand
10
- subcommand ["remove", "rm"], "Remove environment variable", Envs::RemoveCommand
5
+ subcommand ["list", "ls"], "List service environment variables", load_subcommand('services/envs/list_command')
6
+ subcommand "add", "Add environment variable", load_subcommand('services/envs/add_command')
7
+ subcommand ["remove", "rm"], "Remove environment variable", load_subcommand('services/envs/remove_command')
11
8
  end
12
9
  end
@@ -1,10 +1,8 @@
1
1
  module Kontena::Cli::Services
2
2
 
3
- require_relative 'secrets/link_command'
4
- require_relative 'secrets/unlink_command'
5
3
 
6
4
  class SecretCommand < Kontena::Command
7
- subcommand "link", "Link secret from Vault", Secrets::LinkCommand
8
- subcommand "unlink", "Unlink secret from Vault", Secrets::UnlinkCommand
5
+ subcommand "link", "Link secret from Vault", load_subcommand('services/secrets/link_command')
6
+ subcommand "unlink", "Unlink secret from Vault", load_subcommand('services/secrets/unlink_command')
9
7
  end
10
8
  end
@@ -1,28 +1,15 @@
1
- require_relative 'stacks/install_command'
2
- require_relative 'stacks/remove_command'
3
- require_relative 'stacks/deploy_command'
4
- require_relative 'stacks/upgrade_command'
5
- require_relative 'stacks/list_command'
6
- require_relative 'stacks/show_command'
7
- require_relative 'stacks/build_command'
8
- require_relative 'stacks/monitor_command'
9
- require_relative 'stacks/logs_command'
10
- require_relative 'stacks/registry_command'
11
- require_relative 'stacks/validate_command'
12
-
13
1
  class Kontena::Cli::StackCommand < Kontena::Command
14
-
15
- subcommand "install", "Install a stack to a grid", Kontena::Cli::Stacks::InstallCommand
16
- subcommand ["ls", "list"], "List installed stacks in a grid", Kontena::Cli::Stacks::ListCommand
17
- subcommand ["remove","rm"], "Remove a deployed stack from a grid", Kontena::Cli::Stacks::RemoveCommand
18
- subcommand "show", "Show details about a stack in a grid", Kontena::Cli::Stacks::ShowCommand
19
- subcommand "upgrade", "Upgrade a stack in a grid", Kontena::Cli::Stacks::UpgradeCommand
20
- subcommand ["start", "deploy"], "Deploy an installed stack in a grid", Kontena::Cli::Stacks::DeployCommand
21
- subcommand "logs", "Show logs from services in a stack", Kontena::Cli::Stacks::LogsCommand
22
- subcommand "monitor", "Monitor services in a stack", Kontena::Cli::Stacks::MonitorCommand
23
- subcommand "build", "Build images listed in a stack file and push them to an image registry", Kontena::Cli::Stacks::BuildCommand
24
- subcommand ["reg", "registry"], "Stack registry related commands", Kontena::Cli::Stacks::RegistryCommand
25
- subcommand "validate", "Process and validate a stack file", Kontena::Cli::Stacks::ValidateCommand
2
+ subcommand "install", "Install a stack to a grid", load_subcommand('stacks/install_command')
3
+ subcommand ["ls", "list"], "List installed stacks in a grid", load_subcommand('stacks/list_command')
4
+ subcommand ["remove","rm"], "Remove a deployed stack from a grid", load_subcommand('stacks/remove_command')
5
+ subcommand "show", "Show details about a stack in a grid", load_subcommand('stacks/show_command')
6
+ subcommand "upgrade", "Upgrade a stack in a grid", load_subcommand('stacks/upgrade_command')
7
+ subcommand ["start", "deploy"], "Deploy an installed stack in a grid", load_subcommand('stacks/deploy_command')
8
+ subcommand "logs", "Show logs from services in a stack", load_subcommand('stacks/logs_command')
9
+ subcommand "monitor", "Monitor services in a stack", load_subcommand('stacks/monitor_command')
10
+ subcommand "build", "Build images listed in a stack file and push them to an image registry", load_subcommand('stacks/build_command')
11
+ subcommand ["reg", "registry"], "Stack registry related commands", load_subcommand('stacks/registry_command')
12
+ subcommand "validate", "Process and validate a stack file", load_subcommand('stacks/validate_command')
26
13
 
27
14
  def execute
28
15
  end
@@ -1,17 +1,10 @@
1
1
  module Kontena::Cli::Stacks
2
-
3
- require_relative 'registry/push_command'
4
- require_relative 'registry/pull_command'
5
- require_relative 'registry/search_command'
6
- require_relative 'registry/show_command'
7
- require_relative 'registry/remove_command'
8
-
9
2
  class RegistryCommand < Kontena::Command
10
3
 
11
- subcommand "push", "Push a stack into the stacks registry", Registry::PushCommand
12
- subcommand "pull", "Pull a stack from the stacks registry", Registry::PullCommand
13
- subcommand "search", "Search for stacks in the stacks registry", Registry::SearchCommand
14
- subcommand "show", "Show info about a stack in the stacks registry", Registry::ShowCommand
15
- subcommand ["remove", "rm"], "Remove a stack (or version) from the stacks registry", Registry::RemoveCommand
4
+ subcommand "push", "Push a stack into the stacks registry", load_subcommand('stacks/registry/push_command')
5
+ subcommand "pull", "Pull a stack from the stacks registry", load_subcommand('stacks/registry/pull_command')
6
+ subcommand "search", "Search for stacks in the stacks registry", load_subcommand('stacks/registry/search_command')
7
+ subcommand "show", "Show info about a stack in the stacks registry", load_subcommand('stacks/registry/show_command')
8
+ subcommand ["remove", "rm"], "Remove a stack (or version) from the stacks registry", load_subcommand('stacks/registry/remove_command')
16
9
  end
17
10
  end
@@ -15,6 +15,8 @@ module Kontena::Cli::Stacks
15
15
 
16
16
  option '--[no-]deploy', :flag, 'Trigger deploy after upgrade', default: true
17
17
 
18
+ option '--force', :flag, 'Force upgrade'
19
+
18
20
  requires_current_master
19
21
  requires_current_master_token
20
22
 
@@ -25,6 +27,10 @@ module Kontena::Cli::Stacks
25
27
 
26
28
  stack = stack_from_yaml(filename, name: name, values: values, defaults: master_data['variables'])
27
29
 
30
+ unless force? || master_data['stack'] == stack['stack']
31
+ confirm "Replacing stack #{Kontena.pastel.cyan(master_data['stack'])} on master with #{Kontena.pastel.cyan(stack['stack'])} from #{Kontena.pastel.yellow(filename)}. Are you sure?"
32
+ end
33
+
28
34
  spinner "Upgrading stack #{pastel.cyan(name)}" do |spin|
29
35
  update_stack(stack) || spin.fail!
30
36
  end
@@ -7,6 +7,16 @@ module Kontena::Cli::Stacks
7
7
  module Setters; end
8
8
  end
9
9
 
10
+ # Workaround for nil-valued variables in Liquid templates:
11
+ # https://github.com/Shopify/liquid/issues/749
12
+ # This is something that we can pass in to `Liquid::Template.render` that gets evaluated as nil.
13
+ # If we pass in a nil value directly, then Liquid ignores it and considers the variable to be undefined.
14
+ class LiquidNull
15
+ def to_liquid
16
+ nil
17
+ end
18
+ end
19
+
10
20
  class Reader
11
21
  include Kontena::Util
12
22
  include Kontena::Cli::Common
@@ -102,7 +112,7 @@ module Kontena::Cli::Stacks
102
112
  )
103
113
  if defaults
104
114
  defaults.each do |key, val|
105
- var = variables.option(key)
115
+ var = @variables.option(key)
106
116
  var.default = val if var
107
117
  end
108
118
  end
@@ -147,10 +157,15 @@ module Kontena::Cli::Stacks
147
157
  raise RuntimeError, "Variable validation failed: #{variables.errors.inspect}" unless variables.valid?
148
158
  end
149
159
 
160
+ # @raise [Liquid::Error]
150
161
  def interpolate_liquid(content, vars)
151
162
  Liquid::Template.error_mode = :strict
152
163
  template = Liquid::Template.parse(content)
153
- template.render(vars, strict_variables: true, strict_filters: true)
164
+
165
+ # Wrap nil values in LiquidNull to not have Liquid consider them as undefined
166
+ vars = Hash[vars.map {|key, value| [key, value.nil? ? LiquidNull.new : value]}]
167
+
168
+ template.render!(vars, strict_variables: true, strict_filters: true)
154
169
  end
155
170
 
156
171
  def stack_name