Class: Lono::Script::Upload
Constant Summary
Constants inherited
from Base
Base::SCRIPTS_INFO_PATH
Instance Method Summary
collapse
#pretty_time
#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts
#rollback_complete?, #testing_update?
#find_stack_set, #stack_set_exists?
#find_stack, #stack_exists?
#initialize, #reinitialize, #template_path
#find_blueprint_root, #set_blueprint_root
Instance Method Details
#bucket_name ⇒ Object
38
39
40
|
# File 'lib/lono/script/upload.rb', line 38
def bucket_name
Lono::S3::Bucket.name
end
|
#dest_folder ⇒ Object
42
43
44
|
# File 'lib/lono/script/upload.rb', line 42
def dest_folder
"#{Lono.env}/scripts"
end
|
#filesize ⇒ Object
25
26
27
|
# File 'lib/lono/script/upload.rb', line 25
def filesize
Filesize.from(File.size(tarball_path).to_s + " B").pretty
end
|
#key ⇒ Object
33
34
35
36
|
# File 'lib/lono/script/upload.rb', line 33
def key
"#{dest_folder}/#{File.basename(tarball_path)}"
end
|
#run ⇒ Object
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_dest ⇒ Object
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
47
48
49
|
# File 'lib/lono/script/upload.rb', line 47
def scripts_built?
File.exist?(SCRIPTS_INFO_PATH) && !tarball_path.empty?
end
|
#tarball_path ⇒ Object
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
|