class Omnibus::S3Cache
Public Class Methods
new()
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 53 def initialize unless config.s3_bucket && config.s3_access_key && config.s3_secret_key raise InvalidS3Configuration.new(config.s3_bucket, config.s3_access_key, config.s3_secret_key) end @client = UberS3.new( :access_key => config.s3_access_key, :secret_access_key => config.s3_secret_key, :bucket => config.s3_bucket, :adaper => :net_http ) end
Public Instance Methods
config()
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 69 def config Omnibus.config end
fetch_missing()
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 105 def fetch_missing missing.each do |software| fetch(software) end end
list()
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 73 def list existing_keys = list_by_key tarball_software.select {|s| existing_keys.include?(key_for_package(s))} end
list_by_key()
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 78 def list_by_key bucket.objects('/').map(&:key) end
log(msg)
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 65 def log(msg) puts "[S3 Cacher] #{msg}" end
missing()
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 82 def missing already_cached = list_by_key tarball_software.delete_if {|s| already_cached.include?(key_for_package(s))} end
populate()
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 93 def populate missing.each do |software| fetch(software) key = key_for_package(software) content = IO.read(software.project_file) log "Uploading #{software.project_file} as #{config.s3_bucket}/#{key}" @client.store(key, content, :access => :public_read, :content_md5 => software.checksum) end end
tarball_software()
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 87 def tarball_software Omnibus.projects.map do |project| project.library.select {|s| s.source && s.source.key?(:url)} end.flatten end
Private Instance Methods
bucket()
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 128 def bucket @bucket ||= begin b = UberS3::Bucket.new(@client, @client.bucket) # creating the bucket is idempotent, make sure it's created: @client.connection.put("/") b end end
ensure_cache_dir()
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 113 def ensure_cache_dir FileUtils.mkdir_p(config.cache_dir) end
fetch(software)
click to toggle source
# File lib/omnibus/s3_cacher.rb, line 117 def fetch(software) log "Fetching #{software.name}" fetcher = Fetcher.without_caching_for(software) if fetcher.fetch_required? fetcher.download fetcher.verify_checksum! else log "Cached copy up to date, skipping." end end