lib/cloudspin/stack/rake/stack_task.rb in cloudspin-stack-rake-0.1.18 vs lib/cloudspin/stack/rake/stack_task.rb in cloudspin-stack-rake-0.1.19

- old
+ new

@@ -5,17 +5,15 @@ class StackTask < ::Rake::TaskLib attr_reader :environment attr_reader :stack_name - attr_reader :definition_folder attr_reader :configuration_files def initialize( environment = nil, stack_name: 'instance', - definition_folder: nil, # Should be deprecated definition_location: nil, base_folder: '.', configuration_files: nil ) @environment = environment @@ -24,13 +22,10 @@ set_configuration_files(configuration_files) # TODO: Pick this up from the configuration files? @definition_location = if definition_location definition_location - elsif definition_folder - puts "'definition_folder': is deprecated for Cloudspin::Stack::Rake::StackTask - use 'definition_location' instead" - definition_folder else './src' end # @remote_zipfile = remote_zipfile @@ -133,72 +128,10 @@ TF_BACKEND_SOURCE ) } end - # TODO: This stuff belongs in a core class, so the CLI and other stuff can use it, too. - - def fetch_definition - if /^http.*\.zip$/.match @definition_location - puts "Downloading stack definition source from a remote zipfile" - fetch_definition_zipfile - elsif /^[\.\/]/.match @definition_location - puts "Using local stack definition source" - @definition_location - else - raise UnsupportedStackDefinitionLocationError, @definition_location - end - end - - def fetch_definition_zipfile - unpack(download_artefact(@definition_location), '.cloudspin/definitions') - end - - def download_artefact(artefact_url) - download_dir = Dir.mktmpdir(['cloudspin-', '-download']) - zipfile = "#{download_dir}/undetermined-spin-stack-artefact.zip" - puts "Downloading artefact from #{artefact_url} to #{zipfile}" - File.open(zipfile, 'wb') do |saved_file| - open(artefact_url, 'rb') do |read_file| - saved_file.write(read_file.read) - end - end - zipfile - end - - def unpack(zipfile, where_to_put_it) - folder_name = path_of_source_in(zipfile) - puts "Unzipping #{zipfile} to #{where_to_put_it}" - Zip::File.open(zipfile) { |zip_file| - zip_file.each { |f| - puts "-> #{f.name}" - f_path = File.join(where_to_put_it, f.name) - FileUtils.mkdir_p(File.dirname(f_path)) - zip_file.extract(f, f_path) unless File.exist?(f_path) - } - } - puts "Definition unpacked to #{where_to_put_it}/#{folder_name}" - "#{where_to_put_it}/#{folder_name}" - end - - def path_of_source_in(zipfile_path) - File.dirname(path_of_configuration_file_in(zipfile_path)) - end - - def path_of_configuration_file_in(zipfile_path) - zipfile = Zip::File.open(zipfile_path) - begin - zipfile.entries.select { |entry| - /\/stack-definition.yaml$/.match entry.name - }.first.name - ensure - zipfile.close - end - end - end - - class UnsupportedStackDefinitionLocationError < StandardError; end end end end