Sha256: 8f20cdc423f2419de44ed3b7a1562c6a01c1dee3e8d3caee7157e5d9f424e0cf

Contents?: true

Size: 1.24 KB

Versions: 35

Compression:

Stored size: 1.24 KB

Contents

module Jets
  class TmpLoader
    include AwsServices

    def self.load!
      new.load
    end

    def initialize(yaml_path=nil)
      yaml_path ||= "#{Jets.root}handlers/data.yml"
      @data = YAML.load_file(yaml_path)
      @s3_bucket = @data['s3_bucket']
      @rack_zip = @data['rack_zip']
    end

    def load
      rack
    end

    def rack
      return unless @rack_zip
      download_and_extract(@rack_zip, '/tmp/rack')
    end

    def download_and_extract(zip_file, folder_dest)
      s3_key = "jets/code/#{zip_file}" # jets/code/rack-checksum.zip
      download_path = "/tmp/#{zip_file}" # /tmp/rack-checksum.zip

      download(s3_key, download_path)
      unzip(download_path, folder_dest)
    end

    def download(key, dest)
      # https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#get_object-instance_method
      # stream object directly to disk
      s3.get_object(response_target: dest,
                    bucket: @s3_bucket,
                    key: key)
    end

    def unzip(zipfile, folder_dest)
      sh "unzip -qo #{zipfile} -d #{folder_dest}"
    end

    def sh(command)
      puts "=> #{command}"
      success = system(command)
      raise "Command #{command} failed" unless success
      success
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
jets-1.6.1 lib/jets/tmp_loader.rb
jets-1.6.0 lib/jets/tmp_loader.rb
jets-1.5.10 lib/jets/tmp_loader.rb
jets-1.5.9 lib/jets/tmp_loader.rb
jets-1.5.8 lib/jets/tmp_loader.rb
jets-1.5.7 lib/jets/tmp_loader.rb
jets-1.5.6 lib/jets/tmp_loader.rb
jets-1.5.5 lib/jets/tmp_loader.rb
jets-1.5.4 lib/jets/tmp_loader.rb
jets-1.5.3 lib/jets/tmp_loader.rb
jets-1.5.2 lib/jets/tmp_loader.rb
jets-1.5.1 lib/jets/tmp_loader.rb
jets-1.5.0 lib/jets/tmp_loader.rb
jets-1.4.11 lib/jets/tmp_loader.rb
jets-1.4.10 lib/jets/tmp_loader.rb
jets-1.4.9 lib/jets/tmp_loader.rb
jets-1.4.8 lib/jets/tmp_loader.rb
jets-1.4.7 lib/jets/tmp_loader.rb
jets-1.4.6 lib/jets/tmp_loader.rb
jets-1.4.5 lib/jets/tmp_loader.rb