Sha256: 2e2d932bb32f736a1c1a6d77d3ec330e879665d583def8aa737f83ae83c57843

Contents?: true

Size: 1.6 KB

Versions: 47

Compression:

Stored size: 1.6 KB

Contents

module 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".color(: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)}"
      say "Sometimes blowing away the /tmp/jets cache will reduce the size: rm -rf /tmp/jets"
      # sh "du -kcsh #{stage_area}/*" unless ENV['TEST'] # uncomment to debug
    end

    def compute_size(path)
      # -k option is required for macosx but not for linux
      out = `du -ks #{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

47 entries across 47 versions & 2 rubygems

Version Path
jets-2.3.0 lib/jets/builders/code_size.rb
jets-2.2.5 lib/jets/builders/code_size.rb
jets-2.2.4 lib/jets/builders/code_size.rb
jets-2.2.3 lib/jets/builders/code_size.rb
jets-2.2.2 lib/jets/builders/code_size.rb
jets-2.2.1 lib/jets/builders/code_size.rb
jets-2.2.0 lib/jets/builders/code_size.rb
jets-2.1.7 lib/jets/builders/code_size.rb
jets-2.1.6 lib/jets/builders/code_size.rb
jets-2.1.5 lib/jets/builders/code_size.rb
jets-2.1.4 lib/jets/builders/code_size.rb
jets-2.1.3 lib/jets/builders/code_size.rb
jets-2.1.2 lib/jets/builders/code_size.rb
jets_bb_fork-0.0.4 lib/jets/builders/code_size.rb
jets-2.1.1 lib/jets/builders/code_size.rb
jets-2.1.0 lib/jets/builders/code_size.rb
jets-2.0.6 lib/jets/builders/code_size.rb
jets-2.0.5 lib/jets/builders/code_size.rb
jets-2.0.4 lib/jets/builders/code_size.rb
jets-2.0.3 lib/jets/builders/code_size.rb