Class: Capistrano::SCM::S3Archive::RemoteCache
- Inherits:
-
Object
- Object
- Capistrano::SCM::S3Archive::RemoteCache
- Defined in:
- lib/capistrano/scm/s3_archive/remote_cache.rb
Instance Attribute Summary collapse
-
#archive_object ⇒ Object
readonly
Returns the value of attribute archive_object.
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#download_dir ⇒ Object
readonly
Returns the value of attribute download_dir.
Instance Method Summary collapse
- #cleanup(keep: 0) ⇒ Object
- #download ⇒ Object
-
#initialize(backend, download_dir, archive_object) ⇒ RemoteCache
constructor
A new instance of RemoteCache.
- #target_file ⇒ Object
Constructor Details
#initialize(backend, download_dir, archive_object) ⇒ RemoteCache
Returns a new instance of RemoteCache.
7 8 9 10 11 |
# File 'lib/capistrano/scm/s3_archive/remote_cache.rb', line 7 def initialize(backend, download_dir, archive_object) @backend = backend @download_dir = download_dir @archive_object = archive_object end |
Instance Attribute Details
#archive_object ⇒ Object (readonly)
Returns the value of attribute archive_object.
5 6 7 |
# File 'lib/capistrano/scm/s3_archive/remote_cache.rb', line 5 def archive_object @archive_object end |
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
5 6 7 |
# File 'lib/capistrano/scm/s3_archive/remote_cache.rb', line 5 def backend @backend end |
#download_dir ⇒ Object (readonly)
Returns the value of attribute download_dir.
5 6 7 |
# File 'lib/capistrano/scm/s3_archive/remote_cache.rb', line 5 def download_dir @download_dir end |
Instance Method Details
#cleanup(keep: 0) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/capistrano/scm/s3_archive/remote_cache.rb', line 27 def cleanup(keep: 0) downloaded_files = backend.capture(:ls, "-xtr", download_dir).split return if downloaded_files.count <= keep to_be_removes = (downloaded_files - downloaded_files.last(keep)).flat_map do |file| [File.join(download_dir, file), File.join(download_dir, ".#{f}.etag")] end backend.execute(:rm, '-f', *to_be_removes) end |
#download ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/capistrano/scm/s3_archive/remote_cache.rb', line 13 def download etag_file = File.join(download_dir, ".#{archive_object.key_basename}.etag") if backend.test("[ -f #{target_file} -a -f #{etag_file} ]") && backend.capture(:cat, etag_file) == archive_object.etag backend.info "#{target_file} (etag:#{archive_object.etag}) is found. download skipped." else backend.info "Download s3://#{archive_object.bucket}/#{archive_object.key} to #{target_file}" backend.execute(:mkdir, "-p", download_dir) backend.execute(:aws, *['s3api', 'get-object', "--bucket #{archive_object.bucket}", "--key #{archive_object.key}", archive_object.version_id ? "--version-id #{archive_object.version_id}" : nil, target_file].compact) backend.execute(:echo, "-n", "'#{archive_object.etag}'", "|tee", etag_file) end end |
#target_file ⇒ Object
37 38 39 40 |
# File 'lib/capistrano/scm/s3_archive/remote_cache.rb', line 37 def target_file basename = [archive_object.key_basename, archive_object.version_id].join('__') File.join(download_dir, basename) end |