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
@@ -0,0 +1,27 @@
1
+ require_relative 'common'
2
+
3
+ module Kontena::Cli::Stacks
4
+ class UpdateCommand < Clamp::Command
5
+ include Kontena::Cli::Common
6
+ include Kontena::Cli::GridOptions
7
+ include Common
8
+
9
+ option ['-f', '--file'], 'FILE', 'Specify an alternate Kontena stack file', attribute_name: :filename, default: 'kontena.yml'
10
+
11
+ def execute
12
+ require_api_url
13
+ require_token
14
+ require_config_file(filename)
15
+ @stack = stack_from_yaml(filename)
16
+
17
+ update_stack
18
+ end
19
+
20
+ private
21
+
22
+ def update_stack
23
+ client(token).put("stacks/#{current_grid}/#{@stack['name']}", @stack)
24
+ end
25
+
26
+ end
27
+ end
@@ -1,12 +1,12 @@
1
1
  require 'json'
2
2
  require 'excon'
3
3
  require_relative 'errors'
4
- require 'kontena/cli/version'
4
+ require_relative 'cli/version'
5
5
 
6
6
  module Kontena
7
7
  class Client
8
8
 
9
- attr_accessor :default_headers
9
+ attr_accessor :default_headers, :path_prefix
10
10
  attr_reader :http_client
11
11
 
12
12
  # Initialize api client
@@ -16,8 +16,13 @@ module Kontena
16
16
  def initialize(api_url, default_headers = {})
17
17
  Excon.defaults[:ssl_verify_peer] = false if ignore_ssl_errors?
18
18
  @http_client = Excon.new(api_url)
19
- @default_headers = {'Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => "kontena-cli/#{Kontena::Cli::VERSION}"}.merge(default_headers)
19
+ @default_headers = {
20
+ 'Accept' => 'application/json',
21
+ 'Content-Type' => 'application/json',
22
+ 'User-Agent' => "kontena-cli/#{Kontena::Cli::VERSION}"
23
+ }.merge(default_headers)
20
24
  @api_url = api_url
25
+ @path_prefix = '/v1/'
21
26
  end
22
27
 
23
28
  # Get request
@@ -134,7 +139,7 @@ module Kontena
134
139
  # @param [String] path
135
140
  # @return [String]
136
141
  def request_uri(path)
137
- "/v1/#{path}"
142
+ "#{path_prefix}#{path}"
138
143
  end
139
144
 
140
145
  ##
@@ -190,10 +195,12 @@ module Kontena
190
195
  JSON.dump(obj)
191
196
  end
192
197
 
198
+ # @return [Boolean]
193
199
  def ignore_ssl_errors?
194
200
  ENV['SSL_IGNORE_ERRORS'] == 'true'
195
201
  end
196
202
 
203
+ # @param [Excon::Response] response
197
204
  def handle_error_response(response)
198
205
  message = response.body
199
206
  if response.status == 404 && message == ''
@@ -0,0 +1,4 @@
1
+ require 'clamp'
2
+
3
+ class Kontena::Command < Clamp::Command
4
+ end
@@ -0,0 +1,61 @@
1
+ require 'clamp'
2
+ require_relative 'command'
3
+ require_relative 'util'
4
+ require_relative 'cli/common'
5
+ require_relative 'cli/bytes_helper'
6
+ require_relative 'cli/grid_options'
7
+ require_relative 'cli/app_command'
8
+ require_relative 'cli/register_command'
9
+ require_relative 'cli/login_command'
10
+ require_relative 'cli/logout_command'
11
+ require_relative 'cli/whoami_command'
12
+ require_relative 'cli/container_command'
13
+ require_relative 'cli/grid_command'
14
+ require_relative 'cli/master_command'
15
+ require_relative 'cli/node_command'
16
+ require_relative 'cli/service_command'
17
+ require_relative 'cli/vpn_command'
18
+ require_relative 'cli/registry_command'
19
+ require_relative 'cli/external_registry_command'
20
+ require_relative 'cli/app_command'
21
+ require_relative 'cli/etcd_command'
22
+ require_relative 'cli/vault_command'
23
+ require_relative 'cli/user_command'
24
+ require_relative 'cli/plugin_command'
25
+ require_relative 'cli/version_command'
26
+ require_relative 'cli/stack_command'
27
+ require_relative 'cli/certificate_command'
28
+
29
+ class Kontena::MainCommand < Kontena::Command
30
+
31
+ subcommand "grid", "Grid specific commands", Kontena::Cli::GridCommand
32
+ subcommand "app", "App specific commands", Kontena::Cli::AppCommand
33
+ subcommand "stack", "Stack specific commands", Kontena::Cli::StackCommand
34
+ subcommand "service", "Service specific commands", Kontena::Cli::ServiceCommand
35
+ subcommand "vault", "Vault specific commands", Kontena::Cli::VaultCommand
36
+ subcommand "certificate", "LE Certificate specific commands", Kontena::Cli::CertificateCommand
37
+ subcommand "node", "Node specific commands", Kontena::Cli::NodeCommand
38
+ subcommand "master", "Master specific commands", Kontena::Cli::MasterCommand
39
+ subcommand "vpn", "VPN specific commands", Kontena::Cli::VpnCommand
40
+ subcommand "registry", "Registry specific commands", Kontena::Cli::RegistryCommand
41
+ subcommand "container", "Container specific commands", Kontena::Cli::ContainerCommand
42
+ subcommand "etcd", "Etcd specific commands", Kontena::Cli::EtcdCommand
43
+ subcommand "external-registry", "External registry specific commands", Kontena::Cli::ExternalRegistryCommand
44
+ subcommand "register", "Register Kontena Account", Kontena::Cli::RegisterCommand
45
+ subcommand "login", "Login to Kontena Master", Kontena::Cli::LoginCommand
46
+ subcommand "logout", "Logout from Kontena Master", Kontena::Cli::LogoutCommand
47
+ subcommand "whoami", "Shows current logged in user", Kontena::Cli::WhoamiCommand
48
+ subcommand "user", "User related commands", Kontena::Cli::UserCommand
49
+ subcommand "plugin", "Plugin related commands", Kontena::Cli::PluginCommand
50
+ subcommand "version", "Show version", Kontena::Cli::VersionCommand
51
+
52
+ def execute
53
+ end
54
+
55
+ # @param [String] command
56
+ # @param [String] description
57
+ # @param [Class] klass
58
+ def self.register(command, description, command_class)
59
+ subcommand(command, description, command_class)
60
+ end
61
+ end
@@ -0,0 +1,38 @@
1
+ require 'singleton'
2
+
3
+ module Kontena
4
+ class PluginManager
5
+ include Singleton
6
+
7
+ attr_reader :plugins
8
+
9
+ def initialize
10
+ @plugins = []
11
+ end
12
+
13
+ # @return [Array<Gem::Specification>]
14
+ def load_plugins
15
+ Gem::Specification.to_a.each do |spec|
16
+ spec.require_paths.to_a.each do |require_path|
17
+ plugin = File.join(spec.gem_dir, require_path, 'kontena_cli_plugin.rb')
18
+ if File.exist?(plugin)
19
+ begin
20
+ load(plugin)
21
+ @plugins << spec
22
+ rescue LoadError => exc
23
+ STDERR.puts "failed to load plugin: #{spec.name}"
24
+ if ENV['DEBUG']
25
+ STDERR.puts exc.message
26
+ STDERR.puts exc.backtrace.join("\n")
27
+ end
28
+ exit 1
29
+ end
30
+ end
31
+ end
32
+ end
33
+ @plugins
34
+ rescue => exc
35
+ STDERR.puts exc.message
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ module Kontena
2
+ module Util
3
+
4
+ # @param [String] cmd
5
+ def which(cmd)
6
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
7
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
8
+ exts.each { |ext|
9
+ exe = File.join(path, "#{cmd}#{ext}")
10
+ return exe if File.executable?(exe) && !File.directory?(exe)
11
+ }
12
+ end
13
+ return nil
14
+ end
15
+ module_function(:which)
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ module Kontena; end
2
+
3
+ require 'ruby_dig'
4
+ require_relative 'kontena/client'
5
+ require_relative 'kontena/plugin_manager'
6
+ require_relative 'kontena/main_command'
@@ -0,0 +1,26 @@
1
+ web:
2
+ image: nginx
3
+ stateful: false
4
+ health_check:
5
+ protocol: http
6
+ port: 80
7
+ interval: 20
8
+ uri: /
9
+ initial_delay: 10
10
+ timeout: 2
11
+
12
+
13
+ mysql:
14
+ image: mysql
15
+ stateful: false
16
+ deploy:
17
+ strategy: ha
18
+ wait_for_port: 3306
19
+ environment:
20
+ - MYSQL_ALLOW_EMPTY_PASSWORD=true
21
+ health_check:
22
+ protocol: tcp
23
+ port: 3306
24
+ interval: 20
25
+ initial_delay: 10
26
+ timeout: 2
@@ -0,0 +1,16 @@
1
+ wordpress:
2
+ build: .
3
+ image: registry.kontena.local/wordpress:latest
4
+ stateful: true
5
+ environment:
6
+ WORDPRESS_DB_PASSWORD: %{project}_secret
7
+ instances: 2
8
+ deploy:
9
+ strategy: ha
10
+ mysql:
11
+ extends:
12
+ file: docker-compose.yml
13
+ service: mysql
14
+ stateful: true
15
+ environment:
16
+ - MYSQL_ROOT_PASSWORD=%{project}_secret
@@ -0,0 +1,26 @@
1
+ version: '2'
2
+ name: test-project
3
+ services:
4
+ mysql:
5
+ extends:
6
+ file: docker-compose.yml
7
+ service: mysql
8
+ stateful: true
9
+ environment:
10
+ - MYSQL_ROOT_PASSWORD=%{project}_secret
11
+
12
+ webapp:
13
+ image: webapp
14
+ build:
15
+ context: .
16
+ args:
17
+ - foo=bar
18
+ - baz=baf
19
+
20
+ some_app:
21
+ image: some_app
22
+ build:
23
+ context: .
24
+ args:
25
+ foo: bar
26
+ baz:
@@ -9,6 +9,10 @@ describe Kontena::Cli::Apps::BuildCommand do
9
9
  end
10
10
 
11
11
  let(:kontena_yml) do
12
+ fixture('kontena-build.yml')
13
+ end
14
+
15
+ let(:mysql_yml) do
12
16
  fixture('kontena.yml')
13
17
  end
14
18
 
@@ -50,7 +54,15 @@ describe Kontena::Cli::Apps::BuildCommand do
50
54
 
51
55
  it 'requests process_docker_images with given no_cache option' do
52
56
  expect(subject).to receive(:process_docker_images).with(anything, anything, true)
53
- subject.run(['--no-cache', true])
57
+ subject.run(['--no-cache'])
58
+ end
59
+
60
+ it 'raises error if no services found with build options' do
61
+ allow(File).to receive(:read).with("#{Dir.getwd}/kontena.yml").and_return(mysql_yml)
62
+ expect(subject).not_to receive(:process_docker_images)
63
+ expect {
64
+ subject.run([])
65
+ }.to raise_error SystemExit
54
66
  end
55
67
  end
56
68
  end
@@ -25,6 +25,10 @@ describe Kontena::Cli::Apps::Common do
25
25
  fixture('mysql.yml')
26
26
  end
27
27
 
28
+ let(:health_yml) do
29
+ fixture('health.yml')
30
+ end
31
+
28
32
  let(:services) do
29
33
  {
30
34
  'wordpress' => {
@@ -60,6 +64,7 @@ describe Kontena::Cli::Apps::Common do
60
64
  describe '#load_from_yaml' do
61
65
  before(:each) do
62
66
  allow(File).to receive(:read).with("#{Dir.getwd}/kontena.yml").and_return(kontena_yml)
67
+ allow(File).to receive(:read).with("#{Dir.getwd}/health.yml").and_return(health_yml)
63
68
  allow(File).to receive(:read).with("#{Dir.getwd}/docker-compose.yml").and_return(docker_compose_yml)
64
69
  end
65
70
 
@@ -85,5 +90,11 @@ describe Kontena::Cli::Apps::Common do
85
90
  expect(services['wordpress']).not_to be_nil
86
91
  expect(services.size).to eq(1)
87
92
  end
93
+
94
+ it 'populates health check' do
95
+ services = subject.services_from_yaml('health.yml',['web'],'')
96
+ expect(services['web']).not_to be_nil
97
+ expect(services['web']['health_check']).not_to be_nil
98
+ end
88
99
  end
89
100
  end
@@ -220,7 +220,7 @@ describe Kontena::Cli::Apps::DeployCommand do
220
220
  'stateful' => true,
221
221
  'strategy' => 'ha',
222
222
  'links' => [{ 'name' => 'kontena-test-mysql', 'alias' => 'mysql' }],
223
- 'ports' => [{ 'container_port' => '80', 'node_port' => '80', 'protocol' => 'tcp' }]
223
+ 'ports' => [{ 'ip' => '0.0.0.0','container_port' => '80', 'node_port' => '80', 'protocol' => 'tcp' }]
224
224
  }
225
225
  expect(subject).to receive(:create_service).with('1234567', '1', hash_including(data))
226
226
 
@@ -103,4 +103,49 @@ describe Kontena::Cli::Apps::DockerHelper do
103
103
  end
104
104
  end
105
105
 
106
+ describe '#build_docker_image' do
107
+ it 'builds image' do
108
+ service = {
109
+ 'build' => { 'context' => '.' },
110
+ 'image' => 'test_service'
111
+ }
112
+ expect(subject).to receive(:system).with("docker build -t test_service ."). and_return(true)
113
+ subject.build_docker_image(service)
114
+ end
115
+
116
+ it 'builds image with no-cache' do
117
+ service = {
118
+ 'build' => { 'context' => '.' },
119
+ 'image' => 'test_service'
120
+ }
121
+ expect(subject).to receive(:system).with("docker build -t test_service --no-cache ."). and_return(true)
122
+ subject.build_docker_image(service, true)
123
+ end
124
+
125
+ it 'builds image with alternate dockerfile' do
126
+ service = {
127
+ 'build' => { 'context' => '.', 'dockerfile' => 'other_dockerfile' },
128
+ 'image' => 'test_service'
129
+ }
130
+ expected_path = File.join(File.expand_path('.'), 'other_dockerfile')
131
+ expect(subject).to receive(:system).with("docker build -t test_service -f #{expected_path} ."). and_return(true)
132
+ subject.build_docker_image(service)
133
+ end
134
+
135
+ it 'builds image' do
136
+ service = {
137
+ 'build' => {
138
+ 'context' => '.',
139
+ 'args' => {
140
+ 'FOO' => 'bar',
141
+ 'BAR' => 'foo'
142
+ }
143
+ },
144
+ 'image' => 'test_service'
145
+ }
146
+ expect(subject).to receive(:system).with("docker build -t test_service --build-arg FOO=bar --build-arg BAR=foo ."). and_return(true)
147
+ subject.build_docker_image(service)
148
+ end
149
+ end
150
+
106
151
  end
@@ -6,6 +6,12 @@ describe Kontena::Cli::Apps::ServiceGenerator do
6
6
  described_class.new({})
7
7
  end
8
8
 
9
+ let(:env_file) do
10
+ 'APIKEY=12345
11
+ MYSQL_ROOT_PASSWORD=secret
12
+ WP_ADMIN_PASSWORD=verysecret'.split(/\r?\n/)
13
+ end
14
+
9
15
  describe '#parse_data' do
10
16
  context 'volumes' do
11
17
  it 'returns volumes if set' do
@@ -136,7 +142,7 @@ describe Kontena::Cli::Apps::ServiceGenerator do
136
142
  result = subject.send(:parse_data, data)
137
143
  expect(result['links']).to eq([])
138
144
  end
139
-
145
+
140
146
  it 'returns parsed links array' do
141
147
  data = {
142
148
  'image' => 'wordpress:latest',
@@ -382,4 +388,49 @@ describe Kontena::Cli::Apps::ServiceGenerator do
382
388
  end
383
389
  end
384
390
  end
391
+
392
+ describe '#read_env_file' do
393
+ before(:each) do
394
+ allow(File).to receive(:readlines).with('.env').and_return(env_file)
395
+ end
396
+ it 'reads given file' do
397
+ expect(File).to receive(:readlines).with('.env').and_return(env_file)
398
+ subject.send(:read_env_file, '.env')
399
+ end
400
+
401
+ it 'returns array' do
402
+ variables = subject.send(:read_env_file, '.env')
403
+ expect(variables).to eq([
404
+ 'APIKEY=12345',
405
+ 'MYSQL_ROOT_PASSWORD=secret',
406
+ 'WP_ADMIN_PASSWORD=verysecret'
407
+ ])
408
+ end
409
+
410
+ it 'discards comment lines' do
411
+ result = env_file
412
+ result << "#COMMENTLINE"
413
+ allow(File).to receive(:readlines).with('.env').and_return(result)
414
+
415
+ variables = subject.send(:read_env_file, '.env')
416
+ expect(variables).to eq([
417
+ 'APIKEY=12345',
418
+ 'MYSQL_ROOT_PASSWORD=secret',
419
+ 'WP_ADMIN_PASSWORD=verysecret'
420
+ ])
421
+ end
422
+
423
+ it 'discards empty lines' do
424
+ result = env_file
425
+ result << '
426
+ '
427
+ allow(File).to receive(:readlines).with('.env').and_return(result)
428
+ variables = subject.send(:read_env_file, '.env')
429
+ expect(variables).to eq([
430
+ 'APIKEY=12345',
431
+ 'MYSQL_ROOT_PASSWORD=secret',
432
+ 'WP_ADMIN_PASSWORD=verysecret'
433
+ ])
434
+ end
435
+ end
385
436
  end