Class: Lono::Script::Upload

Inherits:
Base show all
Includes:
AwsServices, Utils::PrettyTime
Defined in:
lib/lono/script/upload.rb

Constant Summary

Constants inherited from Base

Base::SCRIPTS_INFO_PATH

Instance Method Summary collapse

Methods included from Utils::PrettyTime

#pretty_time

Methods included from AwsServices

#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts

Methods included from AwsServices::Helper

#rollback_complete?, #testing_update?

Methods included from AwsServices::StackSet

#find_stack_set, #stack_set_exists?

Methods included from AwsServices::Stack

#find_stack, #stack_exists?

Methods inherited from AbstractBase

#initialize, #reinitialize, #template_path

Methods included from Blueprint::Root

#find_blueprint_root, #set_blueprint_root

Constructor Details

This class inherits a constructor from Lono::AbstractBase

Instance Method Details

#bucket_nameObject



38
39
40
# File 'lib/lono/script/upload.rb', line 38

def bucket_name
  Lono::S3::Bucket.name
end

#dest_folderObject



42
43
44
# File 'lib/lono/script/upload.rb', line 42

def dest_folder
  "#{Lono.env}/scripts"
end

#filesizeObject



25
26
27
# File 'lib/lono/script/upload.rb', line 25

def filesize
  Filesize.from(File.size(tarball_path).to_s + " B").pretty
end

#keyObject



33
34
35
36
# File 'lib/lono/script/upload.rb', line 33

def key
  # Example key: cloudformation/development/scripts/scripts-md5
  "#{dest_folder}/#{File.basename(tarball_path)}"
end

#runObject



8
9
10
11
12
13
14
# File 'lib/lono/script/upload.rb', line 8

def run
  Lono::ProjectChecker.check
  return unless scripts_built?

  upload(tarball_path)
  puts "Uploaded #{File.basename(s3_dest)} to s3."
end

#s3_destObject



29
30
31
# File 'lib/lono/script/upload.rb', line 29

def s3_dest
  "s3://#{bucket_name}/#{key}"
end

#scripts_built?Boolean

Scripts are only built if the app/scripts folder is non empty

Returns:

  • (Boolean)


47
48
49
# File 'lib/lono/script/upload.rb', line 47

def scripts_built?
  File.exist?(SCRIPTS_INFO_PATH) && !tarball_path.empty?
end

#tarball_pathObject



51
52
53
# File 'lib/lono/script/upload.rb', line 51

def tarball_path
  IO.read(SCRIPTS_INFO_PATH).strip
end

#upload(tarball_path) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/lono/script/upload.rb', line 16

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 took to upload code to s3: #{time_took}"
end