Sha256: 1f2973e412118c696b1796ffa4b416d80d93ebe4081144632f019e0684081866

Contents?: true

Size: 1.59 KB

Versions: 36

Compression:

Stored size: 1.59 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".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

36 entries across 36 versions & 2 rubygems

Version Path
jets-1.9.7 lib/jets/builders/code_size.rb
jets-1.9.6 lib/jets/builders/code_size.rb
jets-1.9.5 lib/jets/builders/code_size.rb
jets-1.9.4 lib/jets/builders/code_size.rb
jets-1.9.3 lib/jets/builders/code_size.rb
jets-1.9.2 lib/jets/builders/code_size.rb
jets-1.9.1 lib/jets/builders/code_size.rb
jets-1.9.0 lib/jets/builders/code_size.rb
jets-1.8.14 lib/jets/builders/code_size.rb
jets-1.8.13 lib/jets/builders/code_size.rb
jets-1.8.12 lib/jets/builders/code_size.rb
jets-1.8.11 lib/jets/builders/code_size.rb
jets-1.8.10 lib/jets/builders/code_size.rb
jets-1.8.9 lib/jets/builders/code_size.rb
jets-1.8.8 lib/jets/builders/code_size.rb
jets-1.8.7 lib/jets/builders/code_size.rb
jets-1.8.6 lib/jets/builders/code_size.rb
jets-1.8.5 lib/jets/builders/code_size.rb
jets-1.8.4 lib/jets/builders/code_size.rb
jets-1.8.3 lib/jets/builders/code_size.rb