Sha256: 6fb278e0883099218bf1d9c50ca82d01644fdbd0aeffb4a38befcf9d571f626d
Contents?: true
Size: 1.45 KB
Versions: 10
Compression:
Stored size: 1.45 KB
Contents
class Jets::Builders class CodeSize LAMBDA_SIZE_LIMIT = 250 # Total lambda limit is 250MB include Util def self.check! new.check end 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 def within_lambda_limit? total_size < LAMBDA_SIZE_LIMIT * 1024 # 120MB end def total_size code_size = compute_size("#{stage_area}/code") opt_size = compute_size("#{stage_area}/opt") opt_size + code_size # total_size end 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)}" # sh "du -csh #{stage_area}/*" unless ENV['TEST'] # uncomment to debug end def compute_size(path) out = `du -s #{path}` out.split(' ').first.to_i # bytes end def megabytes(bytes) n = bytes / 1024.0 sprintf('%.1f', n) + 'MB' end def say(message) puts message unless ENV['TEST'] end end end
Version data entries
10 entries across 10 versions & 1 rubygems