I am thinking of implementing a rake task that would sync certain files in my repository to S3. The catch is that I only want to update the files when they are changed in my Repo. So if file A gets modified and B stays the same, only file A will be synchronized to S3 during my next app deploy.
What is a reliable way to determine that a file has been modified? I am thinking of using git to determine whether the file has been changed locally…. is there any other way to do this? Does S3 provide similar functionality to this?
S3 does not presently support conditional
PUTs, which would be the ideal solution, but you can get this behavior with two requests instead. Your sync operation would look something like:HEADrequest for that S3 object.PUTrequest if the object’sContent-MD5differs or the object does not exist.That said, this sounds a lot like something you’d do with assets, in which case you’d be reinventing the wheel. The Rails 3 asset pipeline addresses this problem well — in particular, fingerprinting assets and putting the hash in the URL allows you to serve them with insanely long
max-agevalues since they’re immutable — and theasset_syncgem can already put your assets on S3 automatically.