lib/kontena/cli/stacks/common.rb in kontena-cli-1.0.0.pre1 vs lib/kontena/cli/stacks/common.rb in kontena-cli-1.0.0.pre2
- old
+ new
@@ -1,32 +1,32 @@
-require 'yaml'
require_relative 'yaml/reader'
require_relative '../services/services_helper'
require_relative 'service_generator_v2'
+require_relative '../../stacks_client'
module Kontena::Cli::Stacks
module Common
include Kontena::Cli::Services::ServicesHelper
- def stack_from_yaml(filename, skip_validation = false)
- reader = Kontena::Cli::Stacks::YAML::Reader.new(filename, skip_validation)
+ def stack_from_yaml(filename)
+ reader = Kontena::Cli::Stacks::YAML::Reader.new(filename)
if reader.stack_name.nil?
- exit_with_error "Stack MUST have name in YAML! Aborting."
+ exit_with_error "Stack MUST have stack name in YAML top level field 'stack'! Aborting."
end
set_env_variables(self.name || reader.stack_name, current_grid)
- reader.reload
+ #reader.reload
outcome = reader.execute
hint_on_validation_notifications(outcome[:notifications]) if outcome[:notifications].size > 0
abort_on_validation_errors(outcome[:errors]) if outcome[:errors].size > 0
kontena_services = generate_services(outcome[:services], outcome[:version])
stack = {
'name' => outcome[:name],
'stack' => outcome[:stack],
'expose' => outcome[:expose],
'version' => outcome[:version],
- 'source' => reader.raw,
+ 'source' => reader.raw_content,
'registry' => 'file://',
'services' => kontena_services
}
stack
end
@@ -50,16 +50,10 @@
services << service
end
services
end
- def read_yaml(filename, skip_validation = false)
- reader = Kontena::Cli::Stacks::YAML::Reader.new(filename)
- outcome = reader.execute
- outcome
- end
-
def set_env_variables(stack, grid)
ENV['STACK'] = stack
ENV['GRID'] = grid
end
@@ -95,8 +89,15 @@
def abort_on_validation_errors(errors)
STDERR.puts "YAML validation failed! Aborting.".colorize(:red)
display_notifications(errors, :red)
abort
+ end
+
+ def stacks_client
+ return @stacks_client if @stacks_client
+ Kontena.run('cloud login') unless cloud_auth?
+ config.reset_instance
+ @stacks_client = Kontena::StacksClient.new(kontena_account.stacks_url, kontena_account.token)
end
end
end