Class: Jets::TmpLoader
Class Method Summary
collapse
Instance Method Summary
collapse
#apigateway, #aws_lambda, #aws_options, #cfn, #dynamodb, #logs, #s3, #s3_resource, #sns, #sqs, #sts
#lookup, #stack_exists?, #stack_in_progress?
included
Constructor Details
#initialize(yaml_path = nil) ⇒ TmpLoader
Returns a new instance of TmpLoader.
9
10
11
12
13
14
15
|
# File 'lib/jets/tmp_loader.rb', line 9
def initialize(yaml_path=nil)
yaml_path ||= "#{Jets.root}/handlers/data.yml"
return unless File.exist?(yaml_path)
@data = Jets::Util::Yamler.load_file(yaml_path)
@s3_bucket = @data['s3_bucket']
@rack_zip = @data['rack_zip']
end
|
Class Method Details
.load! ⇒ Object
5
6
7
|
# File 'lib/jets/tmp_loader.rb', line 5
def self.load!
new.load
end
|
Instance Method Details
#download(key, dest) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/jets/tmp_loader.rb', line 34
def download(key, dest)
s3.get_object(response_target: dest,
bucket: @s3_bucket,
key: key)
end
|
#download_and_extract(zip_file, folder_dest) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/jets/tmp_loader.rb', line 26
def download_and_extract(zip_file, folder_dest)
s3_key = "jets/code/#{zip_file}" download_path = "/tmp/#{zip_file}"
download(s3_key, download_path)
unzip(download_path, folder_dest)
end
|
#load ⇒ Object
17
18
19
|
# File 'lib/jets/tmp_loader.rb', line 17
def load
rack
end
|
#rack ⇒ Object
21
22
23
24
|
# File 'lib/jets/tmp_loader.rb', line 21
def rack
return unless @rack_zip
download_and_extract(@rack_zip, '/tmp/rack')
end
|
#sh(command) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/jets/tmp_loader.rb', line 46
def sh(command)
puts "=> #{command}"
success = system(command)
raise "Command #{command} failed" unless success
success
end
|
#unzip(zipfile, folder_dest) ⇒ Object
42
43
44
|
# File 'lib/jets/tmp_loader.rb', line 42
def unzip(zipfile, folder_dest)
sh "unzip -qo #{zipfile} -d #{folder_dest}"
end
|