Class: Omnibus::S3Cache

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/omnibus/s3_cache.rb

Class Method Summary collapse

Methods included from Logging

included

Class Method Details

.fetch_missingtrue

Fetch all source tarballs onto the local machine.


93
94
95
96
97
98
99
# File 'lib/omnibus/s3_cache.rb', line 93

def fetch_missing
  missing.each do |software|
    without_caching do
      software.fetch
    end
  end
end

.key_for(software) ⇒ String

The key with which to cache the package on S3. This is the name of the package, the version of the package, and its checksum.

Examples:

"zlib-1.2.6-618e944d7c7cd6521551e30b32322f4a"

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/omnibus/s3_cache.rb', line 114

def key_for(software)
  unless software.name
    raise InsufficientSpecification.new(:name, software)
  end

  unless software.version
    raise InsufficientSpecification.new(:version, software)
  end

  unless software.fetcher.checksum
    raise InsufficientSpecification.new('source md5 checksum', software)
  end

  "#{software.name}-#{software.version}-#{software.fetcher.checksum}"
end

.keysArray<String>

The list of objects in the cache, by their key.


43
44
45
# File 'lib/omnibus/s3_cache.rb', line 43

def keys
  bucket.objects('/').map(&:key)
end

.listArray<Software>

List all software in the cache.


30
31
32
33
34
35
36
# File 'lib/omnibus/s3_cache.rb', line 30

def list
  cached = keys
  softwares.select do |software|
    key = key_for(software)
    cached.include?(key)
  end
end

.missingArray<Software>

List all software missing from the cache.


52
53
54
55
56
57
58
# File 'lib/omnibus/s3_cache.rb', line 52

def missing
  cached = keys
  softwares.select do |software|
    key = key_for(software)
    !cached.include?(key)
  end
end

.populatetrue

Populate the cache with the all the missing software definitions.


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/omnibus/s3_cache.rb', line 65

def populate
  missing.each do |software|
    without_caching do
      software.fetch
    end

    key     = key_for(software)
    fetcher = software.fetcher
    content = IO.read(fetcher.downloaded_file)

    log.info(log_key) do
      "Caching '#{fetcher.downloaded_file}' to '#{Config.s3_bucket}/#{key}'"
    end

    client.store(key, content,
      access: :public_read,
      content_md5: software.fetcher.checksum
    )
  end

  true
end