Sha256: 585b65cc4bd2fd12aaf349a933397be0318926b2dd898d9bb8f7b2ed1dbbf2f9
Contents?: true
Size: 1.57 KB
Versions: 31
Compression:
Stored size: 1.57 KB
Contents
require "filesize" class Lono::Script class Upload < Base include Lono::AwsServices def run Lono::ProjectChecker.check return unless scripts_built? upload(tarball_path) puts "Uploaded #{File.basename(s3_dest)} to s3." end def upload(tarball_path) puts "Uploading scripts.tgz (#{filesize}) to #{s3_dest}" obj = s3_resource.bucket(bucket_name).object(key) start_time = Time.now obj.upload_file(tarball_path) time_took = pretty_time(Time.now-start_time).color(:green) puts "Time to upload code to s3: #{time_took}" end def filesize Filesize.from(File.size(tarball_path).to_s + " B").pretty end def s3_dest "s3://#{bucket_name}/#{key}" end def key # Example key: cloudformation/development/scripts/scripts-md5 "#{dest_folder}/#{File.basename(tarball_path)}" end def bucket_name Lono::S3::Bucket.name end def dest_folder "#{Lono.env}/scripts" end # Scripts are only built if the app/scripts folder is non empty def scripts_built? File.exist?(SCRIPTS_INFO_PATH) && !tarball_path.empty? end def tarball_path IO.read(SCRIPTS_INFO_PATH).strip end # http://stackoverflow.com/questions/4175733/convert-duration-to-hoursminutesseconds-or-similar-in-rails-3-or-ruby def pretty_time(total_seconds) minutes = (total_seconds / 60) % 60 seconds = total_seconds % 60 if total_seconds < 60 "#{seconds.to_i}s" else "#{minutes.to_i}m #{seconds.to_i}s" end end end end
Version data entries
31 entries across 31 versions & 1 rubygems