Sha256: 633376673eaf72083095566b3ca1845c4ae1e2d9bcf5e1dbbb31ff3cc073ca70

Contents?: true

Size: 1.76 KB

Versions: 47

Compression:

Stored size: 1.76 KB

Contents

require "net/http"

module Lambdagem::Extract::ClassMethods
  # Exits early if not all the linux gems are available
  # It better to error now then later on Lambda
  # Provide users with instructions on how to compile gems
  #
  # We check all the availability before even downloading so we can provide a
  # full list of gems they might want to research all at once instead of incrementally
  def check_availability(gems)
    availabilities = gems.inject({}) do |hash, gem_name|
      exist = url_exists?(gem_url(gem_name))
      hash[gem_name] = exist
      hash.merge(hash)
    end

    all_available = availabilities.values.all? {|v| v }
    unless all_available
      puts "Your project requires some pre-compiled Linux gems that are not yet available as a pre-compiled lambda gem.  The build process will not continue because there's no point wasting your time deploying to Lambda and finding out later."
      puts "The unavailable gems are:"
      availabilities.each do |gem_name, available|
        next if available
        puts "  #{gem_name}"
      end
      puts <<-EOL
How to fix this:

  1. Build your jets project on an Amazon Lambda based EC2 Instance and compile your own gems with the proper shared libaries.
  2. Configure jets to lookup your own pre-compiled gems url.
  3. Add the the required gems to boltopslabs/lambdagems and submit a pull request.

More info: http://lambdagems.com
EOL
      exit
    end
  end

  # Example url:
  #   https://gems.lambdagems.com/gems/2.5.0/byebug/byebug-9.1.0-x86_64-linux.tgz
  def url_exists?(url)
    url = URI.parse(url)
    req = Net::HTTP.new(url.host, url.port).tap do |http|
      http.use_ssl = true
    end
    res = req.request_head(url.path)
    res.code == "200"
  rescue SocketError, OpenURI::HTTPError
    false
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
jets-0.8.6 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.8.5 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.8.4 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.8.3 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.8.2 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.8.1 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.8.0 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.7.1 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.7.0 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.6.9 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.6.8 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.6.7 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.6.6 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.6.5 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.6.4 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.6.3 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.6.2 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.6.1 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.6.0 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb
jets-0.5.8 vendor/lambdagem/lib/lambdagem/extract/class_methods.rb