Class: Pipely::Deploy::S3Uploader
- Inherits:
-
Object
- Object
- Pipely::Deploy::S3Uploader
- Defined in:
- lib/pipely/deploy/s3_uploader.rb
Overview
Manage syncing of local files to a particular S3 path
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#s3_path ⇒ Object
readonly
Returns the value of attribute s3_path.
Instance Method Summary collapse
-
#initialize(s3_bucket, s3_path) ⇒ S3Uploader
constructor
A new instance of S3Uploader.
- #s3_file_path(file) ⇒ Object
- #s3_urls(files) ⇒ Object
- #upload(files) ⇒ Object
-
#upload_file(file) ⇒ Object
Upload file to S3 unless ETAGs already match.
Constructor Details
#initialize(s3_bucket, s3_path) ⇒ S3Uploader
Returns a new instance of S3Uploader.
14 15 16 17 18 |
# File 'lib/pipely/deploy/s3_uploader.rb', line 14 def initialize(s3_bucket, s3_path) @s3_bucket = s3_bucket @bucket_name = s3_bucket.name @s3_path = s3_path end |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
Returns the value of attribute bucket_name.
11 12 13 |
# File 'lib/pipely/deploy/s3_uploader.rb', line 11 def bucket_name @bucket_name end |
#s3_path ⇒ Object (readonly)
Returns the value of attribute s3_path.
12 13 14 |
# File 'lib/pipely/deploy/s3_uploader.rb', line 12 def s3_path @s3_path end |
Instance Method Details
#s3_file_path(file) ⇒ Object
20 21 22 23 |
# File 'lib/pipely/deploy/s3_uploader.rb', line 20 def s3_file_path(file) filename = File.basename(file) File.join(@s3_path, filename) end |
#s3_urls(files) ⇒ Object
25 26 27 28 29 |
# File 'lib/pipely/deploy/s3_uploader.rb', line 25 def s3_urls(files) files.map do |file| File.join("s3://", @s3_bucket.name, s3_file_path(file) ) end end |
#upload(files) ⇒ Object
31 32 33 34 35 |
# File 'lib/pipely/deploy/s3_uploader.rb', line 31 def upload(files) files.each do |file| upload_file(file) end end |
#upload_file(file) ⇒ Object
Upload file to S3 unless ETAGs already match.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pipely/deploy/s3_uploader.rb', line 40 def upload_file(file) target_path = s3_file_path(file) s3_object = @s3_bucket.objects[target_path] content = File.read(file) digest = Digest::MD5.hexdigest(content) if s3_object.exists? && (digest == s3_object.etag.gsub('"', '')) puts "skipping #{file} to #{target_path} (ETAG matches)" else puts "uploading #{file} to #{target_path}" s3_object.write(content) end end |