Class: Jets::Builders::CodeSize
- Inherits:
-
Object
- Object
- Jets::Builders::CodeSize
show all
- Includes:
- Util
- Defined in:
- lib/jets/builders/code_size.rb
Constant Summary
collapse
- LAMBDA_SIZE_LIMIT =
Total lambda limit is 250MB
250
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util
#code_area, #full, #headline, #sh, #stage_area
Class Method Details
.check! ⇒ Object
6
7
8
|
# File 'lib/jets/builders/code_size.rb', line 6
def self.check!
new.check
end
|
Instance Method Details
#check ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/jets/builders/code_size.rb', line 10
def check
return if within_lambda_limit?
say "Over the Lambda size limit of #{LAMBDA_SIZE_LIMIT}MB".colorize(:red)
say "Please reduce the size of your code."
display_sizes
exit 1
end
|
#compute_size(path) ⇒ Object
41
42
43
44
|
# File 'lib/jets/builders/code_size.rb', line 41
def compute_size(path)
out = `du -s #{path}`
out.split(' ').first.to_i end
|
#display_sizes ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/jets/builders/code_size.rb', line 28
def display_sizes
code_size = compute_size("#{stage_area}/code")
opt_size = compute_size("#{stage_area}/opt")
total_size = opt_size + code_size
overlimit = (LAMBDA_SIZE_LIMIT * 1024 - total_size) * -1
say "Sizes:"
say "Code: #{megabytes(code_size)} - #{stage_area}/code"
say "Gem Layer: #{megabytes(opt_size)} - #{stage_area}/opt"
say "Total Package: #{megabytes(total_size)}"
say "Over limit by: #{megabytes(overlimit)}"
end
|
#megabytes(bytes) ⇒ Object
46
47
48
49
|
# File 'lib/jets/builders/code_size.rb', line 46
def megabytes(bytes)
n = bytes / 1024.0
sprintf('%.1f', n) + 'MB'
end
|
#say(message) ⇒ Object
51
52
53
|
# File 'lib/jets/builders/code_size.rb', line 51
def say(message)
puts message unless ENV['TEST']
end
|
#total_size ⇒ Object
22
23
24
25
26
|
# File 'lib/jets/builders/code_size.rb', line 22
def total_size
code_size = compute_size("#{stage_area}/code")
opt_size = compute_size("#{stage_area}/opt")
opt_size + code_size end
|
#within_lambda_limit? ⇒ Boolean
18
19
20
|
# File 'lib/jets/builders/code_size.rb', line 18
def within_lambda_limit?
total_size < LAMBDA_SIZE_LIMIT * 1024 end
|