kontena-cli 0.13.4 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/kontena-cli.gemspec +2 -0
  4. data/lib/kontena/cli/app_command.rb +2 -0
  5. data/lib/kontena/cli/apps/common.rb +80 -74
  6. data/lib/kontena/cli/apps/config_command.rb +29 -0
  7. data/lib/kontena/cli/apps/deploy_command.rb +12 -81
  8. data/lib/kontena/cli/apps/docker_helper.rb +3 -3
  9. data/lib/kontena/cli/apps/init_command.rb +0 -3
  10. data/lib/kontena/cli/apps/list_command.rb +2 -3
  11. data/lib/kontena/cli/apps/logs_command.rb +2 -3
  12. data/lib/kontena/cli/apps/monitor_command.rb +3 -4
  13. data/lib/kontena/cli/apps/remove_command.rb +4 -4
  14. data/lib/kontena/cli/apps/restart_command.rb +2 -3
  15. data/lib/kontena/cli/apps/scale_command.rb +3 -5
  16. data/lib/kontena/cli/apps/service_generator.rb +123 -0
  17. data/lib/kontena/cli/apps/service_generator_v2.rb +26 -0
  18. data/lib/kontena/cli/apps/show_command.rb +1 -2
  19. data/lib/kontena/cli/apps/start_command.rb +2 -3
  20. data/lib/kontena/cli/apps/stop_command.rb +2 -3
  21. data/lib/kontena/cli/apps/yaml/reader.rb +150 -0
  22. data/lib/kontena/cli/apps/yaml/service_extender.rb +60 -0
  23. data/lib/kontena/cli/apps/yaml/validations.rb +79 -0
  24. data/lib/kontena/cli/apps/yaml/validator.rb +55 -0
  25. data/lib/kontena/cli/apps/yaml/validator_v2.rb +74 -0
  26. data/lib/kontena/cli/common.rb +23 -0
  27. data/lib/kontena/cli/etcd/remove_command.rb +2 -0
  28. data/lib/kontena/cli/grids/remove_command.rb +2 -0
  29. data/lib/kontena/cli/grids/users/remove_command.rb +3 -0
  30. data/lib/kontena/cli/master/azure/create_command.rb +0 -2
  31. data/lib/kontena/cli/master/packet/create_command.rb +42 -0
  32. data/lib/kontena/cli/master/packet_command.rb +14 -0
  33. data/lib/kontena/cli/master/upcloud/create_command.rb +39 -0
  34. data/lib/kontena/cli/master/upcloud_command.rb +13 -0
  35. data/lib/kontena/cli/master/users/remove_command.rb +3 -0
  36. data/lib/kontena/cli/master/users/roles/remove_command.rb +2 -0
  37. data/lib/kontena/cli/master_command.rb +4 -0
  38. data/lib/kontena/cli/node_command.rb +4 -0
  39. data/lib/kontena/cli/nodes/azure/create_command.rb +0 -2
  40. data/lib/kontena/cli/nodes/list_command.rb +4 -8
  41. data/lib/kontena/cli/nodes/packet/create_command.rb +35 -0
  42. data/lib/kontena/cli/nodes/packet/restart_command.rb +17 -0
  43. data/lib/kontena/cli/nodes/packet/terminate_command.rb +20 -0
  44. data/lib/kontena/cli/nodes/packet_command.rb +15 -0
  45. data/lib/kontena/cli/nodes/remove_command.rb +2 -0
  46. data/lib/kontena/cli/nodes/show_command.rb +3 -1
  47. data/lib/kontena/cli/nodes/upcloud/create_command.rb +33 -0
  48. data/lib/kontena/cli/nodes/upcloud/restart_command.rb +20 -0
  49. data/lib/kontena/cli/nodes/upcloud/terminate_command.rb +20 -0
  50. data/lib/kontena/cli/nodes/upcloud_command.rb +15 -0
  51. data/lib/kontena/cli/registry/remove_command.rb +3 -0
  52. data/lib/kontena/cli/services/remove_command.rb +2 -0
  53. data/lib/kontena/cli/services/services_helper.rb +1 -0
  54. data/lib/kontena/cli/vault/list_command.rb +2 -0
  55. data/lib/kontena/cli/vault/read_command.rb +2 -0
  56. data/lib/kontena/cli/vault/remove_command.rb +4 -0
  57. data/lib/kontena/cli/vault/update_command.rb +8 -1
  58. data/lib/kontena/cli/vault/write_command.rb +2 -0
  59. data/lib/kontena/cli/vpn/remove_command.rb +3 -0
  60. data/lib/kontena/machine/azure/master_provisioner.rb +2 -2
  61. data/lib/kontena/machine/azure/node_provisioner.rb +7 -4
  62. data/lib/kontena/machine/digital_ocean/node_provisioner.rb +1 -1
  63. data/lib/kontena/machine/packet.rb +17 -0
  64. data/lib/kontena/machine/packet/cloudinit.yml +66 -0
  65. data/lib/kontena/machine/packet/cloudinit_master.yml +118 -0
  66. data/lib/kontena/machine/packet/master_provisioner.rb +93 -0
  67. data/lib/kontena/machine/packet/node_destroyer.rb +42 -0
  68. data/lib/kontena/machine/packet/node_provisioner.rb +77 -0
  69. data/lib/kontena/machine/packet/node_restarter.rb +41 -0
  70. data/lib/kontena/machine/packet/packet_common.rb +89 -0
  71. data/lib/kontena/machine/upcloud.rb +9 -0
  72. data/lib/kontena/machine/upcloud/cloudinit.yml +64 -0
  73. data/lib/kontena/machine/upcloud/cloudinit_master.yml +118 -0
  74. data/lib/kontena/machine/upcloud/master_provisioner.rb +136 -0
  75. data/lib/kontena/machine/upcloud/node_destroyer.rb +82 -0
  76. data/lib/kontena/machine/upcloud/node_provisioner.rb +119 -0
  77. data/lib/kontena/machine/upcloud/node_restarter.rb +47 -0
  78. data/lib/kontena/machine/upcloud/upcloud_common.rb +70 -0
  79. data/lib/kontena/scripts/completer +8 -3
  80. data/spec/fixtures/docker-compose_v2.yml +10 -0
  81. data/spec/fixtures/kontena-invalid.yml +4 -0
  82. data/spec/fixtures/kontena-with-variables.yml +19 -0
  83. data/spec/fixtures/kontena.yml +2 -2
  84. data/spec/fixtures/kontena_v2.yml +35 -0
  85. data/spec/kontena/cli/app/common_spec.rb +39 -101
  86. data/spec/kontena/cli/app/deploy_command_spec.rb +37 -388
  87. data/spec/kontena/cli/app/docker_helper_spec.rb +4 -4
  88. data/spec/kontena/cli/app/service_generator_spec.rb +374 -0
  89. data/spec/kontena/cli/app/service_generator_v2_spec.rb +74 -0
  90. data/spec/kontena/cli/app/yaml/reader_spec.rb +249 -0
  91. data/spec/kontena/cli/app/yaml/service_extender_spec.rb +104 -0
  92. data/spec/kontena/cli/app/yaml/validator_spec.rb +263 -0
  93. data/spec/kontena/cli/app/yaml/validator_v2_spec.rb +309 -0
  94. data/spec/kontena/cli/common_spec.rb +39 -1
  95. data/spec/kontena/cli/master/users/remove_command_spec.rb +9 -0
  96. data/spec/kontena/cli/master/users/roles/remove_command_spec.rb +2 -0
  97. metadata +86 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da142dfc08d132509576f6528f71e4b7989ff75b
4
- data.tar.gz: bbedea611445eb276e445b6f0b2347f649ace193
3
+ metadata.gz: 13295c1c17a8bc5e8a328ba103a1ce03d22f083e
4
+ data.tar.gz: d1c228f5eb5decefb19bf73892858161f69da2ad
5
5
  SHA512:
6
- metadata.gz: 6c95f56157dd5994f2ef75853e3a4e07a0da432534f0840103347a8448bdf6379240a870db2d5fe32b8c61b3755c46e4a9b0c113f8fbd6ba1d9c483d6c51b438
7
- data.tar.gz: ce206e77d23bd77af044692285cb5ba487fe91934c9bcb523590f64023851ebb777ebf0a0e56fcb3b34b63e8f7f77ae398465fcb22c5d5fcbc84f897a34ad89d
6
+ metadata.gz: cac1ed8d7f6c2f44621b7d3ccef67555b732a20e89e8213d9651f66c7b3b0f894826d7f25d176185600045c85b0b543cc23e4f10e0bd481c7b5dc626f7914b79
7
+ data.tar.gz: 770733acf831c0f155289952ec31a03cfbcbc1b3acb45ed7cce7d4bceee8e51c89c0ab68ba9451a90e174016725278ae72918db48aad11a26beb1cc9899c0cb5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.13.4
1
+ 0.14.0
data/kontena-cli.gemspec CHANGED
@@ -28,4 +28,6 @@ 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-logic', "0.2.2"
31
33
  end
@@ -1,5 +1,6 @@
1
1
  require_relative 'apps/init_command'
2
2
  require_relative 'apps/build_command'
3
+ require_relative 'apps/config_command'
3
4
  require_relative 'apps/deploy_command'
4
5
  require_relative 'apps/start_command'
5
6
  require_relative 'apps/stop_command'
@@ -15,6 +16,7 @@ class Kontena::Cli::AppCommand < Clamp::Command
15
16
 
16
17
  subcommand "init", "Init Kontena application", Kontena::Cli::Apps::InitCommand
17
18
  subcommand "build", "Build Kontena services", Kontena::Cli::Apps::BuildCommand
19
+ subcommand "config", "View service configurations", Kontena::Cli::Apps::ConfigCommand
18
20
  subcommand "deploy", "Deploy Kontena services", Kontena::Cli::Apps::DeployCommand
19
21
  subcommand "scale", "Scale services", Kontena::Cli::Apps::ScaleCommand
20
22
  subcommand "start", "Start services", Kontena::Cli::Apps::StartCommand
@@ -1,5 +1,8 @@
1
1
  require 'yaml'
2
2
  require_relative '../services/services_helper'
3
+ require_relative './service_generator'
4
+ require_relative './service_generator_v2'
5
+ require_relative './yaml/reader'
3
6
 
4
7
  module Kontena::Cli::Apps
5
8
  module Common
@@ -13,12 +16,55 @@ module Kontena::Cli::Apps
13
16
  # @param [Array<String>] service_list
14
17
  # @param [String] prefix
15
18
  # @return [Hash]
16
- def load_services(filename, service_list, prefix)
17
- services = parse_services(filename, nil, prefix)
18
- services.delete_if { |name, service| !service_list.include?(name)} unless service_list.empty?
19
+ def services_from_yaml(filename, service_list, prefix)
20
+ set_env_variables(prefix, current_grid)
21
+ reader = YAML::Reader.new(filename)
22
+ outcome = reader.execute
23
+ hint_on_validation_notifications(outcome[:notifications]) if outcome[:notifications].size > 0
24
+ abort_on_validation_errors(outcome[:errors]) if outcome[:errors].size > 0
25
+ kontena_services = generate_services(outcome[:services], outcome[:version])
26
+ kontena_services.delete_if { |name, service| !service_list.include?(name)} unless service_list.empty?
27
+ kontena_services
28
+ end
29
+
30
+ ##
31
+ # @param [Hash] yaml
32
+ # @param [String] version
33
+ # @return [Hash]
34
+ def generate_services(yaml_services, version)
35
+ services = {}
36
+ if version == '2'
37
+ generator_klass = ServiceGeneratorV2
38
+ else
39
+ generator_klass = ServiceGenerator
40
+ end
41
+ yaml_services.each do |service_name, config|
42
+ abort("Image is missing for #{service_name}. Aborting.") unless config['image']
43
+ services[service_name] = generator_klass.new(config).generate
44
+ end
19
45
  services
20
46
  end
21
47
 
48
+ def set_env_variables(project, grid)
49
+ ENV['project'] = project
50
+ ENV['grid'] = grid
51
+ end
52
+
53
+ def service_prefix
54
+ @service_prefix ||= project_name || project_name_from_yaml(filename) || current_dir
55
+ end
56
+
57
+ def project_name_from_yaml(file)
58
+ reader = YAML::Reader.new(file, true)
59
+ outcome = reader.execute
60
+ if outcome[:version] == '2'
61
+ outcome[:name]
62
+ else
63
+ nil
64
+ end
65
+ end
66
+
67
+
22
68
  # @return [String]
23
69
  def token
24
70
  @token ||= require_token
@@ -28,7 +74,6 @@ module Kontena::Cli::Apps
28
74
  # @return [String]
29
75
  def prefixed_name(name)
30
76
  return name if service_prefix.strip == ""
31
-
32
77
  "#{service_prefix}-#{name}"
33
78
  end
34
79
 
@@ -43,76 +88,6 @@ module Kontena::Cli::Apps
43
88
  get_service(token, prefixed_name(name)) rescue false
44
89
  end
45
90
 
46
- # @param [String] file
47
- # @param [String,NilClass] name
48
- # @param [String] prefix
49
- # @return [Hash]
50
- def parse_services(file, name = nil, prefix = '')
51
- services = YAML.load(File.read(File.expand_path(file)) % {project: prefix, grid: current_grid})
52
- Dir.chdir(File.dirname(File.expand_path(file))) do
53
- services.each do |name, options|
54
- normalize_env_vars(options)
55
- if options.has_key?('extends')
56
- extension_file = options['extends']['file']
57
- service_name = options['extends']['service']
58
- options.delete('extends')
59
- services[name] = extend_options(options, extension_file , service_name, prefix)
60
- end
61
- end
62
- end
63
- if name.nil?
64
- services
65
- else
66
- abort("Service #{name} not found in #{file}") unless services.has_key?(name)
67
- services[name]
68
- end
69
- end
70
-
71
- # @param [Hash] options
72
- # @param [String] file
73
- # @param [String] service_name
74
- # @param [String] prefix
75
- # @return [Hash]
76
- def extend_options(options, file, service_name, prefix)
77
- parent_options = parse_services(file, service_name, prefix)
78
- options['environment'] = extend_env_vars(parent_options['environment'], options['environment'])
79
- options['secrets'] = extend_secrets(parent_options['secrets'], options['secrets'])
80
- parent_options.merge(options)
81
- end
82
-
83
- # @param [Hash] options
84
- def normalize_env_vars(options)
85
- if options['environment'].is_a?(Hash)
86
- options['environment'] = options['environment'].map{|k, v| "#{k}=#{v}"}
87
- end
88
- end
89
-
90
- # @param [Array] from
91
- # @param [Array] to
92
- # @return [Array]
93
- def extend_env_vars(from, to)
94
- env_vars = to || []
95
- if from
96
- from.each do |env|
97
- env_vars << env unless to && to.find {|key| key.split('=').first == env.split('=').first}
98
- end
99
- end
100
- env_vars
101
- end
102
-
103
- # @param [Array] from
104
- # @param [Array] to
105
- # @return [Array]
106
- def extend_secrets(from, to)
107
- secrets = to || []
108
- if from
109
- from.each do |from_secret|
110
- secrets << from_secret unless to && to.any? {|to_secret| to_secret['secret'] == from_secret['secret']}
111
- end
112
- end
113
- secrets
114
- end
115
-
116
91
  # @param [Hash] services
117
92
  # @param [String] file
118
93
  def create_yml(services, file = 'kontena.yml')
@@ -131,6 +106,37 @@ module Kontena::Cli::Apps
131
106
  @app_json
132
107
  end
133
108
 
109
+ def display_notifications(messages, color = :yellow)
110
+ messages.each do |files|
111
+ files.each do |file, services|
112
+ STDERR.puts "#{file}:".colorize(color)
113
+ services.each do |service|
114
+ service.each do |name, errors|
115
+ STDERR.puts " #{name}:".colorize(color)
116
+ if errors.is_a?(String)
117
+ STDERR.puts " - #{errors}".colorize(color)
118
+ else
119
+ errors.each do |key, error|
120
+ STDERR.puts " - #{key}: #{error.to_json}".colorize(color)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ def hint_on_validation_notifications(errors)
130
+ STDERR.puts "YAML contains the following unsupported options and they were rejected:".colorize(:yellow)
131
+ display_notifications(errors)
132
+ end
133
+
134
+ def abort_on_validation_errors(errors)
135
+ STDERR.puts "YAML validation failed! Aborting.".colorize(:red)
136
+ display_notifications(errors, :red)
137
+ abort
138
+ end
139
+
134
140
  def valid_addons(prefix=nil)
135
141
  if prefix
136
142
  prefix = "#{prefix}-"
@@ -0,0 +1,29 @@
1
+ require_relative 'common'
2
+ require 'pp'
3
+
4
+ module Kontena::Cli::Apps
5
+ class ConfigCommand < Clamp::Command
6
+ include Kontena::Cli::Common
7
+ include Kontena::Cli::GridOptions
8
+ include Common
9
+
10
+ option ['-f', '--file'], 'FILE', 'Specify an alternate Kontena compose file', attribute_name: :filename, default: 'kontena.yml'
11
+ option ['-p', '--project-name'], 'NAME', 'Specify an alternate project name (default: directory name)'
12
+
13
+ parameter "[SERVICE] ...", "Services to view"
14
+
15
+ attr_reader :service_prefix
16
+
17
+ def execute
18
+ require_config_file(filename)
19
+ @service_prefix = project_name || current_dir
20
+ services = services_from_yaml(filename, service_list, service_prefix)
21
+ services.each do |name, config|
22
+ config['cmd'] = config['cmd'].join(" ") if config['cmd']
23
+ config.delete_if {|key, value| value.nil? || (value.respond_to?(:empty?) && value.empty?) }
24
+ end
25
+ services = { 'services' => services }
26
+ puts services.to_yaml
27
+ end
28
+ end
29
+ end
@@ -17,15 +17,14 @@ module Kontena::Cli::Apps
17
17
 
18
18
  parameter "[SERVICE] ...", "Services to start"
19
19
 
20
- attr_reader :services, :service_prefix, :deploy_queue
20
+ attr_reader :services, :deploy_queue
21
21
 
22
22
  def execute
23
23
  require_api_url
24
24
  require_token
25
25
  require_config_file(filename)
26
- @deploy_queue = []
27
- @service_prefix = project_name || current_dir
28
- @services = load_services(filename, service_list, service_prefix)
26
+ @deploy_queue = []
27
+ @services = services_from_yaml(filename, service_list, service_prefix)
29
28
  process_docker_images(services) if !no_build?
30
29
  create_or_update_services(services)
31
30
  deploy_services(deploy_queue)
@@ -60,19 +59,19 @@ module Kontena::Cli::Apps
60
59
  # @param [Hash] options
61
60
  def create_or_update_service(name, options)
62
61
  # skip if service is already processed or it's not present
63
- return nil if in_deploy_queue?(name) || !services.keys.include?(name)
62
+ return nil if in_deploy_queue?(name) || !services.key?(name)
64
63
 
65
64
  # create/update linked services recursively before continuing
66
- unless options['links'].nil?
67
- parse_links(options['links']).each_with_index do |linked_service, index|
65
+ unless options['links'].empty?
66
+ options['links'].each_with_index do |linked_service, index|
68
67
  # change prefixed service name also to links options
69
- options['links'][index] = "#{prefixed_name(linked_service[:name])}:#{linked_service[:alias]}"
70
- create_or_update_service(linked_service[:name], services[linked_service[:name]]) unless in_deploy_queue?(linked_service[:name])
68
+ linked_service_name = linked_service['name']
69
+ options['links'][index]['name'] = "#{prefixed_name(linked_service['name'])}"
70
+ create_or_update_service(linked_service_name, services[linked_service_name]) unless in_deploy_queue?(linked_service_name)
71
71
  end
72
72
  end
73
73
 
74
74
  merge_external_links(options)
75
- merge_env_vars(options)
76
75
 
77
76
  if service_exists?(name)
78
77
  service = update(name, options)
@@ -93,8 +92,8 @@ module Kontena::Cli::Apps
93
92
  def create(name, options)
94
93
  puts "creating #{name.colorize(:cyan)}"
95
94
  name = prefixed_name(name)
96
- data = {name: name}
97
- data.merge!(parse_data(options))
95
+ data = { 'name' => name }
96
+ data.merge!(options)
98
97
  create_service(token, current_grid, data)
99
98
  end
100
99
 
@@ -103,8 +102,7 @@ module Kontena::Cli::Apps
103
102
  def update(id, options)
104
103
  puts "updating #{id.colorize(:cyan)}"
105
104
  id = prefixed_name(id)
106
- data = parse_data(options)
107
- update_service(token, id, data)
105
+ update_service(token, id, options)
108
106
  end
109
107
 
110
108
  # @param [String] name
@@ -122,20 +120,6 @@ module Kontena::Cli::Apps
122
120
  end
123
121
  end
124
122
 
125
- # @param [Hash] options
126
- def merge_env_vars(options)
127
- return unless options['env_file']
128
-
129
- options['env_file'] = [options['env_file']] if options['env_file'].is_a?(String)
130
- options['environment'] = [] unless options['environment']
131
-
132
- options['env_file'].each do |env_file|
133
- options['environment'].concat(read_env_file(env_file))
134
- end
135
-
136
- options['environment'].uniq! {|s| s.split('=').first}
137
- end
138
-
139
123
  # @param [Hash] options
140
124
  def merge_external_links(options)
141
125
  if options['external_links']
@@ -144,58 +128,5 @@ module Kontena::Cli::Apps
144
128
  options.delete('external_links')
145
129
  end
146
130
  end
147
-
148
- # @param [String] path
149
- def read_env_file(path)
150
- File.readlines(path).delete_if { |line| line.start_with?('#') || line.empty? }
151
- end
152
-
153
- ##
154
- # @param [Hash] options
155
- def parse_data(options)
156
- data = {}
157
- data[:image] = parse_image(options['image'])
158
- data[:env] = options['environment']
159
- data[:container_count] = options['instances']
160
- data[:links] = parse_links(options['links'] || [])
161
- data[:ports] = parse_ports(options['ports'] || [])
162
- data[:memory] = parse_memory(options['mem_limit'].to_s) if options['mem_limit']
163
- data[:memory_swap] = parse_memory(options['memswap_limit'].to_s) if options['memswap_limit']
164
- data[:cpu_shares] = options['cpu_shares'] if options['cpu_shares']
165
- data[:volumes] = options['volumes'] || []
166
- data[:volumes_from] = options['volumes_from'] || []
167
- data[:cmd] = options['command'].split(" ") if options['command']
168
- data[:affinity] = options['affinity'] || []
169
- data[:user] = options['user'] if options['user']
170
- data[:stateful] = options['stateful'] == true
171
- data[:privileged] = options['privileged'] unless options['privileged'].nil?
172
- data[:cap_add] = options['cap_add'] if options['cap_add']
173
- data[:cap_drop] = options['cap_drop'] if options['cap_drop']
174
- data[:net] = options['net'] if options['net']
175
- data[:pid] = options['pid'] if options['pid']
176
- data[:log_driver] = options['log_driver'] if options['log_driver']
177
- data[:log_opts] = options['log_opt'] if options['log_opt'] && !options['log_opt'].empty?
178
-
179
- deploy_opts = options['deploy'] || {}
180
- data[:strategy] = deploy_opts['strategy'] if deploy_opts['strategy']
181
- deploy = {}
182
- if deploy_opts.has_key?('wait_for_port')
183
- deploy[:wait_for_port] = deploy_opts['wait_for_port']
184
- end
185
- if deploy_opts.has_key?('min_health')
186
- deploy[:min_health] = deploy_opts['min_health']
187
- end
188
- if deploy_opts.has_key?('interval')
189
- deploy[:interval] = parse_relative_time(deploy_opts['interval'])
190
- end
191
- unless deploy.empty?
192
- data[:deploy_opts] = deploy
193
- end
194
-
195
- data[:hooks] = options['hooks'] || {}
196
- data[:secrets] = options['secrets'] if options['secrets']
197
-
198
- data
199
- end
200
131
  end
201
132
  end
@@ -12,15 +12,15 @@ module Kontena::Cli::Apps
12
12
 
13
13
  services.each do |name, service|
14
14
  if service['build'] && (!image_exist?(service['image']) || force_build)
15
- dockerfile = service['dockerfile'] || 'Dockerfile'
15
+ dockerfile = service['build']['dockerfile'] || 'Dockerfile'
16
16
  abort("'#{service['image']}' is not valid Docker image name") unless validate_image_name(service['image'])
17
- abort("'#{service['build']}' does not have #{dockerfile}") unless dockerfile_exist?(service['build'], dockerfile)
17
+ abort("'#{service['build']['context']}' does not have #{dockerfile}") unless dockerfile_exist?(service['build']['context'], dockerfile)
18
18
  if service['hooks'] && service['hooks']['pre_build']
19
19
  puts "Running pre_build hook".colorize(:cyan)
20
20
  run_pre_build_hook(service['hooks']['pre_build'])
21
21
  end
22
22
  puts "Building image #{service['image'].colorize(:cyan)}"
23
- build_docker_image(service['image'], service['build'], dockerfile, no_cache)
23
+ build_docker_image(service['image'], service['build']['context'], dockerfile, no_cache)
24
24
  puts "Pushing image #{service['image'].colorize(:cyan)} to registry"
25
25
  push_docker_image(service['image'])
26
26
  end
@@ -15,13 +15,10 @@ module Kontena::Cli::Apps
15
15
  option ["-b", "--base-image"], "BASE_IMAGE_NAME", "Specify a docker base image name", default: "kontena/buildstep"
16
16
  option ["-p", "--project-name"], "NAME", "Specify an alternate project name (default: directory name)"
17
17
 
18
- attr_reader :service_prefix
19
18
 
20
19
  def execute
21
20
  require 'highline/import'
22
21
 
23
- @service_prefix = project_name || File.basename(Dir.getwd)
24
-
25
22
  if File.exist?('Dockerfile')
26
23
  puts 'Found Dockerfile'
27
24
  elsif create_dockerfile?
@@ -11,13 +11,12 @@ module Kontena::Cli::Apps
11
11
 
12
12
  parameter "[SERVICE] ...", "Services to start"
13
13
 
14
- attr_reader :services, :service_prefix
14
+ attr_reader :services
15
15
 
16
16
  def execute
17
17
  require_config_file(filename)
18
18
 
19
- @service_prefix = project_name || current_dir
20
- @services = load_services(filename, service_list, service_prefix)
19
+ @services = services_from_yaml(filename, service_list, service_prefix)
21
20
  if services.size > 0
22
21
  show_services(services)
23
22
  elsif !service_list.empty?