Class: Lono::AppFile::Build
- Inherits:
-
Base
show all
- Defined in:
- lib/lono/app_file/build.rb,
lib/lono/app_file/build/lambda_layer.rb
Defined Under Namespace
Classes: LambdaLayer
Instance Method Summary
collapse
Methods inherited from Base
#initialize
#initialize, #reinitialize, #template_path
#find_blueprint_root, #set_blueprint_root
Instance Method Details
#build_all ⇒ Object
15
16
17
18
19
20
|
# File 'lib/lono/app_file/build.rb', line 15
def build_all
clean_output
copy_to_output
build_layers
compress_output
end
|
#build_layers ⇒ Object
22
23
24
25
26
27
|
# File 'lib/lono/app_file/build.rb', line 22
def build_layers
layer_items = Registry.layers
layer_items.each do |item|
LambdaLayer.new(@blueprint, item).build
end
end
|
#clean_output ⇒ Object
82
83
84
|
# File 'lib/lono/app_file/build.rb', line 82
def clean_output
FileUtils.rm_rf(@output_files_path)
end
|
#compress_output ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/lono/app_file/build.rb', line 29
def compress_output
Registry.items.each do |item|
if item.type == "lambda_layer" || item.directory?
zip_directory(item)
elsif item.file?
zip_file(item)
else
puts "WARN: #{item.path} does not exist. Double check that the path is correct in the s3_key call.".color(:yellow)
end
end
end
|
#context ⇒ Object
48
49
50
|
# File 'lib/lono/app_file/build.rb', line 48
def context
Lono::Template::Context.new(@options)
end
|
#copy_to_output ⇒ Object
42
43
44
45
46
|
# File 'lib/lono/app_file/build.rb', line 42
def copy_to_output
override_source_paths("#{Lono.blueprint_root}/app/files")
self.destination_root = @output_files_path
directory(".", verbose: false, context: context.get_binding)
end
|
#detect_files? ⇒ Boolean
86
87
88
89
90
91
92
93
94
|
# File 'lib/lono/app_file/build.rb', line 86
def detect_files?
app_files = Dir["#{Lono.blueprint_root}/app/files/*"]
if app_files.empty?
false
else
puts "Detected app/files for blueprint #{@blueprint}"
true
end
end
|
#initialize_variables ⇒ Object
5
6
7
|
# File 'lib/lono/app_file/build.rb', line 5
def initialize_variables
@output_files_path = "#{Lono.config.output_path}/#{@blueprint}/files"
end
|
#run ⇒ Object
9
10
11
12
13
|
# File 'lib/lono/app_file/build.rb', line 9
def run
return unless detect_files?
puts "Building app/files for blueprint #{@blueprint}"
build_all
end
|
#zip(command) ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/lono/app_file/build.rb', line 72
def zip(command)
`#{command}`
unless $?.success?
puts "ERROR: Fail to run #{command}".color(:red)
puts "Maybe zip is not installed or path is incorrect?"
exit 1
end
end
|
#zip_directory(item) ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/lono/app_file/build.rb', line 62
def zip_directory(item)
path = item.path
zip_file = item.zip_file_name
puts "Zipping folder and generating md5 named file from: #{path}"
command = "cd #{path} && zip --symlinks -rq #{zip_file} ."
zip(command)
FileUtils.mv("#{path}/#{zip_file}", "#{File.dirname(path)}/#{zip_file}")
end
|
#zip_file(item) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/lono/app_file/build.rb', line 53
def zip_file(item)
path = item.path
zip_file = item.zip_file_name
puts "Zipping file and generating md5 named file from: #{path}"
command = "cd #{File.dirname(path)} && zip -q #{zip_file} #{File.basename(path)}"
zip(command)
end
|