class Pipely::Deploy::S3Uploader
Manage syncing of local files to a particular S3 path
Attributes
bucket_name[R]
s3_path[R]
Public Class Methods
new(s3_bucket, s3_path)
click to toggle source
# 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
Public Instance Methods
s3_file_path(file)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/pipely/deploy/s3_uploader.rb, line 31 def upload(files) files.each do |file| upload_file(file) end end
upload_file(file)
click to toggle source
Upload file to S3 unless ETAGs already match.
# File lib/pipely/deploy/s3_uploader.rb, line 40 def upload_file(file) target_path = s3_file_path(file) s3_object = @s3_bucket.object(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.put(body: content) end end